Skip to content

Instantly share code, notes, and snippets.

@jackfoxy
Created November 3, 2012 17:36
Show Gist options
  • Save jackfoxy/4008071 to your computer and use it in GitHub Desktop.
Save jackfoxy/4008071 to your computer and use it in GitHub Desktop.
Step four in creating a fold over a BinomialHeap
static member private foldHeapStep4 nodeF leafV (h : list<BinomialTree<'a>>) =
let rec loop (h : list<BinomialTree<'a>>) cont =
match h with
| Node(_, a, [])::[] -> loop [] (fun lacc ->
loop [] (fun racc ->
cont (nodeF a lacc racc)))
| Node(_, a, h')::[] -> loop h' (fun lacc ->
loop [] (fun racc ->
cont (nodeF a lacc racc)))
| Node(_, a, [])::tl -> loop [] (fun lacc ->
loop tl (fun racc ->
cont (nodeF a lacc racc)))
| Node(_, a, h')::tl -> loop h' (fun lacc ->
loop tl (fun racc ->
cont (nodeF a lacc racc)))
| _ -> cont leafV
loop h (fun x -> x)
static member private inOrderStep4 (h : list<BinomialTree<'a>>) =
let x = (BinomialHeap.foldHeap (fun x l r acc -> l (x :: (r acc))) (fun acc -> acc) h)
x []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment