Skip to content

Commit

Permalink
rename Tree to RadixTree
Browse files Browse the repository at this point in the history
  • Loading branch information
jub0bs committed Jan 26, 2025
1 parent 50e0f6a commit e302ef9
Show file tree
Hide file tree
Showing 5 changed files with 1,500 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/origins/corpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// The keys in this map correspond to origin schemes.
//
// [Web origins]: https://developer.mozilla.org/en-US/docs/Glossary/Origin
type Corpus map[string]radix.Tree
type Corpus map[string]radix.RadixTree

// Add augments c with all Web origins encompassed by pattern.
func (c Corpus) Add(pattern *Pattern) {
Expand Down
12 changes: 6 additions & 6 deletions internal/origins/radix/radix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (
"github.com/jub0bs/cors/internal/util"
)

// A Tree is radix tree whose edges are each labeled by a byte,
// A RadixTree is radix tree whose edges are each labeled by a byte,
// and whose conceptual leaf nodes each contain a set of ints.
// The zero value of a Tree is an empty tree.
type Tree struct {
// The zero value of a RadixTree is an empty tree.
type RadixTree struct {
root node
}

// Insert inserts v in the tree according to keyPattern.
// A leading * byte (0x2a) denotes a wildcard for any non-empty byte sequence.
// A non-leading * has no special meaning and is treated as any other byte.
// Sentinel value -1 represents a wildcard value that subsumes all others.
func (t *Tree) Insert(keyPattern string, v int) {
func (t *RadixTree) Insert(keyPattern string, v int) {
var hasLeadingAsterisk bool
// check for a leading asterisk
if b, rest, ok := splitAfterFirstByte(keyPattern); ok && b == '*' {
Expand Down Expand Up @@ -89,7 +89,7 @@ func (t *Tree) Insert(keyPattern string, v int) {
}

// Contains reports whether t contains key-value pair (k,v).
func (t *Tree) Contains(k string, v int) bool {
func (t *RadixTree) Contains(k string, v int) bool {
n := &t.root
for {
label, ok := lastByte(k)
Expand Down Expand Up @@ -149,7 +149,7 @@ func splitAtCommonSuffix(a, b string) (string, string, string) {
}

// Elems returns a slice containing textual representations of t's elements.
func (t *Tree) Elems() []string {
func (t *RadixTree) Elems() []string {
var res []string
t.root.Elems(&res, "")
slices.Sort(res)
Expand Down
2 changes: 1 addition & 1 deletion internal/origins/radix/radix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func TestRadix(t *testing.T) {
}
for _, tc := range cases {
f := func(t *testing.T) {
var tree radix.Tree
var tree radix.RadixTree
for _, pair := range tc.patterns {
tree.Insert(pair.key, pair.value)
}
Expand Down
Loading

0 comments on commit e302ef9

Please sign in to comment.