Class NormalSketch

  • All Implemented Interfaces:
    Cloneable

    public class NormalSketch
    extends Sketch<NormalSketch>
    Sketch used by the HyperLogLog (HLL) algorithm.
    Author:
    bjorncs
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int classId  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void aggregate​(int hash)
      Aggregates the hash value.
      void aggregate​(Iterable<Integer> hashValues)
      Aggregates the hash values.
      byte[] data()
      Returns the underlying byte array backing the sketch.
      boolean equals​(Object o)  
      int hashCode()  
      void merge​(NormalSketch other)
      Lossless merge of sketches.
      protected void onDeserialize​(com.yahoo.vespa.objects.Deserializer buf)  
      protected int onGetClassId()  
      protected void onSerialize​(com.yahoo.vespa.objects.Serializer buf)
      Serializes the Sketch.
      int size()
      Sketch size.
      String toString()  
      • Methods inherited from class com.yahoo.vespa.objects.Identifiable

        clone, create, createFromId, deserialize, deserializeOptional, deserializeWithId, equals, getClassId, getRawUtf8Bytes, getUtf8, putUtf8, registerClass, serialize, serializeOptional, serializeWithId, visitMembers
      • Methods inherited from class com.yahoo.vespa.objects.Selectable

        select, select, selectMembers
    • Field Detail

      • classId

        public static final int classId
    • Constructor Detail

      • NormalSketch

        public NormalSketch​(int precision)
        Create a sketch with a given HLL precision parameter.
        Parameters:
        precision - The precision parameter used by HLL. Determines the size of the sketch.
    • Method Detail

      • merge

        public void merge​(NormalSketch other)
        Lossless merge of sketches. Performs a pairwise maximum on the underlying data array.
        Specified by:
        merge in class Sketch<NormalSketch>
        Parameters:
        other - Other sketch
      • aggregate

        public void aggregate​(Iterable<Integer> hashValues)
        Aggregates the hash values.
        Specified by:
        aggregate in class Sketch<NormalSketch>
        Parameters:
        hashValues - Provides an iterator for the hash values
      • aggregate

        public void aggregate​(int hash)
        Aggregates the hash value.
        Specified by:
        aggregate in class Sketch<NormalSketch>
        Parameters:
        hash - Hash value.
      • onSerialize

        protected void onSerialize​(com.yahoo.vespa.objects.Serializer buf)
        Serializes the Sketch. Serialization format ================== Original size: 4 bytes Compressed size: 4 bytes Compressed data: N * 1 bytes Invariant: compressed size <= original size Special case: compressed size == original size => data is uncompressed
        Overrides:
        onSerialize in class com.yahoo.vespa.objects.Identifiable
        Parameters:
        buf - Serializer
      • onDeserialize

        protected void onDeserialize​(com.yahoo.vespa.objects.Deserializer buf)
        Overrides:
        onDeserialize in class com.yahoo.vespa.objects.Identifiable
      • data

        public byte[] data()
        Returns the underlying byte array backing the sketch.
        Returns:
        The underlying sketch data
      • size

        public int size()
        Sketch size.
        Returns:
        Number of buckets in the sketch.
      • equals

        public boolean equals​(Object o)
        Overrides:
        equals in class com.yahoo.vespa.objects.Identifiable
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class com.yahoo.vespa.objects.Identifiable
      • onGetClassId

        protected int onGetClassId()
        Overrides:
        onGetClassId in class com.yahoo.vespa.objects.Identifiable
      • toString

        public String toString()
        Overrides:
        toString in class com.yahoo.vespa.objects.Identifiable