Skip to content

Commit

Permalink
InnerPrefixes is also used to store prefix lens
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Nov 26, 2020
1 parent 2cc84c1 commit 678c2c5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 58 deletions.
88 changes: 41 additions & 47 deletions trie/nodes.pb.go

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

15 changes: 7 additions & 8 deletions trie/nodes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ message Nodes {


// 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.
// - If only inner node prefix length is stored, it is a array with fixed-size elts. An array elt is the length in 4-bit of a prefix.
//
// In full-prefix mode:
// An array element is a control byte followed by several data bytes.
//
// The 0-th bit in the control byte indicates whether a prefix is
Expand All @@ -175,16 +180,10 @@ message Nodes {
VLenArray InnerPrefixes = 38;


// InnerPrefixLens stores how many bits to move forword before looking up a key on an
// inner node.
// The length of this array is len(inner nodes).
// Whether an inner node has prefix is stored in InnerPrefixBM.
// LeafPrefixes stores prefix of every leaf if it is not nil.
// A leaf prefix unlike inner node prefix, is just a byte sequence, without a control byte.
//
// Since 0.5.10
bytes InnerPrefixLens = 51;



VLenArray LeafPrefixes = 58;


Expand Down
2 changes: 1 addition & 1 deletion trie/slimtrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (st *SlimTrie) content() []string {
if ns.InnerPrefixes.PositionBM != nil {
rst = append(rst, fmt.Sprintf(`PrefixStarts: %+v`, bitmap.ToArray(ns.InnerPrefixes.PositionBM.Words)))
} else {
rst = append(rst, fmt.Sprintf(`Steps: %+v`, ns.InnerPrefixLens))
rst = append(rst, fmt.Sprintf(`Steps: %+v`, ns.InnerPrefixes.Bytes))
}

return rst
Expand Down
3 changes: 2 additions & 1 deletion trie/slimtrie_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ func (c *creator) build(e encode.Encoder) *SlimTrie {
ns.InnerPrefixes.Bytes = c.prefixes

} else {
ns.InnerPrefixLens = c.prefix4BitLens
ns.InnerPrefixes.FixedSize = 2
ns.InnerPrefixes.Bytes = c.prefix4BitLens
}

// TODO separate leaf init
Expand Down
2 changes: 1 addition & 1 deletion trie/slimtrie_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (st *SlimTrie) getInner(nodeid int32, qr *querySession) {
qr.hasPrefixContent = true

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

0 comments on commit 678c2c5

Please sign in to comment.