diff --git a/src/dune b/src/dune index 540a6bb..3725251 100644 --- a/src/dune +++ b/src/dune @@ -1,5 +1,5 @@ (library (name mew) (public_name mew) - (libraries result) + (libraries result trie) (flags (:standard -safe-string))) diff --git a/src/trie.ml b/src/trie.ml deleted file mode 100644 index 00b6a24..0000000 --- a/src/trie.ml +++ /dev/null @@ -1,78 +0,0 @@ -(* - * trie.ml - * ----------- - * Copyright : (c) 2019 - 2020, ZAN DoYe - * Licence : MIT - * - * This file is a part of mew. - *) - -module type S = 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): (S 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 - diff --git a/src/trie.mli b/src/trie.mli deleted file mode 100644 index 7b0d44f..0000000 --- a/src/trie.mli +++ /dev/null @@ -1,39 +0,0 @@ -(* - * trie.mli - * ----------- - * Copyright : (c) 2019 - 2020, ZAN DoYe - * Licence : MIT - * - * This file is a part of mew. - * This module implements strict impure trie tree data structure. - *) - -module type S = - sig - (** type of path point *) - type path - - (** type of trie node *) - type 'a node - - (** create a new trie tree with or without an 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 - - (** [is_leaf node] returns whether the [node] is leaf *) - val is_leaf: 'a node -> bool - end - -module Make (H : Hashtbl.HashedType): S with type path= H.t list -