Skip to content
Snippets Groups Projects
Commit 16a2286d authored by Reynold Xin's avatar Reynold Xin
Browse files

Return the vector itself for trim and resize method in PrimitiveVector.

parent c30979c7
No related branches found
No related tags found
No related merge requests found
...@@ -48,16 +48,17 @@ class PrimitiveVector[@specialized(Long, Int, Double) V: ClassManifest](initialS ...@@ -48,16 +48,17 @@ class PrimitiveVector[@specialized(Long, Int, Double) V: ClassManifest](initialS
def size: Int = _numElements def size: Int = _numElements
/** Get the underlying array backing this vector. */ /** Gets the underlying array backing this vector. */
def array: Array[V] = _array def array: Array[V] = _array
/** Trims this vector so that the capacity is equal to the size. */ /** Trims this vector so that the capacity is equal to the size. */
def trim(): Unit = resize(size) def trim(): PrimitiveVector[V] = resize(size)
/** Resizes the array, dropping elements if the total length decreases. */ /** Resizes the array, dropping elements if the total length decreases. */
def resize(newLength: Int) { def resize(newLength: Int): PrimitiveVector[V] = {
val newArray = new Array[V](newLength) val newArray = new Array[V](newLength)
_array.copyToArray(newArray) _array.copyToArray(newArray)
_array = newArray _array = newArray
this
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment