added an cleanup to remove items
Dieser Commit ist enthalten in:
Ursprung
9065f21af7
Commit
1645757b9e
|
@ -98,3 +98,14 @@ func (wr *WeightRandom[T]) Get() (t T) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Cleanup deletes the items where the the function returns true
|
||||
func (wr *WeightRandom[T]) Cleanup(f func(T) bool) {
|
||||
nl := make(wflist[T], 0, wr.data.Len())
|
||||
for _, item := range wr.data {
|
||||
if !f(item.value) {
|
||||
nl = append(nl, item)
|
||||
}
|
||||
}
|
||||
wr.data = nl
|
||||
}
|
||||
|
|
Laden…
In neuem Issue referenzieren