Class AbstractFixedLengthListCompressor<K extends java.lang.Number>

  • Type Parameters:
    K -
    All Implemented Interfaces:
    Deflater<java.util.List<K>>, EqualOperation<java.util.List<K>>, HashOperation<java.util.List<K>>, Inflater<java.util.List<K>>
    Direct Known Subclasses:
    ByteListCompressor, IntListCompressor, LongListCompressor, ShortListCompressor

    public abstract class AbstractFixedLengthListCompressor<K extends java.lang.Number>
    extends java.lang.Object
    implements EqualOperation<java.util.List<K>>, Deflater<java.util.List<K>>, Inflater<java.util.List<K>>, HashOperation<java.util.List<K>>
    Abstract base class for vector storage Note that the hashCode operation does not just look at the bitmask, but the equals does. If the hashCode operation would only consider the bitmask, then all vectors with the same bitmask would end up in the same bin in the hashSet and this would require each hash collision to use the full equality, rather than the quick check on the bitmasks. It is required that each list that is stored in a CompressedStore using an instance of this class has the same length.
    Author:
    bfvdonge
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int length  
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractFixedLengthListCompressor​(int length)
      Construct the compressor with a fixed length for all vectors.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void deflate​(java.util.List<K> object, java.io.OutputStream stream)
      deflate the given object into the provided stream.
      protected void deflateHead​(java.util.List<K> object, java.io.OutputStream stream)  
      boolean equals​(java.util.List<K> vector, CompressedStore<java.util.List<K>> store, long l)
      Check for equality between a given object and a location in the store.
      protected abstract K fromByteArray​(byte[] bytes)
      reads an object of type K from an array of bytes of size numBytes()
      protected BitMask getBitMask​(java.util.List<K> vector)  
      int getHashCode​(java.util.List<K> object)
      Return the hashCode of the object
      int getHashCode​(CompressedStore<java.util.List<K>> store, long l)
      Retrieve the object from the store and return its hashCode.
      java.util.List<K> inflate​(java.io.InputStream stream)
      read an object from a stream.
      protected java.util.List<K> inflateContent​(java.io.InputStream stream, int[] ids)  
      protected abstract boolean isZero​(K number)
      Indicates if the given number equals 0
      protected abstract K[] newEmptyArray​(int length)
      Instantiates a new array of the given length, such that for all elements, isZero() returns true.
      protected abstract int numBytes()
      returns the number of bytes for storing one object of type K
      protected BitMask readMask​(java.io.InputStream stream)  
      protected abstract byte[] toByteArray​(K number)
      writes an object of type K to an array of bytes, of size numBytes();
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • length

        protected final int length
    • Constructor Detail

      • AbstractFixedLengthListCompressor

        public AbstractFixedLengthListCompressor​(int length)
        Construct the compressor with a fixed length for all vectors.
        Parameters:
        length -
    • Method Detail

      • isZero

        protected abstract boolean isZero​(K number)
        Indicates if the given number equals 0
        Parameters:
        number -
        Returns:
      • numBytes

        protected abstract int numBytes()
        returns the number of bytes for storing one object of type K
        Returns:
      • toByteArray

        protected abstract byte[] toByteArray​(K number)
        writes an object of type K to an array of bytes, of size numBytes();
        Parameters:
        number -
        Returns:
      • fromByteArray

        protected abstract K fromByteArray​(byte[] bytes)
        reads an object of type K from an array of bytes of size numBytes()
        Parameters:
        bytes -
        Returns:
      • newEmptyArray

        protected abstract K[] newEmptyArray​(int length)
        Instantiates a new array of the given length, such that for all elements, isZero() returns true.
        Parameters:
        length -
        Returns:
      • inflate

        public java.util.List<K> inflate​(java.io.InputStream stream)
                                  throws java.io.IOException
        Description copied from interface: Inflater
        read an object from a stream. The inflater should know when to stop reading and should NOT close the stream;
        Specified by:
        inflate in interface Inflater<K extends java.lang.Number>
        Returns:
        Throws:
        java.io.IOException
      • readMask

        protected BitMask readMask​(java.io.InputStream stream)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • inflateContent

        protected java.util.List<K> inflateContent​(java.io.InputStream stream,
                                                   int[] ids)
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • deflate

        public void deflate​(java.util.List<K> object,
                            java.io.OutputStream stream)
                     throws java.io.IOException
        Description copied from interface: Deflater
        deflate the given object into the provided stream. This method should NOT close the stream.
        Specified by:
        deflate in interface Deflater<K extends java.lang.Number>
        Throws:
        java.io.IOException
      • deflateHead

        protected void deflateHead​(java.util.List<K> object,
                                   java.io.OutputStream stream)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • getBitMask

        protected BitMask getBitMask​(java.util.List<K> vector)
      • equals

        public boolean equals​(java.util.List<K> vector,
                              CompressedStore<java.util.List<K>> store,
                              long l)
                       throws StorageException,
                              java.io.IOException
        Description copied from interface: EqualOperation
        Check for equality between a given object and a location in the store. Should return true, if and only if the given object is indeed stored at index l in the store.
        Specified by:
        equals in interface EqualOperation<K extends java.lang.Number>
        Returns:
        Throws:
        StorageException
        java.io.IOException
      • getHashCode

        public int getHashCode​(java.util.List<K> object)
        Return the hashCode of the object
        Specified by:
        getHashCode in interface HashOperation<K extends java.lang.Number>
        Parameters:
        object -
        Returns:
      • getHashCode

        public int getHashCode​(CompressedStore<java.util.List<K>> store,
                               long l)
                        throws StorageException
        Retrieve the object from the store and return its hashCode. Requires the store to have a non-null inflater
        Specified by:
        getHashCode in interface HashOperation<K extends java.lang.Number>
        Parameters:
        store -
        l -
        Returns:
        Throws:
        StorageException