Package nl.tue.storage.compressor
Class AbstractFixedLengthListCompressor<K extends java.lang.Number>
- java.lang.Object
-
- nl.tue.storage.compressor.AbstractFixedLengthListCompressor<K>
-
- 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface nl.tue.storage.EqualOperation
EqualOperation.Default<K>
-
Nested classes/interfaces inherited from interface nl.tue.storage.HashOperation
HashOperation.Default<K>
-
-
Field Summary
Fields Modifier and Type Field Description protected intlength
-
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 voiddeflate(java.util.List<K> object, java.io.OutputStream stream)deflate the given object into the provided stream.protected voiddeflateHead(java.util.List<K> object, java.io.OutputStream stream)booleanequals(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 KfromByteArray(byte[] bytes)reads an object of type K from an array of bytes of size numBytes()protected BitMaskgetBitMask(java.util.List<K> vector)intgetHashCode(java.util.List<K> object)Return the hashCode of the objectintgetHashCode(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 booleanisZero(K number)Indicates if the given number equals 0protected abstract K[]newEmptyArray(int length)Instantiates a new array of the given length, such that for all elements, isZero() returns true.protected abstract intnumBytes()returns the number of bytes for storing one object of type Kprotected BitMaskreadMask(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
-
Methods inherited from interface nl.tue.storage.Deflater
getMaxByteCount
-
-
-
-
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:Inflaterread an object from a stream. The inflater should know when to stop reading and should NOT close the stream;
-
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:Deflaterdeflate the given object into the provided stream. This method should NOT close the stream.
-
deflateHead
protected void deflateHead(java.util.List<K> object, java.io.OutputStream stream) throws java.io.IOException
- Throws:
java.io.IOException
-
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:EqualOperationCheck 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:
equalsin interfaceEqualOperation<K extends java.lang.Number>- Returns:
- Throws:
StorageExceptionjava.io.IOException
-
getHashCode
public int getHashCode(java.util.List<K> object)
Return the hashCode of the object- Specified by:
getHashCodein interfaceHashOperation<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:
getHashCodein interfaceHashOperation<K extends java.lang.Number>- Parameters:
store-l-- Returns:
- Throws:
StorageException
-
-