Source

(***********************************************************************)(* *)(* OCamlSpotter *)(* *)(* Jun FURUSE *)(* *)(* Copyright 2008-2012 Jun Furuse. All rights reserved. *)(* This file is distributed under the terms of the GNU Library *)(* General Public License, with the special exception on linking *)(* described in file LICENSE. *)(* *)(***********************************************************************)(* Set with binary custom search *)moduletypeOrderedType=Set.OrderedTypemoduletypeS=sigincludeSet.Svalmiddle:t->eltoptionvalfind:elt->t->eltoptionendmoduleMake(Ord:OrderedType):Swithtypeelt=Ord.t=structincludeSet.Make(Ord)(* find the middle element in [t] *)letmiddlet=ifis_emptytthenNoneelseletfound=refNoneintryignore(filter(funelt->found:=Someelt;raiseExit)t);assertfalsewith|Exit->!found(* find the "same" element as [elt] in [t] *)letrecfindeltt=matchmiddletwith|None->None|Someelt'->matchOrd.compareeltelt'with|0->Someelt'|-1->letl,present,_=splitelt'tinassertpresent;findeltl|1->let_,present,r=splitelt'tinassertpresent;findeltr|_->assertfalseend