Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active March 18, 2017 21:09
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 kunigami/d0cf8389d9026c72c9e955711211c341 to your computer and use it in GitHub Desktop.
Save kunigami/d0cf8389d9026c72c9e955711211c341 to your computer and use it in GitHub Desktop.
let conformToInvariants (queue: 'a queueSuspended): ('a queueSuspended) =
let queue = conformToFrontNotSmallerThanRear queue
in conformToForcedFrontInvariant queue
;;
let push (queue: 'a queueSuspended) (elem: 'a): ('a queueSuspended) =
match queue with (forcedFront, frontSize, lazyFront, rearSize, rear) ->
conformToInvariants (
forcedFront,
frontSize,
lazyFront,
rearSize + 1,
elem :: rear
)
;;
let pop (queue: 'a queueSuspended): ('a queueSuspended) = match queue with
| ([], _, _, _, _) -> raise Empty_queue
| (head :: forcedFront, frontSize, lazyFront, rearSize, rear) ->
conformToInvariants (
forcedFront,
frontSize - 1,
lazy (List.tl (Lazy.force lazyFront)),
rearSize,
rear
)
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment