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

Add a map-based bag #9

Open
12 of 14 tasks
mwermelinger opened this issue Jan 6, 2024 · 0 comments
Open
12 of 14 tasks

Add a map-based bag #9

mwermelinger opened this issue Jan 6, 2024 · 0 comments
Assignees
Labels
effort: high These issues require the most work priority: medium type: feature New feature
Milestone

Comments

@mwermelinger
Copy link
Member

mwermelinger commented Jan 6, 2024

A bag (multiset) can be implemented as a map of items to their frequency.

In subfolder paddles, add a file bag.py:

  • The file imports Iterable and Hashable from collections.abc
  • Create a class HashTableBag. The docstring states that it implements a bag with a hash table (Python dictionary).
  • The class should have methods to
    • add one occurrence of an item (in this and the next two methods, the item parameter is annotated with type Hashable)
    • remove one occurrence of an item (do nothing if the bag hasn't the item)
    • return the frequency of an item (0 if it's not a member of the bag)
    • return the size of the bag (total number of items)
    • return a new bag with the union of two bags
    • return a new bag with the intersection of two bags
    • return a new bag with the difference of two bags
    • check if two bags are equal (same items, with the same frequency)
    • check if one bag is included in another (each item of the first bag occurs with the same of higher frequency in the second bag)
  • The __init__ method takes an optional iterable collection (type annotation: Iterable[Hashable]) as argument and adds all its items to the newly created bag, with a for loop as in stack.py.
  • Add a docstring to each method, including the method's complexity.
  • Add a docstring at the start of the file, explaining what bags are. (See stack.py for the structure of the explanation.)

In subfolder tests, add a file test_bag that tests the bag's methods following the structure described in CONTRIBUTING.md.

Doing all of the above requires some effort for a single person, so you may wish to do only part of it, e.g. the code or the docstrings or the tests, and leave the other parts to others. We can give guidance on how multiple people can work on a single issue.

@mwermelinger mwermelinger added effort: high These issues require the most work priority: medium type: feature New feature labels Jan 6, 2024
@mwermelinger mwermelinger added this to the Version 0.2 milestone Jan 31, 2024
@mwermelinger mwermelinger self-assigned this Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: high These issues require the most work priority: medium type: feature New feature
Projects
None yet
Development

No branches or pull requests

1 participant