/sortedset

Simple set implementation. Uses sorted slices and generics

Primary LanguageGoApache License 2.0Apache-2.0

Sorted Set

Go Reference Test License

Simple set implementation. Uses sorted slices and generics.

Documentation

Full documentation is available on go.dev.

Example

package main

import (
  "fmt"

  "github.com/bsm/sortedset"
)

func main() {
	// Create a new set
	set := sortedset.New[string]()

	// Seed with data
	set = set.Add("b")
	set = set.Add("a")
	set = set.Add("c", "a")
	fmt.Println(set.Slice()) // [a b c]

	// Check
	fmt.Println(set.Has("a")) // true
	fmt.Println(set.Has("d")) // false

	// Delete items
	set = set.Delete("a")
	set = set.Delete("d")
	fmt.Println(set.Slice()) // [b c]
}