Author: mes
Date: 2012-04-09 14:37:46 -0700 (Mon, 09 Apr 2012)
New Revision: 28772
Removed:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/IntTHash.java
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/IntTHashTest.java
Log:
removed unused IntTHash because we now have LongTHash
Deleted:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/IntTHash.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/IntTHash.java
2012-04-09 20:58:39 UTC (rev 28771)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/IntTHash.java
2012-04-09 21:37:46 UTC (rev 28772)
@@ -1,239 +0,0 @@
-
-/*
- Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
-
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
- 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
- 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. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-
-package org.cytoscape.model.internal;
-
-import java.util.NoSuchElementException;
-import java.util.Arrays;
-
-
-/**
- * An insert-only hashtable that has non-negative 32 bit integer keys and
- * non-null object values.<p>
- * In the underlying implementation, this hashtable increases in size to adapt
- * to key/value pairs being added (the underlying size of the hashtable is
- * invisible to the programmer). In the underlying implementation, this
- * hashtable never decreases in size. As a hashtable increases in size,
- * it takes at most four times as much memory as it would take
- * to store the hashtable's keys and values in perfectly-sized arrays.
- * Underlying size expansions are implemented such that the operation of
- * expanding in size is amortized over the contstant time complexity needed to
- * insert new elements.<p>
- * An instance of this class is serializable; however, serialized instances of
- * this class should not be stored in a persistent manner because the
- * serialization implemented in this class makes no attempt at handling
- * class versioning. For an instance of this class to be properly
- * serialized, all object values stored in that instance must be
- * serializable.
- */
-public final class IntTHash<T> {
- private final static long serialVersionUID = 121374594955439L;
- private static final int[] PRIMES = {
- 11, 23, 53, 113, 251, 509,
1019, 2039, 4079, 8179, 16369,
- 32749, 65521, 131063, 262133,
524269, 1048571, 2097143,
- 4194287, 8388587, 16777183,
33554393, 67108837,
- 134217689, 268435399,
536870879, 1073741789, 2147483647
- };
- private static final int INITIAL_SIZE = PRIMES[0];
- private static final double THRESHOLD_FACTOR = 0.77;
- private int[] m_keys;
- private Object[] m_vals;
- private int m_elements;
- private int m_thresholdSize;
-
- // These are caching variables. The idea is that programmers will
- // frequently first do a get(), and based on that result, will perform
- // some other operations and then maybe do a put() operation with the
same
- // key as the previous get() operation.
- private int m_prevKey;
- private int m_prevInx;
-
- private final Class<T> clazz;
-
- /**
- * Creates a new hashtable.
- */
- public IntTHash(Class<T> clazz) {
- this.clazz = clazz;
- m_keys = new int[INITIAL_SIZE];
- m_vals = new Object[INITIAL_SIZE];
- m_elements = 0;
- m_thresholdSize = (int) (THRESHOLD_FACTOR * (double)
m_keys.length);
-
- for (int i = 0; i < m_keys.length; i++)
- m_keys[i] = -1;
-
- m_prevKey = -1;
- m_prevInx = -1;
- }
-
- /**
- * Puts a new key/value pair into this hashtable, potentially
overwriting
- * an existing value whose key is the same as the one specified.
- * Returns the old value associated with the specified key or null if no
- * value is associated with specified key at the time of this call.<p>
- * Insertions into the hashtable are performed in [amortized] time
- * complexity O(1).
- * @exception IllegalArgumentException if key is negative.
- * @exception NullPointerException if value is null.
- */
- public final T put(final int key, final T value) {
- //System.out.println("putting: " + key + " -> " + value);
- if (key < 0)
- throw new IllegalArgumentException("key is negative");
-
- if (key != m_prevKey) {
- calcPrevInx(key);
- m_prevKey = key;
- }
-
- final Object returnVal = m_vals[m_prevInx];
-
- if (returnVal == null) {
- //System.out.println("m_elements: " + m_elements + "
m_thres: " + m_thresholdSize);
- if (m_elements == m_thresholdSize) {
- incrSize();
-
- return put(key, value);
- }
-
- m_elements++;
- }
-
- m_vals[m_prevInx] = value;
- if ( value == null )
- m_keys[m_prevInx] = -1;
- else
- m_keys[m_prevInx] = key;
-
- return clazz.cast(returnVal);
- }
-
- /**
- * Returns the value bound to the specified key or null if no value is
- * currently bound to the specified key.<p>
- * Searches in this hashtable are performed in [amortized] time
- * complexity O(1).
- * @exception IllegalArgumentException if key is negative.
- */
- public final T get(final int key) {
- if (key < 0)
- return null;
-
- if (key != m_prevKey) {
- calcPrevInx(key);
- m_prevKey = key;
- }
-
- return clazz.cast(m_vals[m_prevInx]);
- }
-
- public final T remove(final int key) {
- //System.out.println("about to remove: " + key + " size: " +
m_elements);
- Object ret = get(key);
- put(key,null);
- m_elements--;
- //System.out.println("removed: " + key + " size: " +
m_elements);
- return clazz.cast(ret);
- }
-
- // for unit testing
- int size() {
- return m_elements;
- }
-
- private void calcPrevInx(int key) {
- int incr = 0;
-
- for (m_prevInx = key % m_keys.length;
- (m_keys[m_prevInx] >= 0) && (m_keys[m_prevInx] != key);
- m_prevInx = (m_prevInx + incr) % m_keys.length)
- if (incr == 0)
- incr = 1 + (key % (m_keys.length - 1));
- }
-
- private int calcNewSize() {
- try {
- int primesInx = 0;
-
- while (m_keys.length != PRIMES[primesInx++]);
-
- return PRIMES[primesInx];
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new IllegalStateException("too many elements in
this hashtable");
- }
- }
-
- private final void incrSize() {
- //System.out.println("incrSize " + m_elements + " mkeys size:
" + m_keys.length);
- final int newSize = calcNewSize();
- //System.out.println("newSize " + newSize);
- final int[] newKeys = new int[newSize];
- final Object[] newVals = new Object[newSize];
- Arrays.fill(newKeys, -1);
-
- m_thresholdSize = (int) (THRESHOLD_FACTOR * (double)
newKeys.length);
-
- int incr;
- int newIndex;
- int oldIndex = -1;
-
- for (int i = 0; i < m_elements; i++) {
- //System.out.println("element: " + i + " oldIndex: " +
oldIndex);
- //System.out.println("INCR SIZE: " +
Arrays.toString(m_keys));
- while (m_keys[++oldIndex] < 0);
-
- incr = 0;
-
- for (newIndex = m_keys[oldIndex] % newKeys.length;
- newKeys[newIndex] >= 0;
- newIndex = (newIndex + incr) % newKeys.length)
- if (incr == 0)
- incr = 1 + (m_keys[oldIndex] %
(newKeys.length - 1));
-
- newKeys[newIndex] = m_keys[oldIndex];
- newVals[newIndex] = m_vals[oldIndex];
- //System.out.println("new index: " + newIndex + "
(old: " + oldIndex +")");
- //System.out.println("new key: " + newKeys[newIndex] +
" (old: " + m_keys[oldIndex] +")");
- }
-
- m_keys = newKeys;
- m_vals = newVals;
- m_prevKey = -1;
- m_prevInx = -1;
- //System.out.println("new keys: " + Arrays.toString(newKeys));
- }
-}
Deleted:
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/IntTHashTest.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/IntTHashTest.java
2012-04-09 20:58:39 UTC (rev 28771)
+++
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/internal/IntTHashTest.java
2012-04-09 21:37:46 UTC (rev 28772)
@@ -1,80 +0,0 @@
-
-package org.cytoscape.model.internal;
-
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class IntTHashTest {
-
- @Test
- public void testBasicPutGet() {
- IntTHash<String> ith = new IntTHash<String>(String.class);
- ith.put(1,"homer");
- ith.put(2,"marge");
- ith.put(3,"lisa");
- assertEquals( "homer", ith.get(1) );
- assertEquals( "marge", ith.get(2) );
- assertEquals( "lisa", ith.get(3) );
- }
-
- @Test
- public void testSize() {
- IntTHash<String> ith = new IntTHash<String>(String.class);
- ith.put(1,"homer");
- ith.put(2,"marge");
- ith.put(3,"lisa");
- assertEquals( 3, ith.size() );
- }
-
- @Test
- public void testRemove() {
- IntTHash<String> ith = new IntTHash<String>(String.class);
- ith.put(1,"homer");
- ith.put(2,"marge");
- ith.put(3,"lisa");
-
- assertEquals( 3, ith.size() );
-
- ith.remove(3);
- assertEquals( 2, ith.size() );
- assertNull( ith.get(3) );
-
- ith.remove(2);
- assertEquals( 1, ith.size() );
- assertNull( ith.get(2) );
-
- ith.remove(1);
- assertEquals( 0, ith.size() );
- assertNull( ith.get(1) );
- }
-
- @Test
- public void testAddRemove() {
- IntTHash<String> ith = new IntTHash<String>(String.class);
- ith.put(1,"homer");
- ith.put(2,"marge");
- ith.put(3,"lisa");
- ith.put(4,"bart");
- ith.put(5,"maggie");
- ith.put(6,"smithers");
- ith.put(7,"burns");
-
- ith.remove(1);
- ith.remove(2);
- ith.remove(3);
-
- ith.put(1,"homer");
- ith.put(2,"marge");
- ith.put(3,"lisa");
-
- ith.remove(4);
- ith.remove(5);
- ith.remove(6);
-
- ith.put(4,"bart");
- ith.put(5,"maggie");
- ith.put(6,"smithers");
- }
-
-}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.