Skip to content

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

@ynm3n

Description

@ynm3n

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions