GithubHelp home page GithubHelp logo

go-radix's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-radix's Issues

[Question] Router any paths

Hi,

Before anything, great package ๐Ÿ‘

I'm creating an personal web framework and I need to route my routes ๐Ÿ˜„. I'm studying and find a possible solution, use radix tree, and found this package.

But I've a problem, how to route the path if I catch a path with parameters ?

Ex.:

package main

import (
	"fmt"

	radix "github.com/armon/go-radix"
)

func main() {

	r := radix.New()

	r.Insert("/a/b/c/:d", 1)
	r.Insert("/a/b/n/:d", 2)
	r.Insert("/a/t/u/:i", 2)

	m, _, _ := r.LongestPrefix("/a/b/c/test")

	fmt.Println(m) // Don't match path

}

In this scene this code not match my path, but should. Can you help me, it is possible to do?

Tks

t.Delete() doesn't actually free memory

I have a high traffic server where I'm maintaining prefix trees of a number of data sets with tens of thousands to millions of elements. When keys expire, I'm removing them from the tree. However, memory usage is still increasing. I believe this is because t.Delete() doesn't clean up n.edges[] when an element is deleted and also because the string slicing for n.prefix holds onto the underlying strings, not allowing them to be freed once the keys are no longer referenced.

concurrency

Can this be used from multiple concurrent goroutines?

Can you tag a release?

There are some commits after the latest release, most notably this one f30034d -- could you just create a new release tag?

Safe for concurrent use?

It a question and sorry for asking this here. Is it safe to use it concurrently for getting and inserting nodes? Or maybe I have to implement locks?

Does it support unicode?

Since go-radix stores characters as bytes instead of runes, I'd guess not. Or am I missing something?

Insert can be 25% faster, using 28% fewer allocations

Sorry for the drive by. This is a useful package and I've made extensive changes to my version. There is an easy performance improvement. If you like it, you can take it, no attribution necessary. If not, feel free to close with no further comment.

The numbers I quoted in the header are for benchmarks when 10,000 entries are added to a tree. The order of insertions doesn't matter. They can be ordered, unordered, and even reverse ordered. Always 28% fewer allocations occur.

The package requires the edges are kept sorted. Currently the addEdge method performs a full sort after appending the new edge. Using the same binary search other parts of the package use, the insertion point can be found exactly. The binary search is much more efficient than the sort.

Replace

func (n *node) addEdge(e edge) {
	n.edges = append(n.edges, e)
	n.edges.Sort()
}

with

func (n *node) addEdge(e edge) {
	num := len(n.edges)
	idx := sort.Search(num, func(i int) bool {
		return n.edges[i].label >= e.label
	})

	n.edges = append(n.edges, edge{})
	copy(n.edges[idx+1:], n.edges[idx:])
	n.edges[idx] = e
}

Queryable Sub-trees?

I see that the implementation is recursive, but this isn't exposed in the public API. For example it would be powerful to get a reference to a sub-tree and then to be able to query it the same as the root tree.

I don't have the time to deep dive into the implementation, so I was hoping you could answer this for me: Is there any technical reason why non-root Nodes can't be exposed and queried like the root Node? Is there some quirk in the implementation that prevents this, that requires all queries to be made from the root?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.