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

Use smart insertion and deletion in alterF #289

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sjakobi
Copy link
Member

@sjakobi sjakobi commented Jul 22, 2020

No description provided.

@sjakobi
Copy link
Member Author

sjakobi commented Jul 22, 2020

@treeowl does this look like a good idea?

If so, I can extend it to alter and strict alterF.

@treeowl
Copy link
Collaborator

treeowl commented Jul 22, 2020

Sounds plausible. Please be sure to do some benchmarking.

@treeowl
Copy link
Collaborator

treeowl commented Feb 12, 2021

You have a chance to benchmark any?

@sjakobi
Copy link
Member Author

sjakobi commented Feb 28, 2021

You have a chance to benchmark any?

Not yet. I had a look at the existing benchmarks for alterF and noticed that all of these are being rewritten to use insert and delete under the hood. What would be good functors to benchmark the basic alterF and alterFEager with?

@sjakobi
Copy link
Member Author

sjakobi commented Feb 28, 2021

What would be good functors to benchmark the basic alterF and alterFEager with?

Maybe I can simply use something like

data Pair a = Pair a a

instance Functor Pair where
  fmap f (Pair a b) = Pair (f a) (f b)

@treeowl
Copy link
Collaborator

treeowl commented Feb 28, 2021 via email

@sjakobi
Copy link
Member Author

sjakobi commented Nov 29, 2021

FWIW, here's the Core diff for the current patch:

--- RHS size: {terms: 65, types: 88, coercions: 0, joins: 0/3}
+-- RHS size: {terms: 79, types: 99, coercions: 0, joins: 0/2}
 $walterF
   = \ @ f @ k @ v w w1 w2 w3 w4 ->
       case w3 of k1 { __DEFAULT ->
       case w4 of m { __DEFAULT ->
       case hash w1 k1 of { I# x# ->
-      let { $dEq = $p1Hashable w1 } in
       let { ipv = int2Word# x# } in
       let {
-        mv
-          = case $wlookupRecordCollision# $dEq ipv k1 m of {
-              (#_|#) ds1 -> Nothing;
-              (#|_#) ds1 -> case ds1 of { (# a, _i #) -> Just a }
+        lookupRes
+          = case $wlookupRecordCollision# ($p1Hashable w1) ipv k1 m of {
+              (#_|#) ds1 -> Absent;
+              (#|_#) ds1 -> case ds1 of { (# a, i #) -> Present a i }
             } } in
       fmap
         w
         (\ fres ->
            case fres of {
              Nothing ->
-               case mv of {
-                 Nothing -> m;
-                 Just x -> $wdelete' $dEq ipv k1 m
+               case lookupRes of {
+                 Absent -> m;
+                 Present ds dt -> $wdeleteKeyExists dt ipv k1 m
                };
-             Just v' -> $winsert' $dEq ipv k1 v' m
+             Just v' ->
+               case lookupRes of {
+                 Absent -> $winsertNewKey ipv k1 v' m;
+                 Present ds dt -> $winsertKeyExists dt ipv k1 v' m
+               }
            })
-        (w2 mv)
+        (w2
+           (case lookupRes of {
+              Absent -> Nothing;
+              Present x dt -> Just x
+            }))
       }
       }
       }

@sjakobi sjakobi force-pushed the sjakobi/alterF-smart-insert-delete branch from 0b39809 to 497aba5 Compare May 10, 2022 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants