Class HashBuilder
- java.lang.Object
-
- dev.brachtendorf.jimagehash.hashAlgorithms.HashBuilder
-
public class HashBuilder extends Object
Helper class to quickly create a bitwise byte array representation which can be converted to a big integer object.To maintain the capability to decode the created hash value back to an image the order of the byte array is of utmost importance. Due to hashes ability to contain non 8 compliment bit values and
BigIntegerstripping leading zero bits the partial bit value has to be present at the 0 slot.The hashbuilder systematically grows the base byte[] array as needed but performs the best if the correct amount of bits are known beforehand.
In other terms this class performs the same operation as
But scales much much better for higher hash values. The order of the bits are flipped using the hashbuilder approach.StringBuilder sb = new StringBuilder(); sb.append("100011"); BigInteger b = new BigInteger(sb.toString(),2);- Since:
- 3.0.0
- Author:
- Kilian TODO we don't really need a Big Integer at all. We can use a byte array.
-
-
Field Summary
Fields Modifier and Type Field Description protected intlength
-
Constructor Summary
Constructors Constructor Description HashBuilder(int bits)Create a hashbuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidprependOne()Add a one bit to the hashvoidprependZero()Add a zero bit to the hashBigIntegertoBigInteger()Convert the internal state of the hashbuilder to a big integer object
-
-
-
Constructor Detail
-
HashBuilder
public HashBuilder(int bits)
Create a hashbuilder.- Parameters:
bits- the number of bits the hash will have [8 - Integer.MAX_VALUE]. If the builder requires more space than specified copy operations will take place to grow the builder automatically.Allocating to much space also results in the correct hash value being created but might also result in a slight performance penalty
-
-
Method Detail
-
prependZero
public void prependZero()
Add a zero bit to the hash
-
prependOne
public void prependOne()
Add a one bit to the hash
-
toBigInteger
public BigInteger toBigInteger()
Convert the internal state of the hashbuilder to a big integer object- Returns:
- a big integer object
-
-