Replies: 5 comments 12 replies
-
This is great!
It looks like this view in particular is where it comes in handy to keep track of both the "total weight" and the "size" of each subtree as you were saying above, right? That way the total weight of the multiset is its Juggling that terminology is a bit awkward. What I really want to say is that the multiset's |
Beta Was this translation helpful? Give feedback.
-
@mflatt For HAMTs, Racket's HAMTs don't have the size and weight features needed to implement the proposed collection views. Do you think it would be better to extend and reuse Racket's HAMTs, or to make a new HAMT implementation for Rhombus? |
Beta Was this translation helpful? Give feedback.
-
On stencil vectors and HAMTs: "Compiler and Runtime Support for HAMTS", Sona Torosyan |
Beta Was this translation helpful? Give feedback.
-
I didn't know the terminology, so I'll copy the definition from the other thread in case it's useful for others:
|
Beta Was this translation helpful? Give feedback.
-
This was the discussion topic at the May 26th meeting. We discussed the following:
|
Beta Was this translation helpful? Give feedback.
-
This is an extension of #201. I've been thinking about persistent collections lately so I figured I'd write my thoughts down.
To provide a good collections library, we'll need some good immutable data structures. This discussion proposes three persistent data structures we can use as building blocks to build the rest of the persistent collections library:
A sized tree is a tree where each branch node records the total number of transitive children that branch has. A weighted tree is a tree where each leaf node, in addition to containing some user-supplied data, also contains a positive integer weight, and each branch contains the total weight of that branch. Recording the size of each subtree makes the
size()
operation trivially constant-time for all collections, but much more crucially, it enables efficient random access into the trees. Recording weights is similarly useful for collections like multisets where each leaf may correspond to many elements. With these data structures, we can implement the following persistent collections:#false
(or some other constant) (Racket already does this)#false
and whose weights are the number of times the element occurs in the multiset#false
#false
and whose weights are the number of times the element occurs in the multisetAdditionally, we can implement the following collection views:
This lets us perform many complex queries on these collections efficiently. Here are some examples, with
xs[a..b]
being the syntax for selecting a subrange of a collection where botha
andb
endpoints are optional:xs[..10].size
xs.asList[..5]
xs.uniqueElements[10..20].size
xs.entries.asList[..5]
xs[10..20].asMap.values
Out of scope for this discussion
This discussion only covers persistent immutable collections. Non-persistent immutable collections backed by flat arrays and optimized for read-only use are out of scope for now. Those are important to have for performance, but the persistent implementations need to come first since the non-persistent ones would have to switch to the persistent implementations upon first modification.
Also, I'm not touching mutable collections yet. Those deserve their own separate discussion.
Beta Was this translation helpful? Give feedback.
All reactions