Generic data structures for Go 1.23+. Focuses on type safety, minimal allocations, and predictable performance.
go get github.com/lock14/collectionspackage main
import (
"fmt"
"github.com/lock14/collections/treeset"
)
func main() {
set := treeset.NewOrdered[int]()
set.Add(5)
set.Add(1)
set.Add(10)
for val := range set.All() {
fmt.Println(val)
}
}Implementations leverage Go generics to eliminate interface{} boxing and runtime type assertions.
- Maps
hashmap: Map backed by a hash table.linkedhashmap: Hash map preserving insertion or access order.treemap: Sorted map backed by a B-Tree.
- Sets
hashset: Set backed by a hash table.linkedhashset: Hash set preserving insertion or access order.treeset: Sorted set backed by a B-Tree.bitset: Word-aligned dense integer set.
- Lists, Queues, & Stacks
arraylist: Dynamically resizing array.linkedlist: Doubly-linked list.arraydeque: Double-ended queue backed by a ring buffer.heap: Priority queue.
- Graphs
graph: Directed and undirected graphs.labeledgraph: Graphs with labeled edges.
Design prioritizes mechanical sympathy and GC pressure reduction.
- Zero-Allocation Reads: Read paths (
Get,Contains, etc.) bypass heap allocations. - Continuous Benchmarking: CI gates PRs via
cob, comparing allocation metrics and execution times againstmain. Regressions fail the build. - Test Coverage: Table-driven tests are mandatory. Edge cases, bounds checks, and generic fallback paths must be explicitly exercised.
Submit PRs with passing tests and benchmarks. Table-driven testing is required. Performance regressions will not be merged.
Apache 2.0. See LICENSE.