github.com/nats-io/nats-server/v2@v2.11.0-preview.2/server/stree/node.go (about)

     1  // Copyright 2023-2024 The NATS Authors
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package stree
    15  
    16  // Internal node interface.
    17  type node interface {
    18  	isLeaf() bool
    19  	base() *meta
    20  	setPrefix(pre []byte)
    21  	addChild(c byte, n node)
    22  	findChild(c byte) *node
    23  	deleteChild(c byte)
    24  	isFull() bool
    25  	grow() node
    26  	shrink() node
    27  	matchParts(parts [][]byte) ([][]byte, bool)
    28  	kind() string
    29  	iter(f func(node) bool)
    30  	children() []node
    31  	numChildren() uint16
    32  	path() []byte
    33  }
    34  
    35  // Maximum prefix len
    36  // We expect the most savings to come from long shared prefixes.
    37  const maxPrefixLen = 24
    38  
    39  // 64 bytes total - an L1 cache line.
    40  type meta struct {
    41  	prefix    [maxPrefixLen]byte
    42  	prefixLen uint16
    43  	size      uint16
    44  }