com.twitter.algebird

Bytes

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

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
Serializable, Product, Equals, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Bytes
  2. Serializable
  3. Product
  4. Equals
  5. Serializable
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

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

    array

    the wrapped array of bytes

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def apply(idx: Int): Byte

  7. val array: Array[Byte]

    the wrapped array of bytes

  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. 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
  12. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Definition Classes
    Bytes → AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  19. def size: Int

  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  21. def toString(): String

    Definition Classes
    Bytes → AnyRef → Any
  22. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped