pax_global_header00006660000000000000000000000064136005530460014514gustar00rootroot0000000000000052 comment=9dc8a84da277ed4a28d66cb148deb4f4cba1cbc2 trie-1.0.0/000077500000000000000000000000001360055304600124555ustar00rootroot00000000000000trie-1.0.0/.gitignore000066400000000000000000000001611360055304600144430ustar00rootroot00000000000000**/*.annot **/.\#* **/*~ **/Session.vim **/.*.swp **/*.o **/*.a **/*.so **/*.cm* .merlin _build trie.install trie-1.0.0/LICENSE000066400000000000000000000021031360055304600134560ustar00rootroot00000000000000The MIT License Copyright (c) 2019, ZAN DoYe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. trie-1.0.0/Makefile000066400000000000000000000003621360055304600141160ustar00rootroot00000000000000default: dune build install: dune install uninstall: dune uninstall doc: dune build @doc clean: dune clean runtest: dune runtest all-supported-ocaml-versions: dune build @install @runtest --workspace dune-workspace.dev --root . trie-1.0.0/VERSION000066400000000000000000000000061360055304600135210ustar00rootroot000000000000001.0.0 trie-1.0.0/dune-project000066400000000000000000000000341360055304600147740ustar00rootroot00000000000000(lang dune 1.0) (name trie) trie-1.0.0/src/000077500000000000000000000000001360055304600132445ustar00rootroot00000000000000trie-1.0.0/src/dune000066400000000000000000000001201360055304600141130ustar00rootroot00000000000000(library (name trie) (public_name trie) (flags (:standard -safe-string))) trie-1.0.0/src/trie.ml000066400000000000000000000036521360055304600145470ustar00rootroot00000000000000(* * trie.ml * ----------- * Copyright : (c) 2019, ZAN DoYe * Licence : MIT *) module type Intf = sig type path type 'a node val create : 'a option -> 'a node val get : 'a node -> path -> 'a option val set : 'a node -> path -> 'a -> unit val unset : 'a node -> path -> unit val sub: 'a node -> path -> 'a node option val is_leaf: 'a node -> bool end module Make (H:Hashtbl.HashedType): (Intf with type path= H.t list) = struct module Path = Hashtbl.Make(H) type path= H.t list type 'a node= { mutable value: 'a option; next: 'a node Path.t } let create value= { value; next= Path.create 0 } let append ?(value=None) node key= match Path.find node.next key with | child-> child | exception Not_found-> let child= create value in Path.replace node.next key child; child let rec set node path value= match path with | []-> node.value <- Some value | hd::tl-> match Path.find node.next hd with | child-> set child tl value | exception Not_found-> set (append node hd) tl value let rec get node path= match path with | []-> node.value | hd::tl-> match Path.find node.next hd with | child-> get child tl | exception Not_found-> None let unset node path= let rec unset node path= match path with | []-> node.value <- None; true | hd::tl-> match Path.find node.next hd with | child-> if unset child tl then if Path.length child.next = 0 && child.value = None then (Path.remove node.next hd; true) else false else false | exception Not_found-> false in unset node path |> ignore let rec sub node path= match path with | []-> Some node | hd::tl-> match Path.find node.next hd with | child-> sub child tl | exception Not_found-> None let is_leaf node= Path.length node.next = 0 end trie-1.0.0/src/trie.mli000066400000000000000000000015211360055304600147110ustar00rootroot00000000000000(** trie tree This module implements strict impure trie tree data structure. *) module type Intf = sig (** type of path point *) type path (** type of trie node *) type 'a node (** create a new trie tree with an optional element *) val create : 'a option -> 'a node (** returns the value associated with the path *) val get : 'a node -> path -> 'a option (** associate the value with the path *) val set : 'a node -> path -> 'a -> unit (** remove an association of the path *) val unset : 'a node -> path -> unit (** returns the sub node associated with the path *) val sub : 'a node -> path -> 'a node option (** returns whether the node is a leaf of the tree *) val is_leaf : 'a node -> bool end module Make (H : Hashtbl.HashedType) : Intf with type path= H.t list trie-1.0.0/trie.opam000066400000000000000000000006451360055304600143030ustar00rootroot00000000000000opam-version: "2.0" maintainer: "zandoye@gmail.com" authors: [ "ZAN DoYe" ] homepage: "https://github.com/kandu/trie/" bug-reports: "https://github.com/kandu/trie/issues" license: "MIT" synopsis: "Strict impure trie tree" dev-repo: "git://github.com/kandu/trie" build: [ ["dune" "build" "-p" name "-j" jobs] ] depends: [ "ocaml" {>= "4.02"} "dune" {>= "1.0"} ] synopsis: "Implementation of strict impure trie tree"