Documentation ¶
Overview ¶
The persistent package defines various persistent data structures; that is, data structures that can be efficiently copied and modified in sublinear time.
Index ¶
- type Map
- func (pm *Map[K, V]) Clear()
- func (pm *Map[K, V]) Clone() *Map[K, V]
- func (pm *Map[K, V]) Delete(key K) bool
- func (pm *Map[K, V]) Destroy()
- func (pm *Map[K, V]) Get(key K) (V, bool)
- func (pm *Map[K, V]) Keys() []K
- func (pm *Map[K, V]) Range(f func(key K, value V))
- func (pm *Map[K, V]) Set(key K, value V, release func(key, value any))
- func (pm *Map[K, V]) SetAll(other *Map[K, V])
- func (m *Map[K, V]) String() string
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K constraints.Ordered, V any] struct { // contains filtered or unexported fields }
Map is an associative mapping from keys to values.
Maps can be Cloned in constant time. Get, Set, and Delete operations are done on average in logarithmic time. Maps can be merged (via SetAll) in O(m log(n/m)) time for maps of size n and m, where m < n.
Values are reference counted, and a client-supplied release function is called when a value is no longer referenced by a map or any clone.
Internally the implementation is based on a randomized persistent treap: https://en.wikipedia.org/wiki/Treap.
The zero value is ready to use.
func (*Map[K, V]) Clone ¶
Clone returns a copy of the given map. It is a responsibility of the caller to Destroy it at later time.
func (*Map[K, V]) Delete ¶
Delete deletes the value for a key.
The result reports whether the key was present in the map.
func (*Map[K, V]) Destroy ¶
func (pm *Map[K, V]) Destroy()
Destroy destroys the map.
After Destroy, the Map should not be used again.
func (*Map[K, V]) Get ¶
Get returns the map value associated with the specified key. The ok result indicates whether an entry was found in the map.
func (*Map[K, V]) Range ¶
func (pm *Map[K, V]) Range(f func(key K, value V))
Range calls f sequentially in ascending key order for all entries in the map.
func (*Map[K, V]) Set ¶
Set updates the value associated with the specified key. If release is non-nil, it will be called with entry's key and value once the key is no longer contained in the map or any clone.
type Set ¶
type Set[K constraints.Ordered] struct { // contains filtered or unexported fields }
Set is a collection of elements of type K.
It uses immutable data structures internally, so that sets can be cloned in constant time.
The zero value is a valid empty set.
func (*Set[K]) Destroy ¶
func (s *Set[K]) Destroy()
Destroy destroys the set.
After Destroy, the Set should not be used again.