Skip to content

Instantly share code, notes, and snippets.

@jackfoxy
Created November 2, 2012 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackfoxy/4004030 to your computer and use it in GitHub Desktop.
Save jackfoxy/4004030 to your computer and use it in GitHub Desktop.
Step two in creating a fold over a BinomialHeap
static member private foldHeapStep2 c1 c2 c3 (t : list<BinomialTree<'a>>) =
let rec loop (h : list<BinomialTree<'a>>) cont =
match t with
| Node(_, a, [])::[] -> cont (c1 [a])
| Node(_, a, h')::[] -> loop h' (fun acc -> cont (c2 a acc))
| Node(_, a, [])::tl -> loop tl (fun acc -> cont (c2 a acc))
| Node(_, a, h')::tl -> loop h' (fun lacc ->
loop tl (fun racc ->
cont (c3 a lacc racc)))
| _ -> failwith "can't get here"
loop h (fun x -> x)
static member private inOrderStep2 (h : list<BinomialTree<'a>>) = BinomialHeap.foldHeap (fun acc -> acc) (fun a acc -> a::(acc)) (fun x l r -> x :: r @ l) h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment