Skip to content

Commit 4e644b5

Browse files
committed
Reformat all
1 parent 853cab9 commit 4e644b5

30 files changed

+1568
-1482
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
distribution: 'temurin'
3939
java-version: '17'
4040
- name: Scala 2.12 test
41-
run: ./sbt "++2.12; projectJVM/test"
41+
run: ./sbt "++2.12; test"
4242
- name: Publish Test Report
4343
uses: mikepenz/action-junit-report@v3
4444
if: always() # always run even if the previous step fails
@@ -55,7 +55,7 @@ jobs:
5555
distribution: 'temurin'
5656
java-version: '17'
5757
- name: Scala 2.13 test
58-
run: ./sbt "++2.13; projectJVM/test"
58+
run: ./sbt "++2.13; test"
5959
- name: Publish Test Report
6060
uses: mikepenz/action-junit-report@v3
6161
if: always() # always run even if the previous step fails
@@ -72,7 +72,7 @@ jobs:
7272
distribution: 'temurin'
7373
java-version: '17'
7474
- name: Scala 3 test
75-
run: ./sbt "++3; projectJVM/test"
75+
run: ./sbt "++3; test"
7676
- name: Publish Test Report
7777
uses: mikepenz/action-junit-report@v3
7878
if: always() # always run even if the previous step fails

larray-buffer/src/test/scala/xerial/larray/DataUnit.scala

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,36 @@ package xerial.larray
2424
/**
2525
* Translators of data sizes
2626
*
27-
* @author Taro L. Saito
27+
* @author
28+
* Taro L. Saito
2829
*/
2930
object DataUnit {
3031

3132
/**
3233
* Convert the given byte size into human readable format like 1024 -> 1K
3334
* @param byteSize
34-
* @return string representation of the byte size
35+
* @return
36+
* string representation of the byte size
3537
*/
36-
def toHumanReadableFormat(byteSize:Long) : String = {
38+
def toHumanReadableFormat(byteSize: Long): String = {
3739
// kilo, mega, giga, tera, peta, exa, zetta, yotta
3840
val unitName = Seq("", "K", "M", "G", "T", "P", "E", "Z", "Y")
3941

40-
def loop(index:Int, v:Long) : (Long, String) = {
41-
if(index >= unitName.length)
42+
def loop(index: Int, v: Long): (Long, String) = {
43+
if (index >= unitName.length)
4244
(byteSize, "")
4345
val next = v >> 10L
44-
if(next == 0L)
46+
if (next == 0L)
4547
(v, unitName(index))
4648
else
47-
loop(index+1, next)
49+
loop(index + 1, next)
4850
}
4951

50-
val (prefix, unit) = if(byteSize > 0)
51-
loop(0, byteSize)
52-
else
53-
loop(0, -byteSize) match { case (p, u) => (-p, u)}
52+
val (prefix, unit) =
53+
if (byteSize > 0)
54+
loop(0, byteSize)
55+
else
56+
loop(0, -byteSize) match { case (p, u) => (-p, u) }
5457
s"$prefix$unit"
5558
}
5659

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
1-
/*--------------------------------------------------------------------------
2-
* Copyright 2013 Taro L. Saito
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*--------------------------------------------------------------------------*/
16-
//--------------------------------------
17-
//
18-
// LArrayLoaderTest.scala
19-
// Since: 2013/03/29 9:56
20-
//
21-
//--------------------------------------
22-
23-
package xerial.larray.impl
24-
25-
import java.net.{URL, URLClassLoader}
26-
import java.io.File
27-
import xerial.larray.LArraySpec
28-
29-
30-
/**
31-
* @author Taro L. Saito
32-
*/
33-
class LArrayLoaderTest extends LArraySpec {
34-
35-
"LArrayLoader" should {
36-
37-
"use a different library name for each class loader" in {
38-
39-
val larrayNativeCls = "xerial.larray.impl.LArrayNative"
40-
41-
val cl = Thread.currentThread().getContextClassLoader
42-
val parentCl = cl.getParent.getParent // Fix for sbt-0.13
43-
debug(s"context cl: ${cl}, parent cl: $parentCl")
44-
val classPath = Array(new File("larray-mmap/target/classes").toURI.toURL)
45-
val cl1 = new URLClassLoader(classPath, parentCl)
46-
val cl2 = new URLClassLoader(classPath, parentCl)
47-
48-
import java.{lang=>jl}
49-
50-
val nativeCls1 = cl1.loadClass(larrayNativeCls)
51-
val ni1 = nativeCls1.newInstance()
52-
val arr1 = Array.ofDim[Byte](100)
53-
val m1 = nativeCls1.getDeclaredMethod("copyToArray", jl.Long.TYPE, classOf[AnyRef], jl.Integer.TYPE, jl.Integer.TYPE)
54-
m1.invoke(ni1, Seq.apply[AnyRef](new jl.Long(0L), arr1, new jl.Integer(0), new jl.Integer(0)):_*)
55-
val nativeCls1_2 = cl1.loadClass(larrayNativeCls)
56-
57-
val nativeCls2 = cl2.loadClass(larrayNativeCls)
58-
val ni2 = nativeCls2.newInstance()
59-
val arr2 = Array.ofDim[Byte](100)
60-
val m2 = nativeCls2.getDeclaredMethod("copyToArray", jl.Long.TYPE, classOf[AnyRef], jl.Integer.TYPE, jl.Integer.TYPE)
61-
m2.invoke(ni1, Seq.apply[AnyRef](new jl.Long(0L), arr2, new jl.Integer(0), new jl.Integer(0)):_*)
62-
63-
nativeCls1 should not be (nativeCls2)
64-
nativeCls1 shouldBe (nativeCls1_2)
65-
66-
val arr3 = Array.ofDim[Byte](100)
67-
LArrayNative.copyToArray(0, arr3, 0, 0)
68-
}
69-
70-
71-
}
72-
73-
}
1+
/*--------------------------------------------------------------------------
2+
* Copyright 2013 Taro L. Saito
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*--------------------------------------------------------------------------*/
16+
//--------------------------------------
17+
//
18+
// LArrayLoaderTest.scala
19+
// Since: 2013/03/29 9:56
20+
//
21+
//--------------------------------------
22+
23+
package xerial.larray.impl
24+
25+
import java.net.{URL, URLClassLoader}
26+
import java.io.File
27+
import xerial.larray.LArraySpec
28+
29+
/**
30+
* @author
31+
* Taro L. Saito
32+
*/
33+
class LArrayLoaderTest extends LArraySpec {
34+
35+
"LArrayLoader" should {
36+
37+
"use a different library name for each class loader" in {
38+
39+
val larrayNativeCls = "xerial.larray.impl.LArrayNative"
40+
41+
val cl = Thread.currentThread().getContextClassLoader
42+
val parentCl = cl.getParent.getParent // Fix for sbt-0.13
43+
debug(s"context cl: ${cl}, parent cl: $parentCl")
44+
val classPath = Array(new File("larray-mmap/target/classes").toURI.toURL)
45+
val cl1 = new URLClassLoader(classPath, parentCl)
46+
val cl2 = new URLClassLoader(classPath, parentCl)
47+
48+
import java.{lang => jl}
49+
50+
val nativeCls1 = cl1.loadClass(larrayNativeCls)
51+
val ni1 = nativeCls1.newInstance()
52+
val arr1 = Array.ofDim[Byte](100)
53+
val m1 =
54+
nativeCls1.getDeclaredMethod("copyToArray", jl.Long.TYPE, classOf[AnyRef], jl.Integer.TYPE, jl.Integer.TYPE)
55+
m1.invoke(ni1, Seq.apply[AnyRef](new jl.Long(0L), arr1, new jl.Integer(0), new jl.Integer(0)): _*)
56+
val nativeCls1_2 = cl1.loadClass(larrayNativeCls)
57+
58+
val nativeCls2 = cl2.loadClass(larrayNativeCls)
59+
val ni2 = nativeCls2.newInstance()
60+
val arr2 = Array.ofDim[Byte](100)
61+
val m2 =
62+
nativeCls2.getDeclaredMethod("copyToArray", jl.Long.TYPE, classOf[AnyRef], jl.Integer.TYPE, jl.Integer.TYPE)
63+
m2.invoke(ni1, Seq.apply[AnyRef](new jl.Long(0L), arr2, new jl.Integer(0), new jl.Integer(0)): _*)
64+
65+
nativeCls1 should not be (nativeCls2)
66+
nativeCls1 shouldBe (nativeCls1_2)
67+
68+
val arr3 = Array.ofDim[Byte](100)
69+
LArrayNative.copyToArray(0, arr3, 0, 0)
70+
}
71+
72+
}
73+
74+
}

larray/src/main/scala/xerial/larray/AltLArray.scala

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,34 @@
2323
package xerial.larray
2424

2525
/**
26-
* A common trait for alternative implementations of LArray. This implementation is provided only for testing purpose, so many features might be missing
27-
* in LArrays impemented this trait.
28-
*/
26+
* A common trait for alternative implementations of LArray. This implementation is provided only for testing purpose,
27+
* so many features might be missing in LArrays impemented this trait.
28+
*/
2929
trait AltLIntArrayImpl extends LArray[Int] {
3030

3131
def address = LArray.EmptyArray.address // throws an exception
3232

33-
def copyTo(dest:LByteArray, destOffset:Long) {
33+
def copyTo(dest: LByteArray, destOffset: Long) {
3434
throw new UnsupportedOperationException("copyTo")
3535
}
3636

37-
def copyTo[B](srcOffset:Long, dest:RawByteArray[B], destOffset:Long, blen:Long) {
37+
def copyTo[B](srcOffset: Long, dest: RawByteArray[B], destOffset: Long, blen: Long) {
3838
throw new UnsupportedOperationException("copyTo")
3939
}
4040

4141
def view(from: Long, to: Long) = new LArrayView.LIntArrayView(this, from, to - from)
4242
}
4343

4444
/**
45-
* Alternative implementation of LArray that might be inefficient, but written for comparing performances.
46-
* LIntArraySimple wraps Array[Int] to support Long-type indexes
47-
* @param size array size
48-
*/
45+
* Alternative implementation of LArray that might be inefficient, but written for comparing performances.
46+
* LIntArraySimple wraps Array[Int] to support Long-type indexes
47+
* @param size
48+
* array size
49+
*/
4950
class LIntArraySimple(val size: Long) extends LArray[Int] with AltLIntArrayImpl {
5051

5152
protected[this] def newBuilder = LArray.newBuilder[Int]
5253

53-
5454
private def boundaryCheck(i: Long) {
5555
if (i > Int.MaxValue)
5656
sys.error(f"index must be smaller than ${Int.MaxValue}%,d")
@@ -65,13 +65,13 @@ class LIntArraySimple(val size: Long) extends LArray[Int] with AltLIntArrayImpl
6565
}
6666

6767
def apply(i: Long): Int = {
68-
//boundaryCheck(i)
68+
// boundaryCheck(i)
6969
arr.apply(i.toInt)
7070
}
7171

7272
// a(i) = a(j) = 1
7373
def update(i: Long, v: Int): Int = {
74-
//boundaryCheck(i)
74+
// boundaryCheck(i)
7575
arr.update(i.toInt, v)
7676
v
7777
}
@@ -81,64 +81,66 @@ class LIntArraySimple(val size: Long) extends LArray[Int] with AltLIntArrayImpl
8181
}
8282

8383
/**
84-
* Byte size of an element. For example, if A is Int, its elementByteSize is 4
85-
*/
84+
* Byte size of an element. For example, if A is Int, its elementByteSize is 4
85+
*/
8686
private[larray] def elementByteSize: Int = 4
8787

88-
89-
9088
}
9189

92-
9390
/**
94-
* Emulate large arrays using two-diemensional matrix of Int. Array[Int](page index)(offset in page)
95-
* @param size array size
96-
*/
97-
class MatrixBasedLIntArray(val size:Long) extends LArray[Int] with AltLIntArrayImpl {
91+
* Emulate large arrays using two-diemensional matrix of Int. Array[Int](page index)(offset in page)
92+
* @param size
93+
* array size
94+
*/
95+
class MatrixBasedLIntArray(val size: Long) extends LArray[Int] with AltLIntArrayImpl {
9896

9997
private[larray] def elementByteSize: Int = 4
10098

10199
protected[this] def newBuilder = LArray.newBuilder[Int]
102100

101+
private val maskLen: Int = 24
102+
private val B: Int = 1 << maskLen // block size
103+
private val mask: Long = ~(~0L << maskLen)
103104

104-
private val maskLen : Int = 24
105-
private val B : Int = 1 << maskLen // block size
106-
private val mask : Long = ~(~0L << maskLen)
107-
108-
@inline private def index(i:Long) : Int = (i >>> maskLen).toInt
109-
@inline private def offset(i:Long) : Int = (i & mask).toInt
105+
@inline private def index(i: Long): Int = (i >>> maskLen).toInt
106+
@inline private def offset(i: Long): Int = (i & mask).toInt
110107

111-
private val numBlocks = ((size + (B - 1L))/ B).toInt
112-
private val arr = Array.ofDim[Int](numBlocks, B)
108+
private val numBlocks = ((size + (B - 1L)) / B).toInt
109+
private val arr = Array.ofDim[Int](numBlocks, B)
113110

114111
def clear() {
115-
for(a <- arr) {
112+
for (a <- arr) {
116113
java.util.Arrays.fill(a, 0, a.length, 0)
117114
}
118115
}
119116

120117
/**
121-
* Retrieve an element
122-
* @param i index
123-
* @return the element value
124-
*/
118+
* Retrieve an element
119+
* @param i
120+
* index
121+
* @return
122+
* the element value
123+
*/
125124
def apply(i: Long) = arr(index(i))(offset(i))
126125

127126
/**
128-
* Update an element
129-
* @param i index to be updated
130-
* @param v value to set
131-
* @return the value
132-
*/
127+
* Update an element
128+
* @param i
129+
* index to be updated
130+
* @param v
131+
* value to set
132+
* @return
133+
* the value
134+
*/
133135
def update(i: Long, v: Int) = {
134136
arr(index(i))(offset(i)) = v
135137
v
136138
}
137139

138140
/**
139-
* Release the memory of LArray. After calling this method, the results of calling the other methods becomes undefined or might cause JVM crash.
140-
*/
141+
* Release the memory of LArray. After calling this method, the results of calling the other methods becomes
142+
* undefined or might cause JVM crash.
143+
*/
141144
def free {}
142145

143-
144146
}

0 commit comments

Comments
 (0)