File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,13 @@ func (packets packets) delete(key uint64) bool {
77
77
return false
78
78
}
79
79
packets [i ] = nil
80
+ i = (i + 1 ) & (uint64 (len (packets )) - 1 )
81
+ for packets [i ] != nil {
82
+ p := packets [i ]
83
+ packets [i ] = nil
84
+ packets .set (p )
85
+ i = (i + 1 ) & (uint64 (len (packets )) - 1 )
86
+ }
80
87
return true
81
88
}
82
89
Original file line number Diff line number Diff line change @@ -121,6 +121,23 @@ func TestDeleteAll(t *testing.T) {
121
121
}
122
122
}
123
123
124
+ func TestDeleteCollision (t * testing.T ) {
125
+ // 1, 27, 42 all hash to the same value using our hash function % 32
126
+ if hash (1 )% 32 != 12 || hash (27 )% 32 != 12 || hash (42 )% 32 != 12 {
127
+ t .Error ("test values don't hash to the same value" )
128
+ }
129
+
130
+ m := New (32 )
131
+ m .Set (1 , 1 )
132
+ m .Set (27 , 27 )
133
+ m .Set (42 , 42 )
134
+
135
+ m .Delete (27 )
136
+ value , ok := m .Get (42 )
137
+ assert .True (t , ok )
138
+ assert .Equal (t , uint64 (42 ), value )
139
+ }
140
+
124
141
func BenchmarkInsert (b * testing.B ) {
125
142
numItems := uint64 (1000 )
126
143
You can’t perform that action at this time.
0 commit comments