Documentation ¶
Overview ¶
Package ctrie provides an implementation of the Ctrie data structure, which is a concurrent, lock-free hash trie. This data structure was originally presented in the paper Concurrent Tries with Efficient Non-Blocking Snapshots:
Index ¶
- type Ctrie
- func (c *Ctrie) Clear()
- func (c *Ctrie) Insert(key []byte, value interface{})
- func (c *Ctrie) Iterator(cancel <-chan struct{}) <-chan *Entry
- func (c *Ctrie) Lookup(key []byte) (interface{}, bool)
- func (c *Ctrie) ReadOnlySnapshot() *Ctrie
- func (c *Ctrie) Remove(key []byte) (interface{}, bool)
- func (c *Ctrie) Size() uint
- func (c *Ctrie) Snapshot() *Ctrie
- type Entry
- type HashFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ctrie ¶
type Ctrie struct {
// contains filtered or unexported fields
}
Ctrie is a concurrent, lock-free hash trie. By default, keys are hashed using FNV-1a unless a HashFactory is provided to New.
func New ¶
func New(hashFactory HashFactory) *Ctrie
New creates an empty Ctrie which uses the provided HashFactory for key hashing. If nil is passed in, it will default to FNV-1a hashing.
func (*Ctrie) Insert ¶
Insert adds the key-value pair to the Ctrie, replacing the existing value if the key already exists.
func (*Ctrie) Iterator ¶
Iterator returns a channel which yields the Entries of the Ctrie. If a cancel channel is provided, closing it will terminate and close the iterator channel. Note that if a cancel channel is not used and not every entry is read from the iterator, a goroutine will leak.
func (*Ctrie) Lookup ¶
Lookup returns the value for the associated key or returns false if the key doesn't exist.
func (*Ctrie) ReadOnlySnapshot ¶
ReadOnlySnapshot returns a stable, point-in-time snapshot of the Ctrie which is read-only. Write operations on a read-only snapshot will panic.
type Entry ¶
type Entry struct { Key []byte Value interface{} // contains filtered or unexported fields }
Entry contains a Ctrie key-value pair.
type HashFactory ¶
HashFactory returns a new Hash32 used to hash keys.