![]() |
Section 8.5.4.2.1: |
![]() |
This class specifies features appropriate to the abstraction of a mutable list from which it sub-types. The sub-typing from $ELT_NIL permits the definition of creation for an empty list.
This class implements lists of elements with mutable semantics. These may be viewed as extensible stacks. Like any list abstraction (eg linked lists) they serve as general container objects for holding collections of other objects. The requirement for this class is specified in order that implementations may provide a highly efficient list facility.
The following features are required to be implemented for this class in accordance with the specification given in the class $FLISTS{} of which this is a sub-type :-
The following features are required to be implemented for this class in accordance with the specification given in the class $LISTS{} of which $FLISTS{} is a sub-type :-
The following features are required to be implemented for this class in accordance with the specification given in the class $ARR{} of which $FLISTS{} is a sub-type :-
The following features are required to be implemented for this class in accordance with the specification given in the class $RO_ARR{} of which $FLISTS{} is a sub-type :-
The following features are required to be implemented for this class in accordance with the specification given in the class $CONTAINER{} of which $FLISTS{} is a sub-type :-
The following features are required to be implemented for this class in accordance with the specification given in $FILTERS of which $FLISTS{} is a sub-type :-
The following feature is required to be implemented for this class in accordance with the specification given in the class $COPY of which $FLISTS{} is a sub-type :-
The following features are required to be implemented for this class in accordance with the specification given in $ELT of which $FLISTS{} is a sub-type :-
The following features are required to be implemented for this class in accordance with the specifications given by inheritance in $STR of which $FLISTS{} is a sub-type :-
The following features are required to be implemented for this class in accordance with the specifications given by inheritance in $ELT_NIL of which this class is a sub-type :-
This feature creates and returns a list of the elements for which the argument is a textual representation.
This feature creates a new list, the elements of which are set to have the values represented in the string argument, the result having the size given by the number of elements in the src string.
This feature creates and returns a list of any kind of container which derives from the abstraction $ELT.
create_from | ( |
container : $ELT{ETP} | |
) : SAME |
Since the argument is not an optional type, the pre-condition is vacuously true.
This feature creates a new list, the elements of which are set to have the values of the elements in the given container in such a way that the order of elements in the sequence indexed for the result is the same as that of the argument.
This feature creates and returns a list of the required size all of the elements of which are nil.
create_empty_sized | ( |
size : CARD | |
) : SAME |
Since the argument is never negative, the pre-condition is vacuously true.
This feature creates a new list, the elements of which are set to have the value elt_nil.
This feature creates and returns a list of the elements from the cursor given, taking the start argument as the character which is expected as the first non-space character in the buffer and the finish argument as the non-space element in the buffer which closes the list source in the buffer.
build | ( |
cursor : STR_CURSOR, | |
start : CHAR, | |
finish : CHAR | |
) : SAME |
This feature creates a new list, the elements of which are set to have the values represented in the string argument, the result having the size given by the number of elements in the src string.
This feature provides a conventional stack operation for the list, successive calls returning items in LIFO order.
pop | : ETP |
This is vacuously true since the list itself is required to exist by the definition of this feature.
This routine removes the element at the head of the list and returns the object removed.
This feature provides a conventional stack operation for the list, always returning the item at the head of it.
top | : ETP |
This is vacuously true since the list itself is required to exist by the definition of this feature.
This routine returns the element at the head of the list.
This feature provides a mechanism for re-using, rather than re-creating a mutable list.
This is vacuously true since the list itself is required to exist by the definition of this feature.
This routine resets the list to be the empty list.
This feature returns the index of the first occurrence of the given element in the list.
Since the arguments are not optional this is vacuously true.
This feature searches the list from the beginning to find the first occurrence (if any) of the given element in the list. If the search was successful then the index where it was found is returned, otherwise CARD::nil.
This feature returns the result of appending the argument list to self.
append | ( |
list : SAME | |
) : SAME |
Since the arguments are not optional this is vacuously true.
This routine appends the given list to the end of a copy of self and returns the result. Self may be void; list must not be the same as self unless it is void!
This feature returns the result of appending the argument list to self destructively and should therefore be faster than append above.
concat | ( |
list : SAME | |
) : SAME |
Since the arguments are not optional this is vacuously true.
This routine appends the given list to the end of self and returns the result. Self may be void; list must not be the same as self unless it is void!
sublist( beg, num : CARD ) : SAME pre ~void(self) and (beg <= (loc - 1)) and (num <= (loc - beg)) post (result.size = num) -- and (result[0] = [beg]) is -- This routine returns a sublist of num entries starting at beg. -- Self may not be void. to_reverse pre true post (self.size = initial(self.size)) -- (initial([0]) = [size - 1]) is -- This routine sets self to be rearranged in the reverse order of -- elements. fill( elem : ETP ) pre ~void(self) post true -- should be every(bind(_.elt_eq(elem))) is -- This routine fills all elements of the list with the given element -- value. inds : ARRAY{CARD} pre ~void(self) post ((result.size = size) and (result[size - 1] = (size - 1))) is -- This routine produces an array containing the same number of elements -- as self, the individual elements of which contain a value corresponding -- to their index. delete( index : CARD ) : SAME pre ~void(self) and (index <= (loc - 1)) post (result.loc = (initial(loc) - 1)) is -- This routine returns the result of deleting the indexed element from -- self. delete_elt( elem : ETP ) : SAME pre ~void(self) and contains(elem) post (result.loc = (initial(loc) - 1)) is -- This routine returns the result of deleting the given element from -- self. delete_ordered( index : CARD ) : SAME pre ~void(self) and (index <= (loc - 1)) post (result.loc = (initial(loc) - 1)) is -- This routine returns the result of deleting the indexed element from -- self in such a way as to preserve the order of the list. delete_elt_ordered( elem : ETP ) : SAME pre ~void(self) and contains(elem) post (result.loc = (initial(loc) - 1)) is -- This routine returns the result of deleting the given element from -- self in such a way as to preserve the order of the list.This iter version and the one following complement the one inherited by this abstraction. This permits the first element yielded to be the element indexed by the start argument.
Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
For quit actions see the specification of the quit statement.
This iter yields the elements of self in order beginning with the element at the given starting index.
This iter version specifies both the element to yield first and the number of elements to be yielded.
Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
For quit actions see the specification of the quit statement.
This iter yields num elements of self in order beginning with the element at the given starting index.
This final version of the elt! iter specifies the element to yield first, the number of elements to be yielded and the index interval between the elements to be yielded.
Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
For quit actions see the specification of the quit statement.
This iter yields num elements of self in order beginning with the element at the given starting index, each element yielded being at an interval step (which may be negative) from the previous element yielded.
This is a specialised version of the text string representation routine which specifies the character which is to be treated as the separator between list elements in the text.
Since there is a representation of an empty list - as {}, the pre-condition is vacuously true.
This feature returns a text string consisting of the textual representation of each list element separated by the given character sep, enclosed in braces.
The remaining features of this class provide facilities for set-like operations on mutable lists. These are defined as a convenience where occasional use of such a feature on a list is required.
An implementation is required to provide the features above in as efficient a manner as possible. The set-like feature efficiency must be subordinate in this context (see, however, the class FSET{ELT}).
union( list : SAME ) : SAME pre true post (result.size <= (size + list.size)) is -- This routine returns a new list containing the elements in the union -- of self and list. Self may be void. intersect( list : SAME ) : SAME pre true post (result.size <= list.size) is -- This routine returns a new list containing the elements which are -- in both self and list. Self may be void. difference( list : SAME ) : SAME pre true post (result.size <= size) is -- This routine returns a new list containing the elements of self -- which are not in list. Self may be void. sym_difference( list : SAME ) : SAME pre true post (result.size <= (size + list.size)) is -- This routine returns a new list containing the elements in self or in -- list but not in both. Self may be void.![]() |
Language Index | ![]() |
Library Index | ![]() |
Container Index |
Comments or enquiries should be made to
Keith
Hopper. Page last modified: Monday, 26 February 2001. |
![]() |