private String readName() throws JSONException { byte[] bytes = new byte[65536]; int length = 0; if (!bit()) { while (true) { int c = this.namehuff.read(this.bitreader); if (c == end) { break; } bytes[length] = (byte) c; length += 1; } if (length == 0) { return ""; } Kim kim = new Kim(bytes, length); this.namekeep.register(kim); return kim.toString(); } return getAndTick(this.namekeep, this.bitreader).toString(); }
/** * Write the name of an object property. Names have their own Keep and * Huffman encoder because they are expected to be a more restricted set. * * @param name * @throws JSONException */ private void writeName(String name) throws JSONException { // If this name has already been registered, then emit its integer and // increment its usage count. Kim kim = new Kim(name); int integer = this.namekeep.find(kim); if (integer != none) { one(); writeAndTick(integer, this.namekeep); } else { // Otherwise, emit the string with Huffman encoding, and register // it. zero(); write(kim, this.namehuff); write(end, namehuff); this.namekeep.register(kim); } }
/** * Find the integer value associated with this key, or nothing if this key * is not in the keep. * * @param key * An object. * @return An integer */ public int match(Kim kim, int from, int thru) { Node node = this.root; int best = none; for (int at = from; at < thru; at += 1) { node = node.get(kim.get(at)); if (node == null) { break; } if (node.integer != none) { best = node.integer; } from += 1; } return best; }
public boolean postMortem(PostMortem pm) { boolean result = true; TrieKeep that = (TrieKeep) pm; if (this.length != that.length) { JSONzip.log("\nLength " + this.length + " <> " + that.length); return false; } if (this.capacity != that.capacity) { JSONzip.log("\nCapacity " + this.capacity + " <> " + that.capacity); return false; } for (int i = 0; i < this.length; i += 1) { Kim thiskim = this.kim(i); Kim thatkim = that.kim(i); if (!thiskim.equals(thatkim)) { JSONzip.log("\n[" + i + "] " + thiskim + " <> " + thatkim); result = false; } } return result && this.root.postMortem(that.root); }
/** * Write the name of an object property. Names have their own Keep and * Huffman encoder because they are expected to be a more restricted set. * * @param name * @throws JSONException */ private void writeName(String name) throws JSONException { // If this name has already been registered, then emit its integer and // increment its usage count. Kim kim = new Kim(name); int integer = this.namekeep.find(kim); if (integer != none) { one(); writeAndTick(integer, this.namekeep); } else { // Otherwise, emit the string with Huffman encoding, and register it. zero(); write(kim, this.namehuff); write(end, namehuff); this.namekeep.register(kim); } }
/** * Write the name of an object property. Names have their own Keep and * Huffman encoder because they are expected to be a more restricted set. * * @param name The name string. * @throws JSONException */ private void writeName(String name) throws JSONException { // If this name has already been registered, then emit its integer and // increment its usage count. Kim kim = new Kim(name); int integer = this.namekeep.find(kim); if (integer != none) { one(); write(integer, this.namekeep); } else { // Otherwise, emit the string with Huffman encoding, and register it. zero(); write(kim, this.namehuff, this.namehuffext); write(end, namehuff); this.namekeep.register(kim); } }