Packages

final case class Bytes(array: Array[Byte]) extends Serializable with Product

A wrapper for Array[Byte] that provides sane implementations of hashCode, equals, and toString. The wrapped array of bytes is assumed to be never modified.

Note: Unfortunately we cannot make Bytes a value class because a value class may not override the hashCode and equals methods (cf. SIP-15, criterion 4).

Alternatives

Instead of wrapping an Array[Byte] with this class you can also convert an Array[Byte] to a Seq[Byte] via Scala's toSeq method:

val arrayByte: Array[Byte] = Array(1.toByte)
val seqByte: Seq[Byte] = arrayByte.toSeq

Like Bytes, a Seq[Byte] has sane hashCode, equals, and toString implementations.

Performance-wise we found that a Seq[Byte] is comparable to Bytes. For example, a CMS[Seq[Byte]] was measured to be only slightly slower than CMS[Bytes] (think: single-digit percentages).

array

the wrapped array of bytes

See also

MinHasher

Linear Supertypes
Product, Equals, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Bytes
  2. Product
  3. Equals
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Bytes(array: Array[Byte])

    array

    the wrapped array of bytes

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply(idx: Int): Byte
  5. val array: Array[Byte]
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(that: Any): Boolean

    Implementation detail: This equals method is defined in terms of the wrapped array, which is a mutable field.

    Implementation detail: This equals method is defined in terms of the wrapped array, which is a mutable field. In general such a definition of equals is considered bad practice, but in our case we justify the use of a mutable field because the contract of Bytes requires that the wrapped array must never be modified (and we intentionally do not create a defensive, immutable copy because of performance considerations).

    Definition Classes
    Bytes → Equals → AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    Bytes → AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. def productElementNames: Iterator[String]
    Definition Classes
    Product
  18. def size: Int
  19. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String
    Definition Classes
    Bytes → AnyRef → Any
  21. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Product

Inherited from Equals

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped