All Projects → beevik → prefixtree

beevik / prefixtree

Licence: BSD-2-Clause license
A prefix tree (trie) implementation in go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to prefixtree

csharp-trie
A trie (prefix tree) data structure implementation in C#.
Stars: ✭ 30 (+42.86%)
Mutual labels:  trie, prefix-tree
trie
Trie (a.k.a. prefix tree) C# implementation. Has constant-time string prefix lookup.
Stars: ✭ 84 (+300%)
Mutual labels:  trie, prefix-tree
trie-perf
Performance shootout of various trie implementations
Stars: ✭ 18 (-14.29%)
Mutual labels:  trie, prefix-tree
goblin
A golang http router based on trie tree.
Stars: ✭ 52 (+147.62%)
Mutual labels:  trie
trie
My take on an efficient implementation of a Trie in Javascript
Stars: ✭ 72 (+242.86%)
Mutual labels:  trie
trie-mux
A minimal and powerful trie based url path router (or mux) for Go.
Stars: ✭ 25 (+19.05%)
Mutual labels:  trie
treebitmap
Fast IP lookup table for IPv4/IPv6 prefixes
Stars: ✭ 81 (+285.71%)
Mutual labels:  trie
unitdb
Fast specialized time-series database for IoT, real-time internet connected devices and AI analytics.
Stars: ✭ 97 (+361.9%)
Mutual labels:  trie
xcdat
Fast compressed trie dictionary library
Stars: ✭ 51 (+142.86%)
Mutual labels:  trie
Algorithms-Java
A collection of common algorithms and data structures implemented in Java.
Stars: ✭ 141 (+571.43%)
Mutual labels:  trie
feathers-versionate
Create and work with nested services.
Stars: ✭ 29 (+38.1%)
Mutual labels:  prefix
lexpy
Python package for lexicon; Trie and DAWG implementation.
Stars: ✭ 47 (+123.81%)
Mutual labels:  trie
global-prefix
Get the npm global path prefix. Same code used internally by npm.
Stars: ✭ 27 (+28.57%)
Mutual labels:  prefix
distube-music-bot
An advanced music bot based on distube.js.org with filters and more
Stars: ✭ 24 (+14.29%)
Mutual labels:  prefix
HArray
Fastest Trie structure (Linux & Windows)
Stars: ✭ 89 (+323.81%)
Mutual labels:  trie
Jolf
A golfier prefix version of JavaScript
Stars: ✭ 13 (-38.1%)
Mutual labels:  prefix
prefix
CSS auto-prefix in < 0.5 KB
Stars: ✭ 21 (+0%)
Mutual labels:  prefix
Competitive Programming
Contains solutions and codes to various online competitive programming challenges and some good problems. The links to the problem sets are specified at the beginning of each code.
Stars: ✭ 65 (+209.52%)
Mutual labels:  trie
django-redirects
↪️ ✅ redirects as they should be, with full control.
Stars: ✭ 32 (+52.38%)
Mutual labels:  prefix
go-erasure
Erasure coding (Reed–Solomon coding) in Go
Stars: ✭ 44 (+109.52%)
Mutual labels:  trie

Build Status GoDoc

prefixtree

The prefixtree package implements a simple prefix trie data structure. The tree enables rapid searching for strings that uniquely match a given prefix. The implementation allows the user to associate data with each string, so it can act as a sort of flexible key-value store where searches succeed with the shortest unambiguous key prefix.

See http://godoc.org/github.com/beevik/prefixtree for godoc-formatted API documentation.

Example: Building a prefix tree

The following code adds strings and associated data (an integer) to a prefix tree.

tree := prefixtree.New()

tree.Add("apple", 10)
tree.Add("orange", 20)
tree.Add("apple pie", 30)
tree.Add("lemon", 40)
tree.Add("lemon meringue pie", 50)

Example: Searching the prefix tree

The following code searches the prefix tree generated by the previous example and outputs the results.

fmt.Printf("%-18s %-8s %s\n", "prefix", "data", "error")
fmt.Printf("%-18s %-8s %s\n", "------", "----", "-----")

for _, prefix := range []string{
    "a",
    "appl",
    "apple",
    "apple p",
    "apple pie",
    "apple pies",
    "o",
    "oran",
    "orange",
    "oranges",
    "l",
    "lemo",
    "lemon",
    "lemon m",
    "lemon meringue",
    "pear",
} {
    data, err := tree.Find(prefix)
    fmt.Printf("%-18s %-8v %v\n", s, data, err)
}

Output:

prefix             data     error
------             ----     -----
a                  <nil>    prefixtree: prefix ambiguous
appl               <nil>    prefixtree: prefix ambiguous
apple              10       <nil>
apple p            30       <nil>
apple pie          30       <nil>
apple pies         <nil>    prefixtree: prefix not found
o                  20       <nil>
orang              20       <nil>
orange             20       <nil>
oranges            <nil>    prefixtree: prefix not found
l                  <nil>    prefixtree: prefix ambiguous
lemo               <nil>    prefixtree: prefix ambiguous
lemon              40       <nil>
lemon m            50       <nil>
lemon meringue     50       <nil>
pear               <nil>    prefixtree: prefix not found
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].