Sather Home Page

Section 8.1.1.5:
$HASH

abstract class $HASH

Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types

SAME = object_type ;
$HASH = set of object_type

state

multi : $HASH
inv multi_types ==
forall obj in set multi_types & sub_type($HASH,obj)
NOTE See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstract class defines the concept of an object of which a hash value may be derived which is uniform over the domain of CARD.


hash

This requirement provides a facility to hash a vlaue of the sub-typing class. The way in which this may be done depends on the class concerned and there can be no guarrantee of uniformity over the domain of cardinal numbers.

hash CARD
Formal Signature
hash(self : SAME) res : CARD
Pre-condition

Note that in contrast to a pre-condition written in Sather source code, in vdm-sl the type SAME is not an optional type and therefore self must exist, leading to the vacuous pre-condition - true.

Post-condition

Providing that the domain is larger than the range of values making up self then this feature yields a unique value. If the range of self is larger, then the mapping from self to result is no longer one-to-one.

post let hash_map = {obj |-> num | obj in set dom SAME & num in set dom nat1} in
let val = hash_map(self) in
res = val mod card dom CARD

This feature returns a numeric hash value which may be of use in hashing map (or other) containers.


Language Index Library Index Basic Index
Comments or enquiries should be made to Keith Hopper.
Page last modified: Monday, 26 February 2001.
Produced with Amaya