File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,13 @@ func (m ConcurrentMap) IterBuffered() <-chan Tuple {
186186 return ch
187187}
188188
189+ // Clear removes all items from map.
190+ func (m ConcurrentMap ) Clear () {
191+ for item := range m .IterBuffered () {
192+ m .Remove (item .Key )
193+ }
194+ }
195+
189196// Returns a array of channels that contains elements in each shard,
190197// which likely takes a snapshot of `m`.
191198// It returns once the size of each buffered channel is determined,
Original file line number Diff line number Diff line change @@ -326,6 +326,21 @@ func TestBufferedIterator(t *testing.T) {
326326 }
327327}
328328
329+ func TestClear (t * testing.T ) {
330+ m := New ()
331+
332+ // Insert 100 elements.
333+ for i := 0 ; i < 100 ; i ++ {
334+ m .Set (strconv .Itoa (i ), Animal {strconv .Itoa (i )})
335+ }
336+
337+ m .Clear ()
338+
339+ if m .Count () != 0 {
340+ t .Error ("We should have 0 elements." )
341+ }
342+ }
343+
329344func TestIterCb (t * testing.T ) {
330345 m := New ()
331346
You can’t perform that action at this time.
0 commit comments