Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"sort"
"alon.kr/x/faststringmap"
)
func main() {
m := []faststringmap.MapEntry[uint32]{
{"key1", 42},
{"key2", 27644437},
{"l", 2},
}
fm := faststringmap.NewMap[uint32](m)
// add an entry that is not in the fast map
m = append(m, faststringmap.MapEntry[uint32]{"m", 4})
// sort the keys so output is the same for each test run
keys := make([]string, 0, len(m))
for _, e := range m {
keys = append(keys, e.Key)
}
sort.Strings(keys)
// lookup every key in the fast map and print the corresponding value
for _, k := range keys {
v, ok := fm.LookupString(k)
fmt.Printf("%q: %d, %v\n", k, v, ok)
}
}
Output: "key1": 42, true "key2": 27644437, true "l": 2, true "m": 0, false
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[T any] struct { // contains filtered or unexported fields }
Map[T] is a fast read only map from string to generic type T Lookups are about 5x faster than the built-in Go map type
func (*Map[T]) IndexBytes ¶
IndexBytes returns the index of the value in the map for the supplied byte slice, or 0 if the value is not present in the map. Use AtIndex() to get the value using the resulting index.
func (*Map[T]) IndexString ¶
IndexString returns the index of the value in the map for the supplied string, or 0 if the value is not present in the map. Use AtIndex() to get the value using the resulting index.
func (*Map[T]) LookupBytes ¶
LookupBytes looks up the supplied byte slice in the map
func (*Map[T]) LookupString ¶
LookupString looks up the supplied string in the map
Click to show internal directories.
Click to hide internal directories.