Documentation
¶
Index ¶
- Variables
- type RoarIndex
- func (om *RoarIndex[K, V]) Count() int
- func (om *RoarIndex[K, V]) DeleteMap(key K)
- func (om *RoarIndex[K, V]) GetMap(key K) ([]V, error)
- func (om *RoarIndex[K, V]) HasValue(key K, value V) bool
- func (om *RoarIndex[K, V]) Keys() []K
- func (om *RoarIndex[K, V]) PushMap(key K, value V)
- func (om *RoarIndex[K, V]) Values() []V
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is returned when a key is not found in the RoarIndex.
Functions ¶
This section is empty.
Types ¶
type RoarIndex ¶
type RoarIndex[K comparable, V comparable] struct { // contains filtered or unexported fields }
RoarIndex is a mapping from keys of type K to sets of values of type V. It uses RoaringBitmap internally for efficient storage and operations.
Example ¶
package main
import (
"fmt"
"slices"
"github.com/thisisdevelopment/roarindex"
)
func main() {
cm := roarindex.NewRoarIndex[string, string]()
cm.PushMap("testMap", "value1")
cm.PushMap("testMap", "value2")
cm.PushMap("testMap", "value3")
values, _ := cm.GetMap("testMap")
// order is not guaranteed
slices.Sort(values)
fmt.Println(values)
}
Output: [value1 value2 value3]
func NewRoarIndex ¶
func NewRoarIndex[K comparable, V comparable]() *RoarIndex[K, V]
NewRoarIndex creates a new RoarIndex.
func (*RoarIndex[K, V]) Count ¶
Count returns the number of keys in the RoarIndex.
Example ¶
package main
import (
"fmt"
"github.com/thisisdevelopment/roarindex"
)
func main() {
cm := roarindex.NewRoarIndex[string, string]()
cm.PushMap("testMap", "value1")
cm.PushMap("testMap", "value2")
cm.PushMap("testMap", "value3")
fmt.Println(cm.Count())
}
Output: 1
func (*RoarIndex[K, V]) DeleteMap ¶
func (om *RoarIndex[K, V]) DeleteMap(key K)
DeleteMap removes a key and its associated values from the RoarIndex.
Example ¶
package main
import (
"fmt"
"github.com/thisisdevelopment/roarindex"
)
func main() {
cm := roarindex.NewRoarIndex[string, string]()
cm.PushMap("testMap", "value1")
cm.DeleteMap("testMap")
fmt.Println(cm.GetMap("testMap"))
}
Output: [] key not found
func (*RoarIndex[K, V]) HasValue ¶
HasValue checks if a value is associated with a key.
Example ¶
package main
import (
"fmt"
"github.com/thisisdevelopment/roarindex"
)
func main() {
cm := roarindex.NewRoarIndex[string, string]()
cm.PushMap("testMap", "value1")
cm.PushMap("testMap2", "value1")
fmt.Printf("%t %t %t", cm.HasValue("testMap", "value1"), cm.HasValue("testMap2", "value1"), cm.HasValue("testMap", "value2"))
}
Output: true true false
func (*RoarIndex[K, V]) Keys ¶
func (om *RoarIndex[K, V]) Keys() []K
Keys returns a slice of all keys in the RoarIndex.
func (*RoarIndex[K, V]) PushMap ¶
func (om *RoarIndex[K, V]) PushMap(key K, value V)
PushMap associates a value with a key.
func (*RoarIndex[K, V]) Values ¶
func (om *RoarIndex[K, V]) Values() []V
Values returns a slice of all values in the RoarIndex.
Example ¶
package main
import (
"fmt"
"slices"
"github.com/thisisdevelopment/roarindex"
)
func main() {
cm := roarindex.NewRoarIndex[string, string]()
cm.PushMap("testMap1", "value1")
cm.PushMap("testMap2", "value2")
cm.PushMap("testMap3", "value2")
values := cm.Values()
// order is not guaranteed
slices.Sort(values)
fmt.Println(values)
}
Output: [value1 value2]
Click to show internal directories.
Click to hide internal directories.