123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869(*
* Copyright (c) 2018-2021 Tarides <contact@tarides.com>
*
* 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.
*)open!ImportincludePack_index_intfmoduleMake(K:Irmin.Hash.S)=structmoduleKey=structtypet=K.t[@@derivingirmin]lethash=Irmin.Type.(unstage(short_hashK.t))?seed:Nonelethash_size=30letequal=Irmin.Type.(unstage(equalK.t))letencode=Irmin.Type.(unstage(to_bin_stringK.t))letencoded_size=K.hash_sizeletdecode_bin=Irmin.Type.(unstage(decode_binK.t))letdecodesoff=let_,v=decode_binsoffinvendmoduleVal=structtypet=int63*int*Pack_value.Kind.t[@@derivingirmin]letencoded_size=(64/8)+(32/8)+1letencode((off,len,kind):t)=letbuf=Bytes.createencoded_sizeinBytes.set_int64_bebuf0(Int63.to_int64off);Bytes.set_int32_bebuf8(Int32.of_intlen);Bytes.setbuf12(Pack_value.Kind.to_magickind);Bytes.unsafe_to_stringbufletdecodespos:t=letbuf=Bytes.unsafe_of_stringsinletoff=Bytes.get_int64_bebufpos|>Int63.of_int64inletlen=Bytes.get_int32_bebuf(pos+8)|>Int32.to_intinletkind=Bytes.getbuf(pos+12)|>Pack_value.Kind.of_magic_exnin(off,len,kind)endmoduleStats=Index.StatsmoduleIndex=Index_unix.Make(Key)(Val)(Index.Cache.Unbounded)includeIndex(** Implicit caching of Index instances. TODO: Require the user to pass Pack
instance caches explicitly. See
https://github.com/mirage/irmin/issues/1017. *)letcache=Index.empty_cache()letv=Index.v~cacheletadd?overcommittkv=replace?overcommittkvletfindtk=matchfindtkwithexceptionNot_found->None|h->Somehletcloset=Index.closetend