Skip to content
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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Counted Set #132

wants to merge 9 commits into from

Commits on Oct 10, 2021

  1. Add MultiSets product

    This module will contain CountedSet and potentially other multiset
    implementations.
    Saklad5 committed Oct 10, 2021
    Configuration menu
    Copy the full SHA
    7ec883e View commit details
    Browse the repository at this point in the history

Commits on Nov 1, 2021

  1. Add CountedSet storage

    Similar to other collections in the package, CountedSet is backed by an internal _storage property, and exposes an initializer for preallocating storage.
    Saklad5 committed Nov 1, 2021
    Configuration menu
    Copy the full SHA
    88524bf View commit details
    Browse the repository at this point in the history

Commits on Nov 4, 2021

  1. Add Sequence conformance to MultiSets.CountedSet

    Sequence conformance is implemented by iterating over the stored elements, repeating according to each stored count.
    Saklad5 committed Nov 4, 2021
    Configuration menu
    Copy the full SHA
    4375f7c View commit details
    Browse the repository at this point in the history

Commits on Dec 4, 2021

  1. 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.
    Saklad5 committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    e43e7d2 View commit details
    Browse the repository at this point in the history
  2. 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.
    Saklad5 committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    0c5fd75 View commit details
    Browse the repository at this point in the history
  3. 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.
    Saklad5 committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    a379f8c View commit details
    Browse the repository at this point in the history
  4. 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.
    Saklad5 committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    1c567ea View commit details
    Browse the repository at this point in the history
  5. 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.
    Saklad5 committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    89fd08f View commit details
    Browse the repository at this point in the history
  6. Implement sum operation for MultiSets.CountedSet

    This operation adds the multiplicities of each element together.
    
    A test has been added to cover it.
    Saklad5 committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    e77d82c View commit details
    Browse the repository at this point in the history