Class FuzzyBinaryTree
- java.lang.Object
-
- dev.brachtendorf.jimagehash.datastructures.tree.AbstractBinaryTree<FuzzyHash>
-
- dev.brachtendorf.jimagehash.datastructures.tree.binaryTreeFuzzy.FuzzyBinaryTree
-
- All Implemented Interfaces:
Serializable
public class FuzzyBinaryTree extends AbstractBinaryTree<FuzzyHash>
A binary tree implementation allowing to quickly lookup be aware that fuzzy trees currently are of one time use and are rendered invalid as soon as one of the underlying hashes changes it's internal state.! TODO for mutability add a list of uncertainties to each node and allow remove operation by supplying the old and the new fuzzy hash state- Since:
- 3.0.0
- Author:
- Kilian
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class dev.brachtendorf.jimagehash.datastructures.tree.AbstractBinaryTree
algoId, ensureHashConsistency, hashCount, root
-
-
Constructor Summary
Constructors Constructor Description FuzzyBinaryTree(boolean ensureHashConsistency)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHash(FuzzyHash hash)protected voidaddHash(Hash hash, FuzzyHash value)Insert a value associated with the supplied hash in the binary tree (similar to a map).voidaddHashes(FuzzyHash... fuzzyHashs)voidaddHashes(Collection<FuzzyHash> fuzzyHashs)PriorityQueue<Result<FuzzyHash>>getElementsWithinHammingDistance(Hash hash, int maxDistance)Return all elements of the tree whose hamming distance is smaller or equal than the supplied max distance.List<Result<FuzzyHash>>getNearestNeighbour(Hash hash)Get the most similar to the queried argument.-
Methods inherited from class dev.brachtendorf.jimagehash.datastructures.tree.AbstractBinaryTree
equals, getHashCount, getRoot, hashCode, printTree
-
-
-
-
Method Detail
-
addHash
public void addHash(FuzzyHash hash)
-
addHashes
public void addHashes(FuzzyHash... fuzzyHashs)
-
addHashes
public void addHashes(Collection<FuzzyHash> fuzzyHashs)
-
addHash
protected void addHash(Hash hash, FuzzyHash value)
Description copied from class:AbstractBinaryTreeInsert a value associated with the supplied hash in the binary tree (similar to a map). Saved values can be found by invokingAbstractBinaryTree.getElementsWithinHammingDistance(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.
- Overrides:
addHashin classAbstractBinaryTree<FuzzyHash>- 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
-
getNearestNeighbour
public List<Result<FuzzyHash>> getNearestNeighbour(Hash hash)
Description copied from class:AbstractBinaryTreeGet the most similar to the queried argument. In case of equidistant hashes, multiple objects may be returned.- Specified by:
getNearestNeighbourin classAbstractBinaryTree<FuzzyHash>- Parameters:
hash- the hash to search the closest match for- Returns:
- the hash the most similar to the supplied hash
-
getElementsWithinHammingDistance
public PriorityQueue<Result<FuzzyHash>> getElementsWithinHammingDistance(Hash hash, int maxDistance)
Description copied from class:AbstractBinaryTreeReturn 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.- Specified by:
getElementsWithinHammingDistancein classAbstractBinaryTree<FuzzyHash>- 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.
-
-