Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ds: add EraseIter to Set, MultiSet and MultiMap #21

Open
ynm3n opened this issue Jul 3, 2023 · 0 comments
Open

ds: add EraseIter to Set, MultiSet and MultiMap #21

ynm3n opened this issue Jul 3, 2023 · 0 comments

Comments

@ynm3n
Copy link

ynm3n commented Jul 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant