mourner / flatqueue Goto Github PK
View Code? Open in Web Editor NEWA very fast and simple JavaScript priority queue
License: ISC License
A very fast and simple JavaScript priority queue
License: ISC License
Hi!
I noticed that you only reduce this.length
in pop()
and clear()
, but don't actually update ids
. That means if I store large objects (e.g. DOM nodes) in the queue, they might not get garbage collected even if my code has no other references to them.
I don't know what the performance impact would be to always shrink ids
. In any case, it should be safe to assign undefined
to the unused indexes.
I tried using FlatQueue but accidentally mixed up id
and value
parameters.
I was under the impression that id
would be some order-index, whereas value
would be the actual data associated with that element. However, in reality it's the other way around.
The naming of the id
parameter is what led to this confusion.
Before I understood the issue, I even wrote a wrapper because I wanted to pop the data associated with the element (instead of the order-index), because I thought FlatQueue only allowed popping the order-index.
The naming of the peek()
/ peekValue()
functions made my confusion worse.
Even when I understood this, it also wasn't clear to me wether the order-index (value
parameter) had to be an integer, or wether it could also be a rational number. It was also unclear wether the order-index could be negative.
And lastly, it also wasn't clear what happens if the same order-index is used multiple times.
It's also not clear how people should check for items in the queue: while(flatqueue.length > 0)
or while(flatqueue.peekValue() !== undefined)
; for API stability, this should probably be documented.
Since I'm trying to implement Dijkstra's algorithm, I want to be able to update the priority of an already existing entry in the queue.
Currently, once a FlatQueue was filled, it will use a considerable amount of memory, even when the queue is less full (even after a clear
).
That happens because the FlatQueue itself will only use this.length
to track the size of the queue, but the ids
and values
arrays will never be shrunk again (to match the current this.length
).
There should be a way to trigger a cleanup of the queue, or it should clean up after itself using some heuristic.
Add support for being able to use require instead of import.
This is useful when working with Node.js and you for some reason can't use ES modules
It's great that there are TypeScript types, but they currently don't exist in the npm version. Could a new version including them be pushed?
Trying to take this advice in the README: https://github.com/mourner/flatqueue#using-typed-arrays
But Typescript is not happy:
I am using flatqueue v2.0.3.
What am I doing wrong here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.