Documentation ¶
Overview ¶
Package index uses sorted arrays of integers to assist sorting and searching, particularly of collections of strings.
Index ¶
- func BytesKey(key []byte) uint64
- func CompareBytesToString(a []byte, b string) int
- func CompareStringToBytes(a string, b []byte) int
- func StringKey(key string) uint64
- type Index
- func (idx *Index) FindBytes(key []byte) int
- func (idx *Index) FindBytesRange(key []byte) (int, int)
- func (idx *Index) FindString(key string) int
- func (idx *Index) FindStringRange(key string) (int, int)
- func (idx *Index) FindUint64(key uint64) int
- func (idx *Index) FindUint64Range(key uint64) (a, b int)
- func (idx *Index) Key(i int) uint64
- func (idx *Index) Len() int
- func (idx *Index) Less(i, j int) bool
- func (idx *Index) Summarize()
- func (idx *Index) Swap(i, j int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareBytesToString ¶
CompareBytesToString is a convenience wrapper for CompareStringToBytes.
func CompareStringToBytes ¶
Compares string a to []byte b, returning -1 if a<b, 0 if a==b, and 1 if a>b.
Types ¶
type Index ¶
type Index struct { Keys []uint64 Summary []uint64 // implicit B-tree, if Summarize() was called Data sort.Interface }
func SortWithIndex ¶
SortWithIndex allocates an Index with space for a uint64 key for each item in data, then sorts items by their uint64 keys, using data.Less as a tie-breaker for equal-keyed items. data may implement index.KeySetter or any of sorts.StringInterface, BytesInterface, or Uint64Interface.
func (*Index) FindBytes ¶
FindBytes finds the first item >= key, returning one after the end if there is none. The collection type must implement Key(i) returning string or []byte.
func (*Index) FindBytesRange ¶
FindBytesRange(key) finds the range (a,b] such that Key() returns key for all items in idx.Data[a:b]. It can return an empty range if the item isn't found; in that case, a is where the item would be inserted (and can be one past the end). Data must implement Key(i) returning string or []byte. To find a single item, use FindBytes.
func (*Index) FindString ¶
FindString finds the first item >= key, returning one after the end if there is none. The collection type must implement Key(i) returning string or []byte.
func (*Index) FindStringRange ¶
FindStringRange(key) finds the range (a,b] such that Key() returns key for all items in idx.Data[a:b]. It can return an empty range if the item isn't found; in that case, a and b are both where the item would be inserted (and can be one past the end). Data must implement Key(i) returning string or []byte. To find a single item, use FindString.
func (*Index) FindUint64 ¶
FindUint64 finds the position of the first item >= key in Keys, returning one after the end if there is none. When different values map to the same key, you might want to sort.Search within the returned range to narrow your result down to the desired values.
func (*Index) FindUint64Range ¶
FindUint64Range looks for a range of keys such that all items in idx.Keys[a:b] equal key. It can return an empty range if the item isn't found; in that case, a and b are both where the item would be inserted (and can be one past the end). To find a single key, use FindUint64.
func (*Index) Less ¶
Less compares Index elements by their Keys, falling back to Data.Less for equal-keyed items.