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

Invariants should be documented and tested #366

Closed
sjakobi opened this issue Mar 4, 2022 · 7 comments
Closed

Invariants should be documented and tested #366

sjakobi opened this issue Mar 4, 2022 · 7 comments

Comments

@sjakobi
Copy link
Member

sjakobi commented Mar 4, 2022

Information about invariants is scattered over the code and old issues. It would be good to collect it in one place and add tests or assertions to check that the invariants are upheld.

So far I'm aware of the following actual or supposed invariants:

  1. Empty can appear at the top-level, but never in the tree:

    -- We rely on there being no Empty constructors in the tree!
    -- This ensures that two equal HashMaps will have the same
    -- shape, modulo the order of entries in Collisions.
    equal1 :: Eq k

  2. The array in Full has size 2^bitsPerSubkey:

    -- Invariant: The length of the 1st argument to 'Full' is
    -- 2^bitsPerSubkey

  3. In BitmapIndexed b ary, popcount b == size ary (Add more detailed data structure information #161 (comment))

  4. When a BitmapIndexed contains only one subtree, that subtree is either a Full or BitmapIndexed node, but never Empty, Leaf or Collision.

  5. The size of the array in Collision is at least 2.

  6. The size of the array in BitmapIndexed is at least 1 and less than 2^bitsPerSubkey.

  7. No two keys in a HashMap are equal according to (==).

  8. The hashes in Leaf and Collision are those of the keys they contain.

  9. No two Hashes in a HashMap are the same (but in a Collision multiple keys have the same hash).

  10. In BitmapIndexed b ary, how exactly do the bits in b correspond to the elements of ary?

@treeowl
Copy link
Collaborator

treeowl commented Mar 4, 2022

There's also a file on development/contributing info that I think may have some.

@sjakobi
Copy link
Member Author

sjakobi commented Mar 4, 2022

There's also a file on development/contributing info that I think may have some.

I think you mean https://github.com/haskell-unordered-containers/unordered-containers/blob/master/docs/developer-guide.md. No additional invariants there AFAICT.

@sjakobi
Copy link
Member Author

sjakobi commented Mar 4, 2022

I have added these items to the issue description:

  • No two Hashes in a HashMap are the same (but in a Collision multiple keys have the same hash).
  • In BitmapIndexed b ary, how exactly do the bits in b correspond to the elements of ary?

@sjakobi
Copy link
Member Author

sjakobi commented Mar 20, 2022

TODO: Strictness invariants (#235 is related.)

This was referenced Apr 12, 2022
@sjakobi sjakobi self-assigned this Apr 26, 2022
sjakobi added a commit that referenced this issue Apr 26, 2022
Context: #366
sjakobi added a commit that referenced this issue Apr 26, 2022
Context: #366
@sjakobi sjakobi mentioned this issue Apr 26, 2022
3 tasks
sjakobi added a commit that referenced this issue Apr 27, 2022
Context: #366
sjakobi added a commit that referenced this issue May 3, 2022
@sjakobi
Copy link
Member Author

sjakobi commented May 3, 2022

#444 has added the basic tooling for invariant-checking. Most HashMap-producing functions still need tests though.

I'm pretty pleased with this progress, anyway! :)

@sjakobi
Copy link
Member Author

sjakobi commented May 3, 2022

Most HashMap-producing functions still need tests though.

This is tracked in #449.

@sjakobi sjakobi closed this as completed May 3, 2022
@treeowl
Copy link
Collaborator

treeowl commented May 3, 2022

Indeed. Sorry for the duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants