123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152(*
* Copyright (c) 2021 Tarides <contact@tarides.com>
* Copyright (c) 2021 Gabriel Belouze <gabriel.belouze@ens.psl.eu>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduletypeK=sigtypet(** The type for keys. *)typeinput_keyvalsize:intvalmin:t(* minimal key *)valof_input:input_key->tvalto_input:t->input_keyvalempty:tvalequal:t->t->bool(** The equality function for keys. *)valcompare:t->t->intvalset:marker:(unit->unit)->bytes->off:int->t->unitvalget:bytes->off:int->tvaldump:t->stringvalpp:Format.formatter->t->unitendmoduletypeV=sigtypet(** The type for values. *)typeinput_valuevalsize:intvalof_input:input_value->tvalto_input:t->input_valuevalset:marker:(unit->unit)->bytes->off:int->t->unitvalget:bytes->off:int->tvalpp:Format.formatter->t->unitendmoduletypeEntry=sigtypeinput_keytypeinput_valuemoduleKey:Kwithtypeinput_key=input_keymoduleValue:Vwithtypeinput_value=input_valueendmoduleMake:functor(InKey:Input.Key)(InValue:Input.Value)->Entrywithtypeinput_key=InKey.tandtypeinput_value=InValue.t=functor(InKey:Input.Key)(InValue:Input.Value)->structtypeinput_key=InKey.ttypeinput_value=InValue.tmoduleKey=structtypet=stringtypeinput_key=InKey.tletsize=InKey.encoded_sizeletempty=""letmin=Utils.min_keysizeletequal=String.equalletcompare=String.compareletset~markerbuff~offt=marker();Bytes.blit_stringt0buffoffsizeletgetbuff~off=Bytes.sub_stringbuffoffsizeletof_inputk=letret=InKey.encodekinassert(size=String.lengthret);retletto_input=InKey.decodeletdumps=sopenFmtletascii=String.map(func->letcode=Char.codecinif0x20<=code&&code<=0x7Ethencelse'.')letppppfs=pfppf"%a"(string|>styled(`Bg`Green)|>styled`Reverse)(asciis)endmoduleValue=structtypet=stringtypeinput_value=InValue.tletsize=InValue.encoded_sizeletset~markerbuff~offt=marker();Bytes.blit_stringt0buffoffsizeletgetbuff~off=Bytes.sub_stringbuffoffsizeletof_inputv=letret=InValue.encodevinassert(size=String.lengthret);retletto_input=InValue.decodeopenFmtletpp=string|>styled(`Bg`Blue)|>styled`Reverseendend