Skip to content

Use smart insertion and deletion in alterF#289

Draft
sjakobi wants to merge 1 commit into
masterfrom
sjakobi/alterF-smart-insert-delete
Draft

Use smart insertion and deletion in alterF#289
sjakobi wants to merge 1 commit into
masterfrom
sjakobi/alterF-smart-insert-delete

Conversation

@sjakobi

@sjakobi sjakobi commented Jul 22, 2020

Copy link
Copy Markdown
Member

No description provided.

@sjakobi

sjakobi commented Jul 22, 2020

Copy link
Copy Markdown
Member Author

@treeowl does this look like a good idea?

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

@treeowl

treeowl commented Jul 22, 2020

Copy link
Copy Markdown
Collaborator

Sounds plausible. Please be sure to do some benchmarking.

@treeowl

treeowl commented Feb 12, 2021

Copy link
Copy Markdown
Collaborator

You have a chance to benchmark any?

@sjakobi

sjakobi commented Feb 28, 2021

Copy link
Copy Markdown
Member Author

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

sjakobi commented Feb 28, 2021

Copy link
Copy Markdown
Member Author

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

treeowl commented Feb 28, 2021 via email

Copy link
Copy Markdown
Collaborator

@sjakobi

sjakobi commented Nov 29, 2021

Copy link
Copy Markdown
Member Author

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