Skip to content

Commit

Permalink
new-feature: slimarray: VLenArray add field EltCnt to store the total…
Browse files Browse the repository at this point in the history
… number of present elts
  • Loading branch information
drmingdrmer committed Nov 26, 2020
1 parent 657a774 commit 01e40d1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 63 deletions.
92 changes: 47 additions & 45 deletions trie/nodes.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions trie/nodes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ message Bitmap {
// Since 0.5.10
message VLenArray {

// N is the max set bit index plus 1.
//
// Since 0.5.10
int32 N = 10;

// EltCnt is the number of present elts.
//
// Since 0.5.10
int32 EltCnt = 11;

// PresenceBM set 1 at the i-th bit if the i-th elt presents.
//
Expand Down Expand Up @@ -69,6 +76,7 @@ message Nodes {
// Since 0.5.10
int32 BigInnerCnt = 11;


// BigInnerOffset is the offset caused by "BigInner" nodes:
//
// Supposing that the i-th inner node is the j-th short inner node(an inner
Expand Down Expand Up @@ -99,24 +107,19 @@ message Nodes {
// Since 0.5.10
int32 ShortMinusInner = 13;


// ShortSize is the number of bit of short bitmap that reduce most memory
// cost.
//
// Since 0.5.10
int32 ShortSize = 14;


// ShortMask has the lower ShortSize bit set to 1.
//
// Since 0.5.10
uint64 ShortMask = 15;

// Number of InnerPrefixes.
// It is used to speed up lookup when there are not any prefixes.
//
// Since 0.5.10
int32 InnerPrefixCnt = 16;



// NodeTypeBM is a bitmap in which a "1" indicates the i-th node is an inner
// node, otherwise it is a leaf.
Expand Down Expand Up @@ -145,10 +148,6 @@ message Nodes {
repeated uint32 ShortTable = 32;


// // InnerPrefixFlags indicates if a prefix is truncated, e.g., the last "1" indicates the end of prefix.
// Bitmap InnerPrefixFlags = 55;


// InnerPrefixes of inner nodes.
// There are two usages with this field:
// - If inner node prefix is stored, it is a var-len array of stored prefix string.
Expand Down
2 changes: 1 addition & 1 deletion trie/slimtrie_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ func (c *creator) build(e encode.Encoder) *SlimTrie {
}
ns.Inners.indexit("r128")

ns.InnerPrefixCnt = int32(len(c.prefixIndexes))
ns.InnerPrefixes = &VLenArray{}
ns.InnerPrefixes.EltCnt = int32(len(c.prefixIndexes))
ns.InnerPrefixes.PresenceBM = newBM(c.prefixIndexes, innerCnt, "r128")
if c.option.CompleteInner {
ns.InnerPrefixes.PositionBM = newBM(stepToPos(c.prefixByteLens, 0), 0, "s32")
Expand Down
13 changes: 7 additions & 6 deletions trie/slimtrie_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,23 +451,24 @@ func (st *SlimTrie) getInner(nodeid int32, qr *querySession) {

// if this node has prefix
// TODO no prefix mode when create
if ns.InnerPrefixCnt > 0 && ns.InnerPrefixes.PresenceBM.Words[innWordI]&bitmap.Bit[innBitI] != 0 {
prefs := ns.InnerPrefixes
if prefs.EltCnt > 0 && prefs.PresenceBM.Words[innWordI]&bitmap.Bit[innBitI] != 0 {

inn := ns.InnerPrefixes.PresenceBM
inn := prefs.PresenceBM
ithPref := rank128(inn.Words, inn.RankIndex, ithInner)

if ns.InnerPrefixes.PositionBM != nil {
if prefs.PositionBM != nil {

// stored actual prefix of a node.
ps := ns.InnerPrefixes.PositionBM
ps := prefs.PositionBM
from, to := ps.select32(ithPref)

qr.prefix = ns.InnerPrefixes.Bytes[from:to]
qr.prefix = prefs.Bytes[from:to]
qr.prefixLen = prefixLen(qr.prefix)
qr.hasPrefixContent = true

} else {
qr.prefixLen = decStep(ns.InnerPrefixes.Bytes[ithPref<<1:])
qr.prefixLen = decStep(prefs.Bytes[ithPref<<1:])
}
}
}
Expand Down

0 comments on commit 01e40d1

Please sign in to comment.