darvaza.org/x/container

Overview
The container package provides generic data structure implementations that
extend Go's standard library containers. It includes type-safe wrappers and
advanced collection types with a focus on performance and ergonomics.
Packages
list
Type-safe wrapper around the standard container/list, providing a
generic doubly linked list implementation.
l := list.New[string]("first", "second")
l.PushBack("third")
for e := l.First(); e != nil; e = e.Next() {
fmt.Println(e.Value)
}
l.ForEach(func(value string) bool {
fmt.Println(value)
return true
})
set
Thread-safe set implementation using a map internally with configurable key
extraction and hashing functions.
cfg := set.Config[string, string, Person]{
Key: func(p Person) string { return p.ID },
Hash: func(k string) string { return k },
}
s := &set.Set[string, string, Person]{}
s.Init(cfg, person1, person2)
s.Push(person3)
if s.Has(person1) {
s.ForEach(func(p Person) bool {
fmt.Printf("Person: %s\n", p.ID)
return false
})
}
slices
Provides slice-based set implementations and utilities. See the
slices README for detailed documentation.
s := slices.NewOrderedSet[int](3, 1, 4, 1, 5)
s.Add(9)
exists := s.Contains(4)
values := s.Values()
custom := slices.NewCustomSet(func(a, b string) int {
return strings.Compare(strings.ToLower(a), strings.ToLower(b))
}, "Hello", "world", "HELLO")
Features
- Type Safety: All containers use Go generics for compile-time type safety.
- Thread Safety: Map-based set includes built-in synchronisation.
- Performance: Optimised implementations for common operations.
- Flexibility: Configurable comparison and hashing functions.
- Comprehensive Testing: All packages now have extensive test coverage
with examples.
Installation
go get darvaza.org/x/container
Dependencies
This package only depends on the standard library and
darvaza.org/core.
Development
For development guidelines, architecture notes, and AI agent instructions, see
AGENTS.md.
Licence
This project is licensed under the MIT Licence. See LICENCE.txt
for details.