Class AbstractBinaryTree<T>

    • 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 invoking 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.

        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
      • 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 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.
      • 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object