All Projects → gbrlsnchs → radix

gbrlsnchs / radix

Licence: MIT license
Golang radix tree implementation

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to radix

DataTanker
Embedded persistent key-value store for .NET. Pure C# code.
Stars: ✭ 53 (+76.67%)
Mutual labels:  radix-tree, radix
SwiftRadix
Easily convert integers to binary/hex/octal strings and back again with clean functional syntax.
Stars: ✭ 34 (+13.33%)
Mutual labels:  radix
Algorithms-Java
A collection of common algorithms and data structures implemented in Java.
Stars: ✭ 141 (+370%)
Mutual labels:  trie
sgo
A simple, light and fast Web framework written in Go.
Stars: ✭ 75 (+150%)
Mutual labels:  radix-tree
unitdb
Fast specialized time-series database for IoT, real-time internet connected devices and AI analytics.
Stars: ✭ 97 (+223.33%)
Mutual labels:  trie
prefixtree
A prefix tree (trie) implementation in go
Stars: ✭ 21 (-30%)
Mutual labels:  trie
rust sequence trie
Ergonomic trie data structure
Stars: ✭ 22 (-26.67%)
Mutual labels:  trie
triebeard
Radix trees in Rcpp and R
Stars: ✭ 29 (-3.33%)
Mutual labels:  trie
DEPRECATED-data-structures
A collection of powerful data structures
Stars: ✭ 2,648 (+8726.67%)
Mutual labels:  trie
HArray
Fastest Trie structure (Linux & Windows)
Stars: ✭ 89 (+196.67%)
Mutual labels:  trie
treebitmap
Fast IP lookup table for IPv4/IPv6 prefixes
Stars: ✭ 81 (+170%)
Mutual labels:  trie
trie-mux
A minimal and powerful trie based url path router (or mux) for Go.
Stars: ✭ 25 (-16.67%)
Mutual labels:  trie
BaseNcoding
Library for encoding of binary data into strings using base32, base85, base128 and other algorithms.
Stars: ✭ 42 (+40%)
Mutual labels:  radix
csharp-trie
A trie (prefix tree) data structure implementation in C#.
Stars: ✭ 30 (+0%)
Mutual labels:  trie
Data-Structures
Algorithmic Problems Solutions -- hash table code featured in geeksforgeeks
Stars: ✭ 44 (+46.67%)
Mutual labels:  trie
lexpy
Python package for lexicon; Trie and DAWG implementation.
Stars: ✭ 47 (+56.67%)
Mutual labels:  trie
go-erasure
Erasure coding (Reed–Solomon coding) in Go
Stars: ✭ 44 (+46.67%)
Mutual labels:  trie
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 (+116.67%)
Mutual labels:  trie
AlgoDaily
just for fun
Stars: ✭ 118 (+293.33%)
Mutual labels:  trie
simorgh
Simorgh is a simple server/client and key/value database using radix tree
Stars: ✭ 19 (-36.67%)
Mutual labels:  radix-tree

radix (Radix tree implementation in Go)

Build Status Sourcegraph GoDoc Minimal Version

About

This package is an implementation of a radix tree in Go (or Golang).

Searching for static values in the tree doesn't allocate memory on the heap, what makes it pretty fast.
It can also sort nodes by priority, therefore traversing nodes that hold more non-nil values first.

Usage

Full documentation here.

Installing

Go 1.10

vgo get -u github.com/gbrlsnchs/radix

Go 1.11

go get -u github.com/gbrlsnchs/radix

Importing

import (
	// ...

	"github.com/gbrlsnchs/radix"
)

Building this example from Wikipedia

tr := radix.New(radix.Tdebug)
tr.Add("romane", 1)
tr.Add("romanus", 2)
tr.Add("romulus", 3)
tr.Add("rubens", 4)
tr.Add("ruber", 5)
tr.Add("rubicon", 6)
tr.Add("rubicundus", 7)
tr.Sort(radix.PrioritySort) // optional step
fmt.Println(tr)

The code above will print this

. (14 nodes)
└── 7↑ r → <nil>
    ├── 4↑ ub → <nil>
    │   ├── 2↑ ic → <nil>
    │   │   ├── 1↑ undus 🍂 → 7
    │   │   └── 1↑ on 🍂 → 6
    │   └── 2↑ e → <nil>
    │       ├── 1↑ r 🍂 → 5
    │       └── 1↑ ns 🍂 → 4
    └── 3↑ om → <nil>
        ├── 2↑ an → <nil>
        │   ├── 1↑ us 🍂 → 2
        │   └── 1↑ e 🍂 → 1
        └── 1↑ ulus 🍂 → 3

Retrieving a value from the tree

n, _ := tr.Get("rubicon") // zero-allocation search
fmt.Println(n.Value)      // prints "6"

Building a dynamic tree

A dynamic tree is a tree that can match labels based on a placeholder and a demiliter (e.g. an HTTP router that accepts dynamic routes).
Note that this only works with prefix trees, not binary ones.

tr := radix.New(0) // passing 0 means passing no flags
tr.Add("/dynamic/path/@id", 1)
tr.Add("/dynamic/path/@id/subpath/@name", 2)
tr.Add("/static/path", 3)
tr.SetBoundaries('@', '/')

var (
	n *radix.Node
	p map[string]string
)
n, p = tr.Get("/dynamic/path/123")
fmt.Println(n.Value) // prints "1"
fmt.Println(p["id"]) // prints "123"

n, p = tr.Get("/dynamic/path/456/subpath/foobar")
fmt.Println(n.Value)   // prints "2"
fmt.Println(p["id"])   // prints "456"
fmt.Println(p["name"]) // prints "foobar"

n, _ = tr.Get("/static/path") // p would be nil
fmt.Println(n.Value)          // prints "3"

Building a binary tree

tr := radix.New(radix.Tdebug | radix.Tbinary)
tr.Add("deck", 1)
tr.Add("did", 2)
tr.Add("doe", 3)
tr.Add("dog", 4)
tr.Add("doge", 5)
tr.Add("dogs", 6)

The code above will print this

. (71 nodes)
01100100011001010110001101101011 🍂 → 1
011001000110100101100100 🍂 → 2
011001000110111101100101 🍂 → 3
011001000110111101100111 → 4
01100100011011110110011101100101 🍂 → 5
01100100011011110110011101110011 🍂 → 6

Contributing

How to help

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].