Abstract data types to be used in specifications
This module implements mappings from values of an arbitrary type
(specified by a generic instantiation parameter) to unique definition table
keys.
It is instantiated by
$/Adt/Table.gnrc +instance=NAME +referto=TYPE :inst
where NAME identifies the table instance and TYPE
is the type of the values being mapped to definition table keys.
Note: if TYPE is not a type that is predefined in C then its
definition must be made available by some .head specification.
Each table is implemented by a dynamically allocated memory with a 32-bit
address space.
The user must supply a hash function to compute a 32-bit value that
characterizes a given TYPE value.
If TYPE is representable in 32 bits, then this function is simply an
identity function that casts the given value to type ub4
(representing an unsigned 32-bit value).
Otherwise the general hash function available in the Eli library can
compute an appropriate value
(see Computing a Hash Value of Solutions of common problems).
Each element of the memory may hold more than one table entry; the user
must supply a comparison function to verify that a particular table entry
is the one sought.
If TYPE values are ordered, this function should return an integer
less than, equal to, or greater than zero when its first TYPE
argument is less than, equal to, or greater than its second.
Otherwise, the function must return zero if its TYPE arguments are
equal, and an integer greater than zero if they are unequal.
The following functions are supplied by the module:
void NAMEInitTable (ub4 (*hash)(TYPE), int (*cmp)(TYPE, TYPE))
- Initializes the table.
hash is the hash function on TYPE values,
and cmp is the comparison function on TYPE values.
DefTableKey NAMEKeyInTable (TYPE v)
- Yields the definition table key associated with the value
v .
If there is no definition table key associated with the value v
then NAMEKeyInTable yields NoKey .
DefTableKey NAMEDefInTable (TYPE v)
- Yields the definition table key associated with the value
v .
If there is no definition table key associated with the value v
then NAMEDefInTable associates the value v with a new
definition table key and yields that key.
These functions can be used in specifications
of type .lido , .init , .finl , and .con .
They can also be used in .pdl specifications or in C modules
if the interface file NAMETable.h is imported there.
|