File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 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 {
7777 return false
7878 }
7979 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+ }
8087 return true
8188}
8289
Original file line number Diff line number Diff line change @@ -121,6 +121,23 @@ func TestDeleteAll(t *testing.T) {
121121 }
122122}
123123
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+
124141func BenchmarkInsert (b * testing.B ) {
125142 numItems := uint64 (1000 )
126143
You can’t perform that action at this time.
0 commit comments