private void fillHashTable(List<ChecksumPair> list) { int i = 16; // spocteme velikost hashtable podle poctu bloku dat while ((2 << (i - 1)) > blockNum && i > 4) { i--; } // vytvorime hashtable o velikosti 2^i (max. 2^16, min. 2^4) hashtable = new ChainingHash(2 << (i - 1)); for (ChecksumPair pair : list) { hashtable.insert(pair); } }
/** * Fills a chaining hash table with ChecksumPairs * * @param checksums Byte array with bytes of whole metafile */ private void fillHashTable(byte[] checksums) { int i = 16; // spocteme velikost hashtable podle poctu bloku dat while ((2 << (i - 1)) > blockNum && i > 4) { i--; } // vytvorime hashtable o velikosti 2^i (max. 2^16, min. 2^4) hashtable = new ChainingHash(2 << (i - 1)); ChecksumPair p = null; // Link item; int offset = 0; int weakSum = 0; int seq = 0; int off = fileOffset; byte[] weak = new byte[4]; byte[] strongSum = new byte[headers.getChecksumBytes()]; while (seq < blockNum) { for (int w = 0; w < headers.getRsumButes(); w++) { weak[w] = checksums[off]; off++; } for (int s = 0; s < strongSum.length; s++) { strongSum[s] = checksums[off]; off++; } weakSum = 0; weakSum += (weak[2] & 0x000000FF) << 24; weakSum += (weak[3] & 0x000000FF) << 16; weakSum += (weak[0] & 0x000000FF) << 8; weakSum += (weak[1] & 0x000000FF); p = new ChecksumPair(weakSum, strongSum.clone(), offset, headers.blocksize, seq); offset += headers.blocksize; seq++; // item = new Link(p); hashtable.insert(p); } }