Documentation ¶
Overview ¶
Package xor implements a nearest-neighbor data structure for the XOR-metric.
Index ¶
- Variables
- func Proximity(x, y Point) int
- type Key
- type Metric
- func (m *Metric) Add(item Point) (level int, err error)
- func (m *Metric) ChooseMinK(k int) Key
- func (m *Metric) Clear()
- func (m *Metric) Copy() *Metric
- func (m *Metric) Dump() []Point
- func (m *Metric) Iterate(f func(Point))
- func (m *Metric) Nearest(pivot Key, k int) []Point
- func (m *Metric) Remove(id Key) Point
- func (m *Metric) Size() int
- type Point
Constants ¶
This section is empty.
Variables ¶
var ErrDup = errors.New("duplicate point")
Functions ¶
Types ¶
type Key ¶
type Key uint64
Key represents a point in the 64-bit XOR-space.
func HashString ¶
func (Key) Bit ¶
Bit returns the k-th bit from metric point of view. The zero-th bit is most significant.
func (Key) ShortString ¶
String returns a textual representation of the id, truncated to the k MSBs.
type Metric ¶
type Metric struct { Point // contains filtered or unexported fields }
Metric is an XOR-metric space that supports point addition and nearest neighbor (NN) queries. The zero value is an empty metric space.
func (*Metric) Add ¶
Add adds the item to the metric. It returns the smallest number of significant bits that distinguish this item from the rest in the metric.
func (*Metric) ChooseMinK ¶
ChooseMinK chooses k random keys and returns the one which, if inserted into the metric, would result in the shallowest position in the XOR tree. In other words, it returns the most balanced choice. We recommend k equals 7.