oxson / rrb.rhm Goto Github PK
View Code? Open in Web Editor NEWWIP: an RRB-tree implementation of a persistent vector in Rhombus
WIP: an RRB-tree implementation of a persistent vector in Rhombus
Store the last node's-worth of elements separately from the tree itself to allow constant time access and update near the end of the vector. Clojure does this. Nicolas Stucki's version includes a generalized notion of a tail called a 'focus' or 'display', that moves the constant-time accessible portion to most recently accessed. So operations near the same portion of the tree that has been touched most recently will be fast. Do we want this? Maybe.
method take(n :: Int) :: Tree
method drop(n :: Int) :: Tree
method splitAt(idx :: Int) :: Tree
per Matthew's feedback
At the point where you worry about performance, the
leaf
function may
need to be converted into a macro that constructs a vector more
directly. Right now,leaf
will build up a list to receive its
arguments, and then have toapply
thevec
function to that list.
And then thevec
function will also receive the arguments in a fresh
list andapply
the#{vector-immutable}
function. It's possible that
inlining at the Racket or Chez Scheme level works better than I think,
but I don't think the intermediate list allocations will be optimized
away.
utils.rhm
, don't wrap racket's vector->immutable-vector
in a rhombus function, just export and rename to vec
leaf
a macro instead of a functionTest concatenating trees of differing heights
The main structure of the code is there, now, but it is not yet working as intended in some ways. The result of some_tree.concat(other_tree).to_list()
will always be as expected, but there are performance issues lurking and a lack of thorough testing involving trees of varied sizes as well as trees created through complex-ish series of operations including concats, appends, sets, etc.
as proposed in racket/rhombus-prototype#351
leftwise-dense nodes should not have sizes arrays. Currently all nodes created via concatenation except leaf nodes end up with sizes arrays. This means some future operations will take the slow path that should not. Example:
> check: Tree(leaf(& List.iota(32)), 32, 0).concat(Tree(leaf(& List.iota(32)), 32, 0)).root.sizes
~is #false
check: failed
got: Array(32, 64)
expected: #false
Note, though, that only the nodes along the join path of the new tree will get sizes arrays always set. So, for example:
> def (t, l, r):
def l:
for values(t = Tree()):
each i: List.iota(32^3)
t.add(i)
def r:
for values(t = Tree()):
each i: List.iota(32^3)
t.add(i + 32^3)
values(l.concat(r), l, r)
> values(l.balanced, r.balanced)
#true
#true
> t.root.balanced
#false
> t.root.size
2
> values(t.root.get(0).balanced, t.root.get(1).balanced)
#false
#false
> for values(balanced = #true):
each i: 0 .. t.root.get(0).size - 1
balanced && t.root.get(0).get(i).balanced
#true
> t.root.get(t.root.size - 1).balanced
#false
> for values(balanced = #true):
each i: 1 .. t.root.get(1).size
balanced && t.root.get(1).get(i).balanced
#true
> t.root.get(1).get(0).balanced
#false```
For ease of testing, it's nice to be able to change the branch factor / max width of a tree (it's much easier to write out a manual test for a 2 or 4-way branching tree than a 32-way branching tree), but in the end, this configuration capability is probably not needed and also probably negatively affects performance. What Clojure does is maintain separate copies of the code where one is parameterized and one is not (see here). We could do something like that, if maintaining parameterized capability is desired (maybe for future dev work / testing, maybe there is some actual production code use case)
Parameters
with_shift_inc(....)
stuffA 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.