package org.json.zip; import java.util.HashMap; import org.json.Kim; /* Copyright (c) 2013 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The Software shall be used for Good, not Evil. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * A keep is a data structure that associates strings (or substrings) with * numbers. This allows the sending of small integers instead of strings. * * @author JSON.org * @version 2013-05-03 */ class Keep implements None, PostMortem { private int capacity; protected int length; private Object[] list; private HashMap map; private int power; private long[] ticks; public Keep(int bits) { this.capacity = 1 (this.capacity); } /** * When an item ages, its use count is reduced by at least half. * * @param ticks * The current use count of an item. * @return The new use count for that item. */ public static long age(long ticks) { return ticks >= 32 ? 16 : ticks / 2; } /** * Return the number of bits required to contain an integer based on the * current length of the keep. As the keep fills up, the number of bits * required to identify one of its items goes up. */ public int bitsize() { while (1 0) { this.ticks[to] = usage; this.list[to] = key; this.map.put(key, to); to += 1; } else { this.map.remove(key); } from += 1; } if (to " + that.length); return false; } for (int i = 0; i = 0) { JSONzip.log("\nDuplicate key " + value); } } if (this.length >= this.capacity) { compact(); } this.list[this.length] = value; this.map.put(value, this.length); this.ticks[this.length] = 1; if (JSONzip.probe) { JSONzip.log(" "); } this.length += 1; } /** * Return the value associated with the integer. * @param integer The number of an item in the keep. * @return The value. */ public Object value(int integer) { return this.list[integer]; } }