Giter Site home page Giter Site logo

Comments (5)

tidwall avatar tidwall commented on May 24, 2024

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.

tommie avatar tommie commented on May 24, 2024

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.

tidwall avatar tidwall commented on May 24, 2024

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.

tommie avatar tommie commented on May 24, 2024

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.

tommie avatar tommie commented on May 24, 2024

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)

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.