Class 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
    • Constructor Detail

      • FuzzyBinaryTree

        public FuzzyBinaryTree​(boolean ensureHashConsistency)
    • Method Detail

      • addHash

        public void addHash​(FuzzyHash hash)
      • addHashes

        public void addHashes​(FuzzyHash... fuzzyHashs)
      • addHash

        protected void addHash​(Hash hash,
                               FuzzyHash value)
        Description copied from class: AbstractBinaryTree
        Insert a value associated with the supplied hash in the binary tree (similar to a map). Saved values can be found by invoking AbstractBinaryTree.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:
        addHash in class AbstractBinaryTree<FuzzyHash>
        Parameters:
        hash - The hash used to save the value in the tree
        value - 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: AbstractBinaryTree
        Get the most similar to the queried argument. In case of equidistant hashes, multiple objects may be returned.
        Specified by:
        getNearestNeighbour in class AbstractBinaryTree<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: AbstractBinaryTree
        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.
        Specified by:
        getElementsWithinHammingDistance in class AbstractBinaryTree<FuzzyHash>
        Parameters:
        hash - The hash to search for
        maxDistance - 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.