-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1027 from ergoplatform/release/3.2.1
Candidate for 3.2.1
- Loading branch information
Showing
89 changed files
with
854 additions
and
729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package scorex; | ||
|
||
import java.util.Comparator; | ||
|
||
public class ByteUtils { | ||
/** | ||
* Compares primitive Byte Arrays. | ||
* It uses unsigned binary comparation; so the byte with negative value is always higher than byte with non-negative value. | ||
*/ | ||
public static final Comparator<byte[]> BYTE_ARRAY_COMPARATOR = (o1, o2) -> compare(o1, o2); | ||
|
||
public static int compare(byte[] o1, byte[] o2) { | ||
final int len = Math.min(o1.length, o2.length); | ||
for (int i = 0; i < len; i++) { | ||
int b1 = o1[i] & 0xFF; | ||
int b2 = o2[i] & 0xFF; | ||
if (b1 != b2) | ||
return b1 - b2; | ||
} | ||
return o1.length - o2.length; | ||
} | ||
|
||
|
||
public static int byteArrayHashCode(byte[] data) { | ||
//do not use Arrays.hashCode, it generates too many collisions (31 is too low) | ||
int h = 1; | ||
for (byte b : data) { | ||
h = h * (-1640531527) + b; | ||
} | ||
return h; | ||
} | ||
|
||
public static long getLong(byte[] buf, int pos) { | ||
return | ||
((((long) buf[pos++]) << 56) | | ||
(((long) buf[pos++] & 0xFF) << 48) | | ||
(((long) buf[pos++] & 0xFF) << 40) | | ||
(((long) buf[pos++] & 0xFF) << 32) | | ||
(((long) buf[pos++] & 0xFF) << 24) | | ||
(((long) buf[pos++] & 0xFF) << 16) | | ||
(((long) buf[pos++] & 0xFF) << 8) | | ||
(((long) buf[pos] & 0xFF))); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package scorex.db | ||
|
||
|
||
import java.io.Serializable | ||
import java.nio.ByteBuffer | ||
import java.util | ||
|
||
import scorex.ByteUtils | ||
|
||
object ByteArrayWrapper { | ||
|
||
def fromLong(id: Long): ByteArrayWrapper = { | ||
val b = ByteBuffer.allocate(8) | ||
b.putLong(0, id) | ||
ByteArrayWrapper(b.array()) | ||
} | ||
} | ||
|
||
/** | ||
* Wraps byte array and provides hashCode, equals and compare methods. | ||
*/ | ||
case class ByteArrayWrapper(data: Array[Byte]) | ||
extends Serializable | ||
with Comparable[ByteArrayWrapper] | ||
with Ordered[ByteArrayWrapper] { | ||
|
||
/** alternative constructor which takes array size and creates new empty array */ | ||
def this(size:Int) = this(new Array[Byte](size)) | ||
|
||
def size = data.length | ||
|
||
require(data != null) | ||
|
||
//TODO wrapped data immutable? | ||
|
||
override def equals(o: Any): Boolean = | ||
o.isInstanceOf[ByteArrayWrapper] && | ||
util.Arrays.equals(data, o.asInstanceOf[ByteArrayWrapper].data) | ||
|
||
override def hashCode: Int = ByteUtils.byteArrayHashCode(data) | ||
|
||
override def compareTo(o: ByteArrayWrapper): Int = ByteUtils.BYTE_ARRAY_COMPARATOR.compare(this.data, o.data) | ||
|
||
override def compare(that: ByteArrayWrapper): Int = compareTo(that) | ||
|
||
override def toString: String = { | ||
val v = if (size == 8) { | ||
//if size is 8, display as a number | ||
ByteUtils.getLong(data, 0).toString + "L" | ||
} else { | ||
javax.xml.bind.DatatypeConverter.printHexBinary(data) | ||
} | ||
getClass.getSimpleName + "[" + v + "]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
benchmarks/src/test/scala/org/ergoplatform/bench/misc/TempDir.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.ergoplatform.bench | ||
package org.ergoplatform.bench.misc | ||
|
||
import scorex.testkit.utils.FileUtils | ||
|
||
|
Oops, something went wrong.