Skip to content

Commit

Permalink
M trie/nodes.pb.go
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Nov 24, 2020
1 parent 497b89d commit 59f68a6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 94 deletions.
121 changes: 54 additions & 67 deletions trie/nodes.pb.go

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

22 changes: 8 additions & 14 deletions trie/nodes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ message VLenArray {
Bitmap PositionBM = 20;


// FixedSize is set to elt size in Bytes field, if all the elts have equal sizes.
//
// Since 0.5.10
int32 FixedSize = 23;


// Bytes is the content in bytes
//
// Since 0.5.10
Expand All @@ -58,24 +64,12 @@ message VLenArray {
// Since 0.5.10
message Nodes {

// WithLeaves indicates whether to store leaf values(as an index).
// Otherwise, it is a "filter" which can only provide existence information
// but not location information.
//
// Since 0.5.10
bool WithLeaves = 8;

// WithPrefixContent indicates whether full inner prefixes are stored or only the
// lengths of inner prefix are stored.
//
// Since 0.5.10
bool WithPrefixContent = 9;

// WithLeafPrefix indicates whether to store prefix of leaves.
//
// Since 0.5.10
bool WithLeafPrefix = 10;

// BigInnerCnt is number of big (267 bit) inner node.
//
// Since 0.5.10
Expand Down Expand Up @@ -200,8 +194,8 @@ message Nodes {
VLenArray LeafPrefixes = 58;


// LeafBytes stores serialized leaf values.
// Leaves stores serialized leaf values.
//
// Since 0.5.10
bytes LeafBytes = 60;
VLenArray Leaves = 60;
}
7 changes: 6 additions & 1 deletion trie/slimtrie_complete_bench_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package trie

import (
"fmt"
"testing"

"github.com/openacid/low/size"
"github.com/openacid/slim/encode"
)

var OutputCompleteGetID20kvl10 int32

func BenchmarkSlimTrie_Complete_GetID_20k_vlen10(b *testing.B) {

keys := getKeys("20kvl10")
// keys := getKeys("20kvl10")
keys := getKeys("1mvl5_10")
values := makeI32s(len(keys))
st, _ := NewSlimTrie(encode.I32{}, keys, values, Opt{Complete: true})

fmt.Println(size.Stat(st, 10, 2))

var id int32

b.ResetTimer()
Expand Down
5 changes: 2 additions & 3 deletions trie/slimtrie_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ func (c *creator) build(e encode.Encoder) *SlimTrie {
BigInnerOffset: (bigInnerSize - innerSize) * c.bigCnt,
BigInnerCnt: c.bigCnt,
WithPrefixContent: c.option.CompleteInner,
WithLeafPrefix: c.option.CompleteLeaf,
WithLeaves: c.withLeaves,
}

// Mapping most used 17-bit bitmap inner node to short inner node.
Expand Down Expand Up @@ -613,7 +611,8 @@ func (ns *Nodes) initLeaves(elts interface{}, e encode.Encoder) {
bs := e.Encode(ee)
lb = append(lb, bs...)
}
ns.LeafBytes = lb
ns.Leaves = &VLenArray{}
ns.Leaves.Bytes = lb
}

func stepToPos(steps []int32, shift int32) []int32 {
Expand Down
8 changes: 4 additions & 4 deletions trie/slimtrie_getint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (st *SlimTrie) GetI8(key string) (int8, bool) {

ith, _ := st.getLeafIndex(eqID)

v := int8(st.nodes.LeafBytes[ith])
v := int8(st.nodes.Leaves.Bytes[ith])

return v, true
}
Expand All @@ -32,7 +32,7 @@ func (st *SlimTrie) GetI16(key string) (int16, bool) {
ith, _ := st.getLeafIndex(eqID)
stIdx := ith << 1

b := st.nodes.LeafBytes[stIdx : stIdx+2]
b := st.nodes.Leaves.Bytes[stIdx : stIdx+2]

v := int16(b[0]) | int16(b[1])<<8

Expand All @@ -53,7 +53,7 @@ func (st *SlimTrie) GetI32(key string) (int32, bool) {
ith, _ := st.getLeafIndex(eqID)
stIdx := ith << 2

b := st.nodes.LeafBytes[stIdx : stIdx+4]
b := st.nodes.Leaves.Bytes[stIdx : stIdx+4]

v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24

Expand All @@ -74,7 +74,7 @@ func (st *SlimTrie) GetI64(key string) (int64, bool) {
ith, _ := st.getLeafIndex(eqID)
stIdx := ith << 3

b := st.nodes.LeafBytes[stIdx : stIdx+8]
b := st.nodes.Leaves.Bytes[stIdx : stIdx+8]

v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56

Expand Down
11 changes: 6 additions & 5 deletions trie/slimtrie_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (st *SlimTrie) GetID(key string) int32 {

// eqID must not be -1

if st.nodes.WithLeafPrefix {
if st.nodes.LeafPrefixes != nil {
if i == l {
if qr.hasLeafPrefix {
return -1
Expand All @@ -208,7 +208,7 @@ func (st *SlimTrie) GetID(key string) int32 {

func (st *SlimTrie) cmpLeafPrefix(tail string, qr *querySession) int32 {

if st.nodes.WithLeafPrefix {
if st.nodes.LeafPrefixes != nil {
var leafPrefix []byte
if qr.hasLeafPrefix {
leafPrefix = qr.leafPrefix
Expand Down Expand Up @@ -375,7 +375,7 @@ func (st *SlimTrie) getLeafPrefix(nodeid int32, qr *querySession) {

qr.hasLeafPrefix = false

if st.nodes.WithLeafPrefix {
if st.nodes.LeafPrefixes != nil {

ns := st.nodes

Expand Down Expand Up @@ -542,14 +542,15 @@ func (st *SlimTrie) getLeaf(nodeid int32) interface{} {

func (st *SlimTrie) getIthLeaf(ith int32) interface{} {

if !st.nodes.WithLeaves {
ls := st.nodes.Leaves
if ls == nil {
return nil
}

eltsize := st.encoder.GetEncodedSize(nil)
stIdx := ith * int32(eltsize)

bs := st.nodes.LeafBytes[stIdx:]
bs := ls.Bytes[stIdx:]

_, v := st.encoder.Decode(bs)
return v
Expand Down

0 comments on commit 59f68a6

Please sign in to comment.