⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tintdoublehashmap.java~3~

📁 垃圾邮件过滤器源代码
💻 JAVA~3~
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.///////////////////////////////////////////////////////////////////////////////package gnu.trove;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;/** * An open addressed Map implementation for int keys and double values. * *整数与双精度浮点数之间映射的实现????? * Created: Sun Nov  4 08:52:45 2001 * * @author Eric D. Friedman * @version $Id: TIntDoubleHashMap.java,v 1.17 2005/03/26 17:52:56 ericdf Exp $ */public class TIntDoubleHashMap extends TIntHash implements Serializable {    /** compatible serialization ID - not present in 1.1b3 and earlier */    static final long serialVersionUID = 1L;    /** the values of the map */    // 映射值    protected transient double[] _values;    /**     * Creates a new <code>TIntDoubleHashMap</code> instance with the default     * capacity and load factor.     */    public TIntDoubleHashMap() {        super();    }    /**     * Creates a new <code>TIntDoubleHashMap</code> instance with a prime     * capacity equal to or greater than <tt>initialCapacity</tt> and     * with the default load factor.     *     * @param initialCapacity an <code>int</code> value     */    public TIntDoubleHashMap(int initialCapacity) {        super(initialCapacity);    }    /**     * Creates a new <code>TIntDoubleHashMap</code> instance with a prime     * capacity equal to or greater than <tt>initialCapacity</tt> and     * with the specified load factor.     *     * @param initialCapacity an <code>int</code> value     * @param loadFactor a <code>float</code> value     */    public TIntDoubleHashMap(int initialCapacity, float loadFactor) {        super(initialCapacity, loadFactor);    }    /**     * Creates a new <code>TIntDoubleHashMap</code> instance with the default     * capacity and load factor.     * @param strategy used to compute hash codes and to compare keys.     */    public TIntDoubleHashMap(TIntHashingStrategy strategy) {        super(strategy);    }    /**     * Creates a new <code>TIntDoubleHashMap</code> instance whose capacity     * is the next highest prime above <tt>initialCapacity + 1</tt>     * unless that value is already prime.     *     * @param initialCapacity an <code>int</code> value     * @param strategy used to compute hash codes and to compare keys.     */    public TIntDoubleHashMap(int initialCapacity, TIntHashingStrategy strategy) {        super(initialCapacity, strategy);    }    /**     * Creates a new <code>TIntDoubleHashMap</code> instance with a prime     * value at or near the specified capacity and load factor.     *     * @param initialCapacity used to find a prime capacity for the table.     * @param loadFactor used to calculate the threshold over which     * rehashing takes place.     * @param strategy used to compute hash codes and to compare keys.     */    public TIntDoubleHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) {        super(initialCapacity, loadFactor, strategy);    }    /**     * @return a deep clone of this collection     */    public Object clone() {      TIntDoubleHashMap m = (TIntDoubleHashMap)super.clone();      m._values = (double[])this._values.clone();      return m;    }    /**     * @return a TIntDoubleIterator with access to this map's keys and values     */    public TIntDoubleIterator iterator() {        return new TIntDoubleIterator(this);    }    /**     * initializes the hashtable to a prime capacity which is at least     * <tt>initialCapacity + 1</tt>.     *     * @param initialCapacity an <code>int</code> value     * @return the actual capacity chosen     */    protected int setUp(int initialCapacity) {        int capacity;        capacity = super.setUp(initialCapacity);        _values = new double[capacity];        return capacity;    }    /**     * Inserts a key/value pair into the map.     * 向HASH映射中插入一个键/值对     * @param key an <code>int</code> value     * @param value an <code>double</code> value     * @return the previous value associated with <tt>key</tt>,     * or (double)0 if none was found.     */    public double put(int key, double value) {        byte previousState;        double previous = (double)0;        int index = insertionIndex(key);        boolean isNewMapping = true;        if (index < 0) {            index = -index -1;            previous = _values[index];            isNewMapping = false;        }        previousState = _states[index];        _set[index] = key;        _states[index] = FULL;        _values[index] = value;        if (isNewMapping) {            postInsertHook(previousState == FREE);        }        return previous;    }    /**     * rehashes the map to the new capacity.     *     * @param newCapacity an <code>int</code> value     */    protected void rehash(int newCapacity) {        int oldCapacity = _set.length;        int oldKeys[] = _set;        double oldVals[] = _values;        byte oldStates[] = _states;        _set = new int[newCapacity];        _values = new double[newCapacity];        _states = new byte[newCapacity];        for (int i = oldCapacity; i-- > 0;) {            if(oldStates[i] == FULL) {                int o = oldKeys[i];                int index = insertionIndex(o);                _set[index] = o;                _values[index] = oldVals[i];                _states[index] = FULL;            }        }    }    /**     * retrieves the value for <tt>key</tt>     * 根据键,检索值     * @param key an <code>int</code> value     * @return the value of <tt>key</tt> or (double)0 if no such mapping exists.     */    public double get(int key) {        int index = index(key);        return index < 0 ? (double)0 : _values[index];    }    /**     * Empties the map.     *     */    public void clear() {        super.clear();        int[] keys = _set;        double[] vals = _values;        byte[] states = _states;        for (int i = keys.length; i-- > 0;) {            keys[i] = (int)0;            vals[i] = (double)0;            states[i] = FREE;        }    }    /**     * Deletes a key/value pair from the map.     *     * @param key an <code>int</code> value     * @return an <code>double</code> value, or (double)0 if no mapping for key exists     */    public double remove(int key) {        double prev = (double)0;        int index = index(key);        if (index >= 0) {            prev = _values[index];            removeAt(index);    // clear key,state; adjust size        }        return prev;    }    /**     * Compares this map with another map for equality of their stored     * entries.     *     * @param other an <code>Object</code> value     * @return a <code>boolean</code> value     */    public boolean equals(Object other) {        if (! (other instanceof TIntDoubleHashMap)) {            return false;        }        TIntDoubleHashMap that = (TIntDoubleHashMap)other;        if (that.size() != this.size()) {            return false;        }        return forEachEntry(new EqProcedure(that));    }    public int hashCode() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -