Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oneofone/radix
radix: a go radix tree with nearest matching
https://github.com/oneofone/radix
go golang radix-tree
Last synced: about 5 hours ago
JSON representation
radix: a go radix tree with nearest matching
- Host: GitHub
- URL: https://github.com/oneofone/radix
- Owner: OneOfOne
- License: other
- Created: 2021-07-04T05:16:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-16T22:34:50.000Z (over 3 years ago)
- Last Synced: 2024-10-21T04:53:57.192Z (about 1 month ago)
- Topics: go, golang, radix-tree
- Language: Go
- Homepage: https://pkg.go.dev/go.oneofone.dev/radix@main
- Size: 101 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# radix
[![Go Reference](https://pkg.go.dev/badge/go.oneofone.dev/radix.svg)](https://pkg.go.dev/go.oneofone.dev/radix)
![test status](https://github.com/OneOfOne/radix/actions/workflows/test.yml/badge.svg)
[![Coverall](https://coveralls.io/repos/github/OneOfOne/radix/badge.svg?branch=main)](https://coveralls.io/github/OneOfOne/radix)Implements a [radix tree](http://en.wikipedia.org/wiki/Radix_tree), optimized for sparse nodes.
This is a hard-fork based of [armon/go-radix](https://github.com/armon/go-radix), with some additions.
# Features
* O(k) operations. In many cases, this can be faster than a hash table since the hash function is an O(k) operation, and hash tables have very poor cache locality.
* Minimum / Maximum value lookups
* Ordered iteration## New
* Can walk the tree from the nearest path
* Includes a thread-safe version.
* Unicode safe.
* Case-insensitive matching support.
* Go Generics support.# TODO
* Marshaling/Unmarshaling support (currently you can dump to json).
* More optimizations.
* More benchmarks.# Usage
```go
// go get go.oneofone.dev/radix@main
// Create a case-insensistive tree
r := radix.New[int](true)// or thread-safe version
// t := NewSafe[int](true)
t.Set("foo", 1)
t.Set("bar", 2)
t.Set("foobar", 2)// Find the longest prefix match
m, _, _ := t.LongestPrefix("fOoZiP")
if m != "foo" {
panic("should be foo")
}
```### Generating a typed version for go < 1.18 (requires perl and posix shell)
```sh
# outside a module
$ go get go.oneofone.dev/radix
$ sh $(go env GOPATH)/src/go.oneofone.dev/radix/gen.sh "interface{}" # or "string" or "[]pkg.SomeStruct"
```# Using the generic version
Install Go 1.18 ([dev.typeparams](https://github.com/golang/go/tree/dev.typeparams))
```sh
$ go get golang.org/dl/gotip
$ gotip download dev.typeparams
$ gotip get go.oneofone.dev/radix@main # note that the go proxy does not support go 1.18 yet.
```# Contributions
Anyone is more than welcome to open pull requests provided they adhere to the Go community [code of conduct](https://golang.org/conduct).
It's recommended that any modifications should be on the [generic](radix.go),
however if that's not possible, I'll port any changes from the [compact](radix_go117.go).# License
[MIT](LICENSE)