Code Monkey home page Code Monkey logo

Comments (5)

rtheunissen avatar rtheunissen commented on May 17, 2024

Something like a BST, with an in-order traversal?

from ext-ds.

rtheunissen avatar rtheunissen commented on May 17, 2024

You could easily create something like this around a PriorityQueue, can't you? You can use an internal Sequence as a buffer.

from ext-ds.

rtheunissen avatar rtheunissen commented on May 17, 2024

Just coming back to this to clarify what I meant by using a sequence as a buffer. You can pop all the items in the queue into a sequence (tuple would be better in 2.0) as you process (for example emit events), then push them all back into the priority queue.

Would be best to push them back in from highest to lowest priority to reduce the number of swaps that the priority would need to do.

from ext-ds.

nikic avatar nikic commented on May 17, 2024

@rtheunissen It might make sense to allow constructing the PQ from an array. You can construct a heap in O(n) time, while pushing into a heap element-wise is O(n log n).

from ext-ds.

rtheunissen avatar rtheunissen commented on May 17, 2024

@nikic What would the structure of the array be? Pairs of value/priority? It also just occurred to me that in order for the intermediary to work we'd have to pop the priority along with the value, as the priority it was inserted with might not be known at the time.

A better strucuture for the suggested use case might just be a sequence then, that you sort in O(n log n) after registering the events, or insert into using a binary search, which I think would be an O(log n) insert but the buffer unshift would make it a worst case O(n log n).

🤔

from ext-ds.

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.