1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(*
* 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.
*)includeContent_addressable_intfopen!Import(* FIXME: remove code duplication with irmin/content_addressable *)moduleCloseable(S:S)=structtype'at={closed:boolref;t:'aS.t}typekey=S.keytypevalue=S.valueletcheck_not_closedt=if!(t.closed)thenraiseIrmin.Closedletmemtk=check_not_closedt;S.memt.tkletfindtk=check_not_closedt;S.findt.tkletaddtv=check_not_closedt;S.addt.tvletunsafe_addtkv=check_not_closedt;S.unsafe_addt.tkvletbatchtf=check_not_closedt;S.batcht.t(funw->f{t=w;closed=t.closed})letcloset=if!(t.closed)thenLwt.return_unitelse(t.closed:=true;S.closet.t)letunsafe_append~ensure_unique~overcommittkv=check_not_closedt;S.unsafe_append~ensure_unique~overcommitt.tkvletunsafe_memtk=check_not_closedt;S.unsafe_memt.tkletunsafe_find~check_integritytk=check_not_closedt;S.unsafe_find~check_integrityt.tkletcleart=check_not_closedt;S.cleart.tletgenerationt=check_not_closedt;S.generationt.tletclear_keep_generationt=check_not_closedt;S.clear_keep_generationt.tletmake_closeablet={closed=reffalse;t}letget_open_exnt=check_not_closedt;t.tend