-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TreapMap union and intersection (#19)
`TreapMap.merge` is a very flexible way to merge two `TreapMap`s, but it has a couple of drawbacks: 1) It always visits every entry in both maps 2) It doesn't allow `null` values to be added to the result map (because `merge` treats `null` as meaning "remove this entry") The first issue can be a major performance problem if you're merging two large maps with a relatively small key intersection, and you only need to apply custom merge logic to the keys in the intersection. This turns out to be very common. To address this, we add new methods to `TreapMap`: ```kotlin public fun union( m: Map<K, V>, merger: (K, V, V) -> V ): TreapMap<K, V> public fun intersect( m: Map<K, V>, merger: (K, V, V) -> V ): TreapMap<K, V> ``` These apply the `merger` function only to the intersection of the two maps' keys, and don't permit `merger` to discard entries. `union` preserves all non-intersecting entries from both maps, while `intersect` discards them. We also add parallel versions of both functions, following the example of `merge`/`parallelMerge`. See Certora/EVMVerifier#6819 for an example of where this can be used to get some significant performance benefits.
- Loading branch information
Showing
7 changed files
with
367 additions
and
1 deletion.
There are no files selected for viewing
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
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
Oops, something went wrong.