https://github.com/bsm/sortedset
Simple set implementation. Uses sorted slices and generics
https://github.com/bsm/sortedset
Last synced: about 1 year ago
JSON representation
Simple set implementation. Uses sorted slices and generics
- Host: GitHub
- URL: https://github.com/bsm/sortedset
- Owner: bsm
- License: apache-2.0
- Created: 2022-10-28T14:52:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-28T14:57:16.000Z (over 3 years ago)
- Last Synced: 2025-04-13T05:54:46.851Z (about 1 year ago)
- Language: Go
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sorted Set
[](https://pkg.go.dev/github.com/bsm/sortedset)
[](https://github.com/bsm/sortedset/actions/workflows/test.yml)
[](https://opensource.org/licenses/Apache-2.0)
Simple set implementation. Uses sorted slices and generics.
### Documentation
Full documentation is available on [go.dev](https://pkg.go.dev/github.com/bsm/sortedset).
### Example
```go
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]
}
```