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

Is the PatriciaTree matchGr too strict? #96

Open
noughtmare opened this issue Nov 3, 2020 · 0 comments
Open

Is the PatriciaTree matchGr too strict? #96

noughtmare opened this issue Nov 3, 2020 · 0 comments

Comments

@noughtmare
Copy link

noughtmare commented Nov 3, 2020

I was trying to figure out the time complexity of suc which lead me to the matchGr function.

matchGr :: Node -> Gr a b -> Decomp Gr a b
matchGr node (Gr g)
= case IM.lookup node g of
Nothing
-> (Nothing, Gr g)
Just (p, label, s)
-> let !g1 = IM.delete node g
!p' = IM.delete node p
!s' = IM.delete node s
!g2 = clearPred g1 node s'
!g3 = clearSucc g2 node p'
in (Just (toAdj p', node, label, toAdj s), Gr g3)

All the work being done with the bang patterns does not seem to be necessary for the suc function as far as I can tell. I think the strict evaluation could cause the asymptotic complexity of the suc function to change from O(k + min(n,W)) (where k is the number of nodes in the output and n and W are the familiar IntMap variables) to O(n) (because of the clearPred and clearSucc functions). Should this be rewritten to:

 matchGr :: Node -> Gr a b -> Decomp Gr a b 
 matchGr node (Gr g) 
     = case IM.lookup node g of 
         Nothing 
             -> (Nothing, Gr g) 
  
         Just (p, label, s) 
             -> let g1 = IM.delete node g 
                    p' = IM.delete node p 
                    s' = IM.delete node s 
                    g2 = clearPred g1 node s' 
                    g3 = clearSucc g2 node p' 
                in (Just (p' `seq` toAdj p', node, label, toAdj s), g3 `seq` Gr g3) 

Or something similar.

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

No branches or pull requests

1 participant