kellydunn / go-art Goto Github PK
View Code? Open in Web Editor NEWan adaptive radix tree implementation in go
License: MIT License
an adaptive radix tree implementation in go
License: MIT License
Interesting implementation of an interesting concept, but what is the license? Can I use it?
anachronistic [3:18 PM]
@kellydunn looking at `ArtNode` (thinking about allocations, etc.) you can shave 8 bytes off regardless of platform by reordering the struct members
anachronistic [3:19 PM]
type ArtNode struct {
keys []byte
prefix []byte
children []*ArtNode
prefixLen int
size uint8
nodeType uint8
key []byte
keySize uint64
value interface{}
} // 72 on 32-bit, 136 on 64-bit
Coupled with the findings at github.com/tv42/benchmark-ordered-map , this lib could dramatically reduce the number of bytes allocated for searching and inserting.
Acceptance criteria:
It would be great if this repo could support go modules (and semantically versioned git tags).
Thanks,
Ben
It is often useful to look up the set of nodes with a common prefix.
This makes e.g. iterating the tree a bit pointless; you can't even round-trip a map[string]string to ART and back (without kludges).
It would be great to have a tree size function to return the number of nodes in the tree.
package main
import (
"encoding/binary"
"math/rand"
"github.com/kellydunn/go-art"
)
func main() {
rand.Seed(42)
key := make([]byte, 8)
tree := art.NewArtTree()
for i := 0; i < 135; i++ {
binary.BigEndian.PutUint64(key, uint64(rand.Int63()))
tree.Insert(key, key)
}
}
$ go run bug.go
panic: runtime error: index out of range
goroutine 1 [running]:
github.com/kellydunn/go-art.(*ArtTree).insertHelper(0xc20800a1f0, 0xc20803f170, 0xc20805c3b0, 0xc20800aca0, 0x9, 0x10, 0x483380, 0xc20801f5c0, 0x1)
/home/tv/go/src/github.com/kellydunn/go-art/art_tree.go:115 +0x619
github.com/kellydunn/go-art.(*ArtTree).insertHelper(0xc20800a1f0, 0xc20803e090, 0xc20800a1f0, 0xc20800aca0, 0x9, 0x10, 0x483380, 0xc20801f5c0, 0x0)
/home/tv/go/src/github.com/kellydunn/go-art/art_tree.go:170 +0xde7
github.com/kellydunn/go-art.(*ArtTree).Insert(0xc20800a1f0, 0xc20800aca0, 0x9, 0x10, 0x483380, 0xc20801f5c0)
/home/tv/go/src/github.com/kellydunn/go-art/art_tree.go:62 +0xa9
main.main()
/home/tv/tmp/max.go:16 +0x154
goroutine 2 [runnable]:
runtime.forcegchelper()
/home/tv/src/go1.4/src/runtime/proc.go:90
runtime.goexit()
/home/tv/src/go1.4/src/runtime/asm_amd64.s:2232 +0x1
goroutine 3 [runnable]:
runtime.bgsweep()
/home/tv/src/go1.4/src/runtime/mgc0.go:82
runtime.goexit()
/home/tv/src/go1.4/src/runtime/asm_amd64.s:2232 +0x1
goroutine 4 [runnable]:
runtime.runfinq()
/home/tv/src/go1.4/src/runtime/malloc.go:712
runtime.goexit()
/home/tv/src/go1.4/src/runtime/asm_amd64.s:2232 +0x1
exit status 2
As discovered by @nick-codes, it looks like inserting a unicode key into a new ArtTree panics with an index out of range error.
Here's some code to reproduce the error:
// Tests a Unicode insertion.
func TestArtTreeInsertWithInternalZeroByte(t *testing.T) {
tree := NewArtTree()
// โa' followed by unicode accent character.
accent := []byte{0x61, 0x00, 0x60}
tree.Insert([]byte("a"), "a")
tree.Insert(accent, string(accent))
res := tree.Search(accent)
if res == nil {
t.Errorf("Could not find Leaf Node with expected key: '%s'", accent)
} else {
if !bytes.Equal(res.([]byte), accent) {
t.Error("Unexpected search result.")
}
}
}
Acceptance critieria:
As requested by a few users, it seems like it would be pretty useful to access the inserted key of the current node. Currently, this isn't possible because the path compression implementation alters the key so it's null terminated to differentiate between an internal node and a leaf node.
Suggested implementation:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.