123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)moduleInt=Belt_SetIntmoduleString=Belt_SetStringmoduleDict=Belt_SetDicttype('value,'id)id=('value,'id)Belt_Id.comparabletype('value,'id)cmp=('value,'id)Belt_Id.cmptype('value,'id)t={cmp:('value,'id)cmp;data:('value,'id)Dict.t}letfromArray(typevalueidentity)data~(id:(value,identity)id)=letmoduleM=(valid)inletcmp=M.cmpin{cmp;data=Dict.fromArray~cmpdata}letremoveme=let{cmp;data}=minletnewData=Dict.remove~cmpdataeinifnewData==datathenmelse{cmp;data=newData}letaddme=let{cmp;data}=minletnewData=Dict.add~cmpdataeinifnewData==datathenmelse{cmp;data=newData}letmergeMany({cmp;_}asm)e={cmp;data=Dict.mergeMany~cmpm.datae}letremoveMany({cmp;_}asm)e={cmp;data=Dict.removeMany~cmpm.datae}letunion({cmp;_}asm)n={data=Dict.union~cmpm.datan.data;cmp}letintersectmn=letcmp=m.cmpin{data=Dict.intersect~cmpm.datan.data;cmp}letdiffmn=letcmp=m.cmpin{cmp;data=Dict.diff~cmpm.datan.data}letsubsetmn=letcmp=m.cmpinDict.subset~cmpm.datan.dataletsplitme=letcmp=m.cmpinlet(l,r),b=Dict.split~cmpm.dataein(({cmp;data=l},{cmp;data=r}),b)letmake(typevalueidentity)~(id:(value,identity)id)=letmoduleM=(valid)in{cmp=M.cmp;data=Dict.empty}letisEmptym=Dict.isEmptym.dataletcmpmn=letcmp=m.cmpinDict.cmp~cmpm.datan.dataleteqmn=Dict.eq~cmp:m.cmpm.datan.dataletforEachUmf=Dict.forEachUm.datafletforEachmf=forEachUm(fun[@u]a->fa)letreduceUmaccf=Dict.reduceUm.dataaccfletreducemaccf=reduceUmacc(fun[@u]ab->fab)leteveryUmf=Dict.everyUm.datafleteverymf=everyUm(fun[@u]a->fa)letsomeUmf=Dict.someUm.datafletsomemf=someUm(fun[@u]a->fa)letkeepUmf={cmp=m.cmp;data=Dict.keepUm.dataf}letkeepmf=keepUm(fun[@u]a->fa)letpartitionUmf=letl,r=Dict.partitionUm.datafinletcmp=m.cmpin({data=l;cmp},{data=r;cmp})letpartitionmf=partitionUm(fun[@u]a->fa)letsizem=Dict.sizem.datalettoListm=Dict.toListm.datalettoArraym=Dict.toArraym.dataletminimumm=Dict.minimumm.dataletminUndefinedm=Dict.minUndefinedm.dataletmaximumm=Dict.maximumm.dataletmaxUndefinedm=Dict.maxUndefinedm.dataletgetme=Dict.get~cmp:m.cmpm.dataeletgetUndefinedme=Dict.getUndefined~cmp:m.cmpm.dataeletgetExnme=Dict.getExn~cmp:m.cmpm.dataelethasme=Dict.has~cmp:m.cmpm.dataeletfromSortedArrayUnsafe(typevalueidentity)xs~(id:(value,identity)id)=letmoduleM=(valid)in{cmp=M.cmp;data=Dict.fromSortedArrayUnsafexs}letgetDatam=m.dataletgetId(typevalueidentity)(m:(value,identity)t):(value,identity)id=letmoduleT=structtypenonrecidentity=identitytypenonrect=valueletcmp=m.cmpendin(moduleT)letpackIdData(typevalueidentity)~(id:(value,identity)id)~data=letmoduleM=(valid)in{cmp=M.cmp;data}letcheckInvariantInternald=Dict.checkInvariantInternald.data