yaooqinn commented on a change in pull request #1333:
URL: https://github.com/apache/incubator-kyuubi/pull/1333#discussion_r742789228
##########
File path:
dev/kyuubi-extension-spark-common/src/main/scala/org/apache/kyuubi/sql/zorder/ZorderBytesUtils.scala
##########
@@ -30,27 +30,284 @@ object ZorderBytesUtils {
private final val BIT_32_MASK = 1 << 31
private final val BIT_64_MASK = 1L << 63
- def interleaveMultiByteArray(arrays: Array[Array[Byte]]): Array[Byte] = {
+ def interleaveBits(inputs: Array[Any]): Array[Byte] = {
+ if (inputs.length > 8) {
+ // it's the default approach, use O(64 * n), n is the length of inputs
+ interleaveBitsDefault(inputs.map(toByteArray))
+ } else {
+ // it's a more fast approach, use O(8 * 8)
+ // can see
http://graphics.stanford.edu/~seander/bithacks.html#InterleaveTableObvious
+ inputs.length match {
+ case 1 => longToByte(toLong(inputs(0)))
+ case 2 => interleave2Longs(toLong(inputs(0)), toLong(inputs(1)))
+ case 3 => interleave3Longs(toLong(inputs(0)), toLong(inputs(1)),
toLong(inputs(2)))
+ case 4 => interleave4Longs(toLong(inputs(0)), toLong(inputs(1)),
toLong(inputs(2)),
+ toLong(inputs(3)))
+ case 5 => interleave5Longs(toLong(inputs(0)), toLong(inputs(1)),
toLong(inputs(2)),
+ toLong(inputs(3)), toLong(inputs(4)))
+ case 6 => interleave6Longs(toLong(inputs(0)), toLong(inputs(1)),
toLong(inputs(2)),
+ toLong(inputs(3)), toLong(inputs(4)), toLong(inputs(5)))
+ case 7 => interleave7Longs(toLong(inputs(0)), toLong(inputs(1)),
toLong(inputs(2)),
+ toLong(inputs(3)), toLong(inputs(4)), toLong(inputs(5)),
toLong(inputs(6)))
+ case 8 => interleave8Longs(toLong(inputs(0)), toLong(inputs(1)),
toLong(inputs(2)),
+ toLong(inputs(3)), toLong(inputs(4)), toLong(inputs(5)),
toLong(inputs(6)),
+ toLong(inputs(7)))
+ }
+ }
+ }
+
+ private def interleave2Longs(l1: Long, l2: Long): Array[Byte] = {
+ // output 16 bits
+ val result = new Array[Byte](16)
+ (0 until 8).foreach { i =>
Review comment:
Use while loops instead of for loops or functional transformations (e.g.
map, foreach). For loops and functional transformations are very slow (due to
virtual function calls and boxing).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]