-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
Motivation
I wanted to delete a element one by one from MultiSet
and MultiMap
. However, Erase(K)
delete all elements having key K
.
Solution
Using EraseIter(iter)
, we can delete the element one by one.
Example
package main
import (
"fmt"
"github.com/liyue201/gostl/ds/set"
"github.com/liyue201/gostl/utils/comparator"
)
func main() {
ms := set.NewMultiSet(comparator.IntComparator)
// Insert
for i := 0; i < 3; i++ {
ms.Insert(5000)
}
fmt.Println(ms) // [5000 5000 5000]
// EraseIter (one element)
it := ms.Find(5000)
ms.EraseIter(it)
fmt.Println(ms) // [5000 5000]
// Erase (all elements)
ms.Erase(5000)
fmt.Println(ms) // []
}
Other little things
Map
already have had EraseIter
, so I did nothing to that.
I am ready to send a pull request related this issue. If you approve of this feature addition, I will send that to this repository.
ftrihardjo and Tomoki108
Metadata
Metadata
Assignees
Labels
No labels