This structure can be used to compute an approximation of the similarity
between two files. The index is used by
org. to compute scores
between files.
To save space in memory, this index uses a space efficient encoding which will not exceed 1 MiB per instance. The index starts out at a smaller size (closer to 2 KiB), but may grow as more distinct blocks within the scanned file are discovered.
| Modifier and Type | Class and Description |
|---|---|
| public static class | SimilarityIndex.
Thrown by |
| Modifier and Type | Field and Description |
|---|---|
| private long | hashedCnt
Total amount of bytes hashed into the structure, including \n. |
| private int | |
| private long[] | idHash
Pairings of content keys and counters. |
| private int | idHashBits
|
| private int | |
| private static final int | KEY_SHIFT
Shift to apply before storing a key. |
| private static final long | MAX_COUNT
Maximum value of the count field, also mask to extract the count. |
| public static final SimilarityIndex. | TABLE_FULL_OUT_OF_MEMORY
A special |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv long | |
| private static long | |
| private static long | |
| pack-priv long | |
| private static long | |
| public static SimilarityIndex | Returns: similarity index for this objectthe object to hash obj)Create a new similarity index for the given object |
| pack-priv int | |
| private void | |
| private static int | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| private void | |
| pack-priv static boolean | |
| pack-priv int | |
| private static int | |
| private int | |
| private static long | |
| public int | Returns: the similarity scorethe other index dst, int the score representing a 100% match maxScore)Compute the similarity score between this index and another. |
| pack-priv int | |
| private int | |
| pack-priv void |
| hashedCnt | back to summary |
|---|---|
| private long hashedCnt Total amount of bytes hashed into the structure, including \n. This is usually the size of the file minus number of CRLF encounters. | |
| idGrowAt | back to summary |
|---|---|
| private int idGrowAt | |
| idHash | back to summary |
|---|---|
| private long[] idHash Pairings of content keys and counters. Slots in the table are actually two ints wedged into a single long. The upper 32 bits stores the content key, and the remaining lower bits stores the number of bytes associated with that key. Empty slots are denoted by 0, which cannot occur because the count cannot be 0. Values can only be positive, which we enforce during key addition. | |
| idHashBits | back to summary |
|---|---|
| private int idHashBits
| |
| idSize | back to summary |
|---|---|
| private int idSize Number of non-zero entries in | |
| KEY_SHIFT | back to summary |
|---|---|
| private static final int KEY_SHIFT Shift to apply before storing a key. Within the 64 bit table record space, we leave the highest bit unset so all values are positive. The lower 32 bits to count bytes. | |
| MAX_COUNT | back to summary |
|---|---|
| private static final long MAX_COUNT Maximum value of the count field, also mask to extract the count. | |
| TABLE_FULL_OUT_OF_MEMORY | back to summary |
|---|---|
| public static final SimilarityIndex. A special | |
| SimilarityIndex | back to summary |
|---|---|
| pack-priv SimilarityIndex() | |
| add | back to summary |
|---|---|
| pack-priv void add(int key, int cnt) throws TableFullException | |
| common | back to summary |
|---|---|
| pack-priv long common(SimilarityIndex dst) | |
| common | back to summary |
|---|---|
| private static long common(SimilarityIndex src, SimilarityIndex dst) | |
| common | back to summary |
|---|---|
| private static long common(long[] srcHash, int srcIdx, long[] dstHash, int dstIdx) | |
| count | back to summary |
|---|---|
| pack-priv long count(int idx) | |
| countOf | back to summary |
|---|---|
| private static long countOf(long v) | |
| create | back to summary |
|---|---|
| public static SimilarityIndex create(ObjectLoader obj) throws IOException, TableFullException Create a new similarity index for the given object
| |
| findIndex | back to summary |
|---|---|
| pack-priv int findIndex(int key) | |
| grow | back to summary |
|---|---|
private void grow() throws TableFullException
| |
| growAt | back to summary |
|---|---|
| private static int growAt(int idHashBits) | |
| hash | back to summary |
|---|---|
| pack-priv void hash(ObjectLoader obj) throws MissingObjectException, IOException, TableFullException | |
| hash | back to summary |
|---|---|
| pack-priv void hash(byte[] raw, int ptr, int end) throws TableFullException | |
| hash | back to summary |
|---|---|
| pack-priv void hash(InputStream in, long remaining, boolean text) throws IOException, TableFullException | |
| hashLargeObject | back to summary |
|---|---|
| private void hashLargeObject(ObjectLoader obj) throws IOException, TableFullException | |
| isBinary | back to summary |
|---|---|
| pack-priv static boolean isBinary(ObjectLoader obj) throws IOException | |
| key | back to summary |
|---|---|
| pack-priv int key(int idx) | |
| keyOf | back to summary |
|---|---|
| private static int keyOf(long v) | |
| packedIndex | back to summary |
|---|---|
| private int packedIndex(int idx) | |
| pair | back to summary |
|---|---|
| private static long pair(int key, long cnt) throws TableFullException | |
| score | back to summary |
|---|---|
| public int score(SimilarityIndex dst, int maxScore) Compute the similarity score between this index and another. A region of a file is defined as a line in a text file or a fixed-size block in a binary file. To prepare an index, each region in the file is hashed; the values and counts of hashes are retained in a sorted table. Define the similarity fraction F as the count of matching regions between the two files divided between the maximum count of regions in either file. The similarity score is F multiplied by the maxScore constant, yielding a range [0, maxScore]. It is defined as maxScore for the degenerate case of two empty files. The similarity score is symmetrical; i.e. a.score(b) == b.score(a).
| |
| size | back to summary |
|---|---|
| pack-priv int size() | |
| slot | back to summary |
|---|---|
| private int slot(int key) | |
| sort | back to summary |
|---|---|
| pack-priv void sort() Sort the internal table so it can be used for efficient scoring. Once sorted, additional lines/blocks cannot be added to the index. | |
create() when file is too large.
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| TableFullException | back to summary |
|---|---|
| public TableFullException() | |