-
Notifications
You must be signed in to change notification settings - Fork 297
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
Counted Set #132
base: main
Are you sure you want to change the base?
Counted Set #132
Commits on Oct 10, 2021
-
This module will contain CountedSet and potentially other multiset implementations.
Configuration menu - View commit details
-
Copy full SHA for 7ec883e - Browse repository at this point
Copy the full SHA 7ec883eView commit details
Commits on Nov 1, 2021
-
Similar to other collections in the package, CountedSet is backed by an internal _storage property, and exposes an initializer for preallocating storage.
Configuration menu - View commit details
-
Copy full SHA for 88524bf - Browse repository at this point
Copy the full SHA 88524bfView commit details
Commits on Nov 4, 2021
-
Add Sequence conformance to MultiSets.CountedSet
Sequence conformance is implemented by iterating over the stored elements, repeating according to each stored count.
Configuration menu - View commit details
-
Copy full SHA for 4375f7c - Browse repository at this point
Copy the full SHA 4375f7cView commit details
Commits on Dec 4, 2021
-
Add Collection conformance to MultiSets.CountedSet
Collection conformance is implemented by using the index of an element in the underlying storage along with a position to distinguish between copies of the same element.
Configuration menu - View commit details
-
Copy full SHA for e43e7d2 - Browse repository at this point
Copy the full SHA e43e7d2View commit details -
Add ExpressibleByDictionaryLiteral conformance to MultiSets.CountedSet
The implementation requires all elements to be unique and all multiplicities to be positive. Tests have been added for initializing empty CountedSets with and without a minimum capacity.
Configuration menu - View commit details
-
Copy full SHA for 0c5fd75 - Browse repository at this point
Copy the full SHA 0c5fd75View commit details -
Change MultiSets.CountedSet.RawValue.Value to UInt
Using unsigned integers for multiplicity of an element in a counted set makes it much clearer that negative values are not allowed. Initializing a counted set with a dictionary literal can now be done with any given multiplicity. Negative values are now barred by the compiler, and multiplicities of zero can simply be discarded. This change necessitated a slight tweak to the way iteration is performed: since Swift.repeatElement(_:count:) requires Int counts, multiple calls are used for multiplicities larger than Int.max. CountedSet.count will trap on cardinalities larger than Int.max, as with most Sequences.
Configuration menu - View commit details
-
Copy full SHA for a379f8c - Browse repository at this point
Copy the full SHA a379f8cView commit details -
Customize implementation of MultiSets.CountedSet.count
The custom implementation of count adds the multiplicities of the elements together, which is far more efficient than the default approach of iterating through the set manually. underestimatedCount has also been customized: it exposes the count of the underlying dictionary, which is guaranteed to be less than or equal to the cardinality of the counted set itself. This may be used to avoid trapping for sets with very large multiplicities.
Configuration menu - View commit details
-
Copy full SHA for 1c567ea - Browse repository at this point
Copy the full SHA 1c567eaView commit details -
Add SetAlgebra conformance to MultiSets.CountedSet
Each requirement has been implemented according to the mathematical definitions, complete with careful documentation to ensure users understand how that may diverge from expectations. Because Swift.Dictionary does not specify time complexity for every method being used, part of the implementation cannot either. Tests have been added to exercise all of the SetAlgebra implementation, including each of the axioms required by SetAlgebra.
Configuration menu - View commit details
-
Copy full SHA for 89fd08f - Browse repository at this point
Copy the full SHA 89fd08fView commit details -
Implement sum operation for MultiSets.CountedSet
This operation adds the multiplicities of each element together. A test has been added to cover it.
Configuration menu - View commit details
-
Copy full SHA for e77d82c - Browse repository at this point
Copy the full SHA e77d82cView commit details