scala.collection.mutable

class ArrayStack

[source: scala/collection/mutable/ArrayStack.scala]

class ArrayStack[T](private table : Array[AnyRef], private index : Int)
extends Collection[T]
Simple stack class backed by an array. Should be significantly faster than the standard mutable stack.
Author
David MacIver
Additional Constructor Summary
def this : ArrayStack[T]
Method Summary
def ++= (x : Iterator[T]) : Unit
Pushes all the provided elements onto the stack.
def ++= (x : Iterable[T]) : Unit
Pushes all the provided elements onto the stack.
def += (x : T) : Unit
Alias for push.
def clear : Unit
Empties the stack.
override def clone : ArrayStack[T]
This method creates and returns a copy of the receiver object.
def combine (f : (T, T) => T) : Unit
Pop the top two elements off the stack, apply f to them and push the result back on to the stack.
def drain (f : (T) => Unit) : Unit
Empties the stack, passing all elements on it in FIFO order to the provided function.
def dup : Unit
Duplicate the top element of the stack.
def elements : Iterator[T]
Iterates over the stack in fifo order.
override def foreach (f : (T) => Unit) : Unit
Apply a function f to all elements of this iterable object.
override def isEmpty : Boolean
Is this collection empty?
def peek : T
View the top element of the stack.
def pop : T
Pop the top element off the stack.
def preserving [T](action : => T) : T
Evaluates the expression, preserving the contents of the stack so that any changes the evaluation makes to the stack contents will be undone after it completes.
def push (x : T) : Unit
Push an element onto the stack.
def reduceWith (f : (T, T) => T) : Unit
Repeatedly combine the top elements of the stack until the stack contains only one element.
def size : Int
Returns the number of elements in this collection.
Methods inherited from Collection
toArray, toString, stringPrefix
Methods inherited from Iterable
concat, ++, map, flatMap, filter, partition, takeWhile, dropWhile, take, drop, forall, exists, find, findIndexOf, indexOf, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toList, toSeq, toStream, mkString, mkString, mkString, addString, addString, addString, copyToArray, projection, hasDefiniteSize
Methods inherited from AnyRef
getClass, hashCode, equals, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Additional Constructor Details
def this : ArrayStack[T]

Method Details
def push(x : T) : Unit
Push an element onto the stack.
Parameters
x - The element to push

def pop : T
Pop the top element off the stack.

def peek : T
View the top element of the stack.

def dup : Unit
Duplicate the top element of the stack.

def clear : Unit
Empties the stack.

def drain(f : (T) => Unit) : Unit
Empties the stack, passing all elements on it in FIFO order to the provided function.
Parameters
f - The function to drain to.

def ++=(x : Iterable[T]) : Unit
Pushes all the provided elements onto the stack.
Parameters
x - The source of elements to push

def ++=(x : Iterator[T]) : Unit
Pushes all the provided elements onto the stack.
Parameters
x - The source of elements to push

def +=(x : T) : Unit
Alias for push.
Parameters
x - The element to push

def combine(f : (T, T) => T) : Unit
Pop the top two elements off the stack, apply f to them and push the result back on to the stack.
Parameters
f - The combining function

def reduceWith(f : (T, T) => T) : Unit
Repeatedly combine the top elements of the stack until the stack contains only one element.

def size : Int
Returns the number of elements in this collection.
Returns
number of collection elements.
Overrides
Collection.size

def preserving[T](action : => T) : T
Evaluates the expression, preserving the contents of the stack so that any changes the evaluation makes to the stack contents will be undone after it completes.
Parameters
action - The action to run.

override def isEmpty : Boolean
Is this collection empty?

def elements : Iterator[T]
Iterates over the stack in fifo order.

override def foreach(f : (T) => Unit) : Unit
Apply a function f to all elements of this iterable object.
Notes
Will not terminate for infinite-sized collections.
Parameters
f - a function that is applied to every element.

override def clone : ArrayStack[T]
This method creates and returns a copy of the receiver object.

The default implementation of the clone method is platform dependent.

Returns
a copy of the receiver object.