https://github.com/mitranim/gord
Simple ordered sets for Go.
https://github.com/mitranim/gord
golang ordered-set
Last synced: 11 months ago
JSON representation
Simple ordered sets for Go.
- Host: GitHub
- URL: https://github.com/mitranim/gord
- Owner: mitranim
- License: unlicense
- Created: 2021-01-31T14:42:51.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-13T16:34:33.000Z (about 4 years ago)
- Last Synced: 2025-02-24T06:44:38.641Z (11 months ago)
- Topics: golang, ordered-set
- Language: Go
- Homepage: https://pkg.go.dev/github.com/mitranim/gord
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Overview
**Go** **ord**ered sets.
Features:
* `LinkedSet`: ordered set with near-constant-time (O(1)) performance for inserting, deleting, and moving elements. Backed by a map and a doubly-linked list.
* `SyncLinkedSet`: concurrency-safe `LinkedSet`, slightly slower.
* `SliceSet`: slice-backed ordered set. Simpler and faster for small sets, extreme performance degradation for large sets.
* All implementations share a common interface.
* Small with no dependencies.
See the documentation at https://godoc.org/github.com/mitranim/gord.
Example:
```go
import "github.com/mitranim/gord"
set := gord.NewOrdSet()
// Note the order.
set.Add(20)
set.Add(10)
set.Add(30)
// Redundant and doesn't change the order.
set.Add(30)
set.Add(10)
set.Add(20)
set.Has(10) // true
set.Has(40) // false
set.Values() // []interface{}{20, 10, 30}
set.PopFirst() // 20
set.PopLast() // 30
set.Values() // []interface{}{10}
```
## Known Limitations
* Has room for performance optimizations.
* `LinkedSet` and `SyncLinkedSet` don't expose a way to iterate over elements without allocating a slice via `.Values()`. Can be rectified on demand.
## License
https://unlicense.org
## Misc
I'm receptive to suggestions. If this library _almost_ satisfies you but needs changes, open an issue or chat me up. Contacts: https://mitranim.com/#contacts