8000 Fix Chunk Packed Boolean Hash Code by adamgfraser · Pull Request #7109 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Chunk Packed Boolean Hash Code #7109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ object ChunkPackedBooleanSpec extends ZIOBaseSpec {
val expected = toBinaryString(bools, bits = 64, endianness)
assert(actual)(equalTo(expected))
}
},
test("hashcode") {
val actual = Chunk(false, true, false).toPackedByte.hashCode
assert(actual)(anything)
}
)

Expand Down
36 changes: 26 additions & 10 deletions core/shared/src/main/scala/zio/Chunk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1384,16 +1384,17 @@ object Chunk extends ChunkFactory with ChunkPlatformSpecific {
*/
private[zio] def classTagOf[A](chunk: Chunk[A]): ClassTag[A] =
chunk match {
case x: AppendN[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Arr[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Concat[_] => x.classTag.asInstanceOf[ClassTag[A]]
case Empty => classTag[java.lang.Object].asInstanceOf[ClassTag[A]]
case x: PrependN[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Singleton[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Slice[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Update[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: VectorChunk[_] => x.classTag.asInstanceOf[ClassTag[A]]
case _: BitChunk[_] => ClassTag.Boolean.asInstanceOf[ClassTag[A]]
case x: AppendN[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Arr[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Concat[_] => x.classTag.asInstanceOf[ClassTag[A]]
case Empty => classTag[java.lang.Object].asInstanceOf[ClassTag[A]]
case x: PrependN[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Singleton[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Slice[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: Update[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: VectorChunk[_] => x.classTag.asInstanceOf[ClassTag[A]]
case x: ChunkPackedBoolean[_] => x.classTag.asInstanceOf[ClassTag[A]]
case _: BitChunk[_] => ClassTag.Boolean.asInstanceOf[ClassTag[A]]
}

/**
Expand Down Expand Up @@ -1873,6 +1874,7 @@ object Chunk extends ChunkFactory with ChunkPlatformSpecific {
def &(x: T, y: T): T
def ^(x: T, y: T): T
def unary_~(x: T): T
def classTag: ClassTag[T]
}

private[zio] object BitOps {
Expand All @@ -1887,6 +1889,7 @@ object Chunk extends ChunkFactory with ChunkPlatformSpecific {
def &(x: Byte, y: Byte): Byte = (x & y).toByte
def ^(x: Byte, y: Byte): Byte = (x ^ y).toByte
def unary_~(x: Byte): Byte = (~x).toByte
def classTag: ClassTag[Byte] = ClassTag.Byte
}
implicit val IntOps: BitOps[Int] = new BitOps[Int] {
def zero: Int = 0
Expand All @@ -1898,6 +1901,7 @@ object Chunk extends ChunkFactory with ChunkPlatformSpecific {
def &(x: Int, y: Int): Int = x & y
def ^(x: Int, y: Int): Int = x ^ y
def unary_~(x: Int): Int = ~x
def classTag: ClassTag[Int] = ClassTag.Int
}
implicit val LongOps: BitOps[Long] = new BitOps[Long] {
def zero: Long = 0L
Expand All @@ -1909,6 +1913,7 @@ object Chunk extends ChunkFactory with ChunkPlatformSpecific {
def &(x: Long, y: Long): Long = x & y
def ^(x: Long, y: Long): Long = x ^ y
def unary_~(x: Long): Long = ~x
def classTag: ClassTag[Long] = ClassTag.Long
}
}

Expand Down Expand Up @@ -2361,9 +2366,20 @@ object Chunk extends ChunkFactory with ChunkPlatformSpecific {
if (endianness == BitChunk.Endianness.BigEndian) elem else ops.reverse(elem)
}

override protected[zio] def toArray[T1 >: T](n: Int, dest: Array[T1]): Unit = {
var i = n
while (i < length) {
dest(i + n) = self.apply(i)
i += 1
}
}

override def chunkIterator: ChunkIterator[T] =
self

implicit val classTag: ClassTag[T] =
ops.classTag

def hasNextAt(index: Int): Boolean =
index < length

Expand Down
0