Class/Object

com.twitter.algebird

Bytes

Related Docs: object Bytes | package algebird

Permalink

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
Visibility
  1. Public
  2. All

Instance Constructors

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

    Permalink

    array

    the wrapped array of bytes

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. def apply(idx: Int): Byte

    Permalink
  5. val array: Array[Byte]

    Permalink

    the wrapped array of bytes

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

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

    Permalink
    Definition Classes
    AnyRef
  9. def equals(that: Any): Boolean

    Permalink

    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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. def size: Int

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

    Permalink
    Definition Classes
    AnyRef
  19. def toString(): String

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped