Scalqa/Stream provides a general indexed collection - Idx, defined as following:
package scalqa trait Idx[+A] extends Any { def size: Int def apply(idx: Int): A def all: ~[A] }
Idx is functionally equivalent to scala.collections.IndexedSeq, but it is additionally specialized for primitives
For example, following calculations do not auto-box Int values and are 20 times faster compared to same done with IndexedSeq
val idx: Idx[Int] = (1 to 1000).all.to[Idx] var sum, i = 0 while(i < idx.size){ sum += idx(i); i+=1 } println(sum == idx.all.sum) // Prints true
Idx.Buffer is an Idx extension functionally equivalent to scala.collections.mutable.Buffer, but providing better growth performance for primitives
Idx.Immutable is a trait, which has following implementations: Refs, Bytes, Chars, Shorts, Ints, Longs, Floats, and Doubles
All these are an immutable Array wraps and their growth performance is on par with Array in general
Idx.Immutables could be the most efficient storage, consider following example:
val list: List[Int] = (1 to 1000000).toList val ints: Ints = (1 to 1000000).all.toRaw[Ints]
list holds 1 million objects of type List and 1 million objects of type java.lang.Integer. At conservative 16 bytes per object, this is 32Mb
list
ints holds a single object: Array[Int] of size = 1 million. At 4 bytes per Int, this is 4Mb
ints
Not to mention that ints (in this particular case) were created over 10 times faster
Indexed Collection
Scalqa/Stream provides a general indexed collection - Idx, defined as following:
Idx is functionally equivalent to scala.collections.IndexedSeq, but it is additionally specialized for primitives
For example, following calculations do not auto-box Int values and are 20 times faster compared to same done with IndexedSeq
Buffer
Idx.Buffer is an Idx extension functionally equivalent to scala.collections.mutable.Buffer, but providing better growth performance for primitives
Immutables
Idx.Immutable is a trait, which has following implementations: Refs, Bytes, Chars, Shorts, Ints, Longs, Floats, and Doubles
All these are an immutable Array wraps and their growth performance is on par with Array in general
Idx.Immutables could be the most efficient storage, consider following example:
list
holds 1 million objects of type List and 1 million objects of type java.lang.Integer. At conservative 16 bytes per object, this is 32Mbints
holds a single object: Array[Int] of size = 1 million. At 4 bytes per Int, this is 4MbNot to mention that
ints
(in this particular case) were created over 10 times faster