Skip to content

Instantly share code, notes, and snippets.

@jackfoxy
Created November 2, 2012 19:51
Show Gist options
  • Save jackfoxy/4003928 to your computer and use it in GitHub Desktop.
Save jackfoxy/4003928 to your computer and use it in GitHub Desktop.
Step one in creating a fold over a BinomialHeap
static member private foldHeapStep1 (h : list<BinomialTree<'a>>) =
let rec loop (h : list<BinomialTree<'a>>) cont =
match h with
| Node(_, a, [])::[] -> cont [a]
| Node(_, a, h')::[] -> loop h' (fun acc -> cont (a :: acc))
| Node(_, a, [])::tl -> loop tl (fun acc -> cont (a :: acc))
| Node(_, a, h')::tl -> loop h' (fun lacc -> loop tl (fun racc -> cont (a :: racc @ lacc)))
| _ -> failwith "can't get here"
loop h (fun x -> x)
static member private inOrderStep1 (h : list<BinomialTree<'a>>) = BinomialHeap.foldHeap h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment