Skip to content

Commit

Permalink
[UTILS-114] Add abstract duplicate method to IntervalArray.
Browse files Browse the repository at this point in the history
Resolves #114.
  • Loading branch information
fnothaft committed Mar 17, 2017
1 parent 2431d6c commit 56c4849
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ trait IntervalArray[K <: Interval[K], T] extends Serializable {

protected def replace(arr: Array[(K, T)], maxWidth: Long): IntervalArray[K, T]

/**
* @return Makes a copy of the interval array. The underlying array is shallow
* copied, but the thread unsafe optLastIndex variable is not shared.
*/
def duplicate(): IntervalArray[K, T]

@tailrec private def pow2ceil(i: Int = 1): Int = {
if (2 * i >= length) {
i
Expand Down Expand Up @@ -493,6 +499,10 @@ case class ConcreteIntervalArray[K <: Interval[K], T: ClassTag](
array: Array[(K, T)],
maxIntervalWidth: Long) extends IntervalArray[K, T] {

def duplicate(): IntervalArray[K, T] = {
new ConcreteIntervalArray(array, maxIntervalWidth)
}

protected def replace(arr: Array[(K, T)],
maxWidth: Long): IntervalArray[K, T] = {
new ConcreteIntervalArray(arr, maxWidth)
Expand Down

0 comments on commit 56c4849

Please sign in to comment.