module Dict:This module implements the fundamental data structure of RASCL: the dictionary. This is a key-value structure whose keys are strings and whose values may be strings, lists, or dictionaries. Dictionaries have no fixed size, and their elements are mutable.sig..end
type t
type data =
| |
S of |
| |
L of |
| |
D of |
val create : ?locked:bool -> unit -> tDict.create ?locked () creates a new, empty dictionary. The
locked parameter indicates whether new nested dictionaries
may be added. Its default value is false, i.e. new nested
dictionaries are allowed.val get : ?prefix:string list -> string -> t -> dataDict.get ?prefix key dictionary retrieves the value associated
with key in dictionary, raising Not_found if the key is not
present. When retrieving an item from a subdictionary, ?prefix
may be used to specify the subdictionary.val set : ?prefix:string list -> string -> data -> t -> unitDict.set ?prefix key value dictionary sets the value for key
in dictionary to value. When setting a value in a subdictionary,
?prefix may be used to specify the subdictionary.val get_string : ?prefix:string list -> string -> t -> stringDict.get_string ?prefix key dictionary retrieves the value
associated with key as a string. The stored value should match
the pattern S s, otherwise an exception will be raised.
?prefix behaves as in Dict.get.val get_dict : ?prefix:string list -> string -> t -> tDict.get_dict ?prefix key dictionary retrieves the value
associated with key as a dictionary. The stored value should
match the pattern D d, otherwise an exception will be raised.
?prefix behaves as in Dict.get.val get_list : ?prefix:string list -> string -> t -> string listDict.get_list ?prefix key dictionary retrieves the value
associated with key as a list. The stored value should match
the pattern L l, otherwise an exception will be raised.
?prefix behaves as in Dict.get.val set_string : ?prefix:string list -> string -> string -> t -> unitDict.set_string ?prefix key value dictionary sets the value
for key in dictionary to S value. ?prefix behaves as in
Dict.set.val set_list : ?prefix:string list -> string -> string list -> t -> unitDict.set_list ?prefix key value dictionary sets the value
for key in dictionary to L value. ?prefix behaves as in
Dict.set.val set_dict : ?prefix:string list -> string -> t -> t -> unitDict.set_dict ?prefix key value dictionary sets the value
for key in dictionary to D value. ?prefix behaves as in
Dict.set.val copy : t -> tDict.copy dictionary returns a new dictionary whose elements
are copies of those in the original dictionary. This is a
deep-copy operation.
The following functions are similar to the iter, map, and
filter functions associated with other data structures. Note,
however, that there is no automatic recursion into subdictionaries.
If you require such recursion, you must supply an appropriate
recursive function. For example:
let rec f key value =
match value with
| S s -> ....
| L l -> ....
| D subdict -> Dict.iter f subdict
val iter : (string -> data -> unit) -> t -> unitDict.iter f dictionary applies f in turn to each element of
dictionary.val map : (string -> data -> data) ->
t -> tDict.map f dictionary applies f in turn to each element of
dictionary, returning a new dictionary whose values are the
results of f applied to each value in the original dictionary.val filter : (string -> data -> bool) -> t -> tDict.filter f dictionary applies f in turn to each element of
dictionary, returning a new dictionary whose elements are copies
of all those for which f returned true.val do_in : string list -> (t -> unit) list -> t -> unitDict.do_in context ff dictionary executes in turn a list of
functions, each of which takes a dictionary as its argument.
context specifies the subdictionary to which ff should be
applied; if context is an empty list, ff are applied to
dictionary.val get_from : string list -> string list -> t -> (string * data) listDict.get_from context keys dictionary retrieves an association
list of keys and values from dictionary, or from a subdictionary
identified by context.val set_in : string list -> (string * data) list -> t -> unitDict.set_in context elements dictionary sets the key-value
pairs specified by elements in dictionary, or in a subdictionary
identified by context.module Unsafe:sig..end