From: <ha...@us...> - 2013-12-14 17:43:25
|
Revision: 19100 http://sourceforge.net/p/jmol/code/19100 Author: hansonr Date: 2013-12-14 17:43:19 +0000 (Sat, 14 Dec 2013) Log Message: ----------- Modified Paths: -------------- branches/v14_0/Jmol/test/org/jmol/util/AllTests.java Removed Paths: ------------- branches/v14_0/Jmol/test/org/jmol/util/Int2ObjHash.java branches/v14_0/Jmol/test/org/jmol/util/IntInt2ObjHash.java branches/v14_0/Jmol/test/org/jmol/util/TestInt2ObjHash.java branches/v14_0/Jmol/test/org/jmol/util/TestIntInt2ObjHash.java Modified: branches/v14_0/Jmol/test/org/jmol/util/AllTests.java =================================================================== --- branches/v14_0/Jmol/test/org/jmol/util/AllTests.java 2013-12-13 23:36:19 UTC (rev 19099) +++ branches/v14_0/Jmol/test/org/jmol/util/AllTests.java 2013-12-14 17:43:19 UTC (rev 19100) @@ -32,8 +32,6 @@ TestSuite suite = new TestSuite("Test for org.jmol.util"); //$JUnit-BEGIN$ suite.addTestSuite(TestCommandHistory.class); - suite.addTestSuite(TestIntInt2ObjHash.class); - suite.addTestSuite(TestInt2ObjHash.class); //$JUnit-END$ return suite; } Deleted: branches/v14_0/Jmol/test/org/jmol/util/Int2ObjHash.java =================================================================== --- branches/v14_0/Jmol/test/org/jmol/util/Int2ObjHash.java 2013-12-13 23:36:19 UTC (rev 19099) +++ branches/v14_0/Jmol/test/org/jmol/util/Int2ObjHash.java 2013-12-14 17:43:19 UTC (rev 19100) @@ -1,97 +0,0 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2005 Miguel, Jmol Development, www.jmol.org - * - * Contact: mi...@jm... - * - * 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 - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jmol.util; - -public class Int2ObjHash { - int entryCount; - Entry[] entries; - - - public Int2ObjHash(int initialCapacity) { - entries = new Entry[initialCapacity]; - } - - public Int2ObjHash() { - this(256); - } - - public synchronized Object get(int key) { - Entry[] entries = this.entries; - int hash = (key & 0x7FFFFFFF) % entries.length; - for (Entry e = entries[hash]; e != null; e = e.next) - if (e.key == key) - return e.value; - return null; - } - - public synchronized void put(int key, Object value) { - Entry[] entries = this.entries; - int hash = (key & 0x7FFFFFFF) % entries.length; - for (Entry e = entries[hash]; e != null; e = e.next) - if (e.key == key) { - e.value = value; - return; - } - if (entryCount > entries.length) - rehash(); - entries = this.entries; - hash = (key & 0x7FFFFFFF) % entries.length; - entries[hash] = new Entry(key, value, entries[hash]); - ++entryCount; - } - - private void rehash() { - Entry[] oldEntries = entries; - int oldSize = oldEntries.length; - int newSize = oldSize * 2 + 1; - Entry[] newEntries = new Entry[newSize]; - - for (int i = oldSize; --i >= 0; ) { - for (Entry e = oldEntries[i]; e != null; ) { - Entry t = e; - e = e.next; - - int hash = (t.key & 0x7FFFFFFF) % newSize; - t.next = newEntries[hash]; - newEntries[hash] = t; - } - } - entries = newEntries; - } - - static class Entry { - int key; - Object value; - Entry next; - - Entry(int key, Object value, Entry next) { - this.key = key; - this.value = value; - this.next = next; - } - } -} - - Deleted: branches/v14_0/Jmol/test/org/jmol/util/IntInt2ObjHash.java =================================================================== --- branches/v14_0/Jmol/test/org/jmol/util/IntInt2ObjHash.java 2013-12-13 23:36:19 UTC (rev 19099) +++ branches/v14_0/Jmol/test/org/jmol/util/IntInt2ObjHash.java 2013-12-14 17:43:19 UTC (rev 19100) @@ -1,101 +0,0 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2005 Miguel, Jmol Development, www.jmol.org - * - * Contact: mi...@jm... - * - * 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 - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jmol.util; - -public class IntInt2ObjHash { - int entryCount; - Entry[] entries; - - - public IntInt2ObjHash(int initialCapacity) { - entries = new Entry[initialCapacity]; - } - - public IntInt2ObjHash() { - this(256); - } - - public synchronized Object get(int key1, int key2) { - Entry[] entries = this.entries; - int k = (key1 ^ (key2 >> 1)) & 0x7FFFFFFF; - int hash = k % entries.length; - for (Entry e = entries[hash]; e != null; e = e.next) - if (e.key1 == key1 && e.key2 == key2) - return e.value; - return null; - } - - public synchronized void put(int key1, int key2, Object value) { - Entry[] entries = this.entries; - int k = (key1 ^ (key2 >> 1)) & 0x7FFFFFFF; - int hash = k % entries.length; - for (Entry e = entries[hash]; e != null; e = e.next) - if (e.key1 == key1 && e.key2 == key2) { - e.value = value; - return; - } - if (entryCount > entries.length) - rehash(); - entries = this.entries; - hash = k % entries.length; - entries[hash] = new Entry(key1, key2, value, entries[hash]); - ++entryCount; - } - - private void rehash() { - Entry[] oldEntries = entries; - int oldSize = oldEntries.length; - int newSize = oldSize * 2 + 1; - Entry[] newEntries = entries = new Entry[newSize]; - - for (int i = oldSize; --i >= 0; ) { - for (Entry e = oldEntries[i]; e != null; ) { - Entry t = e; - e = e.next; - - int k = (t.key1 ^ (t.key2 >> 1)) & 0x7FFFFFFF; - int hash = k % newSize; - t.next = newEntries[hash]; - newEntries[hash] = t; - } - } - } - - static class Entry { - int key1; - int key2; - Object value; - Entry next; - - Entry(int key1, int key2, Object value, Entry next) { - this.key1 = key1; - this.key2 = key2; - this.value = value; - this.next = next; - } - } -} - - Deleted: branches/v14_0/Jmol/test/org/jmol/util/TestInt2ObjHash.java =================================================================== --- branches/v14_0/Jmol/test/org/jmol/util/TestInt2ObjHash.java 2013-12-13 23:36:19 UTC (rev 19099) +++ branches/v14_0/Jmol/test/org/jmol/util/TestInt2ObjHash.java 2013-12-14 17:43:19 UTC (rev 19100) @@ -1,102 +0,0 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2005 Miguel, Jmol Development, www.jmol.org - * - * Contact: mi...@jm... - * - * 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 - * 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.jmol.util; - - -public class TestInt2ObjHash extends junit.framework.TestCase { - - public TestInt2ObjHash() { - } - - @Override - public void setUp() { - } - - @Override - public void tearDown() { - } - - public void testOne() { - Int2ObjHash h = new Int2ObjHash(10); - for (int i = 0; i < 10; ++i) - h.put(i, Integer.valueOf(i)); - for (int i = 0; i < 10; ++i) - assertEquals(((Integer)h.get(i)).intValue(), i); - } - - public void test256() { - Int2ObjHash h = new Int2ObjHash(256); - for (int i = 0; i < 256; ++i) - h.put(i, Integer.valueOf(i)); - for (int i = 0; i < 256; ++i) - assertEquals(((Integer)h.get(i)).intValue(), i); - } - - public void test257() { - Int2ObjHash h = new Int2ObjHash(256); - for (int i = 0; i < 257; ++i) - h.put(i, Integer.valueOf(i)); - for (int i = 0; i < 257; ++i) - assertEquals(((Integer)h.get(i)).intValue(), i); - } - - public void testUpTo1000() { - for (int i = 1; i < 1000; i += 100) - tryOne(i); - } - - void tryOne(int count) { - Int2ObjHash h = new Int2ObjHash(4); - for (int i = 0; i < count; ++i) - h.put(i, Integer.valueOf(i)); - // dumpHash(h); - for (int i = 0; i < count; ++i) - assertEquals(((Integer)h.get(i)).intValue(), i); - } - - void dumpHash(Int2ObjHash h) { - Logger.info("dumping hash:" + h); - Logger.info("h.entryCount=" + h.entryCount); - Int2ObjHash.Entry[] entries = h.entries; - for (int i = 0; i < entries.length; ++i) { - StringBuffer log = new StringBuffer(); - log.append(i).append(": "); - for (Int2ObjHash.Entry e = entries[i]; e != null; e = e.next) { - log.append(e.key).append(" "); - } - Logger.info(log.toString()); - } - } - - public void test1000() { - Int2ObjHash h = new Int2ObjHash(); - for (int i = 0; i < 1000; ++i) - h.put(-i, Integer.valueOf(i)); - for (int i = 0; i < 1000; ++i) - assertEquals(((Integer)h.get(-i)).intValue(), i); - } - -} Deleted: branches/v14_0/Jmol/test/org/jmol/util/TestIntInt2ObjHash.java =================================================================== --- branches/v14_0/Jmol/test/org/jmol/util/TestIntInt2ObjHash.java 2013-12-13 23:36:19 UTC (rev 19099) +++ branches/v14_0/Jmol/test/org/jmol/util/TestIntInt2ObjHash.java 2013-12-14 17:43:19 UTC (rev 19100) @@ -1,102 +0,0 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2005 Miguel, Jmol Development, www.jmol.org - * - * Contact: mi...@jm... - * - * 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 - * 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.jmol.util; - - -public class TestIntInt2ObjHash extends junit.framework.TestCase { - - public TestIntInt2ObjHash() { - } - - @Override - public void setUp() { - } - - @Override - public void tearDown() { - } - - public void testOne() { - IntInt2ObjHash h = new IntInt2ObjHash(10); - for (int i = 0; i < 10; ++i) - h.put(i, i, Integer.valueOf(i)); - for (int i = 0; i < 10; ++i) - assertEquals(((Integer)h.get(i, i)).intValue(), i); - } - - public void test256() { - IntInt2ObjHash h = new IntInt2ObjHash(256); - for (int i = 0; i < 256; ++i) - h.put(i, i, Integer.valueOf(i)); - for (int i = 0; i < 256; ++i) - assertEquals(((Integer)h.get(i, i)).intValue(), i); - } - - public void test257() { - IntInt2ObjHash h = new IntInt2ObjHash(256); - for (int i = 0; i < 257; ++i) - h.put(i, i, Integer.valueOf(i)); - for (int i = 0; i < 257; ++i) - assertEquals(((Integer)h.get(i, i)).intValue(), i); - } - - public void testUpTo1000() { - for (int i = 1; i < 1000; i += 100) - tryOne(i); - } - - void tryOne(int count) { - IntInt2ObjHash h = new IntInt2ObjHash(4); - for (int i = 0; i < count; ++i) - h.put(i, i, Integer.valueOf(i)); - // dumpHash(h); - for (int i = 0; i < count; ++i) - assertEquals(((Integer)h.get(i, i)).intValue(), i); - } - - void dumpHash(IntInt2ObjHash h) { - Logger.info("dumping hash:" + h); - Logger.info("h.entryCount=" + h.entryCount); - IntInt2ObjHash.Entry[] entries = h.entries; - for (int i = 0; i < entries.length; ++i) { - StringBuffer log = new StringBuffer(); - log.append(i).append(": "); - for (IntInt2ObjHash.Entry e = entries[i]; e != null; e = e.next) { - log.append(e.key1).append(",").append(e.key2).append(" "); - } - Logger.info(log.toString()); - } - } - - public void test1000() { - IntInt2ObjHash h = new IntInt2ObjHash(); - for (int i = 0; i < 1000; ++i) - h.put(i, -i, Integer.valueOf(i)); - for (int i = 0; i < 1000; ++i) - assertEquals(((Integer)h.get(i, -i)).intValue(), i); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |