public short findCharString(short index, byte b) { int hshidx, nxtidx; if (index == HASH_FREE) return b; hshidx = Hash(index, b); while ((nxtidx = strHsh_[hshidx]) != HASH_FREE) { if (strNxt_[nxtidx] == index && strChr_[nxtidx] == b) return (short) nxtidx; hshidx = (hshidx + HASHSTEP) % HASHSIZE; } // ends while return (short) 0xFFFF; } // ends findCharString(short, byte)
public void ClearTable(int codesize) { numStrings_ = 0; for (int q = 0; q < HASHSIZE; q++) strHsh_[q] = HASH_FREE; int w = (1 << codesize) + RES_CODES; for (int q = 0; q < w; q++) this.addCharString((short) 0xFFFF, (byte) q); } // ends ClearTable(int)
LZWStringTable strings = new LZWStringTable(); limit = (1 << numbits) - 1; strings.ClearTable(codesize); bitFile.writeBits(clearcode, numbits); if ((index = strings.findCharString(prefix, c)) != -1) prefix = index; else { bitFile.writeBits(prefix, numbits); if (strings.addCharString(prefix, c) > limit) { if (++numbits > 12) { bitFile.writeBits(clearcode, numbits - 1); strings.ClearTable(codesize); numbits = codesize + 1;
public int addCharString(short index, byte b) { int hshidx; if (numStrings_ >= MAXSTR) return 0xFFFF; hshidx = Hash(index, b); while (strHsh_[hshidx] != HASH_FREE) hshidx = (hshidx + HASHSTEP) % HASHSIZE; strHsh_[hshidx] = numStrings_; strChr_[numStrings_] = b; strNxt_[numStrings_] = (index != HASH_FREE) ? index : NEXT_FIRST; return numStrings_++; } // ends addCharString(short, byte)