next.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
---------------------------> Sather 1.1 source file <--------------------------
-- Copyright (C) International Computer Science Institute, 1994. COPYRIGHT --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in --
-- the file "Doc/License" of the Sather distribution. The license is also --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. --
--------> Please email comments to sather-bugs@icsi.berkeley.edu. <----------
-- next.sa: Inherited by elements of singly linked lists.
abstract class $NEXT{T < $NEXT{T}}
abstract class $NEXT{T < $NEXT{T}} is
-- The interface obeyed by classes which include NEXT{T}.
next:T; -- Pointer to next element in list, if any.
next(e:T); -- Set next pointer to `e'.
size:INT; -- The number of elements in the list
-- starting with self. Self may be void.
insert(e:T); -- Insert the single element `e' after self.
-- Neither may be void.
append(l:T); -- Append the list `l' to the end of the
-- list self. self may not be void but `l' may be.
end;
class NEXT{T < $NEXT{T}} < $NEXT{T}
class NEXT{T < $NEXT{T}} < $NEXT{T} is
-- Inherited by classes whose objects need to point to a list of
-- objects of type T. Classes which inherit this get a `next'
-- pointer and some features to manipulate it. It doesn't suport
-- circular lists.
attr next:T; -- Pointer to next element in list, if any.
size:INT is
-- The number of elements in the list starting with self.
-- Self may be void.
if void(self) then return 0 end;
r::=1; n::=next;
loop until!(void(n)); r:=r+1; n:=n.next end;
return r end;
insert(e:T)
-- Insert the single element `e' after self. Neither may be void,
-- `e.next' must be void.
pre ~void(self) and ~void(e) and void(e.next) is
e.next:=next; next:=e end;
append(l:T)
-- Append the list `l' to the end of the list self. self may
-- not be void but `l' may be.
pre ~void(self) is
if void(next) then next:=l; return end;
last::=next; loop until!(void(last.next)); last:=last.next end;
last.next:=l end;
end;