-
Notifications
You must be signed in to change notification settings - Fork 126
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
Conversation
…ence methods, now they can handle branchs
Inconsistent naming pattern in method declarationsCategory Redundant checks in hashset intersectionCategory Missing documentation for type constraints in hashmap intersection operationCategory |
Pull Request Test Coverage Report for Build 7010Details
💛 - 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
The issues I reported seem to still exist in the merged PR. Here's the test evidence showing the problematic behavior ///|
priv type MyInt Int derive(Eq, Show)
///|
impl Hash for MyInt with hash_combine(_, _) {
panic()
}
///|
impl Hash for MyInt with hash(self) {
self._
}
///|
test {
let m1 = new().add(MyInt(0b1_00001), 1)
let m2 = m1.add(MyInt(0b11_00001), 1)
inspect(m1.to_array(), content="[(MyInt(33), 1)]")
inspect(m2.to_array(), content="[(MyInt(33), 1), (MyInt(97), 1)]")
inspect(m2.difference(m1).to_array(), content="[]") // should be [(MyInt(97), 1)]
} Another example without test {
let m1 = for i = 0, m1 = new(); i < 100; {
continue i + 1, m1.add(i, i)
} else {
m1
}
let m2 = m1.add(200, 200)
inspect(m2.difference(m1), content="@immut/hashmap.of([])") // should be [(200, 200)]
} |
Sorry, it seems that I mistakenly associated the issue. Please ignore my operation🙂 |
…arse_array` (moonbitlang#2145) * feat: add four new functions to HAMT and their tests * fix(union_with): fix union_with for HAMT,now it can handle branch * feat(sparse_array): add intersection and difference methods * fix(HAMT): fix union_with, intersection, intersection_with and difference methods, now they can handle branchs * feat(hashset): add intersection and difference methods to hashset * commit other files * feat: add four new functions to HAMT and their tests * fix(union_with): fix union_with for HAMT,now it can handle branch * feat(sparse_array): add intersection and difference methods * fix(HAMT): fix union_with, intersection, intersection_with and difference methods, now they can handle branchs * feat(hashset): add intersection and difference methods to hashset * style: change the position of some function declarations * fix: fix formatting of the code * feat: Update the function declarations of hash tables and sparse arrays * refactor:update mbti * refactor: update hashmap and hashset function signatures to include type prefix --------- Co-authored-by: 东灯 <me@lampese.com>
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