Skip to content

Instantly share code, notes, and snippets.

@zinid
Created October 23, 2017 22:29
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 zinid/1da345fcde47f5e6a799288f66ee3857 to your computer and use it in GitHub Desktop.
Save zinid/1da345fcde47f5e6a799288f66ee3857 to your computer and use it in GitHub Desktop.
(** Need ocaml >= 4.04
Compile:
$ ocamlopt -unsafe -o zinid zinid.ml *)
let rec split keys values =
match input_line stdin with
| exception _ ->
(keys, values)
| s ->
match String.split_on_char ' ' s with
| [k; v] ->
split (k::keys) ((String.trim v)::values)
| _ ->
(keys, values)
let _ =
let keys, values = split [] [] in
let keys' = Array.of_list (List.rev keys) in
let values' = Array.of_list (List.rev values) in
let buf = Buffer.create 10000 in
for i = 0 to Array.length keys' - 1 do
for j = 0 to Array.length values' - 1 do
Buffer.add_string buf keys'.(i);
Buffer.add_string buf values'.(j);
Buffer.add_char buf '\n';
if ((j mod 1000) = 0) then (
Buffer.output_buffer stdout buf;
Buffer.clear buf
)
done
done;
Buffer.output_buffer stdout buf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment