Package com.tangosol.util
Class PrimitiveSparseArray
- java.lang.Object
-
- com.tangosol.util.AbstractLongArray<V>
-
- com.tangosol.util.AbstractSparseArray<Long>
-
- com.tangosol.util.PrimitiveSparseArray
-
public class PrimitiveSparseArray extends AbstractSparseArray<Long> implements LongArray<Long>
A data structure resembling a long array indexed by long values.While the PrimitiveSparseArray implements the LongArray interface, it stores all values as primitive longs, and as such any Object supplied to its LongArray interface must be provided as a java.lang.Long. The PrimitiveSparseArray provides additional methods whose signatures utilize primitive longs to avoid the creation of temporary Long objects.
- Author:
- mf 10.08.2007
- See Also:
SparseArray
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
PrimitiveSparseArray.Iterator
Iterator over long values stored in the tree.protected static class
PrimitiveSparseArray.PrimitiveNode
Node mapping long key to Object value.-
Nested classes/interfaces inherited from class com.tangosol.util.AbstractSparseArray
AbstractSparseArray.Crawler, AbstractSparseArray.Node<V>
-
-
Field Summary
-
Fields inherited from class com.tangosol.util.AbstractSparseArray
m_head, m_size
-
-
Constructor Summary
Constructors Constructor Description PrimitiveSparseArray()
Default constructor.PrimitiveSparseArray(PrimitiveSparseArray array)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getPrimitive(long lIndex)
Return the value stored at the specified index.protected AbstractSparseArray.Crawler
instantiateCrawler(AbstractSparseArray.Node head, int fromdir, boolean fForward)
Instantiate a new Crawler at the specified location and direction.protected AbstractSparseArray.Node
instantiateNode(long lKey, long lValue)
Create a new Node with the specified key and value.protected AbstractSparseArray.Node
instantiateNode(long lKey, Long value)
Factory pattern: create a new Node with the specified key and value.PrimitiveSparseArray.Iterator
iterator()
Obtain a LongArray.Iterator of the contents of the LongArray.PrimitiveSparseArray.Iterator
iterator(long lIndex)
Obtain a LongArray.Iterator of the contents of the LongArray, starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is greater than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.long
removePrimitive(long lIndex)
Remove the specified index from the PrimitiveSparseArray, returning its associated value.PrimitiveSparseArray.Iterator
reverseIterator()
Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices).PrimitiveSparseArray.Iterator
reverseIterator(long lIndex)
Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices), starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is less than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.long
setPrimitive(long lIndex, long lValue)
Add the passed item to the PrimitiveSparseArray at the specified index.-
Methods inherited from class com.tangosol.util.AbstractSparseArray
adjustDoubleBalance, balancedInsertion, balancePostRemove, ceiling, ceilingIndex, clear, clone, doubleRotate, exists, find, findInsertionPoint, floor, floorIndex, get, getFirstIndex, getLastIndex, getSize, print, remove, remove, remove, replace, rotate, set, validate
-
Methods inherited from class com.tangosol.util.AbstractLongArray
add, contains, equals, hashCode, indexOf, indexOf, isEmpty, lastIndexOf, lastIndexOf, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface com.tangosol.util.LongArray
add, ceiling, ceilingIndex, clear, clone, contains, equals, exists, floor, floorIndex, get, getFirstIndex, getLastIndex, getSize, indexOf, indexOf, isEmpty, keys, lastIndexOf, lastIndexOf, remove, remove, set, toString
-
-
-
-
Constructor Detail
-
PrimitiveSparseArray
public PrimitiveSparseArray()
Default constructor.
-
PrimitiveSparseArray
public PrimitiveSparseArray(PrimitiveSparseArray array)
Copy constructor.- Parameters:
array
- a PrimitiveSparseArray to copy from.
-
-
Method Detail
-
iterator
public PrimitiveSparseArray.Iterator iterator()
Obtain a LongArray.Iterator of the contents of the LongArray.
-
iterator
public PrimitiveSparseArray.Iterator iterator(long lIndex)
Obtain a LongArray.Iterator of the contents of the LongArray, starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is greater than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.
-
reverseIterator
public PrimitiveSparseArray.Iterator reverseIterator()
Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices).- Specified by:
reverseIterator
in interfaceLongArray<Long>
- Overrides:
reverseIterator
in classAbstractSparseArray<Long>
- Returns:
- an instance of LongArray.Iterator
-
reverseIterator
public PrimitiveSparseArray.Iterator reverseIterator(long lIndex)
Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices), starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is less than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.- Specified by:
reverseIterator
in interfaceLongArray<Long>
- Overrides:
reverseIterator
in classAbstractSparseArray<Long>
- Parameters:
lIndex
- the LongArray index to iterate from- Returns:
- an instance of LongArray.Iterator
-
getPrimitive
public long getPrimitive(long lIndex)
Return the value stored at the specified index.- Parameters:
lIndex
- a long index value- Returns:
- the value stored at the specified index, or NOT_FOUND if none exists
-
removePrimitive
public long removePrimitive(long lIndex)
Remove the specified index from the PrimitiveSparseArray, returning its associated value.- Parameters:
lIndex
- the index into the LongArray- Returns:
- the associated value or NOT_FOUND if the specified index does not exist
-
setPrimitive
public long setPrimitive(long lIndex, long lValue)
Add the passed item to the PrimitiveSparseArray at the specified index.If the index is already used, the passed value will replace the current value stored with the key, and the replaced value will be returned.
It is expected that LongArray implementations will "grow" as necessary to support the specified index.
- Parameters:
lIndex
- a long index valuelValue
- the long value to store at the specified index- Returns:
- the value that was stored at the specified index, or NOT_FOUND if the specified index does not exist
-
instantiateNode
protected AbstractSparseArray.Node instantiateNode(long lKey, Long value)
Factory pattern: create a new Node with the specified key and value.- Specified by:
instantiateNode
in classAbstractSparseArray<Long>
- Parameters:
lKey
- the long keyvalue
- the object value- Returns:
- the new node
-
instantiateNode
protected AbstractSparseArray.Node instantiateNode(long lKey, long lValue)
Create a new Node with the specified key and value.- Parameters:
lKey
- the long keylValue
- the long value- Returns:
- the new node
-
instantiateCrawler
protected AbstractSparseArray.Crawler instantiateCrawler(AbstractSparseArray.Node head, int fromdir, boolean fForward)
Instantiate a new Crawler at the specified location and direction.- Overrides:
instantiateCrawler
in classAbstractSparseArray<Long>
- Parameters:
head
- the node at which to start crawlingfromdir
- the direction in which to start crawlingfForward
- true iff crawler should advance forward towards the next element- Returns:
- the new crawler
-
-