Documentation ¶
Overview ¶
Package watrix provides a wavelet matrix (wavelet tree) that supports Rank/Select and other useful queries in O(1).
WaveletMatrix is a data structure that efficiently performs various queries on an integer value sequence.
Most of the queries are done in O(1) regardless of the length of the sequence. Query time depends on the number of bits of the stored values. Querying on 16-bit value sequence is 4-times faster than that on 64-bit value sequence.
It's based on github.com/hillbig/waveletTree, and added various queries including ranged and ignoreBits version of Rank()/Select().
Index ¶
- Constants
- type Range
- type WaveletMatrix
- func (wm *WaveletMatrix) Dim() uint64
- func (wm *WaveletMatrix) Intersect(ranges []Range, k int) []uint64
- func (wm *WaveletMatrix) Lookup(pos uint64) uint64
- func (wm *WaveletMatrix) LookupAndRank(pos uint64) (uint64, uint64)
- func (wm *WaveletMatrix) MarshalBinary() (out []byte, err error)
- func (wm *WaveletMatrix) MarshalBinaryFile(outpath string) error
- func (wm *WaveletMatrix) Num() uint64
- func (wm *WaveletMatrix) Quantile(posRange Range, k uint64) uint64
- func (wm *WaveletMatrix) RangedRankIgnoreLSBs(posRange Range, val, ignoreBits uint64) (rank uint64)
- func (wm *WaveletMatrix) RangedRankOp(posRange Range, val uint64, op int) (rankResult uint64)
- func (wm *WaveletMatrix) RangedRankRange(posRange Range, valueRange Range) (rank uint64)
- func (wm *WaveletMatrix) RangedSelect(posRange Range, rank uint64, val uint64) uint64
- func (wm *WaveletMatrix) RangedSelectIgnoreLSBs(posRange Range, rank, val, ignoreBits uint64) (position uint64)
- func (wm *WaveletMatrix) Rank(pos uint64, val uint64) (rank uint64)
- func (wm *WaveletMatrix) RankLessThan(pos uint64, val uint64) (rankLessThan uint64)
- func (wm *WaveletMatrix) RankMoreThan(pos uint64, val uint64) (rankLessThan uint64)
- func (wm *WaveletMatrix) Select(rank uint64, val uint64) (position uint64)
- func (wm *WaveletMatrix) UnmarshalBinary(in []byte) (err error)
- func (wm *WaveletMatrix) UnmarshalBinaryFile(inpath string) error
- type WaveletMatrixBuilder
Constants ¶
const ( // OpEqual is used in RangedRankOp() OpEqual = iota // OpLessThan is used in RangedRankOp() OpLessThan // OpMoreThan is used in RangedRankOp() OpMoreThan // OpMax is upper boundary for OpXXXX constants OpMax )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WaveletMatrix ¶
type WaveletMatrix struct {
// contains filtered or unexported fields
}
WaveletMatrix is a data structure that efficiently performs various queries on an integer value sequence.
Most of the queries are done in O(1) regardless of the length of the sequence. Query time depends on the number of bits of the data stored. Querying on 16-bit value sequence is 4-times faster than that on 64-bit value sequence.
func (*WaveletMatrix) Dim ¶
func (wm *WaveletMatrix) Dim() uint64
Dim returns (max. of T[0...Num) + 1)
func (*WaveletMatrix) Intersect ¶
func (wm *WaveletMatrix) Intersect(ranges []Range, k int) []uint64
Intersect returns values that occur at least k ranges.
func (*WaveletMatrix) Lookup ¶
func (wm *WaveletMatrix) Lookup(pos uint64) uint64
Lookup returns T[pos]
func (*WaveletMatrix) LookupAndRank ¶
func (wm *WaveletMatrix) LookupAndRank(pos uint64) (uint64, uint64)
LookupAndRank returns T[pos] and Rank(pos, T[pos]) in one call. Faster than calling Lookup and Rank separately.
func (*WaveletMatrix) MarshalBinary ¶
func (wm *WaveletMatrix) MarshalBinary() (out []byte, err error)
MarshalBinary encodes WaveletMatrix into a binary form and returns the result.
func (*WaveletMatrix) MarshalBinaryFile ¶
func (wm *WaveletMatrix) MarshalBinaryFile(outpath string) error
MarshalBinary encodes WaveletMatrix into a binary form and writes it to a file.
func (*WaveletMatrix) Num ¶
func (wm *WaveletMatrix) Num() uint64
Num return the number of values in T
func (*WaveletMatrix) Quantile ¶
func (wm *WaveletMatrix) Quantile(posRange Range, k uint64) uint64
Quantile returns (k+1)th smallest value in T[posRange.Beg, posRange.End).
func (*WaveletMatrix) RangedRankIgnoreLSBs ¶
func (wm *WaveletMatrix) RangedRankIgnoreLSBs(posRange Range, val, ignoreBits uint64) (rank uint64)
RangedRankIgnoreLSBs searches T[posRange.Beg, posRange.End) and returns the number of c that matches the val.
If ignoreBits > 0, ignoreBits-bit portion from LSB are not considered for the match. This behavior is useful for IP address prefix search such as 192.168.10.0/24 (ignoreBits in this case, is 8).
func (*WaveletMatrix) RangedRankOp ¶
func (wm *WaveletMatrix) RangedRankOp(posRange Range, val uint64, op int) (rankResult uint64)
RangedRankOp returns the number of c that satisfies 'c op val' in T[posRange.Beg, posRange.End). The op should be one of {OpEqual, OpLessThan, OpMoreThan}.
func (*WaveletMatrix) RangedRankRange ¶
func (wm *WaveletMatrix) RangedRankRange(posRange Range, valueRange Range) (rank uint64)
RangedRankRange searches T[posRange.Beg, posRange.End) and returns the number of c that falls within valueRange i.e. [valueRange.Beg, valueRange.End).
func (*WaveletMatrix) RangedSelect ¶
func (wm *WaveletMatrix) RangedSelect(posRange Range, rank uint64, val uint64) uint64
RangedSelect takes T[posRange) and returns the position of rank+1'th val. If no match has been found, it returns posRange.End.
func (*WaveletMatrix) RangedSelectIgnoreLSBs ¶
func (wm *WaveletMatrix) RangedSelectIgnoreLSBs(posRange Range, rank, val, ignoreBits uint64) (position uint64)
RangedSelectIgnoreLSBs searches T[posRange.Beg, posRange.End) and returns the position of (rank+1)'th c that matches the val. If no match has been found, it returns posRange.End.
If ignoreBits > 0, ignoreBits-bit portion from LSB are not considered for the match. This behavior is useful for IP address prefix search such as 192.168.10.0/24 (ignoreBits in this case, is 8).
func (*WaveletMatrix) Rank ¶
func (wm *WaveletMatrix) Rank(pos uint64, val uint64) (rank uint64)
Rank returns the number of c (== val) in T[0...pos)
func (*WaveletMatrix) RankLessThan ¶
func (wm *WaveletMatrix) RankLessThan(pos uint64, val uint64) (rankLessThan uint64)
RankLessThan returns the number of c (< val) in T[0...pos)
func (*WaveletMatrix) RankMoreThan ¶
func (wm *WaveletMatrix) RankMoreThan(pos uint64, val uint64) (rankLessThan uint64)
RankMoreThan returns the number of c (> val) in T[0...pos)
func (*WaveletMatrix) Select ¶
func (wm *WaveletMatrix) Select(rank uint64, val uint64) (position uint64)
Select returns the position of (rank+1)-th val in T. If no match has been found, it returns Num().
func (*WaveletMatrix) UnmarshalBinary ¶
func (wm *WaveletMatrix) UnmarshalBinary(in []byte) (err error)
UnmarshalBinary decodes WaveletMatrix from a binary form generated MarshalBinary.
func (*WaveletMatrix) UnmarshalBinaryFile ¶
func (wm *WaveletMatrix) UnmarshalBinaryFile(inpath string) error
UnmarshalBinaryFile decodes WaveletMatrix from a binary file generated MarshalBinaryFile.
type WaveletMatrixBuilder ¶
type WaveletMatrixBuilder struct {
// contains filtered or unexported fields
}
WaveletMatrixBuilder builds WaveletMatrix from integer array. A user calls PushBack()s followed by Build().
func (*WaveletMatrixBuilder) Build ¶
func (wmb *WaveletMatrixBuilder) Build() *WaveletMatrix
Build constructs WaveletMatrix data structure
func (*WaveletMatrixBuilder) PushBack ¶
func (wmb *WaveletMatrixBuilder) PushBack(val uint64)
PushBack append a value to the builder.