1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(*
* Copyright (c) 2021 Craig Ferguson <craig@tarides.com>
* Copyright (c) 2018-2022 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!ImportincludeIndexable_intfmoduleMaker_concrete_key2_of_1(X:Maker_concrete_key1)=structtype('h,_)key='hX.keymoduleKey(H:Hash.S)(_:Type.S)=X.Key(H)moduleMake=X.MakeendmoduleOf_content_addressable(Key:Type.S)(S:Content_addressable.S)=structincludeStypehash=keytypekey=Key.tmoduleKey=structincludeKeytypenonrechash=hashletto_hashx=xendletindex_h=Lwt.return_somehletunsafe_addthv=unsafe_addthv>|=fun()->hendmoduleCheck_closed_store(CA:S)=structmoduleKey=CA.Keytype'at={closed:boolref;t:'aCA.t}typevalue=CA.valuetypekey=CA.keytypehash=CA.hashletmake_closeablet={closed=reffalse;t}letget_if_open_exnt=if!(t.closed)thenraiseStore_properties.Closedelset.tletmemtk=(get_if_open_exnt|>CA.mem)kletindexth=(get_if_open_exnt|>CA.index)hletfindtk=(get_if_open_exnt|>CA.find)kletaddtv=(get_if_open_exnt|>CA.add)vletunsafe_addtkv=(get_if_open_exnt|>CA.unsafe_add)kvletbatchtf=(get_if_open_exnt|>CA.batch)(funw->f{t=w;closed=t.closed})letcloset=if!(t.closed)thenLwt.return_unitelse(t.closed:=true;CA.closet.t)endmoduleCheck_closed(M:Maker)(Hash:Hash.S)(Value:Type.S)=structmoduleCA=M(Hash)(Value)includeCheck_closed_store(CA)letvconf=let+t=CA.vconfin{closed=reffalse;t}end