Class AbstractBinaryTree<T>
- java.lang.Object
-
- dev.brachtendorf.jimagehash.datastructures.tree.AbstractBinaryTree<T>
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BinaryTree,FuzzyBinaryTree
public abstract class AbstractBinaryTree<T> extends Object implements Serializable
- Author:
- Kilian
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intalgoIdThe algorithm id all hashes have to match if they want to perform an actionprotected booleanensureHashConsistencyFlag indicating if hashes origin should be checkedprotected inthashCountKeep track of how many hashes were added to the treeprotected NoderootThe root node of the tree.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractBinaryTree()AbstractBinaryTree(boolean ensureHashConsistency)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddHash(Hash hash, T value)Insert a value associated with the supplied hash in the binary tree (similar to a map).booleanequals(Object obj)abstract PriorityQueue<Result<T>>getElementsWithinHammingDistance(Hash hash, int maxDistance)Return all elements of the tree whose hamming distance is smaller or equal than the supplied max distance.intgetHashCount()abstract List<Result<T>>getNearestNeighbour(Hash hash)Get the most similar to the queried argument.NodegetRoot()inthashCode()voidprintTree()Traverse the tree and output all key = hashes and values found.
-
-
-
Field Detail
-
root
protected Node root
The root node of the tree.
-
hashCount
protected int hashCount
Keep track of how many hashes were added to the tree
-
ensureHashConsistency
protected boolean ensureHashConsistency
Flag indicating if hashes origin should be checked
-
algoId
protected int algoId
The algorithm id all hashes have to match if they want to perform an action
-
-
Constructor Detail
-
AbstractBinaryTree
public AbstractBinaryTree(boolean ensureHashConsistency)
- Parameters:
ensureHashConsistency- If true adding and matching hashes will check weather they are generated by the same algorithms as the first hash added to the tree
-
AbstractBinaryTree
protected AbstractBinaryTree()
-
-
Method Detail
-
addHash
protected void addHash(Hash hash, T value)
Insert a value associated with the supplied hash in the binary tree (similar to a map). Saved values can be found by invokinggetElementsWithinHammingDistance(dev.brachtendorf.jimagehash.hash.Hash, int).Nodes which do not exist will be created. Please be aware that similar to comparing different hashes for images only hashes produced by the same algorithms will return useable results.
If the tree is configured to ensureHashConsistency this function will throw an unchecked IlleglStateException if the added hash does not comply with the first hash added to the tree.
- Parameters:
hash- The hash used to save the value in the treevalue- The value which will be returned if the hash . Common values point to the image used to create the hash or an id in a SQL table
-
getRoot
public Node getRoot()
- Returns:
- the root of the binary tree
-
getHashCount
public int getHashCount()
- Returns:
- how many hashes were added to the tree
-
printTree
public void printTree()
Traverse the tree and output all key = hashes and values found.
-
getElementsWithinHammingDistance
public abstract PriorityQueue<Result<T>> getElementsWithinHammingDistance(Hash hash, int maxDistance)
Return all elements of the tree whose hamming distance is smaller or equal than the supplied max distance. If the tree is configured to ensureHashConsistency this function will throw an unchecked IlleglStateException if the checked hash does not comply with the first hash added to the tree.- Parameters:
hash- The hash to search formaxDistance- The maximal hamming distance deviation all found hashes may possess. A distance of 0 will return all objects added whose hash is exactly the hash supplied as the first argument- Returns:
- Search results contain objects and distances matching the search criteria. The results returned are ordered to return the closest match first.
-
getNearestNeighbour
public abstract List<Result<T>> getNearestNeighbour(Hash hash)
Get the most similar to the queried argument. In case of equidistant hashes, multiple objects may be returned.- Parameters:
hash- the hash to search the closest match for- Returns:
- the hash the most similar to the supplied hash
-
-