Package com.tonic.analysis.fingerprint
Class FingerprintDatabase
- java.lang.Object
-
- com.tonic.analysis.fingerprint.FingerprintDatabase
-
public class FingerprintDatabase extends Object
In-memory store of method fingerprints with per-level hash indexes for exact and similarity lookups.
-
-
Constructor Summary
Constructors Constructor Description FingerprintDatabase()Creates an empty database.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(MethodFingerprint fp)Stores a fingerprint and indexes it by each level hash it carries.voidaddAll(Collection<MethodFingerprint> fingerprints)Adds every fingerprint in the collection.voidclear()Removes all fingerprints and hash indexes.booleancontains(String methodId)FingerprintMatchfindBestMatch(MethodFingerprint query)Finds the single highest-scoring match for a query.List<String>findExactMatches(MethodFingerprint query, FingerprintLevel level)Finds methods whose hash at the given level equals the query's hash.List<FingerprintMatch>findSimilar(MethodFingerprint query, double threshold)Scores hash-index candidates against a query and keeps those at or above the threshold.List<FingerprintMatch>findTopMatches(MethodFingerprint query, int limit)Finds the highest-scoring matches for a query, capped at a limit.MethodFingerprintget(String methodId)Collection<MethodFingerprint>getAllFingerprints()intsize()
-
-
-
Method Detail
-
add
public void add(MethodFingerprint fp)
Stores a fingerprint and indexes it by each level hash it carries.- Parameters:
fp- the fingerprint to add; null or id-less fingerprints are ignored
-
addAll
public void addAll(Collection<MethodFingerprint> fingerprints)
Adds every fingerprint in the collection.- Parameters:
fingerprints- the fingerprints to add
-
findExactMatches
public List<String> findExactMatches(MethodFingerprint query, FingerprintLevel level)
Finds methods whose hash at the given level equals the query's hash.- Parameters:
query- the fingerprint to matchlevel- the fingerprint level to compare at- Returns:
- the matching method ids, empty if the query lacks that level
-
findSimilar
public List<FingerprintMatch> findSimilar(MethodFingerprint query, double threshold)
Scores hash-index candidates against a query and keeps those at or above the threshold.- Parameters:
query- the fingerprint to match; the query's own method id is excludedthreshold- the minimum score to keep- Returns:
- matches sorted best first
-
findTopMatches
public List<FingerprintMatch> findTopMatches(MethodFingerprint query, int limit)
Finds the highest-scoring matches for a query, capped at a limit.- Parameters:
query- the fingerprint to matchlimit- the maximum number of matches to return- Returns:
- up to limit matches, best first
-
findBestMatch
public FingerprintMatch findBestMatch(MethodFingerprint query)
Finds the single highest-scoring match for a query.- Parameters:
query- the fingerprint to match- Returns:
- the best match, or null if the database has no candidates
-
get
public MethodFingerprint get(String methodId)
- Parameters:
methodId- the method id to look up- Returns:
- the stored fingerprint, or null if absent
-
contains
public boolean contains(String methodId)
- Parameters:
methodId- the method id to look up- Returns:
- true if a fingerprint is stored for the id
-
size
public int size()
- Returns:
- the number of stored fingerprints
-
getAllFingerprints
public Collection<MethodFingerprint> getAllFingerprints()
- Returns:
- an unmodifiable view of all stored fingerprints
-
clear
public void clear()
Removes all fingerprints and hash indexes.
-
-