Skip to content

Instantly share code, notes, and snippets.

@struktured
Last active July 11, 2016 09:10
Show Gist options
  • Save struktured/25c58f35baf0317538a37b681a8bbfcf to your computer and use it in GitHub Desktop.
Save struktured/25c58f35baf0317538a37b681a8bbfcf to your computer and use it in GitHub Desktop.
quick view of a ring buffer as an unordered array
(* Expose the entire array as fast as possible. Copying is avoided when the array is saturated.
If non empty, also return the position of the first element. *)
let to_array_fast b = length b |> function
| 0 -> A.empty, None
| len when A.length b.buf = len -> b.buf, Some b.start
| _ -> to_array b, Some 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment