scala.collection.mutable

class ArrayStack

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

@cloneable

class ArrayStack[T](private table : Array[AnyRef], private index : Int)
extends Seq[T] with Cloneable[ArrayStack[T]]
Simple stack class backed by an array. Should be significantly faster than the standard mutable stack.
Author
David MacIver
Since
2.7
Additional Constructor Summary
def this : ArrayStack[T]
Method Summary
def ++= (x : Iterator[T]) : ArrayStack[T]
Pushes all the provided elements onto the stack.
def ++= (x : Iterable[T]) : ArrayStack[T]
Pushes all the provided elements onto the stack.
def += (x : T) : ArrayStack[T]
Alias for push.
def apply (n : Int) : T
Retrieve n'th element from stack, where top of stack has index 0
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 iterable object.
override def isEmpty : Boolean
Does this iterable contain no elements?
def iterator : Iterator[T]
Iterates over the stack in LIFO order.
def length : Int
The number of elements in the stack
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
Should always be length
def top : T
View the top element of the stack.
Methods inherited from Seq
companion
Methods inherited from SeqLike
thisCollection, toCollection, lengthCompare, isDefinedAt, segmentLength, prefixLength, indexWhere, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, reverse, reverseMap, reverseIterator, reversedElements, startsWith, startsWith, endsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, updated, +:, :+, padTo, sortWith, sortWith, sortBy, toSeq, indices, view, view, hashCode, equals, toString, findLastIndexOf, equalsWith, containsSlice, projection
Methods inherited from IterableLike
elements, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, first, firstOption
Methods inherited from GenericTraversableTemplate
newBuilder, genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
repr, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix, withFilter
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from AnyRef
getClass, 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 apply(n : Int) : T
Retrieve n'th element from stack, where top of stack has index 0

def length : Int
The number of elements in the stack

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
Should always be length

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 LIFO order.

override def foreach[U](f : (T) => U) : Unit
Apply a function f to all elements of this iterable 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.

Overrides
Cloneable.clone