pathtrie

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

View Source
const Separator = '/'

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node[K any, T any] struct {
	// contains filtered or unexported fields
}

Node 表示 PathTrie 中的节点

type PathTrie

type PathTrie[K any, T any] struct {
	// contains filtered or unexported fields
}

PathTrie 表示路径前缀树

func NewPathTrie

func NewPathTrie[K any, T any]() *PathTrie[K, T]

NewPathTrie 创建新的 PathTrie

Example
package main

import (
	"fmt"

	"github.com/omalloc/tavern/pkg/pathtrie"
)

func main() {

	trie := pathtrie.NewPathTrie[string, int64]()

	trie.Insert("/api/users", 0)
	trie.Insert("http://sendya.me.gslb.com/host/path/", 1768480300)

	value1, found1 := trie.Search("/api/users/123")
	value7, found7 := trie.Search("http://sendya.me.gslb.com/host/path/to/1M")

	fmt.Printf("value1: %d found: %t\n", value1, found1)
	fmt.Printf("value7: %d found: %t\n", value7, found7)

}
Output:
value1: 0 found: true
value7: 1768480300 found: true

func (*PathTrie[K, T]) FindByPrefix

func (t *PathTrie[K, T]) FindByPrefix(prefix string) map[string]T

FindByPrefix 通过前缀查找所有匹配的路径和值

func (*PathTrie[K, T]) Insert

func (t *PathTrie[K, T]) Insert(pattern string, value T)

Insert 插入路径和对应的值

func (*PathTrie[K, T]) Search

func (t *PathTrie[K, T]) Search(path string) (T, bool)

Search 查找路径并返回对应的值(支持通配符匹配)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL