Comments (7)
Not currently, but it is something we want to implement.
from rpds.
Are you open to pull requests?
from rpds.
Sure, PRs are welcomed :)
from rpds.
So I've been looking into how best to implement the range function. Would it be worth it to add a parent reference to each node? That way we can create a range iterator that will be very optimized.
For example: suppose a tree of the following. If I range from 3..9 (all inclusive) I start an inorder traversal, arrive at 3 and give back an iterator. Now all I need to do on each .next()
is continue the inorder traversal until I reach 9.
5
/ \
3 8
/ \ / \
2 4 7 9
That said, this all requires that we add a parent reference to each node. This would offer big savings in very large trees.
from rpds.
I don't think you need the a parent field to do this efficiently. Take a look at how the current iterator works: it maintains a stack that will let you go to the parent node.
Try to modify the current iterator (and the normal iterator just calls the "range" iterator with the range (Unbounded, Unbounded)
).
You need to change dig()
:
rpds/src/map/red_black_tree_map/mod.rs
Lines 1135 to 1149 in b713506
to not go left unless left is within the range.
from rpds.
I've taken a look at this, and it seems there's a choice to be made: if I try to reuse the existing ArcIter
implementation then I need to get rid of size_hint
, since there's no efficient way to initialize left_index
and right_index
unless we're iterating over the whole tree. An alternative would be to introduce a new struct (RangeIter
say). That would cause some code duplication, though.
Do you have any thoughts?
from rpds.
Good point: it will not be a implement ExactSizeIterator
. I think we can have the best of both worlds: we can have a RangeIter
that does not override size_hint()
and does not implement ExactSizeIterator
.
Then we can make Iter
just a wrapper around a RangeIter
(with range (Unbounded, Unbounded)
). Iter
will still implement ExactSizeIterator
, but it only needs to have logic to maintain {right,left}_index
from rpds.
Related Issues (20)
- Remove best case from the complexity tables
- Implement optimizations in Vector
- Debug shows internal data in all data structures and iterators
- Avoiding stackoverflow when dropping large List HOT 3
- Add feature to provide Trace and Finalize impls for https://github.com/Manishearth/rust-gc
- HAMP vs CHAMP
- Implement .range_index() for RedBlackTreeMap/RedBlackTreeSet HOT 1
- Memory Usage for Debugging HOT 4
- Is this stable for handling large scale data (> 10^8) HOT 1
- Finger Trees HOT 1
- faster slicing for vectors? HOT 3
- `RedBlackTreeSet`'s docs mention non-existent `get` operation HOT 2
- Consider re-exporting archery items
- Consider providing a .pop_with_value() helper on Stack and List
- Support custom allocator HOT 1
- Serializing multiple instances efficiently HOT 1
- extract variants of remove on HashTrieMap and RedBlackTreeMap
- Add a "feature" to remove _mut methods HOT 4
- Opening doc. HOT 1
- Non-empty containers HOT 1
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 rpds.