Documentation ¶
Overview ¶
Package bytemap is an implementation of https://github.com/google/triemap/blob/main/bytemap.go with generic support for values
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteSliceMap ¶
type ByteSliceMap[V any] struct { // contains filtered or unexported fields }
ByteSliceMap emulates `map[[]byte]V`, implemented as a Trie.
It seems to perform worse than `map[string]V` even when casting `string([]byte)`.
func (*ByteSliceMap[V]) Get ¶
func (n *ByteSliceMap[V]) Get(s []byte) (value V, _ bool)
Get returns a value as mapped by the `[]byte` key and a boolean of whether the value exists in the map.
Example (Bytes) ¶
package main import ( "fmt" "github.com/synapsecns/sanguine/core/bytemap" ) func main() { m := &bytemap.ByteSliceMap[string]{} // Put value using a byte slice key m.Put([]byte("golang"), "awesome") // Get value using a byte slice key value, ok := m.Get([]byte("golang")) if ok { fmt.Println(value) } else { fmt.Println("value not found") } }
Output: awesome
func (*ByteSliceMap[V]) GetString ¶
func (n *ByteSliceMap[V]) GetString(s string) (V, bool)
GetString is a convenience method to get a value using a string key.
See: `Get`.
func (*ByteSliceMap[V]) Put ¶
func (n *ByteSliceMap[V]) Put(s []byte, v V) *ByteSliceMap[V]
Put inserts a value into the `ByteMap` using `[]byte` as a key.
Example (GetString) ¶
package main import ( "fmt" "github.com/synapsecns/sanguine/core/bytemap" ) func main() { m := &bytemap.ByteSliceMap[string]{} // Put value using a string key m.PutString("hello", "world") // Get value using a string key value, ok := m.GetString("hello") if ok { fmt.Println(value) } else { fmt.Println("value not found") } }
Output: world
func (*ByteSliceMap[V]) PutString ¶
func (n *ByteSliceMap[V]) PutString(s string, v V) *ByteSliceMap[V]
PutString is a convenience method to insert a value using a string key.
Click to show internal directories.
Click to hide internal directories.