-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HashMapT salt, which allows creation of salt with Nat.
This allows clients to create custom salted hashmaps. For backwards compatibility we use ```haskell -- backwards compatibility type HashMap = HashMapT DefaultSalt ``` Then modify the functions to be free of salt if they can, for example insert: ```haskell insert :: forall k v salt . (Eq k, Hashable k) => k -> v -> HashMapT salt k v -> HashMapT salt k v insert k v m = insert' (hash salt k) k v m where salt = natVal (Proxy :: Proxy salt) ``` This allows the default HashMap with backwards compatibility, but also any other HashMapT I think this solves the issue with having different salts in an intersect: ```haskell intersection :: (Eq k, Hashable k) => HashMapT salt k v -> HashMapT salt k w -> HashMapT salt k v ``` Because salt is the same type variable for all arguments, it's enforced to be the same. Then you can also provide a function to resalt if the user ever ends up with different salts and still wants to do an intersect. (which results in a reconstruction of the hashmap). See thread: #319 I know these libraries will at least fail with the changes because they have instances on `HashMap`, which now need to be `HashMapT salt`: quickcheck-instances-0.3.25.2.drv semirings-0.6.drv relude-0.7.0.0.drv semigroupoids-5.3.5.drv I did this by stubbing out unordered containers in a 100k loc codebase to see what issues would come up in CI.
- Loading branch information
Showing
10 changed files
with
437 additions
and
229 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
The salt changes are backwards compatible. | ||
|
||
However, if you want to let a client make use of | ||
custom salts some effort is required, | ||
running commands like these should get you somewhere: | ||
|
||
```ed | ||
:%s/HashMap k/HashMapT salt k/g | ||
:%s/Hashable k)/Hashable k, KnownNat salt) | ||
``` | ||
|
||
HashMap is now an alias to HashMapT with a hardcoded DefaultSalt. | ||
These changes allow salt to be anything. | ||
semigroup operations (a -> a -> a) can use the same salt to guarantee | ||
not having to rebuild the hahsmap. | ||
|
||
|
||
If you encounter this error: | ||
``` | ||
• Illegal instance declaration for ‘SomeTypeClass (HashMap k v)’ | ||
(All instance types must be of the form (T t1 ... tn) | ||
where T is not a synonym. | ||
Use TypeSynonymInstances if you want to disable this.) | ||
``` | ||
usually it's good enough to provide the instance with a free salt: | ||
|
||
```haskell | ||
instance SomeTypeClass (HashMap salt k v) where | ||
... | ||
|
||
``` | ||
If it it starts complaining about not salt not matching DefaultSalt, | ||
use the `'` constructors such as `empty'` and `singleton'` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters