SparseArray

@SerialVersionUID(1L)
final class SparseArray[@specialized(Double, Int, Float, Long) V](var index: Array[Int], var data: Array[V], var used: Int, val size: Int, val default: V) extends SparseArrayLike[V] with Storage[V] with Serializable

A SparseArray is a sparse representation of an array using a two-array binary-search approach. There are two arrays: index and data, which together are pairs (i, v) of indices into the array and the value at that position.

The default value is assumed to be null for AnyRef, and 0 for AnyVal types.

Companion:
object
trait Serializable
trait Storage[V]
class Object
trait Matchable
class Any

Value members

Constructors

def this(size: Int, default: V)(implicit manElem: ClassTag[V])
def this(size: Int)(implicit manElem: ClassTag[V], zero: Zero[V])

Concrete methods

final def apply(i: Int): V
def compact(): Unit

Compacts the array by removing all stored default values.

Compacts the array by removing all stored default values.

def concatenate(that: SparseArray[V])(implicit man: ClassTag[V]): SparseArray[V]
override def equals(o: Any): Boolean
Definition Classes
Any
def filter(f: V => Boolean): SparseArray[V]

Filter's the array by removing all values for which f is false.

Filter's the array by removing all values for which f is false.

def get(i: Int): Option[V]
def getOrElse(i: Int, value: => V): V
def getOrElseUpdate(i: Int, value: => V): V
override def hashCode: Int
Definition Classes
Any
final def indexAt(i: Int): Int

Only iterates "active" keys

Only iterates "active" keys

def map[B : Zero](f: V => B): SparseArray[B]

Maps all values. If f(this.default) is not equal to the new default value, the result may be an efficiently dense (or almost dense) paired array.

Maps all values. If f(this.default) is not equal to the new default value, the result may be an efficiently dense (or almost dense) paired array.

Like compact, but doesn't look for defaultValues that can be removed.

Like compact, but doesn't look for defaultValues that can be removed.

def reserve(nnz: Int): Unit
override def toString: String
Definition Classes
Any
final def update(i: Int, value: V): Unit

Sets the given value at the given index if the value is not equal to the current default. The data and index arrays will be grown to support the insertion if necessary. The growth schedule doubles the amount of allocated memory at each allocation request up until the sparse array contains 1024 values, at which point the growth is additive: an additional n * 1024 spaces will be allocated for n in 1,2,4,8,16. The largest amount of space added to this vector will be an additional 161024(sizeof(Elem)+4), which is 196608 bytes at a time for a SparseVector[Double], although more space is needed temporarily while moving to the new arrays.

Sets the given value at the given index if the value is not equal to the current default. The data and index arrays will be grown to support the insertion if necessary. The growth schedule doubles the amount of allocated memory at each allocation request up until the sparse array contains 1024 values, at which point the growth is additive: an additional n * 1024 spaces will be allocated for n in 1,2,4,8,16. The largest amount of space added to this vector will be an additional 161024(sizeof(Elem)+4), which is 196608 bytes at a time for a SparseVector[Double], although more space is needed temporarily while moving to the new arrays.

def use(index: Array[Int], data: Array[V], used: Int): Unit
final def valueAt(i: Int): V

Only iterates "active" elements

Only iterates "active" elements

Inherited methods

def foreach[U](f: V => U): Unit

Only iterates "active" elements. I'm not sure how I feel about this behavior, since it's inconsistent with the rest of Breeze. I will think on it.

Only iterates "active" elements. I'm not sure how I feel about this behavior, since it's inconsistent with the rest of Breeze. I will think on it.

Inherited from:
SparseArrayLike

How many elements must be iterated over using valueAt/indexAt. In HashVectors, activeSize is the number of non-zero elements, while iterableSize is the number of buckets currently allocated. (activeSize <= iterableSize in general, activeSize == iterableSize for everything except hashing implementations.)

How many elements must be iterated over using valueAt/indexAt. In HashVectors, activeSize is the number of non-zero elements, while iterableSize is the number of buckets currently allocated. (activeSize <= iterableSize in general, activeSize == iterableSize for everything except hashing implementations.)

Inherited from:
Storage
def iterator: Iterator[(Int, V)]

Only iterates "active" elements

Only iterates "active" elements

Inherited from:
SparseArrayLike
def length: Int
Inherited from:
SparseArrayLike
def toArray[U >: V : ClassTag]: Array[U]
Inherited from:
SparseArrayLike
Inherited from:
SparseArrayLike
def toList: List[V]
Inherited from:
SparseArrayLike
def toMap: Map[Int, V]
Inherited from:
SparseArrayLike

Concrete fields

var data: Array[V]
val default: V
val size: Int