| 1 | (************************************************************************) |
| 2 | (* * The Rocq Prover / The Rocq Development Team *) |
| 3 | (* v * Copyright INRIA, CNRS and contributors *) |
| 4 | (* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 | (* \VV/ **************************************************************) |
| 6 | (* // * This file is distributed under the terms of the *) |
| 7 | (* * GNU Lesser General Public License Version 2.1 *) |
| 8 | (* * (see LICENSE file for the text of the license) *) |
| 9 | (************************************************************************) |
| 10 | |
| 11 | (** Generic functorized trie data structure. *) |
| 12 | |
| 13 | module type S = |
| 14 | sig |
| 15 | (** A trie is a generalization of the map data structure where the keys are |
| 16 | themselves lists. *) |
| 17 | |
| 18 | type label |
| 19 | (** Keys of the trie structure are [label list]. *) |
| 20 | |
| 21 | type data |
| 22 | (** Data on nodes of tries are finite sets of [data]. *) |
| 23 | |
| 24 | type t |
| 25 | (** The trie data structure. Essentially a finite map with keys [label list] |
| 26 | and content [data Set.t]. *) |
| 27 | |
| 28 | val empty : t |
| 29 | (** The empty trie. *) |
| 30 | |
| 31 | val get : t -> data |
| 32 | (** Get the data at the current node. *) |
| 33 | |
| 34 | val next : t -> label -> t |
| 35 | (** [next t lbl] returns the subtrie of [t] pointed by [lbl]. |
| 36 | @raise Not_found if there is none. *) |
| 37 | |
| 38 | val labels : t -> label list |
| 39 | (** Get the list of defined labels at the current node. *) |
| 40 | |
| 41 | val add : label list -> data -> t -> t |
| 42 | (** [add t path v] adds [v] at path [path] in [t]. *) |
| 43 | |
| 44 | val remove : label list -> data -> t -> t |
| 45 | (** [remove t path v] removes [v] from path [path] in [t]. *) |
| 46 | |
| 47 | val iter : (label list -> data -> unit) -> t -> unit |
| 48 | (** Apply a function to all contents. *) |
| 49 | |
| 50 | end |
| 51 | |
| 52 | module type Grp = |
| 53 | sig |
| 54 | type t |
| 55 | val nil : t |
| 56 | val is_nil : t -> bool |
| 57 | val add : t -> t -> t |
| 58 | val sub : t -> t -> t |
| 59 | end |
| 60 | |
| 61 | module Make (Label : Set.OrderedType) (Data : Grp) : S |
| 62 | with type label = Label.t and type data = Data.t |
| 63 | (** Generating functor, for a given type of labels and data. *) |