Given f
, a function from L
into K
, creates a CMSHasher[L]
whose hash function is equivalent to:
Given f
, a function from L
into K
, creates a CMSHasher[L]
whose hash function is equivalent to:
def hash(a: Int, b: Int, width: Int)(x: L): CMSHasher[L] = CMSHasher[K].hash(a, b, width)(f(x))
Be aware that the use of contramap may come at a cost (e.g. increased time) due to the translation calls between
K
and L
.
The following example creates a CMSHasher for the unsupported type K=Double
:
def f(d: Double): Array[Byte] = { val l: Long = java.lang.Double.doubleToLongBits(d) java.nio.ByteBuffer.allocate(8).putLong(l).array() } implicit val cmsHasherDouble: CMSHasher[Double] = CMSHasherArrayByte.contramap((d: Double) => f(d))
Returns a * x + b (mod p) (mod width)
.
Returns a * x + b (mod p) (mod width)
.
Given f
, a function from L
into K
, creates a CMSHasher[L]
whose hash function is equivalent to:
Given f
, a function from L
into K
, creates a CMSHasher[L]
whose hash function is equivalent to:
def hash(a: Int, b: Int, width: Int)(x: L): CMSHasher[L] = CMSHasher[K].hash(a, b, width)(f(x))