Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file byte_labeled_dag.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112# 1 "Camomile/internal/byte_labeled_dag.ml"(** Dag *)(* Copyright (C) 2002 Yamagata Yoriyuki *)(* This library 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 2 of *)(* the License, or (at your option) any later version. *)(* As a special exception to the GNU Library General Public License, you *)(* may link, statically or dynamically, a "work that uses this library" *)(* with a publicly distributed version of this library to produce an *)(* executable file containing portions of this library, and distribute *)(* that executable file under terms of your choice, without any of the *)(* additional requirements listed in clause 6 of the GNU Library General *)(* Public License. By "a publicly distributed version of this library", *)(* we mean either the unmodified Library as distributed by the authors, *)(* or a modified version of this library that is distributed under the *)(* conditions defined in clause 3 of the GNU Library General Public *)(* License. This exception does not however invalidate any other reasons *)(* why the executable file might be covered by the GNU Library General *)(* Public License . *)(* This library 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 library; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *)(* USA *)(* You can contact the authour by sending email to *)(* yoriyuki.y@gmail.com *)typebytes_node={bytes_leaf_offset:int;bytes_leaf:Bytesvect.t;bytes_default:int;bytes_branch_offset:int;bytes_branch:(bytes_nodeoption)array}typebytes=bytes_nodeletrecsearch_arrayxia=ifArray.lengtha<=i||a.(i)<>xthenielsesearch_arrayx(i+1)aletrecsearch_backward_arrayxia=ifi<0||a.(i)<>xthenielsesearch_backward_arrayx(i-1)aletmake_bytesdefvs=letmake_nodeleafbranch=letleaf_offset=search_arraydef0leafinletbranch_offset=search_arrayNone0branchinletleaf_last=search_backward_arraydef255leafinletbranch_last=search_backward_arrayNone255branchinletleaf_len=max0(leaf_last-leaf_offset+1)inletbranch_len=max0(branch_last-branch_offset+1)inleta=Bytesvect.makeleaf_lendefinletb=Array.subbranchbranch_offsetbranch_leninfori=0toBytesvect.lengtha-1doBytesvect.setaileaf.(leaf_offset+i)done;{bytes_leaf_offset=leaf_offset;bytes_leaf=a;bytes_default=def;bytes_branch_offset=branch_offset;bytes_branch=b}inletrecscandcleafbranch=function[]->(make_nodeleafbranch,[])|(s,n)::restasvs->ifString.lengths<=d||d>=0&&s.[d]<>cthen(make_nodeleafbranch,vs)elseletc'=s.[d+1]inifString.lengths=d+2thenbeginleaf.(Char.codec')<-n;scandcleafbranchrest;endelseletleaf'=Array.make256definletbranch'=Array.make256Noneinletnode,rest=scan(d+1)c'leaf'branch'vsinbranch.(Char.codec')<-Somenode;scandcleafbranchrestinletcomp(s1,_)(s2,_)=Pervasives.compares1s2inletvs=List.sortcompvsinmatchvswith(_,_)::_->letleaf=Array.make256definletbranch=Array.make256Noneinlettbl,_=scan~-1'\000'leafbranchvsintbl|_->invalid_arg"Broken table"letlook_leaf_bytestblb=leti=b-tbl.bytes_leaf_offsetinifi<0||i>=Bytesvect.lengthtbl.bytes_leafthentbl.bytes_defaultelseBytesvect.gettbl.bytes_leafiletlook_branch_bytestblb=leti=b-tbl.bytes_branch_offsetinifi<0||i>=Array.lengthtbl.bytes_branchthenNoneelsetbl.bytes_branch.(i)