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

Multiset support #229

Open
legate opened this issue Oct 3, 2023 · 1 comment
Open

Multiset support #229

legate opened this issue Oct 3, 2023 · 1 comment

Comments

@legate
Copy link

legate commented Oct 3, 2023

Are there any plans to add a multiset implementation? A multiset is an ordered set where multiple keys with equivalent values are allowed.

@578141611
Copy link

578141611 commented Jul 2, 2024

package main

import (
	"fmt"

	"github.com/emirpasic/gods/sets/treeset"
)

// IntComparator provides a basic comparison on int
func IntComparator(a, b interface{}) int {
	aAsserted := a.(int)
	bAsserted := b.(int)
	if aAsserted >= bAsserted {
		return 1
	}

	return -1
}

func main() {
	m := treeset.NewWith(IntComparator, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) // empty (keys are of type int)
	m.Size()
	m.Add(2) // 0
	fmt.Println(m.String())

	m.Add(1) // 0
	fmt.Println(m.String())

	m.Add(6) // 0
	fmt.Println(m.String())

	ff := func(index int, value interface{}) bool {
		if value.(int) == 1 {
			return true
		}
		return false
	}
	fmt.Println(m.Find(ff))
	fmt.Println(m.Contains(1))
}

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

2 participants