scala.collection.mutable

class ArrayStack

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

@cloneable

class ArrayStack[T](private table : Array[AnyRef], private index : Int)
extends Iterable[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 : Iterable[T]) : ArrayStack[T]
Pushes all the provided elements onto the stack.
def ++= (x : Iterator[T]) : ArrayStack[T]
Pushes all the provided elements onto the stack.
def += (x : T) : ArrayStack[T]
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.
override def foreach [U](f : (T) => U) : Unit
Apply a function f to all elements of this traversable object.
override def isEmpty : Boolean
Does this iterable contain no elements?
def iterator : Iterator[T]
Iterates over the stack in fifo order.
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.
override def size : Int
The number of elements in this collection
def top : T
View the top element of the stack.
Methods inherited from Iterable
companion
Methods inherited from IterableTemplate
elements, foldRight, reduceRight, toIterable, head, takeRight, dropRight, sameElements, toStream, view, view, first, firstOption, toSeq, projection
Methods inherited from TraversableClass
newBuilder, genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableTemplate
thisCollection, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, forall, exists, count, find, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, headOption, tail, last, lastOption, init, take, drop, slice, takeWhile, dropWhile, span, splitAt, copyToBuffer, copyToArray, copyToArray, toArray, toList, toSequence, toSet, mkString, mkString, mkString, addString, addString, addString, toString, stringPrefix
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.

@deprecated("use top instead")

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

def top : 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]) : ArrayStack[T]
Pushes all the provided elements onto the stack.
Parameters
x - The source of elements to push

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

def +=(x : T) : ArrayStack[T]
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.

override def size : Int
The number of elements in this collection

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
Does this iterable contain no elements?

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

override def foreach[U](f : (T) => U) : Unit
Apply a function f to all elements of this traversable object.
Parameters
f - A function that is applied for its side-effect to every element. The result (of arbitrary type U) of function `f` is discarded.
Notes
This method underlies the implementation of most other bulk operations. Implementing `foreach` with `iterator` is often suboptimal. So `foreach` should be overridden in concrete collection classes if a more efficient implementation is available.

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.