Comments (5)
Would this work in your case?
var list []interface{}
bt.Ascend(start, func(item interface{}) bool {
if filter(item) {
list = append(list, item)
}
})
var hint btree.PathHint
for _, item := range list {
bt.DeleteHint(item, &hint)
}
from btree.
Thanks for the reply. That would work in my case, yes. I wanted to avoid the accumulation, but you're probably right that's the most reasonable thing to do. Closing for now.
I do think it would make sense to have Ascend/Descend being able to start where it left off without redoing the full search.
from btree.
I wanted to avoid the accumulation
What I've done in the past is something like:
var list []interface{}
var next interface{}
var hint btree.PathHint
for {
list = list[:0]
more := false
bt.Ascend(next, func(item interface{}) bool{
if len(list) == 256 {
next = item
more = true
return false
}
if filter(item) {
list = append(list, item)
}
return true
})
for _, item := range list {
bt.DeleteHint(item, &hint)
}
if !more {
break
}
}
Which accumulates in chunks of no more than a predetermined size, in this case 256 items.
Ascend/Descend being able to start where it left off without redoing the full search.
Yeah. A AscendHint and DescendHint would be nice. Or even a Cursor type with Cursor.Next() and Cursor.Prev()
from btree.
That's an interesting hybrid. It would be interesting to see how that benchmarkas against a non-batching AscendHint/DeleteHint. Since you would seem to accept a PR for AscendHint, I might code something up for that.
Or even a Cursor type with Cursor.Next() and Cursor.Prev()
If Delete-in-Ascend is unsafe, I think it's actually better to just cause a deadlock if you try, so I'd suggest keeping only the callback API.
from btree.
To loop back: I ran some benchmarks, and in the scenarios I tried to conjure up, I couldn't see any performance improvement over batch-slice-delete. So I don't think it's worth pursuing until someone comes up with a case where it does matter.
from btree.
Related Issues (20)
- Generics HOT 8
- ADMIN
- The Map[K, V].find() API design discussion HOT 4
- With go1.18rc1 getting error: constraints: package constraints is not in GOROOT HOT 10
- Seek does not initialize iter item HOT 4
- MapIter[K,V] Seek method does not initialize the item HOT 2
- Documentation for Get() is inaccurate
- Use of interface{} and constant type/length keys
- Breaking changes in switching from uint64 to atomic.Uint64 HOT 1
- Does btree.Map use concurrency locks? HOT 2
- Investigate if we can re-use allocated memory after `Map.Clear()` HOT 1
- How does copy-on-write actually work?
- Map for pre-generics version of Go
- possible panic when writing from multiple goroutines HOT 1
- is b+ tree surport? HOT 5
- add put method to set kvpairs , if old value exists, return val
- Do we need a rebalancing process for the btree? HOT 2
- question about crash during iteration (probably because of mutation during iteration) HOT 2
- PathHint on Map/Set?
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 btree.