-
Notifications
You must be signed in to change notification settings - Fork 122
Add set operations to @immut/hash{map, set}
and @internal/sparse_array
Summary
#2145
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
base: main
Are you sure you want to change the base?
Conversation
…ence methods, now they can handle branchs
Potential memory inefficiency in intersection implementationCategory (Branch(sa1), Branch(sa2)) => {
let res = sa1.intersection(sa2, fn(m1, m2) { m1.intersection(m2) })
match res.size() {
0 => Empty
_ => Branch(res)
}
} Reasoning Missing documentation for type parameters in function signaturesCategory ///| Computes the intersection of two hashmaps
/// K: Key type that must implement Eq + Hash
/// V: Value type
/// f: Function to resolve conflicts between values
pub fn[K : Eq + Hash, V] intersection_with(...) Reasoning Multiple traversals in union_with implementationCategory |
Pull Request Test Coverage Report for Build 6935Details
💛 - Coveralls |
…ence methods, now they can handle branchs
44c0a79
to
eb6ef82
Compare
Add set operations to @immut/hash{map, set} and @internal/sparse_array Summary and re-fmt
other : T[K, V], | ||
f : (K, V, V) -> V | ||
) -> T[K, V] { | ||
match (self, other) { |
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.
can we just make it a method pub fn[K : Eq + Hash, V] T::union_with(
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.
Sure!😊 It's just that I don't quite understand why this was done. When I added this method, I observed that other methods didn't make such modifications
Related Issue
Fixes #1830: Efficient set operations for @immut/hash{map, set}
Changes
@immut/hashmap
union_with(f: (K, V, V) => V)
Merges two hashmaps, resolving key conflicts with a custom function
f
.intersection()
Returns a new hashmap containing keys present in both input maps, with values from the first map.
intersection_with(f: (K, V, V) => V)
Computes intersection, resolving overlapping keys' values with function
f
.difference()
Returns entries present in the first map but not in the second.
@immut/hashset
intersection()
Returns a new set containing elements common to both input sets.
difference()
Returns elements present in the first set but not in the second.
@internal/sparse_array
intersection()
Computes index-wise intersection of two sparse arrays.
difference()
Computes index-wise difference between two sparse arrays.
Motivation
These changes provide a more complete and consistent set of set operations for immutable collections, making it easier to perform common set algebra tasks and improving API parity across collection types.
Tests
Added and updated unit tests for all new and modified methods to ensure correctness and expected behavior.
Checklist
All new and existing tests pass
Code is formatted and documented where appropriate