nr_a_stack.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- a_stack.sa: Array based stack
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- $Id: a_stack.sa,v 1.6 1996/07/16 04:38:09 holger Exp $
--
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.

--!!! THIS FILE HAS BEEN CREATED FROM a_stack.sa, DO NOT EDIT IT !!! class NR_STACK{T} < $NR_STACK{T} is include NR_A_STACK{T} end;

class NR_A_STACK{T} < $NR_STACK{T}

class NR_A_STACK{T} < $NR_STACK{T} is -- An array-based stack implemented by delegation to an FLIST{T}, -- which allocates space by amortized doubling. private attr s: FLIST{T}; create: SAME is res ::= new; res.s := #FLIST{T}; return(res); end; create(e: $ELT{T}): SAME is -- Push the elements of "e" onto the stack. -- If "e" is an ordered collection this will push elements -- such that the last element is left at the top of the stack res ::= #SAME; loop res.push(e.elt!) end; return res; end; create_from(a: ARRAY{T}): SAME is return create(a); end; create_capacity(n: INT): SAME is -- Preallocate n empty elements res ::= new; res.s := #FLIST{T}(n); return(res); end; remove:T is return pop; end; current: T is return top ; end; push(e: T) pre ~void(self) is s := s.push(e); end; pop: T pre ~void(self) and ~is_empty is return(s.pop); end; top: T pre ~void(self) and ~is_empty is -- Return the top element of the stack return(s.top); end; reverse_elt!: T pre ~void(self) is -- Yield the elements of the stack in reverse order i.e. -- ending with "top". loop yield(s.elt!) end; end; elt!: T pre ~void(self) is loop yield s[(s.size-1).downto!(0)]; end; end; top!: T pre ~void(self) is -- Same as elt! loop yield s[(s.size-1).downto!(0)]; end; end; size: INT pre ~void(self) is return(s.size) end; is_empty: BOOL pre ~void(self) is return(size = 0) end; has(e: T): BOOL pre ~void(self) is return(s.has(e)); end; str: STR is return s.str; end; copy: SAME pre ~void(self) is res ::= create_capacity(size); res.s := s.copy; return res; end; end;