Skip to content

Commit 68e247e

Browse files
authored
Replaced chunked arrays with scala native vector implementation (#2002)
1 parent 9ab89e6 commit 68e247e

15 files changed

Lines changed: 348 additions & 1160 deletions

File tree

toolbox/pom.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@
201201
</executions>
202202
</plugin>
203203

204+
<plugin>
205+
<groupId>org.codehaus.mojo</groupId>
206+
<artifactId>build-helper-maven-plugin</artifactId>
207+
<executions>
208+
<execution>
209+
<phase>generate-sources</phase>
210+
<goals>
211+
<goal>add-source</goal>
212+
</goals>
213+
<configuration>
214+
<sources>
215+
<source>src/main/scala</source>
216+
</sources>
217+
</configuration>
218+
</execution>
219+
</executions>
220+
</plugin>
221+
204222
<plugin>
205223
<groupId>org.jacoco</groupId>
206224
<artifactId>jacoco-maven-plugin</artifactId>
@@ -224,7 +242,7 @@
224242
<limit>
225243
<counter>LINE</counter>
226244
<value>COVEREDRATIO</value>
227-
<minimum>0.58</minimum>
245+
<minimum>0.46</minimum>
228246
</limit>
229247
</limits>
230248
</rule>

toolbox/src/main/scala/org/finos/toolbox/collection/array/ChunkedImmutableArray.scala

Lines changed: 0 additions & 292 deletions
This file was deleted.

toolbox/src/main/scala/org/finos/toolbox/collection/array/ImmutableArray.scala

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
package org.finos.toolbox.collection.array
22

3+
import org.finos.toolbox.collection.set.{ImmutableArraySet, VectorImmutableArraySet}
4+
import org.finos.toolbox.collection.set.ImmutableArraySet.{empty, of}
5+
36
import scala.reflect.ClassTag
47

58
object ImmutableArray {
69

10+
def from[T <: Object](iterable: IterableOnce[T])(implicit c: ClassTag[T]): ImmutableArray[T] = {
11+
if (iterable.knownSize == 0) {
12+
empty()
13+
} else if (iterable.knownSize == 1) {
14+
of(iterable.iterator.next())
15+
} else {
16+
VectorImmutableArray.from(iterable)
17+
}
18+
}
19+
720
def empty[T <: Object](implicit c: ClassTag[T]): ImmutableArray[T] = {
8-
ChunkedImmutableArray.empty()
21+
VectorImmutableArray.empty()
922
}
1023

11-
def from[T <: Object](array: Array[T])(implicit c: ClassTag[T]): ImmutableArray[T] = {
12-
ChunkedImmutableArray.from(array)
24+
def of[T <: Object](element: T)(implicit c: ClassTag[T]): ImmutableArray[T] = {
25+
VectorImmutableArray.of(element)
1326
}
1427

1528
}
@@ -23,13 +36,13 @@ object ImmutableArrays{
2336
trait ImmutableArray[T] extends Iterable[T] {
2437

2538
def +(element: T) : ImmutableArray[T]
39+
def add(element: T) : ImmutableArray[T]
2640

2741
def -(element: T): ImmutableArray[T]
2842
def remove(element: T): ImmutableArray[T]
2943

30-
def ++(arr: ImmutableArray[T]) : ImmutableArray[T]
31-
def addAll(arr: ImmutableArray[T]) : ImmutableArray[T]
32-
def fromArray(arr: Array[T]): ImmutableArray[T]
44+
def ++(iterable: IterableOnce[T]) : ImmutableArray[T]
45+
def addAll(iterable: IterableOnce[T]) : ImmutableArray[T]
3346

3447
def getIndex(index: Int): T
3548

@@ -45,6 +58,4 @@ trait ImmutableArray[T] extends Iterable[T] {
4558

4659
def remove(index: Int): ImmutableArray[T]
4760

48-
def distinct: ImmutableArray[T]
49-
5061
}

0 commit comments

Comments
 (0)