Class Fingerprint
java.lang.Object
cloud.opencode.base.hash.simhash.Fingerprint
Text fingerprint representation for SimHash
SimHash 的文本指纹表示
Represents a SimHash fingerprint value with utility methods for comparing similarity between fingerprints.
表示 SimHash 指纹值,提供比较指纹间相似度的工具方法。
Features | 主要功能:
- Hamming distance calculation - 海明距离计算
- Similarity score computation - 相似度分数计算
- Hex and binary representation - 十六进制和二进制表示
Usage Examples | 使用示例:
Fingerprint fp1 = Fingerprint.of64(simHash.hash(text1));
Fingerprint fp2 = Fingerprint.of64(simHash.hash(text2));
int distance = fp1.hammingDistance(fp2);
double similarity = fp1.similarity(fp2);
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-hash V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbits()Gets the number of bits 获取位数booleanstatic FingerprintCreates a fingerprint from hexadecimal string 从十六进制字符串创建指纹inthammingDistance(Fingerprint other) Calculates the Hamming distance to another fingerprint 计算与另一个指纹的海明距离inthashCode()booleanisSimilar(Fingerprint other, int threshold) Checks if similar within threshold 检查是否在阈值内相似static Fingerprintof(long value, int bits) Creates a fingerprint with specified bits 创建指定位数的指纹static Fingerprintof32(int value) Creates a 32-bit fingerprint 创建32位指纹static Fingerprintof64(long value) Creates a 64-bit fingerprint 创建64位指纹doublesimilarity(Fingerprint other) Calculates the similarity to another fingerprint 计算与另一个指纹的相似度toBinary()Converts to binary string 转换为二进制字符串toHex()Converts to hexadecimal string 转换为十六进制字符串toString()longvalue()Gets the fingerprint value 获取指纹值
-
Constructor Details
-
Fingerprint
public Fingerprint(long value, int bits) Creates a fingerprint 创建指纹- Parameters:
value- fingerprint value | 指纹值bits- number of bits | 位数
-
-
Method Details
-
value
public long value()Gets the fingerprint value 获取指纹值- Returns:
- fingerprint value | 指纹值
-
bits
public int bits()Gets the number of bits 获取位数- Returns:
- number of bits | 位数
-
hammingDistance
Calculates the Hamming distance to another fingerprint 计算与另一个指纹的海明距离- Parameters:
other- other fingerprint | 另一个指纹- Returns:
- number of different bits | 不同的位数
-
similarity
Calculates the similarity to another fingerprint 计算与另一个指纹的相似度- Parameters:
other- other fingerprint | 另一个指纹- Returns:
- similarity (0.0 - 1.0) | 相似度(0.0 - 1.0)
-
isSimilar
Checks if similar within threshold 检查是否在阈值内相似- Parameters:
other- other fingerprint | 另一个指纹threshold- Hamming distance threshold | 海明距离阈值- Returns:
- true if similar | 如果相似返回true
-
toHex
Converts to hexadecimal string 转换为十六进制字符串- Returns:
- hexadecimal string | 十六进制字符串
-
toBinary
-
of64
Creates a 64-bit fingerprint 创建64位指纹- Parameters:
value- fingerprint value | 指纹值- Returns:
- fingerprint | 指纹
-
of32
Creates a 32-bit fingerprint 创建32位指纹- Parameters:
value- fingerprint value | 指纹值- Returns:
- fingerprint | 指纹
-
of
Creates a fingerprint with specified bits 创建指定位数的指纹- Parameters:
value- fingerprint value | 指纹值bits- number of bits | 位数- Returns:
- fingerprint | 指纹
-
fromHex
Creates a fingerprint from hexadecimal string 从十六进制字符串创建指纹- Parameters:
hex- hexadecimal string | 十六进制字符串bits- number of bits | 位数- Returns:
- fingerprint | 指纹
-
equals
-
hashCode
-
toString
-