org.feijoas.mango.common

hash

package hash

Visibility
  1. Public
  2. All

Type Members

  1. final case class BloomFilter[T] extends (T) ⇒ Boolean with Serializable with Product

    A Bloom filter for instances of T.

    A Bloom filter for instances of T. A Bloom filter offers an approximate containment test with one-sided error: if it claims that an element is contained in it, this might be in error, but if it claims that an element is not contained in it, then this is definitely true.

    From the Guava BloomFilter tutorial:

    implicit object PersonFunnel extends Funnel[Person] {
       override def funnel(from: Person, into: PrimitiveSink) = ...
    }
    
    val friends: BloomFilter[Person] = BloomFilter.create(500, 0.01)
    friendsList.foreach { case p: Person => friends.put(p) }
    
    // much later
    if (friends.mightContain(dude)) {
       // the probability that dude reached this place if he isn't a friend is 1%
       // we might, for example, start asynchronously loading things for dude while we do a more expensive exact check
    }

    The false positive probability (FPP) of a bloom filter is defined as the probability that #mightContain(T) will erroneously return true for an object that has not actually been put in the BloomFilter.

    Annotations
    @Beta() @SerialVersionUID()
    Since

    0.6 (copied from Guava-libraries)

  2. trait Funnel[T] extends Serializable

    A Funnel is a type class for an object which can send data from an object of type T into a PrimitiveSink.

    A Funnel is a type class for an object which can send data from an object of type T into a PrimitiveSink.

    Note that serialization of a BloomFilter requires the proper serialization of funnels.

    From the Guava Funnel tutorial:

    // A Funnel describes how to decompose a particular object type into primitive field values.
    // For example, if we had
    case class Person(id: Integer, firstName: String, lastName: String, birthYear: Int)
    
    // our Funnel might look like
    implicit val personFunnel = new Funnel[Person] {
       override def funnel(person: Person, into: PrimitiveSink) = {
          into
          .putInt(person.id)
          .putString(person.firstName, Charsets.UTF_8)
          .putString(person.lastName, Charsets.UTF_8)
          .putInt(person.birthYear)
       }
    }
    Annotations
    @Beta()
    Since

    0.6 (copied from Guava-libraries)

Value Members

  1. object BloomFilter extends Serializable

    Factory for BloomFilters

    Factory for BloomFilters

    In order to be able to create a BloomFilter[T] an implementation of a Funnel for T (called type class) must be in implicit scope (recommended) or passed explicitly as a parameter.

  2. object Funnel extends Serializable

    Utility functions for the work with Funnel.

    Utility functions for the work with Funnel.

    Usage example for conversion between Guava and Mango:

    // convert a Guava Funnel[T] to a Mango Funnel[T]
    import com.google.common.hash.{ Funnel => GuavaFunnel }
    val guavaFunnel: GuavaFunnel[T] = ...
    val mangoFunnel: Funnel[T] = guavaFunnel.asScala
    
    import com.google.common.hash.{ Funnel => GuavaFunnel }
    val guavaFunnel: GuavaFunnel[CharSequence] = GuavaFunnels.stringFunnel
    val mangoFunnel: Funnel[CharSequence] = guavaFunnel.asScala
    Since

    0.6

Ungrouped