From 678c2c56338a45536117ee9f1e7b014f84988e7e Mon Sep 17 00:00:00 2001 From: drdr xp Date: Thu, 26 Nov 2020 23:32:50 +0800 Subject: [PATCH] InnerPrefixes is also used to store prefix lens --- trie/nodes.pb.go | 88 +++++++++++++++++++---------------------- trie/nodes.proto | 15 ++++--- trie/slimtrie.go | 2 +- trie/slimtrie_create.go | 3 +- trie/slimtrie_query.go | 2 +- 5 files changed, 52 insertions(+), 58 deletions(-) diff --git a/trie/nodes.pb.go b/trie/nodes.pb.go index 8dd7fee1..9009c46a 100644 --- a/trie/nodes.pb.go +++ b/trie/nodes.pb.go @@ -43,7 +43,7 @@ func (m *Bitmap) Reset() { *m = Bitmap{} } func (m *Bitmap) String() string { return proto.CompactTextString(m) } func (*Bitmap) ProtoMessage() {} func (*Bitmap) Descriptor() ([]byte, []int) { - return fileDescriptor_nodes_b3d1b3a790788803, []int{0} + return fileDescriptor_nodes_44d1ae84380baad8, []int{0} } func (m *Bitmap) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Bitmap.Unmarshal(m, b) @@ -114,7 +114,7 @@ func (m *VLenArray) Reset() { *m = VLenArray{} } func (m *VLenArray) String() string { return proto.CompactTextString(m) } func (*VLenArray) ProtoMessage() {} func (*VLenArray) Descriptor() ([]byte, []int) { - return fileDescriptor_nodes_b3d1b3a790788803, []int{1} + return fileDescriptor_nodes_44d1ae84380baad8, []int{1} } func (m *VLenArray) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_VLenArray.Unmarshal(m, b) @@ -240,6 +240,11 @@ type Nodes struct { // Since 0.5.10 ShortTable []uint32 `protobuf:"varint,32,rep,packed,name=ShortTable,proto3" json:"ShortTable,omitempty"` // 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 @@ -263,14 +268,11 @@ type Nodes struct { // // Since 0.5.10 InnerPrefixes *VLenArray `protobuf:"bytes,38,opt,name=InnerPrefixes,proto3" json:"InnerPrefixes,omitempty"` - // 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 - InnerPrefixLens []byte `protobuf:"bytes,51,opt,name=InnerPrefixLens,proto3" json:"InnerPrefixLens,omitempty"` - LeafPrefixes *VLenArray `protobuf:"bytes,58,opt,name=LeafPrefixes,proto3" json:"LeafPrefixes,omitempty"` + LeafPrefixes *VLenArray `protobuf:"bytes,58,opt,name=LeafPrefixes,proto3" json:"LeafPrefixes,omitempty"` // Leaves stores serialized leaf values. // // Since 0.5.10 @@ -284,7 +286,7 @@ func (m *Nodes) Reset() { *m = Nodes{} } func (m *Nodes) String() string { return proto.CompactTextString(m) } func (*Nodes) ProtoMessage() {} func (*Nodes) Descriptor() ([]byte, []int) { - return fileDescriptor_nodes_b3d1b3a790788803, []int{2} + return fileDescriptor_nodes_44d1ae84380baad8, []int{2} } func (m *Nodes) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Nodes.Unmarshal(m, b) @@ -381,13 +383,6 @@ func (m *Nodes) GetInnerPrefixes() *VLenArray { return nil } -func (m *Nodes) GetInnerPrefixLens() []byte { - if m != nil { - return m.InnerPrefixLens - } - return nil -} - func (m *Nodes) GetLeafPrefixes() *VLenArray { if m != nil { return m.LeafPrefixes @@ -408,35 +403,34 @@ func init() { proto.RegisterType((*Nodes)(nil), "Nodes") } -func init() { proto.RegisterFile("nodes.proto", fileDescriptor_nodes_b3d1b3a790788803) } - -var fileDescriptor_nodes_b3d1b3a790788803 = []byte{ - // 426 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x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f5, 0x78, 0xc1, 0x2f, 0xb0, 0x8d, 0xc5, 0x14, 0x06, 0x33, 0x2a, 0x56, 0x75, 0xeb, - 0xd7, 0x07, 0xad, 0xf7, 0x74, 0x31, 0x81, 0x74, 0x46, 0xc5, 0x2f, 0xf2, 0xf8, 0xe6, 0xc0, 0xf9, - 0xa0, 0x64, 0xe9, 0x97, 0x6e, 0x70, 0x86, 0x6e, 0x52, 0xfe, 0x5f, 0x2e, 0xfe, 0x05, 0x00, 0x00, - 0xff, 0xff, 0x8e, 0xde, 0x05, 0x7c, 0x3e, 0x03, 0x00, 0x00, +func init() { proto.RegisterFile("nodes.proto", fileDescriptor_nodes_44d1ae84380baad8) } + +var fileDescriptor_nodes_44d1ae84380baad8 = []byte{ + // 415 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0xdf, 0x6a, 0xd4, 0x40, + 0x14, 0xc6, 0x09, 0xbb, 0x49, 0xe9, 0x49, 0xb6, 0x95, 0x61, 0xc1, 0xb9, 0x90, 0xed, 0x98, 0x8b, + 0x3a, 0x57, 0x41, 0xf4, 0x4e, 0xf4, 0xc2, 0x08, 0x42, 0x61, 0xb3, 0x96, 0xd9, 0xa2, 0xe0, 0x85, + 0x90, 0x36, 0x27, 0x3a, 0xb4, 0x4e, 0x96, 0x99, 0x51, 0x76, 0x7d, 0x19, 0xdf, 0xd1, 0x27, 0x90, + 0x99, 0xb4, 0xf9, 0xb3, 0xdb, 0xbb, 0x9c, 0xdf, 0xf7, 0x9d, 0x99, 0xef, 0x1c, 0x32, 0x10, 0xab, + 0xa6, 0x42, 0x93, 0x6d, 0x74, 0x63, 0x9b, 0xf4, 0x1b, 0x44, 0xb9, 0xb4, 0x3f, 0xcb, 0x0d, 0x99, + 0x43, 0xf8, 0xa5, 0xd1, 0x95, 0xa1, 0x73, 0x36, 0xe1, 0x53, 0xd1, 0x16, 0xe4, 0x19, 0x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a5, 0xc6, 0x5a, 0x6e, 0x5d, 0xe4, 0x27, 0x6d, 0x9a, 0x31, 0x75, 0xeb, + 0x73, 0x03, 0x5e, 0xed, 0x36, 0xf8, 0xc8, 0xfa, 0x7a, 0x89, 0x9c, 0x41, 0xe4, 0x5b, 0xdb, 0x0d, + 0x0d, 0x4c, 0xf7, 0x98, 0x3c, 0x87, 0x23, 0x7f, 0x7d, 0x5e, 0xd0, 0xb3, 0xb1, 0xe3, 0x81, 0x93, + 0x05, 0x80, 0xff, 0xbc, 0x2a, 0xaf, 0xef, 0x90, 0x32, 0x36, 0xe1, 0x33, 0x31, 0x20, 0xe4, 0x25, + 0xcc, 0x06, 0xf1, 0xd0, 0xd0, 0x73, 0x7f, 0x10, 0x64, 0xdd, 0x5f, 0x22, 0xc6, 0x06, 0x92, 0x41, + 0xb2, 0xc4, 0xb2, 0xee, 0x1a, 0xde, 0x1c, 0x34, 0x8c, 0x74, 0x92, 0x42, 0xb4, 0xc4, 0xf2, 0x37, + 0x1a, 0xfa, 0xf6, 0xc0, 0x79, 0xaf, 0xe4, 0xd1, 0xd7, 0xa9, 0xd5, 0x12, 0xaf, 0x23, 0xff, 0x0a, + 0x5e, 0xff, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x64, 0x96, 0x73, 0x93, 0x14, 0x03, 0x00, 0x00, } diff --git a/trie/nodes.proto b/trie/nodes.proto index 47e0e0a8..7ee87423 100644 --- a/trie/nodes.proto +++ b/trie/nodes.proto @@ -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 @@ -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; diff --git a/trie/slimtrie.go b/trie/slimtrie.go index eaedbc4f..7d4e3adc 100644 --- a/trie/slimtrie.go +++ b/trie/slimtrie.go @@ -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 diff --git a/trie/slimtrie_create.go b/trie/slimtrie_create.go index 9bcfe6ea..575f8ce8 100644 --- a/trie/slimtrie_create.go +++ b/trie/slimtrie_create.go @@ -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 diff --git a/trie/slimtrie_query.go b/trie/slimtrie_query.go index b16e4dfe..51f10c89 100644 --- a/trie/slimtrie_query.go +++ b/trie/slimtrie_query.go @@ -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:]) } } }