| 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 |
kind() string |
| 28 |
iter(f func(node) bool) |
| 29 |
children() []node |
| 30 |
numChildren() uint16 |
| 31 |
path() string |
| 32 |
} |
| 33 |
|
| 34 |
type meta struct { |
| 35 |
prefix string |
| 36 |
size uint16 |
| 37 |
} |
| 38 |
|
| 39 |
func (n *meta) isLeaf() bool { return false } |
| 40 |
func (n *meta) base() *meta { return n } |
| 41 |
|
| 42 |
func (n *meta) setPrefix(pre []byte) { |
| 43 |
n.prefix = string(pre) |
| 44 |
} |
| 45 |
|
| 46 |
func (n *meta) numChildren() uint16 { return n.size } |
| 47 |
func (n *meta) path() string { return n.prefix } |