![]() |
Section 8.16.1.2:
|
![]() |
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 ; $SEARCH_ELT = set of object_type state multi : $SEARCH_ELT inv multi_types == forall obj in set multi_types & sub_type($SEARCH_ELT,obj)
NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification. |
This abstract class models the concept of a searchable immutable string of any object kind which inherits from $IS_EQ. The features include forward and backward searching as well as matching and prefix operations.
It is frequently necessary to be able to recognise a key of some kind which indicates the start of some known sequence of data. This feature is provided to enable this to be done as needed.
is_prefix(self : SAME, try : SAME) res : BOOL
pre len try <= len self
post let test be st test ^ rest = self in res = (test = try)
This predicate returns true if and only if try is identical to the elements starting at the beginning of self.
This feature enables the first occurrence of some individual element value to be found in the string.
search(self : SAME, try : ELT) res : CARD
Since the domain of the result is larger than that of the string length, the pre-condition is vacuously true.
post (self(res + 1) = try and not exists elem | elem in set elems self(1, ..., res) & elem = try) or (res = CARD.nil)
This feature returns the index in self at which the first occurrence of try is to be found. If there is no such occurrence then CARD::nil shall be returned.
This feature enables the first occurrence of some individual element value to be found in the string, starting the search at the given index.
search2(self : SAME, try : ELT, start : CARD) res : CARD
post (self(res + 1) = try and not exists elem in set elems self((start + 1), ..., res) & elem = try) or (res = CARD.nil)
This feature returns the index in self at which the first occurrence of try is to be found, starting to search at the given start index. If there is no such occurrence then CARD::nil shall be returned.
This feature returns the index of the first element of the first occurrence of the string try in self.
search3(self : SAME, try : SAME) res : CARD
Since the domain of the result is larger than that of the string length, the pre-condition is vacuously true.
post let fndidx = res + 1 in (self(fndidx, ...,(fndidx + len try - 1)) = try and forall idx | idx in set inds self(1, ..., res) & not substr(idx, ..., (idx + len try - 1)) = try) or (res = CARD.nil)
This feature returns the index in self at which the first occurrence of try is to be found. If there is no such occurrence then CARD::nil shall be returned.
This feature enables finding the first occurrence of the start of the first occurrence of the string try to be found in the string, starting the search at the given index.
search4(self : SAME, try : SAME, start : CARD) res : CARD
pre start < len self
post let fndidx = res + 1 in (self(fndidx, ...,(fndidx + len try - 1)) = try and forall idx | idx in set inds self((start + 1), ..., res) & not substr(idx, ..., (idx + len try - 1)) = try) or (res = CARD.nil)
This feature returns the index in self at which the first occurrence of try is to be found, starting to search at the given start index. If there is no such occurrence then CARD::nil shall be returned.
This feature enables the first occurrence of some individual element value to be found in the string starting to search backwards from the end of the string.
search_backwards | ( |
try : ELT | |
) : CARD |
search_backwards(self : SAME, try : ELT) res : CARD
Since the domain of the result is larger than that of the string length, the pre-condition is vacuously true.
post (self(res + 1) = try and not exists elem in set elems self(res + 2), ..., len self) & elem = try) or (res = CARD.nil)
This feature returns the index in self at which a backward search starting from the end first finds try. If there is no such occurrence then CARD::nil shall be returned.
This feature enables the next occurrence of try is to be found starting a backward search from the given index. Note that if the element is found at the starting index that is returned.
search_backwards | ( |
try : ELT | |
start : CARD | |
) : CARD |
search_backwards2(self : SAME, try : ELT, start : CARD) res : CARD
pre start < len self
post (self(res + 1) = try and not exists elem in set elems self((res + 2), ..., (start + 1)) & elem = try) or (res = CARD.nil)
This feature returns the index in self at which the next occurrence of elem is to be found, searching backwards from the given start index. If there is no such occurrence then CARD::nil shall be returned.
This feature returns the index of the first element of the two strings which is different.
mismatch(self : SAME, other : SAME) res : CARD
Since the domain of the result is larger than the size of either argument, this pre-condition is vacuously true.
post (is_prefix(other,self) and res = CARD.nil) or (res = len other) or ((forall idx | idx in set inds other(1, ..., res) & self(idx) = other(idx)) and self(res + 1) <> other(res + 1))
Matching elements at the same index in self and other, this feature returns the index of the first element of self and other which have different element values; CARD::nil is returned if self is a prefix of other.
![]() |
Language Index | ![]() |
Library Index | ![]() |
String Index |
Comments
or enquiries should be made toKeith Hopper. Page last modified: Sunday, 25 March 2001. |
![]() |