Comments (2)
Since writing this, have you discovered any issues with your implementation suggestion?
from go-radix.
No problems. The whole design requires the slice of edges remain in sort order so it makes sense to take advantage of that when adding an edge. And there are lots of examples of go code using the results of sort.Search for inserting and for using copy to create the space needed for the insertion.
Of course it also has to work when the list being added to is empty and it does that too. So no problems.
For those to whom speed really matters, I'll point out that the three places addEdge is called can be further optimized. I've gone with removing the addEdge method completely and using a new insertEdge method that takes the insertion index too because even the binary search in addEdge was unnecessary - in the first usage, the edge list had already been searched and found not to contain the edge - hence the call to addEdge, so I used the result of the getEdge binary search; in the second call to addEdge, the list is known to be empty so I passed an index of 0 to insertEdge, and in the third case, where we know the list of edges is size one, I added the code to test whether the new label was less than or greater than the existing label so could pass an insert index of 0 or 1.
Finally, I later found examples in the go std library where they expanded the call to sort.Search. It is a surprisingly small, easy piece of code, once one has it (one 'for' loop, no recursion), and it can be nice not having to create a closure to perform the binary search when the input is just a slice of bytes and a byte. I don't know if the go compiler will ever be smart enough to optimize that kind of thing away on its own.
from go-radix.
Related Issues (10)
- t.Delete() doesn't actually free memory
- Does it support unicode? HOT 3
- [Question] Router any paths HOT 1
- Queryable Sub-trees? HOT 2
- Safe for concurrent use? HOT 1
- concurrency HOT 2
- I want to ask a low-level question, is this an adaptive radix tree? HOT 1
- sort.Search is too slow...
- Can you tag a release?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-radix.