-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Immutable ordered finite maps and sets #561
base: master
Are you sure you want to change the base?
Conversation
// Check if set `s` is empty. | ||
// | ||
// O(1) | ||
def isEmpty[A](s: Set[A]): Bool = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could use empty?
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
In general, feel free to suggest better names everywhere, I really just took the first idea I had every time :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do this change consistently across the stdlib, if we decide for it
@@ -0,0 +1,714 @@ | |||
module map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #488, we agreed to use constructors like $collection_name
for array
, ref
, and bytes
. For example:
// Creates a new Array of size `size` filled with the value `init`
extern global def array[T](size: Int, init: T): Array[T]
// Allocates new bytes with the given `capacity`, setting its values to `0`.
extern io def bytes(capacity: Int): Bytes
// Creates a new reference with the initial value `init`.
extern global def ref[T](init: T): Ref[T]
There are two main ways to make a map
/ set
:
- empty
map
/set
map
/set
created from a (possibly unordered) list
Does the convention mention above apply anywhere here? Personally, I'd always use these namespaced: map::empty()
and map::fromList([...])
, but I'm interested in what y'all think.
libraries/common/set.effekt
Outdated
// Ordered finite set, backed by a `Map`. | ||
record Set[A](internal: Map[A, Unit]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a place where newtypes would be nice: I never want to leak the type Map[A, Unit]
outside, otherwise type Set[A] = Map[A, Unit]
would do. But packing it into a record might have some unpleasant consequences when benchmarking. Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use extern type Set[A]
with identity coercions, but that might get into the way of optimizations.
ee9d209
to
58c8510
Compare
3890ddd
to
889c0f8
Compare
Rebased on current |
Blocked on #629, I'll fix it there and then rebase. :) |
Cherry-picked from #561: adds arithmetic right shifts and a comprehensive test suite.
ef7d4a2
to
498b95f
Compare
I've been sitting on this code for almost 9 months now, it's about time we finalise it.
This PR adds immutable ordered maps and sets based on BB[α]-trees into the standard library.
Important caveat: These structures work only on the JS backend because it's the only one with a generic comparison primitive (#394).
Note that it might take a while before I'm happy with this code, I just want to put it out here in case someone wants to help out / to prevent somebody else from spending too much time on reimplementing this.
TODO:
///
for doc stringsintersection
!via
combinators inSet
actually inline