next.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
abstract class $NEXT{TYP < $NEXT{TYP}}
abstract class $NEXT{TYP < $NEXT{TYP}} is
-- This class defines the interface to be provided by classes which
-- include NEXT{TYP}.
-- Version 1.1 Apr 97. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 1 Jun 94 bg Original
-- 4 Apr 97 kh Changed for INT to CARD
next : TYP ; -- element in the list, if any.
next(
elem : TYP
) ;
-- This routine sets the next pointer to elem.
size : CARD ;
-- This provides the number of elements in the list starting with self.
-- Self may be void.
insert(
elem : TYP
) ;
-- This routine inserts the given element after self. Neither self
-- nor elem may be void.
append(
list : TYP
) ;
-- This routine appends the given list after self. Self may be void,
-- but List may not be void.
end ; -- $NEXT{T}
partial class NEXT{T < $NEXT{T}} < $NEXT{T}
partial class NEXT{T < $NEXT{T}} < $NEXT{T} is
-- This partial class implements the linked list abstraction for those
-- classes whose objects need to point to a list of objects of type T.
-- Classes which inherit this get a `next' component and some features to
-- manipulate it. It does not suport circular lists.
-- Version 1.2 Nov 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 1 Jun 96 bg Original
-- 4 Apr 97 kh Changed for INT to CARD
-- 6 Nov 98 kh Refined, added pre/post conditions.
attr next : T ; -- next element in list, if any.
size : CARD
pre true
post (void(self)
and (result = 0))
or (~void(self)
and (result > 0))
is
-- This routine returns the number of elements in the list starting
-- with self.
if void(self) then
return 0
end ;
res : CARD := 1 ;
loc_next : T := next ;
loop -- scan all the list
until!(void(loc_next)) ;
res := res + 1 ;
loc_next := loc_next.next
end ;
return res
end ;
insert(
elem : T
)
pre ~void(self)
and ~void(elem)
and void(elem.next)
post (size = (initial(size) + 1))
is
-- This routine inserts the single element given after self.
elem.next := next ;
next := elem
end ;
append(
list : T
)
pre ~void(self)
post (size = (initial(size) + list.size))
is
-- This routine appends the given list at the end of self. Self may not
-- be void but the list may be.
if void(next) then
next := list ;
return
end ;
last : T := next ;
loop -- need to scan to end first!
until!(void(last.next)) ;
last := last.next
end ;
last.next := list
end ;
end ; -- NEXT{T}