Ringhash is a golang implementation of a ring hash data structure, with some additional special features:
- Generic key-value store
- Channel based notification system
- Optionally duplicate hashing keys
- Ordering mechanism for channel notifications
- Concurrency safe for every method
- "Empty Node," where keys are assigned when no nodes are present
- Virtual factor (vfactor) to increase key distribution amoung nodes
- Zero non-testing dependencies
import (
"github.com/ethanperry1/ringhash"
)
func main() {
ring, err := ringhash.New()
if err != nil {
// Handle error here -- error will be returned if vFactor is set to any value less than 1.
}
err = ring.CreateNode(Node{
Identifier: "A",
VFactor: 100,
})
if err != nil { /* Handle error */ }
err = ring.Emplace(&Key[int]{
InnerKey: &InnerKey{
Key: "2", // Key must be unique.
Order: 0,
}, Value: 184, // Value associated with this key.
},
"hash_key" // This optional key will be used to hash the key into the ring, and does not need to be unique.
)
}