Module LustreIndex
Indexes for lists, records, tuples and arrays in Lustre
In Lustre some indexes must be static at compile time, we can thus flatten all record, tuple and list values. The remaining indexes are array indexes, which we allow to be variable.
Array indexes are annotated with an expression denoting the bound. However, this bound is not considered when comparing array indexes, because two bounds of expressions can only be evaluated in a context. A syntactic comparison of bound expressions will fail to make expressions equal that should be equal, for example in node calls where the size of an input is parametrized by another input.
Lists in Lustre are similar to tuples, but they cannot be constructed, except as the inputs and outputs of node calls. Further, nested lists are to be flattened such that ((a,
b), c), (a, (b, c)) and (a, b, c) are identical.
- author
- Christoph Sticksel
type one_index=|RecordIndex of string|TupleIndex of int|ListIndex of int|ArrayIntIndex of int|ArrayVarIndex of LustreExpr.expr|AbstractTypeIndex of stringAn index element
type index= one_index listA sequence of indexes
val pp_print_one_index : bool -> Stdlib.Format.formatter -> one_index -> unitPretty-print a single index
val pp_print_index : bool -> Stdlib.Format.formatter -> index -> unitPretty-print an list of indexes
val string_of_index : bool -> index -> stringReturn a string representation of indexes
val empty_index : indexThe empty index
A trie of indexes
include Trie.S with type key = index
type key= indexType of keys in the trie
val empty : 'a tThe empty trie
val is_empty : 'a t -> boolReturn
trueif the trie is empty
val add : key -> 'a -> 'a t -> 'a tBind a value to the key in the trie
Overwrite if the value if the leaf already exists, fail if the sequence of keys is a prefix of a previous sequence, or if a previous sequence is a prefix of the given sequence.
val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b t -> 'c tval compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intComparision function on tries
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'bReduce trie to a value by applying the function to all values
val for_all : (key -> 'a -> bool) -> 'a t -> boolReturn
trueif the given predicate evaluates totruefor all key value pairs in the trie
val exists : (key -> 'a -> bool) -> 'a t -> boolReturn
trueif there is a key value pair in the trie for which the given predicate evaluates totrue
val filter : (key -> 'a -> bool) -> 'a t -> 'a tReturn a trie that only contains the key value pairs that satisfy the predicate
val cardinal : 'a t -> intReturn the number of bindings in the trie
val bindings : 'a t -> (key * 'a) listReturn an association list of key to bindings in the trie
The keys are returned in lexicographic order.
val min_binding : 'a t -> key * 'aval max_binding : 'a t -> key * 'aval choose : 'a t -> key * 'aval split : key -> 'a t -> 'a t * 'a option * 'a tval find : key -> 'a t -> 'aReturn the value for the key in the trie
val mapi : (key -> 'a -> 'b) -> 'a t -> 'b tReturn a new trie with the function applied to the values
The key is given as the first argument to the function.
val mem_prefix : key -> 'a t -> boolReturn
trueif there is a subtrie starting at the given key prefix
val values : 'a t -> 'a listReturn the values in the trie
The values are returned in lexicographic order.
val fold2 : (key -> 'a -> 'b -> 'c -> 'c) -> 'a t -> 'b t -> 'c -> 'cFold over two tries with identical keys
fold2 f t1 t2 aappliesfto each pair of values in oft1andt2that have identical keys. The keys are presented in lexicographic order. Raise exceptionInvalid_argument "Trie.fold2"if the sets of keys the trie are not equal
val map2 : (key -> 'a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tMap over two tries with identical keys
map2 f t1 t2appliesfto each pair of values in oft1andt2that have identical keys and produces a new trie from the result. The keys are presented in lexicographic order. Raise exceptionInvalid_argument "Trie.map2"if the sets of keys the trie are not equal
val iter2 : (key -> 'a -> 'b -> unit) -> 'a t -> 'b t -> unitIterate over two tries with identical keys
iter2 f t1 t2applies the unit valued functionfto each pair of values in oft1andt2that have identical keys. The keys are presented in lexicographic order. Raise exceptionInvalid_argument "Trie.iter2"if the sets of keys the trie are not equal.
val for_all2 : (key -> 'a -> 'b -> bool) -> 'a t -> 'b t -> boolCheck if all pairs of bindings in the trie satisfy the predicate
for_all2 p t1 t2returns true ifpevaluates to true for all pairs of bindings in t1 and t2 with identical keys. Raise exceptionInvalid_argument "Trie.for_all2"if the sets of keys the trie are not equal.
val exists2 : (key -> 'a -> 'b -> bool) -> 'a t -> 'b t -> boolCheck if there is a binding in the trie that satisfies the predicate
exists2 p t1 t2returns true ifpevaluates to true for at least one pair of bindings with identical keys int1andt2. Raise exceptionInvalid_argument "Trie.exists2"if the sets of keys the trie are not equal.
val subsume : 'a t -> key -> (key * 'a) list * 'a tReturn a new trie containing only entries with keys that are not subsets of the given key
subsume t kassumes that all keys in the triet, and the keykare sorted and do not contain duplicates. It returns a new trie with all entries for keys that are subsets ofkremoved.
val is_subsumed : 'a t -> key -> boolReturn
trueif there is a key in the trie such that all elements of that key are in the given key.is_subsumed t kassumes that all keys in the triet, and the keykare sorted and do not contain duplicates.
val pp_print_trie : (Stdlib.Format.formatter -> (key * 'a) -> unit) -> ('b, Stdlib.Format.formatter, unit) Stdlib.format -> Stdlib.Format.formatter -> 'a t -> unitPretty-print bindings in the trie with a printer for key and value pairs
pp_print_trie f s p tprints to the formatterpall bindings of the trie in lexicographic order of the keys with the printerffor key and value pairs. Each binding is separated by the format strings.
Helper Functions
val array_bounds_of_index : index -> LustreExpr.expr listReturn the list of bounds of the array indexes in the index
val array_vars_of_index : index -> StateVar.t listReturn the list of array variables of the array indexes in the index
val top_max_index : 'a t -> intIf the first index is a list, return the greatest integer in a trie of indexes. Return
(- 1)if the index is empty and fail withInvalid_argument "top_max_index"if the first index is not a list
val compatible_indexes : index -> index -> boolval pp_print_index_trie : bool -> (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unitPretty print a trie of indexes
val pp_print_trie_expr : bool -> Stdlib.Format.formatter -> LustreExpr.t t -> unitPretty print a trie with expressions