Socket
Socket
Sign inDemoInstall

github.com/plar/go-adaptive-radix-tree

Package Overview
Dependencies
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/plar/go-adaptive-radix-tree

Package art implements an Adapative Radix Tree(ART) in pure Go. Note that this implementation is not thread-safe but it could be really easy to implement. The design of ART is based on "The Adaptive Radix Tree: ARTful Indexing for Main-Memory Databases" [1]. Usage Also the current implementation was inspired by [2] and [3] [1] http://db.in.tum.de/~leis/papers/ART.pdf (Specification) [2] https://github.com/armon/libart (C99 implementation) [3] https://github.com/kellydunn/go-art (other Go implementation)


Version published

Readme

Source

An Adaptive Radix Tree Implementation in Go

Build Status Coverage Status Go Report Card GoDoc

This library provides a Go implementation of the Adaptive Radix Tree (ART).

Features:

  • Lookup performance surpasses highly tuned alternatives
  • Support for highly efficient insertions and deletions
  • Space efficient
  • Performance is comparable to hash tables
  • Maintains the data in sorted order, which enables additional operations like range scan and prefix lookup
  • O(k) search/insert/delete operations, where k is the length of the key
  • Minimum / Maximum value lookups
  • Ordered iteration
  • Prefix-based iteration
  • Support for keys with null bytes, any byte array could be a key

Usage

package main

import (
    "fmt"
    "github.com/plar/go-adaptive-radix-tree"
)

func main() {

    tree := art.New()

    tree.Insert(art.Key("Hi, I'm Key"), "Nice to meet you, I'm Value")
    value, found := tree.Search(art.Key("Hi, I'm Key"))
    if found {
        fmt.Printf("Search value=%v\n", value)
    }

    tree.ForEach(func(node art.Node) bool {
        fmt.Printf("Callback value=%v\n", node.Value())
        return true
    })

    for it := tree.Iterator(); it.HasNext(); {
        value, _ := it.Next()
        fmt.Printf("Iterator value=%v\n", value.Value())
    }
}

// Output:
// Search value=Nice to meet you, I'm Value
// Callback value=Nice to meet you, I'm Value
// Iterator value=Nice to meet you, I'm Value

Documentation

Check out the documentation on godoc.org

Performance

plar/go-adaptive-radix-tree outperforms kellydunn/go-art by avoiding memory allocations during search operations. It also provides prefix based iteration over the tree.

Benchmarks were performed on datasets extracted from different projects:

  • The "Words" dataset contains a list of 235,886 english words. [2]
  • The "UUIDs" dataset contains 100,000 uuids. [2]
  • The "HSK Words" dataset contains 4,995 words. [4]
go-adaptive-radix-tree#Average timeBytes per operationAllocs per operation
Tree Insert Words9117,888,698 ns/op37,942,744 B/op1,214,541 allocs/op
Tree Search Words2644,555,608 ns/op0 B/op0 allocs/op
Tree Insert UUIDs1859,360,135 ns/op18,375,723 B/op485,057 allocs/op
Tree Search UUIDs5421,265,931 ns/op0 B/op0 allocs/op
go-art
Tree Insert Words5272,047,975 ns/op81,628,987 B/op2,547,316 allocs/op
Tree Search Words10129,011,177 ns/op13,272,278 B/op1,659,033 allocs/op
Tree Insert UUIDs10140,309,246 ns/op33,678,160 B/op874,561 allocs/op
Tree Search UUIDs2082,120,943 ns/op3,883,131 B/op485,391 allocs/op

To see more benchmarks just run

$ make benchmark

References

[1] The Adaptive Radix Tree: ARTful Indexing for Main-Memory Databases (Specification)

[2] C99 implementation of the Adaptive Radix Tree

[3] Another Adaptive Radix Tree implementation in Go

[4] HSK Words. HSK(Hanyu Shuiping Kaoshi) - Standardized test of Standard Mandarin Chinese proficiency.

FAQs

Last updated on 08 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc