trove-2.1.0/0000755000175000017500000000000011241347112011631 5ustar mkochmkochtrove-2.1.0/test/0000755000175000017500000000000011241347111012607 5ustar mkochmkochtrove-2.1.0/test/gnu/0000755000175000017500000000000011241347111013400 5ustar mkochmkochtrove-2.1.0/test/gnu/trove/0000755000175000017500000000000011261456735014556 5ustar mkochmkochtrove-2.1.0/test/gnu/trove/TLinkedListTest.java0000644000175000017500000004441511241347111020440 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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 junit.framework.*; import java.io.*; import java.util.*; /** * * Created: Sat Nov 10 15:57:07 2001 * * @author Eric D. Friedman * @version $Id: TLinkedListTest.java,v 1.7 2009/03/31 19:43:14 robeden Exp $ */ public class TLinkedListTest extends TestCase { protected TLinkedList list; public TLinkedListTest(String name) { super(name); } public void setUp() throws Exception { list = new TLinkedList(); } public void tearDown() throws Exception { list = null; } public void testAdd() throws Exception { Data[] data = { new Data(1), new Data(2), new Data(3) }; for (int i = 0; i < data.length; i++) { list.add(data[i]); } assertEquals(3,list.size()); } public void testInsert() throws Exception { Data[] data = { new Data(2), new Data(4), new Data(6) }; for (int i = 0; i < data.length; i++) { list.add(data[i]); } list.insert( 0, new Data( 1 ) ); list.insert( 2, new Data( 3 ) ); list.insert( 4, new Data( 5 ) ); list.insert( list.size(), new Data( 7 ) ); assertEquals( 7, list.size() ); for( int i = 0; i < list.size(); i++ ) { assertEquals(i + 1, list.get( i )._val ); } } public void testNextIterator() throws Exception { Data[] data = new Data[100]; for (int i = 0; i < data.length; i++) { data[i] = new Data(i); list.add(data[i]); } int count = 0; for (Iterator i = list.iterator(); i.hasNext();) { assertEquals(data[count++], i.next()); } assertEquals(data.length,count); count = 4; for (Iterator i = list.listIterator(4); i.hasNext();) { assertEquals(data[count++], i.next()); } assertEquals(data.length,count); } public void testPreviousIterator() throws Exception { Data[] data = new Data[100]; for (int i = 0; i < data.length; i++) { data[i] = new Data(i); list.add(data[i]); } int count = 100; for (ListIterator i = list.listIterator(list.size()); i.hasPrevious();) { assertEquals(data[--count], i.previous()); } assertEquals(0,count); count = 5; for (ListIterator i = list.listIterator(count); i.hasPrevious();) { assertEquals(data[--count], i.previous()); } assertEquals(0,count); } public void testIteratorSet() throws Exception { Data[] data = new Data[100]; for (int i = 0; i < data.length; i++) { data[i] = new Data(i); list.add(data[i]); } ListIterator i; i = list.listIterator(5); i.next(); Data d = new Data(999); i.set(d); assertEquals(d, list.get(5)); } public void testRemoveOnlyElementInList() throws Exception { Data d = new Data(0); list.add(d); ListIterator i = list.listIterator(); assertTrue(i.hasNext()); assertEquals(d, i.next()); i.remove(); assertTrue(! i.hasNext()); assertTrue(! i.hasPrevious()); assertEquals(0, list.size()); } public void testRemovePrevious() throws Exception { Data[] d = { new Data(0), new Data(1), new Data(2) }; list.addAll(Arrays.asList(d)); ListIterator i = list.listIterator(list.size()); i.previous(); i.previous(); i.remove(); assertEquals(2, list.size()); assertTrue(i.hasPrevious()); assertEquals(d[0], i.previous()); assertTrue(! i.hasPrevious()); assertTrue(i.hasNext()); assertEquals(d[0], i.next()); assertTrue(i.hasNext()); assertEquals(d[2], i.next()); assertTrue(! i.hasNext()); assertTrue(i.hasPrevious()); assertEquals(2, list.size()); } public void testRemoveLast() throws Exception { Data[] d = { new Data(0), new Data(1), new Data(2) }; list.addAll(Arrays.asList(d)); ListIterator i = list.listIterator(list.size()); i.previous(); i.remove(); assertEquals(2, list.size()); assertTrue(i.hasPrevious()); assertTrue(! i.hasNext()); } public void testRemoveFirst() throws Exception { Data[] d = { new Data(0), new Data(1), new Data(2) }; list.addAll(Arrays.asList(d)); ListIterator i = list.listIterator(0); i.next(); i.remove(); assertEquals(2, list.size()); assertTrue(! i.hasPrevious()); assertTrue(i.hasNext()); } public void testRemoveNext() throws Exception { Data[] d = { new Data(0), new Data(1), new Data(2) }; list.addAll(Arrays.asList(d)); ListIterator i = list.listIterator(); assertTrue(i.hasNext()); i.next(); assertTrue(i.hasNext()); assertTrue(i.hasPrevious()); i.remove(); assertEquals(2, list.size()); assertTrue(! i.hasPrevious()); assertTrue(i.hasNext()); assertEquals(d[1], i.next()); assertTrue(i.hasNext()); assertEquals(d[2], i.next()); assertTrue(i.hasPrevious()); assertTrue(! i.hasNext()); } public void testRemoveThrowsAfterAdd() throws Exception { Data d = new Data(0); list.add(d); ListIterator i = list.listIterator(); boolean didThrow = false; try { i.remove(); } catch (IllegalStateException e) { didThrow = true; } // end of try-catch assertTrue(didThrow); } public void testRemoveThrowsWithoutPrevious() throws Exception { Data d = new Data(0); list.add(d); ListIterator i = list.listIterator(list.size()); boolean didThrow = false; assertTrue(i.hasPrevious()); try { i.remove(); } catch (IllegalStateException e) { didThrow = true; } // end of try-catch assertTrue(didThrow); } public void testRemoveThrowsWithoutNext() throws Exception { Data d = new Data(0); list.add(d); ListIterator i = list.listIterator(); boolean didThrow = false; assertTrue(i.hasNext()); try { i.remove(); } catch (IllegalStateException e) { didThrow = true; } // end of try-catch assertTrue(didThrow); } public void testIteratorAddFront() throws Exception { Data[] d = { new Data(0), new Data(1), new Data(2) }; list.addAll(Arrays.asList(d)); ListIterator i = list.listIterator(); Data d1 = new Data(5); assertTrue(! i.hasPrevious()); i.add(d1); assertTrue(i.hasPrevious()); assertEquals(d1, i.previous()); assertEquals(d1, i.next()); assertEquals(d[0], i.next()); assertEquals(d1, list.get(0)); } public void testIteratorAddBack() throws Exception { Data[] d = { new Data(0), new Data(1), new Data(2) }; list.addAll(Arrays.asList(d)); ListIterator i = list.listIterator(list.size()); Data d1 = new Data(5); assertEquals(3, list.size()); assertTrue(i.hasPrevious()); assertTrue(! i.hasNext()); i.add(d1); assertTrue(i.hasPrevious()); assertTrue(! i.hasNext()); assertEquals(4, list.size()); assertEquals(d1, i.previous()); assertEquals(d1, i.next()); assertEquals(d1, list.get(3)); } public void testIteratorAddMiddle() throws Exception { Data[] d = { new Data(0), new Data(1), new Data(2) }; list.addAll(Arrays.asList(d)); ListIterator i = list.listIterator(1); Data d1 = new Data(5); assertEquals(3, list.size()); assertTrue(i.hasPrevious()); assertTrue(i.hasNext()); i.add(d1); assertTrue(i.hasPrevious()); assertTrue(i.hasNext()); assertEquals(4, list.size()); assertEquals(d1, i.previous()); assertEquals(d1, i.next()); assertEquals(d1, list.get(1)); } public void testIteratorSetSingleElementList() throws Exception { Data d1 = new Data(5); Data d2 = new Data(4); list.add(d1); ListIterator i = list.listIterator(0); i.next(); i.set(d2); assertEquals(1, list.size()); assertTrue(! i.hasNext()); assertTrue(i.hasPrevious()); assertEquals(d2, i.previous()); assertTrue(i.hasNext()); assertTrue(! i.hasPrevious()); assertEquals(d2, i.next()); } public void testIteratorAddEmptyList() throws Exception { ListIterator i = list.listIterator(); Data d1 = new Data(5); assertTrue(! i.hasPrevious()); assertTrue(! i.hasNext()); i.add(d1); assertTrue(i.hasPrevious()); assertTrue(! i.hasNext()); assertEquals(d1, i.previous()); assertEquals(d1, i.next()); assertEquals(d1, list.get(0)); } public void testIteratorRemoveOnNext() throws Exception { Data[] data = new Data[100]; for (int i = 0; i < data.length; i++) { data[i] = new Data(i); list.add(data[i]); } ListIterator i; i = list.listIterator(5); i.next(); i.remove(); Data d = new Data(6); assertEquals(d, list.get(5)); } public void testSerialize() throws Exception { TLinkedList list1 = new TLinkedList(); Data[] data = new Data[100]; for (int i = 0; i < data.length; i++) { data[i] = new Data(i); list1.add(data[i]); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(list1); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); TLinkedList list2 = (TLinkedList)ois.readObject(); assertEquals(list1, list2); } public void testForEach() throws Exception { list.add( new Data( 0 ) ); list.add( new Data( 1 ) ); list.add( new Data( 2 ) ); list.add( new Data( 3 ) ); list.add( new Data( 4 ) ); // test exiting early boolean processed_full_list = list.forEachValue(new TObjectProcedure() { public boolean execute(Data object) { if ( object._val == 2 ) return false; object._val++; return true; } } ); assertFalse( processed_full_list ); assertEquals( 1, list.get( 0 )._val ); assertEquals( 2, list.get( 1 )._val ); assertEquals( 2, list.get( 2 )._val ); assertEquals( 3, list.get( 3 )._val ); assertEquals( 4, list.get( 4 )._val ); // test full list processing processed_full_list = list.forEachValue(new TObjectProcedure() { public boolean execute(Data object) { object._val++; return true; } } ); assertTrue( processed_full_list ); assertEquals( 2, list.get( 0 )._val ); assertEquals( 3, list.get( 1 )._val ); assertEquals( 3, list.get( 2 )._val ); assertEquals( 4, list.get( 3 )._val ); assertEquals( 5, list.get( 4 )._val ); } public void testAddBefore() { Data one = new Data( 1 ); Data three = new Data( 3 ); Data four = new Data( 4 ); Data five = new Data( 5 ); list.add( one ); list.add( three ); list.add( four ); list.add( five ); list.addBefore( one, new Data( 0 ) ); list.addBefore( three, new Data( 2 ) ); list.addBefore( null, new Data( 6 ) ); System.out.println("List: " + list); // Iterate forward int value = -1; Data cur = list.getFirst(); while( cur != null ) { assertEquals( value + 1, cur._val ); value = cur._val; cur = cur.getNext(); } assertEquals( 6, value ); // Iterate backward value = 7; cur = list.getLast(); while( cur != null ) { assertEquals( value - 1, cur._val ); value = cur._val; cur = cur.getPrevious(); } assertEquals( 0, value ); } public void testAddAfter() { Data one = new Data( 1 ); Data three = new Data( 3 ); Data five = new Data( 5 ); list.add( one ); list.add( three ); list.add( five ); list.addAfter( one, new Data( 2 ) ); list.addAfter( three, new Data( 4 ) ); list.addAfter( five, new Data( 6 ) ); list.addAfter( null, new Data( 0 ) ); System.out.println("List: " + list); // Iterate forward int value = -1; Data cur = list.getFirst(); while( cur != null ) { assertEquals( value + 1, cur._val ); value = cur._val; cur = cur.getNext(); } assertEquals( 6, value ); // Iterate backward value = 7; cur = list.getLast(); while( cur != null ) { System.out.println("Itr back: " + cur._val); assertEquals( value - 1, cur._val ); value = cur._val; cur = cur.getPrevious(); } assertEquals( 0, value ); } public void testMultipleRemove() { Data one = new Data( 1 ); Data two = new Data( 2 ); Data three = new Data( 3 ); list.add( one ); list.add( two ); list.add( three ); list.remove( one ); assertEquals( 2, list.size() ); assertEquals( new Data( 2 ), list.get( 0 ) ); assertEquals( new Data( 3 ), list.get( 1 ) ); list.remove( one ); assertEquals( 2, list.size() ); assertEquals( new Data( 2 ), list.get( 0 ) ); assertEquals( new Data( 3 ), list.get( 1 ) ); list.remove( one ); assertEquals( 2, list.size() ); assertEquals( new Data( 2 ), list.get( 0 ) ); assertEquals( new Data( 3 ), list.get( 1 ) ); list.remove( one ); assertEquals( 2, list.size() ); assertEquals( new Data( 2 ), list.get( 0 ) ); assertEquals( new Data( 3 ), list.get( 1 ) ); list.remove( one ); assertEquals( 2, list.size() ); assertEquals( new Data( 2 ), list.get( 0 ) ); assertEquals( new Data( 3 ), list.get( 1 ) ); } public void testRemoveFirstAll() { list.add( new Data( 1 ) ); list.add( new Data( 2 ) ); list.add( new Data( 3 ) ); list.add( new Data( 4 ) ); int expected = 1; Data data; while( ( data = list.removeFirst() ) != null ) { assertEquals( expected, data._val ); expected++; } assertTrue( list.isEmpty() ); } public void testRemoveLastAll() { list.add( new Data( 1 ) ); list.add( new Data( 2 ) ); list.add( new Data( 3 ) ); list.add( new Data( 4 ) ); int expected = 4; Data data; while( ( data = list.removeLast() ) != null ) { assertEquals( expected, data._val ); expected--; } assertTrue( list.isEmpty() ); } public void testPastIndexGet() { try { list.get( 0 ); fail( "Shouldn't have allowed get of index 0" ); } catch( IndexOutOfBoundsException ex ) { // this is good } try { list.get( 1 ); fail( "Shouldn't have allowed get of index 1" ); } catch( IndexOutOfBoundsException ex ) { // this is good } list.add( new Data( 1 ) ); list.get( 0 ); try { list.get( 1 ); fail( "Shouldn't have allowed get of index 1" ); } catch( IndexOutOfBoundsException ex ) { // this is good } } static class Data implements TLinkable { protected int _val; public Data(int val) { _val = val; } protected TLinkable _next; // NOTE: use covariant overriding /** * Get the value of next. * @return value of next. */ public Data getNext() { return ( Data ) _next; } /** * Set the value of next. * @param next value to assign to next. */ public void setNext(TLinkable next) { this._next = next; } protected TLinkable _previous; // NOTE: use covariant overriding /** * Get the value of previous. * @return value of previous. */ public Data getPrevious() { return ( Data ) _previous; } /** * Set the value of previous. * @param previous value to assign to previous. */ public void setPrevious(TLinkable previous) { this._previous = previous; } public String toString() { return "" + _val; } public boolean equals(Object o) { Data that = (Data)o; return this._val == that._val; } } } // TLinkedListTests trove-2.1.0/test/gnu/trove/TArrayListTest.java0000644000175000017500000000520711241347111020304 0ustar mkochmkochpackage gnu.trove; import junit.framework.TestCase; import java.util.Arrays; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.ByteArrayInputStream; public class TArrayListTest extends TestCase { private TIntArrayList list; public void setUp() throws Exception { super.setUp(); list = new TIntArrayList(); list.add(1); list.add(2); list.add(3); list.add(4); list.add(5); } public void tearDown() throws Exception { super.tearDown(); } public void testToNativeArray() { assertTrue(Arrays.equals(new int[]{ 1, 2, 3, 4, 5 }, list.toNativeArray())); assertTrue(Arrays.equals(new int[]{ 1, 2, 3, 4 }, list.toNativeArray(0, 4))); assertTrue(Arrays.equals(new int[]{ 2, 3, 4, 5 }, list.toNativeArray(1, 4))); assertTrue(Arrays.equals(new int[]{ 2, 3, 4 }, list.toNativeArray(1, 3))); } public void testSubList() throws Exception { TIntArrayList subList = list.subList(1, 4); assertEquals(3, subList.size()); assertEquals(2, subList.get(0)); assertEquals(4, subList.get(2)); } public void testSublist_Exceptions() { try { list.subList(1, 0); fail("expected IllegalArgumentException when end < begin"); } catch (IllegalArgumentException expected) { } try { list.subList(-1, 3); fail("expected IndexOutOfBoundsException when begin < 0"); } catch (IndexOutOfBoundsException expected) { } try { list.subList(1, 42); fail("expected IndexOutOfBoundsException when end > length"); } catch (IndexOutOfBoundsException expected) { } } public void testMax() { assertEquals( 5, list.max() ); assertEquals( 1, list.min() ); TIntArrayList list2 = new TIntArrayList(); list2.add( 3 ); list2.add( 1 ); list2.add( 2 ); list2.add( 5 ); list2.add( 4 ); assertEquals( 5, list2.max() ); assertEquals( 1, list2.min() ); } public void testSerialization() throws Exception { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream oout = new ObjectOutputStream( bout ); oout.writeObject(list); oout.close(); ObjectInputStream oin = new ObjectInputStream( new ByteArrayInputStream( bout.toByteArray() ) ); TIntArrayList new_list = ( TIntArrayList ) oin.readObject(); assertEquals( list, new_list ); } } trove-2.1.0/test/gnu/trove/THashSetTest.java0000644000175000017500000001727511241347111017741 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001-2006, 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 junit.framework.TestCase; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Arrays; import java.util.HashSet; import java.util.Set; /** * * Created: Sat Nov 3 10:33:15 2001 * * @author Eric D. Friedman * @version $Id: THashSetTest.java,v 1.4 2008/04/04 16:31:12 robeden Exp $ */ public class THashSetTest extends TestCase { protected Set s; public THashSetTest(String name) { super(name); } public void setUp() throws Exception { super.setUp(); s = new THashSet(); } public void tearDown() throws Exception { super.tearDown(); s = null; } public void testIsEmpty() throws Exception { assertTrue("new set wasn't empty", s.isEmpty()); s.add("One"); assertTrue("set with element reports empty", ! s.isEmpty()); s.clear(); assertTrue("cleared set reports not-empty", s.isEmpty()); } public void testContains() throws Exception { Object o = "testContains"; s.add(o); assertTrue("contains failed", s.contains(o)); } public void testContainsAll() throws Exception { Object[] o = { "Hello World", "Goodbye World", "Hello Goodbye" }; s.addAll(Arrays.asList(o)); for (int i = 0; i < o.length; i++) { assertTrue(o[i].toString(),s.contains(o[i])); } assertTrue("containsAll failed: " + s, s.containsAll(Arrays.asList(o))); } public void testAdd() throws Exception { assertTrue("add failed", s.add("One")); assertTrue("duplicated add succeded", ! s.add("One")); } public void testRemove() throws Exception { s.add("One"); s.add("Two"); assertTrue("One was not added", s.contains("One")); assertTrue("One was not removed", s.remove("One")); assertTrue("One was not removed", ! s.contains("One")); } public void testSize() throws Exception { s = new THashSet(); assertEquals("initial size was not 0",0, s.size()); for (int i = 0; i < 99; i++) { s.add(new Object()); assertEquals("size did not increase after add", i+1, s.size()); } } public void testClear() throws Exception { s = new THashSet(); s.addAll(Arrays.asList(new String[] {"one","two","three"})); assertEquals("size was not 3",3, s.size()); s.clear(); assertEquals("initial size was not 0",0, s.size()); } public void testSerialize() throws Exception { s = new THashSet(); s.addAll(Arrays.asList(new String[] {"one","two","three"})); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(s); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); THashSet s2 = (THashSet)ois.readObject(); assertEquals(s, s2); } public void testNormalLoad() throws Exception { THashSet set = new THashSet(11, 0.5f); assertEquals(set._maxSize, 11); for (int i = 0; i < 12; i++) { set.add(new Integer(i)); } assertTrue(set._maxSize > 12); } public void testMaxLoad() throws Exception { THashSet set = new THashSet(11, 1.0f); assertEquals(10, set._maxSize); for (int i = 0; i < 12; i++) { set.add(new Integer(i)); } assertTrue(set._maxSize > 12); } public void testToArray() { Object[] str = { "hi", "bye", "hello", "goodbye" }; s.addAll(Arrays.asList(str)); Object[] res = s.toArray(); Arrays.sort(str); Arrays.sort(res); assertTrue(Arrays.equals(str, res)); } public void testToArrayWithParams() { Object[] str = { "hi", "bye", "hello", "goodbye" }; s.addAll(Arrays.asList(str)); String[] sink = new String[str.length + 2]; sink[sink.length - 1] = "residue"; sink[sink.length - 2] = "will be cleared"; Object[] res = s.toArray(sink); Set copy = new HashSet(); copy.addAll(Arrays.asList(res)); Set bogey = new HashSet(); bogey.addAll(Arrays.asList(str)); bogey.add("residue"); bogey.add(null); assertEquals(bogey, copy); } public void testReusesRemovedSlotsOnCollision() { THashSet set = new THashSet(11, 0.5f); class Foo { public int hashCode() { return 4; } } Foo f1 = new Foo(); Foo f2 = new Foo(); Foo f3 = new Foo(); set.add(f1); int idx = set.insertionIndex(f2); set.add(f2); assertEquals(f2, set._set[idx]); set.remove(f2); assertEquals(set.REMOVED, set._set[idx]); assertEquals(idx, set.insertionIndex(f3)); set.add(f3); assertEquals(f3, set._set[idx]); } public void testRehashing() throws Exception { for (int i = 0; i < 10000; i++) { s.add(new Integer(i)); } } /** * this tests that we throw when people violate the * general contract for hashcode on java.lang.Object */ public void testSomeBadlyWrittenObject() { boolean didThrow = false; int i = 0; try { for (; i < 101; i++) { s.add(new Crap()); } } catch (IllegalArgumentException e) { didThrow = true; } assertTrue("expected THashSet to throw an IllegalArgumentException", didThrow); } public void testIterable() { Set set = new THashSet(); set.add( "One" ); set.add( "Two" ); for( String s : set ) { assertTrue(s.equals("One") || s.equals("Two" )); } } public void testToString() { Set set = new THashSet(); set.add( "One" ); set.add( "Two" ); String to_string = set.toString(); assertTrue( to_string, to_string.equals( "{One,Two}" ) || to_string.equals( "{Two,One}" ) ); } // in this junk class, all instances hash to the same // address, but some objects claim to be equal where // others do not. public static class Crap { public boolean equals(Object other) { return other instanceof Crap; } public int hashCode() { return System.identityHashCode( this ); } } public static void main(String[] args) throws Exception { junit.textui.TestRunner.run(new THashSetTest("testBadlyWrittenObject")); } } // THashSetTests trove-2.1.0/test/gnu/trove/TIdentityHashSetTest.java0000644000175000017500000000302011241347111021432 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001-2006, 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; /** * * Created: Sat Aug 17 12:13:03 2002 * * @author Eric Friedman * @version $Id: TIdentityHashSetTest.java,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public class TIdentityHashSetTest extends THashSetTest { public TIdentityHashSetTest(String name) { super(name); } public void setUp() throws Exception { super.setUp(); s = new THashSet(new TObjectIdentityHashingStrategy()); } public void testSomeBadlyWrittenObject() { ; // this test doesn't apply to identity sets } } // TIdentityHashSetTests trove-2.1.0/test/gnu/trove/TStackTest.java0000644000175000017500000000364511241347111017443 0ustar mkochmkochpackage gnu.trove; import junit.framework.TestCase; /** * */ public class TStackTest extends TestCase { public TStackTest() { super(); } public TStackTest(String string) { super(string); } public void testBasic() { TIntStack stack = new TIntStack(); assertEquals(0, stack.size()); stack.push(10); assertEquals(1, stack.size()); assertEquals(10, stack.peek()); assertEquals(1, stack.size()); assertEquals(10, stack.peek()); assertEquals(1, stack.size()); assertEquals(10, stack.pop()); assertEquals(0, stack.size()); stack.push( 10 ); stack.push( 20 ); stack.push( 30 ); assertEquals(3, stack.size()); assertEquals(30, stack.pop()); assertEquals(20, stack.pop()); assertEquals(10, stack.pop()); } public void testArrays() { TIntStack stack = new TIntStack(); int[] array; array = stack.toNativeArray(); assertNotNull(array); assertEquals(0, array.length); stack.push(10); stack.push(20); array = stack.toNativeArray(); assertNotNull(array); assertEquals(2, array.length); assertEquals(10, array[0]); assertEquals(20, array[1]); assertEquals(2, stack.size()); int[] array_correct_size = new int[ 2 ]; stack.toNativeArray(array_correct_size); assertEquals(10, array_correct_size[0]); assertEquals(20, array_correct_size[1]); int[] array_too_long = new int[ 2 ]; stack.toNativeArray(array_too_long); assertEquals(10, array_too_long[0]); assertEquals(20, array_too_long[1]); int[] array_too_short = new int[ 1 ]; try { stack.toNativeArray(array_too_short); } catch( IndexOutOfBoundsException ex ) { // this is good } } } trove-2.1.0/test/gnu/trove/old_serialized_versions/0000755000175000017500000000000011241347111021460 5ustar mkochmkochtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/0000755000175000017500000000000011261456735021636 5ustar mkochmkochtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-d-6.obj0000644000175000017500000000053411241347111023401 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ff-3.obj0000644000175000017500000000026111241347111023544 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-f-1.obj0000644000175000017500000000017411241347111023376 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ff-4.obj0000644000175000017500000000027111241347111023546 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ff-2.obj0000644000175000017500000000025111241347111023542 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ll-1.obj0000644000175000017500000000023611241347111023560 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-f-4.obj0000644000175000017500000000042111241347111023374 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-d-5.obj0000644000175000017500000000043711241347111023402 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-d-3.obj0000644000175000017500000000021311241347111023643 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-dd-1.obj0000644000175000017500000000024411241347111023537 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-l-1.obj0000644000175000017500000000021111241347111023647 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-d-1.obj0000644000175000017500000000021311241347111023641 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-d-2.obj0000644000175000017500000000021311241347111023642 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ll-3.obj0000644000175000017500000000027611241347111023566 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-i-1.obj0000644000175000017500000000017211241347111023377 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-d-1.obj0000644000175000017500000000023611241347111023466 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-i-2.obj0000644000175000017500000000031511241347111023377 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-i-2.obj0000644000175000017500000000014011241347111023646 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-l-3.obj0000644000175000017500000000035311241347111023405 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~wxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-d-4.obj0000644000175000017500000000045411241347111023400 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-f-6.obj0000644000175000017500000000041511241347111023401 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-f-5.obj0000644000175000017500000000044111241347111023377 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-f-6.obj0000644000175000017500000000026411241347111023476 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-l-2.obj0000644000175000017500000000025211241347111023475 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-f-5.obj0000644000175000017500000000026011241347111023471 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-l-2.obj0000644000175000017500000000032311241347111023401 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-i-1.obj0000644000175000017500000000023011241347111023465 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-d-5.obj0000644000175000017500000000021311241347111023645 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-d-6.obj0000644000175000017500000000021311241347111023646 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ii-1.obj0000644000175000017500000000023311241347111023547 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-i-2.obj0000644000175000017500000000024011241347111023467 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-f-2.obj0000644000175000017500000000031511241347111023374 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-l-4.obj0000644000175000017500000000021111241347111023652 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ll-2.obj0000644000175000017500000000025611241347111023563 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-dd-2.obj0000644000175000017500000000026411241347111023542 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-d-6.obj0000644000175000017500000000031611241347111023472 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw5?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-f-2.obj0000644000175000017500000000024411241347111023470 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-i-2.obj0000644000175000017500000000035711241347111023405 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-i-4.obj0000644000175000017500000000014011241347111023650 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-d-2.obj0000644000175000017500000000037411241347111023377 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xp?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-f-1.obj0000644000175000017500000000023411241347111023466 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-d-6.obj0000644000175000017500000000046711241347111023406 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-l-3.obj0000644000175000017500000000021111241347111023651 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-f-6.obj0000644000175000017500000000014211241347111023651 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-d-2.obj0000644000175000017500000000032711241347111023375 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ff-5.obj0000644000175000017500000000030111241347111023541 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-d-3.obj0000644000175000017500000000026611241347111023473 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-i-1.obj0000644000175000017500000000023611241347111023400 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-f-3.obj0000644000175000017500000000025011241347111023466 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-d-3.obj0000644000175000017500000000035711241347111023401 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-f-3.obj0000644000175000017500000000033511241347111023377 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-l-3.obj0000644000175000017500000000041611241347111023405 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-l-2.obj0000644000175000017500000000036611241347111023410 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Long;̏#Jvaluexrjava.lang.Number xpxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-f-4.obj0000644000175000017500000000025411241347111023473 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-l-4.obj0000644000175000017500000000044611241347111023411 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~wsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-i-4.obj0000644000175000017500000000041711241347111023404 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~wsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-f-4.obj0000644000175000017500000000014211241347111023647 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-dd-6.obj0000644000175000017500000000036411241347111023547 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwU?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-i-3.obj0000644000175000017500000000033511241347111023402 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~wxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-i-3.obj0000644000175000017500000000024411241347111023474 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ii-4.obj0000644000175000017500000000026311241347111023555 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-f-3.obj0000644000175000017500000000040111241347111023371 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-d-1.obj0000644000175000017500000000017511241347111023375 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-l-3.obj0000644000175000017500000000026211241347111023477 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-f-1.obj0000644000175000017500000000024211241347111023372 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-dd-5.obj0000644000175000017500000000034411241347111023544 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwE?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-f-5.obj0000644000175000017500000000014211241347111023650 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-l-1.obj0000644000175000017500000000017311241347111023403 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-i-4.obj0000644000175000017500000000025011241347111023472 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-dd-4.obj0000644000175000017500000000032411241347111023541 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw5?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-d-4.obj0000644000175000017500000000027611241347111023475 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-d-5.obj0000644000175000017500000000050411241347111023375 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ii-3.obj0000644000175000017500000000025311241347111023553 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-l-1.obj0000644000175000017500000000024011241347111023376 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-f-6.obj0000644000175000017500000000046111241347111023402 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-d-4.obj0000644000175000017500000000040711241347111023376 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-l-4.obj0000644000175000017500000000027211241347111023501 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-i-3.obj0000644000175000017500000000037711241347111023410 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-d-2.obj0000644000175000017500000000025611241347111023471 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-f-1.obj0000644000175000017500000000014211241347111023644 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-i-4.obj0000644000175000017500000000035511241347111023405 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~wsq~wxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-f-4.obj0000644000175000017500000000035511241347111023402 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-d-3.obj0000644000175000017500000000042411241347111023374 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-d-1.obj0000644000175000017500000000024411241347111023372 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-i-3.obj0000644000175000017500000000014011241347111023647 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-d-5.obj0000644000175000017500000000030611241347111023470 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw-?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-l-2.obj0000644000175000017500000000021111241347111023650 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/set-l-1.obj0000644000175000017500000000023211241347111023472 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-f-5.obj0000644000175000017500000000037511241347111023405 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-f-2.obj0000644000175000017500000000014211241347111023645 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ll-4.obj0000644000175000017500000000031611241347111023562 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw5xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ii-2.obj0000644000175000017500000000024311241347111023551 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-i-1.obj0000644000175000017500000000014011241347111023645 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-d-4.obj0000644000175000017500000000021311241347111023644 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2o-f-2.obj0000644000175000017500000000036111241347111023375 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xp?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/list-f-3.obj0000644000175000017500000000014211241347111023646 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-dd-3.obj0000644000175000017500000000030411241347111023536 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ff-1.obj0000644000175000017500000000024111241347111023540 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/p2p-ff-6.obj0000644000175000017500000000031111241347111023543 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw-?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/linkedlist-1.obj0000644000175000017500000000040311241347111024610 0ustar mkochmkochsrgnu.trove.TLinkedList xpwsr&gnu.trove.SerializationTest$LinkedNode%j+Ivaluexrgnu.trove.TLinkableAdapterc\K_L_nexttLgnu/trove/TLinkable;L _previousq~xpsq~sq~sq~pq~q~q~pq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/0/o2p-l-4.obj0000644000175000017500000000040311241347111023402 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~wsq~wxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/0000755000175000017500000000000011261456735021637 5ustar mkochmkochtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-d-6.obj0000644000175000017500000000053411241347111023402 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ff-3.obj0000644000175000017500000000026111241347111023545 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-f-1.obj0000644000175000017500000000017411241347111023377 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ff-4.obj0000644000175000017500000000027111241347111023547 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ff-2.obj0000644000175000017500000000025111241347111023543 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ll-1.obj0000644000175000017500000000023611241347111023561 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-f-4.obj0000644000175000017500000000042111241347111023375 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-d-5.obj0000644000175000017500000000043711241347111023403 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-d-3.obj0000644000175000017500000000021311241347111023644 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-dd-1.obj0000644000175000017500000000024411241347111023540 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-l-1.obj0000644000175000017500000000021111241347111023650 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-d-1.obj0000644000175000017500000000021311241347111023642 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-d-2.obj0000644000175000017500000000021311241347111023643 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ll-3.obj0000644000175000017500000000027611241347111023567 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-i-1.obj0000644000175000017500000000017211241347111023400 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-d-1.obj0000644000175000017500000000023611241347111023467 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-i-2.obj0000644000175000017500000000031511241347111023400 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-i-2.obj0000644000175000017500000000014011241347111023647 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-l-3.obj0000644000175000017500000000035311241347111023406 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~wxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-d-4.obj0000644000175000017500000000045411241347111023401 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-f-6.obj0000644000175000017500000000041511241347111023402 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-f-5.obj0000644000175000017500000000044111241347111023400 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-f-6.obj0000644000175000017500000000026411241347111023477 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-l-2.obj0000644000175000017500000000025211241347111023476 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-f-5.obj0000644000175000017500000000026011241347111023472 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-l-2.obj0000644000175000017500000000032311241347111023402 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-i-1.obj0000644000175000017500000000023011241347111023466 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-d-5.obj0000644000175000017500000000021311241347111023646 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-d-6.obj0000644000175000017500000000021311241347111023647 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ii-1.obj0000644000175000017500000000023311241347111023550 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-i-2.obj0000644000175000017500000000024011241347111023470 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-f-2.obj0000644000175000017500000000031511241347111023375 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-l-4.obj0000644000175000017500000000021111241347111023653 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ll-2.obj0000644000175000017500000000025611241347111023564 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-dd-2.obj0000644000175000017500000000026411241347111023543 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-d-6.obj0000644000175000017500000000031611241347111023473 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw5?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-f-2.obj0000644000175000017500000000024411241347111023471 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-i-2.obj0000644000175000017500000000035711241347111023406 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-i-4.obj0000644000175000017500000000014011241347111023651 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-d-2.obj0000644000175000017500000000037411241347111023400 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xp?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-f-1.obj0000644000175000017500000000023411241347111023467 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-d-6.obj0000644000175000017500000000046711241347111023407 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-l-3.obj0000644000175000017500000000021111241347111023652 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-f-6.obj0000644000175000017500000000014211241347111023652 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-d-2.obj0000644000175000017500000000032711241347111023376 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ff-5.obj0000644000175000017500000000030111241347111023542 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-d-3.obj0000644000175000017500000000026611241347111023474 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-i-1.obj0000644000175000017500000000023611241347111023401 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-f-3.obj0000644000175000017500000000025011241347111023467 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-d-3.obj0000644000175000017500000000035711241347111023402 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-f-3.obj0000644000175000017500000000033511241347111023400 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-l-3.obj0000644000175000017500000000041611241347111023406 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-l-2.obj0000644000175000017500000000036611241347111023411 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Long;̏#Jvaluexrjava.lang.Number xpxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-f-4.obj0000644000175000017500000000025411241347111023474 0ustar mkochmkochsrgnu.trove.TFloatHashSet xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-l-4.obj0000644000175000017500000000044611241347111023412 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~wsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-i-4.obj0000644000175000017500000000041711241347111023405 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~wsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-f-4.obj0000644000175000017500000000014211241347111023650 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-dd-6.obj0000644000175000017500000000036411241347111023550 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwU?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-i-3.obj0000644000175000017500000000033511241347111023403 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~wxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-i-3.obj0000644000175000017500000000024411241347111023475 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ii-4.obj0000644000175000017500000000026311241347111023556 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-f-3.obj0000644000175000017500000000040111241347111023372 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-d-1.obj0000644000175000017500000000017511241347111023376 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-l-3.obj0000644000175000017500000000026211241347111023500 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-f-1.obj0000644000175000017500000000024211241347111023373 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-dd-5.obj0000644000175000017500000000034411241347111023545 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwE?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-f-5.obj0000644000175000017500000000014211241347111023651 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-l-1.obj0000644000175000017500000000017311241347111023404 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-i-4.obj0000644000175000017500000000025011241347111023473 0ustar mkochmkochsrgnu.trove.TIntHashSet xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-dd-4.obj0000644000175000017500000000032411241347111023542 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw5?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-d-4.obj0000644000175000017500000000027611241347111023476 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-d-5.obj0000644000175000017500000000050411241347111023376 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ii-3.obj0000644000175000017500000000025311241347111023554 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-l-1.obj0000644000175000017500000000024011241347111023377 0ustar mkochmkochsrgnu.trove.TLongObjectHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-f-6.obj0000644000175000017500000000046111241347111023403 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~wsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-d-4.obj0000644000175000017500000000040711241347111023377 0ustar mkochmkochsrgnu.trove.TObjectDoubleHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-l-4.obj0000644000175000017500000000027211241347111023502 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-i-3.obj0000644000175000017500000000037711241347111023411 0ustar mkochmkochsrgnu.trove.TIntObjectHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-d-2.obj0000644000175000017500000000025611241347111023472 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-f-1.obj0000644000175000017500000000014211241347111023645 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-i-4.obj0000644000175000017500000000035511241347111023406 0ustar mkochmkochsrgnu.trove.TObjectIntHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Integer⠤8Ivaluexrjava.lang.Number xpwsq~wsq~wxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-f-4.obj0000644000175000017500000000035511241347111023403 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-d-3.obj0000644000175000017500000000042411241347111023375 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xpwsq~?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-d-1.obj0000644000175000017500000000024411241347111023373 0ustar mkochmkochsrgnu.trove.TDoubleObjectHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-i-3.obj0000644000175000017500000000014011241347111023650 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-d-5.obj0000644000175000017500000000030611241347111023471 0ustar mkochmkochsrgnu.trove.TDoubleHashSet xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw-?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-l-2.obj0000644000175000017500000000021111241347111023651 0ustar mkochmkochsrgnu.trove.TLongArrayList xpwY xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/set-l-1.obj0000644000175000017500000000023211241347111023473 0ustar mkochmkochsrgnu.trove.TLongHashSet xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-f-5.obj0000644000175000017500000000037511241347111023406 0ustar mkochmkochsrgnu.trove.TObjectFloatHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Floatɢ<Fvaluexrjava.lang.Number xpwsq~wsq~wsq~w?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-f-2.obj0000644000175000017500000000014211241347111023646 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ll-4.obj0000644000175000017500000000031611241347111023563 0ustar mkochmkochsrgnu.trove.TLongLongHashMap xrgnu.trove.TLongHashVXf; xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw5xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ii-2.obj0000644000175000017500000000024311241347111023552 0ustar mkochmkochsrgnu.trove.TIntIntHashMap xrgnu.trove.TIntHashI;vc' xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-i-1.obj0000644000175000017500000000014011241347111023646 0ustar mkochmkochsrgnu.trove.TIntArrayList xpw1 xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-d-4.obj0000644000175000017500000000021311241347111023645 0ustar mkochmkochsrgnu.trove.TDoubleArrayList xpwY ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2o-f-2.obj0000644000175000017500000000036111241347111023376 0ustar mkochmkochsrgnu.trove.TFloatObjectHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw srjava.lang.Floatɢ<Fvaluexrjava.lang.Number xp?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/list-f-3.obj0000644000175000017500000000014211241347111023647 0ustar mkochmkochsrgnu.trove.TFloatArrayList xpw1 ?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-dd-3.obj0000644000175000017500000000030411241347111023537 0ustar mkochmkochsrgnu.trove.TDoubleDoubleHashMap xrgnu.trove.TDoubleHashm7Ԏ xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw%?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ff-1.obj0000644000175000017500000000024111241347111023541 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpwxtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/p2p-ff-6.obj0000644000175000017500000000031111241347111023544 0ustar mkochmkochsrgnu.trove.TFloatFloatHashMap xrgnu.trove.TFloatHash{pq xrgnu.trove.TPrimitiveHashBd xrgnu.trove.THash*>7 xpw-?xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/linkedlist-1.obj0000644000175000017500000000040311241347111024611 0ustar mkochmkochsrgnu.trove.TLinkedList xpwsr&gnu.trove.SerializationTest$LinkedNode%j+Ivaluexrgnu.trove.TLinkableAdapterc\K_L_nexttLgnu/trove/TLinkable;L _previousq~xpsq~sq~sq~pq~q~q~pq~xtrove-2.1.0/test/gnu/trove/old_serialized_versions/1/o2p-l-4.obj0000644000175000017500000000040311241347111023403 0ustar mkochmkochsrgnu.trove.TObjectLongHashMap xrgnu.trove.TObjectHashy1 xrgnu.trove.THash*>7 xpwsrjava.lang.Long;̏#Jvaluexrjava.lang.Number xpwsq~wsq~wxtrove-2.1.0/test/gnu/trove/TIdentityHashMapTest.java0000644000175000017500000000343411241347111021425 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001-2006, 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; /** * * Created: Sat Aug 17 11:22:30 2002 * * @author Eric Friedman * @version $Id: TIdentityHashMapTest.java,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public class TIdentityHashMapTest extends THashMapTest { public TIdentityHashMapTest(String name) { super(name); } public void setUp() throws Exception { super.setUp(); map = new THashMap(new TObjectIdentityHashingStrategy()); count = 0; } public void testIdentityHash() throws Exception { Integer i1, i2; i1 = new Integer(1); i2 = new Integer(1); map.put(i1,i1); assertTrue(map.containsKey(i1)); assertTrue(! map.containsKey(i2)); } public void testBadlyWrittenKey() { ; // this test not applicable in identity hashing } } // TIdentityHashMapTests trove-2.1.0/test/gnu/trove/THashMapTest.java0000644000175000017500000007551511241347111017724 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001-2006, 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 junit.framework.TestCase; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.*; /** * * Created: Sat Nov 3 10:31:38 2001 * * @author Eric D. Friedman * @version $Id: THashMapTest.java,v 1.12 2008/05/07 19:38:11 robeden Exp $ */ public class THashMapTest extends TestCase { protected THashMap map; protected int count; public THashMapTest(String name) { super(name); } public void setUp() throws Exception { super.setUp(); map = new THashMap(); count = 0; } public void tearDown() throws Exception { super.tearDown(); map = null; count = 0; } public void testPut() throws Exception { assertEquals("put succeeded",null, map.put("One","two")); assertEquals("size did not reflect put", 1, map.size()); assertEquals("put/get failed", "two", map.get("One")); assertEquals("second put failed","two",map.put("One","foo")); } public void testPutIfAbsent() throws Exception { assertEquals("putIfAbsent succeeded",null, map.putIfAbsent("One","two")); assertEquals("size did not reflect putIfAbsent", 1, map.size()); assertEquals("putIfAbsent/get failed", "two", map.get("One")); assertEquals("second putIfAbsent failed","two", map.putIfAbsent("One","foo")); assertEquals("size did not reflect putIfAbsent", 1, map.size()); assertEquals("putIfAbsent/get failed", "two", map.get("One")); assertEquals("third putIfAbsent failed", null, map.putIfAbsent("Two","bar")); assertEquals("size did not reflect putIfAbsent", 2, map.size()); assertEquals("putIfAbsent/get failed", "bar", map.get("Two")); } public void testClear() throws Exception { assertEquals("initial size was not zero", 0, map.size()); assertEquals("put succeeded",null, map.put("One","two")); assertEquals("size did not reflect put", 1, map.size()); map.clear(); assertEquals("cleared size was not zero", 0, map.size()); } public void testContainsKey() throws Exception { Object key = "hi"; assertTrue("should not contain key initially", ! map.containsKey(key)); assertEquals("put succeeded",null, map.put(key, new Integer(1))); assertTrue("key not found after put", map.containsKey(key)); } public void testGet() throws Exception { Object key = "hi", val = "one", val2 = "two"; map.put(key,val); assertEquals("get did not return expected value",val, map.get(key)); map.put(key,val2); assertEquals("get did not return expected value on second put", val2, map.get(key)); } public void testValues() throws Exception { Object k1 = "1", k2 = "2", k3 = "3", k4 = "4", k5 = "5"; Object v1 = "x", v2 = "y", v3 = "z"; map.put(k1,v1); map.put(k2,v1); map.put(k3,v2); map.put(k4,v3); map.put(k5,v2); Collection vals = map.values(); assertEquals("size was not 5", 5, vals.size()); vals.remove("z"); assertEquals("size was not 4", 4, vals.size()); vals.remove("y"); assertEquals("size was not 3", 3, vals.size()); vals.remove("y"); assertEquals("size was not 2", 2, vals.size()); assertEquals("map did not diminish to 2 entries", 2, map.size()); } public void testKeySet() throws Exception { Object key1 = "hi", key2 = "bye", key3 = "whatever"; Object val = "x"; map.put(key1, val); map.put(key2, val); map.put(key3, val); Set keys = map.keySet(); assertTrue("keyset did not match expected set", keys.containsAll(Arrays.asList(new Object[] { key1, key2, key3 }))); assertEquals(3, map.size()); int count = 0; Iterator it = keys.iterator(); while( it.hasNext() ) { count++; it.next(); } assertEquals(map.size(),count); for (Iterator i = keys.iterator(); i.hasNext();) { Object o = i.next(); if (o.equals(key2)) { i.remove(); } } assertTrue("keyset did not match expected set", keys.containsAll(Arrays.asList(new Object[] { key1, key3 }))); } public void testForEachEntry() throws Exception { Object[] keys = { "one","two","three","four" }; Object[] vals = { new Integer(1), new Integer(2), new Integer(3), new Integer(4) }; for (int i = 0; i < keys.length; i++) { map.put(keys[i],vals[i]); } TObjectObjectProcedure proc = new TObjectObjectProcedure() { public boolean execute(Object key, Object value) { count += ((Integer)value).intValue(); return true; } }; map.forEachEntry(proc); assertEquals(10,count); } public void testForEachEntryInterrupt() throws Exception { Object[] keys = { "one","two","three","four" }; Object[] vals = { new Integer(1), new Integer(2), new Integer(3), new Integer(4) }; for (int i = 0; i < keys.length; i++) { map.put(keys[i],vals[i]); } TObjectObjectProcedure proc = new TObjectObjectProcedure() { public boolean execute(Object key, Object value) { count += ((Integer)value).intValue(); return count >= 6 ? false: true; } }; map.forEachEntry(proc); assertTrue(count < 10); } public void testTransformValues() throws Exception { Object[] keys = { "one","two","three","four" }; Object[] vals = { new Integer(1), new Integer(2), new Integer(3), new Integer(4) }; for (int i = 0; i < keys.length; i++) { map.put(keys[i],vals[i]); } TObjectFunction func = new TObjectFunction() { public Object execute(Object value) { int num = ((Integer)value).intValue(); return new Integer(num << 1); } }; map.transformValues(func); assertEquals(new Integer(2),map.get("one")); assertEquals(new Integer(4),map.get("two")); assertEquals(new Integer(6),map.get("three")); assertEquals(new Integer(8),map.get("four")); } public void testKeyIterator() throws Exception { Object[] keys = { "one","two","three","four" }; Object[] vals = { new Integer(1), new Integer(2), new Integer(3), new Integer(4) }; for (int i = 0; i < keys.length; i++) { map.put(keys[i],vals[i]); } int count = 0; for (Iterator i = map.keySet().iterator(); i.hasNext();) { i.next(); count++; } assertEquals(4,count); } public void testCompact() throws Exception { Integer[] data = new Integer[1000]; for (int i = 0; i < 1000; i++) { data[i] = new Integer(i); map.put(data[i], data[i]); } assertTrue(map._maxSize > 1000); for (int i = 0; i < 1000; i+=2) { // try { map.remove(data[i]); // } // catch( RuntimeException ex ) { // System.err.println("Error on i: " + i); // System.out.println("Hash codes:"); // for( int j = 0 ; j < data.length; j++ ) { // if ( ( j % 8 ) == 0 ) { // System.out.println(","); // } // else System.out.print(","); // System.out.print(map._hashingStrategy.computeHashCode(data[j])); // } // // // System.out.println("Remove:"); // for( int j = 0 ; j <= i; j+=2 ) { // if ( ( j % 8 ) == 0 ) { // System.out.println(","); // } // else System.out.print(","); // System.out.print(map._hashingStrategy.computeHashCode(data[j])); // } // throw ex; // } } assertEquals(500, map.size()); map.compact(); assertEquals(500, map.size()); assertTrue(map._maxSize < 1000); } public void testContainsNullValue() throws Exception { THashMap mm = new THashMap(); mm.put("a",null); assertTrue(mm.containsValue(null)); } public void testEntrySetContainsEntryWithNullValue() throws Exception { THashMap mm = new THashMap(); mm.put("0", null); Map.Entry ee = (Map.Entry)mm.entrySet().iterator().next(); assertTrue(mm.entrySet().contains(ee)); } public void testValueSetRemoveNullValue() throws Exception { THashMap mm = new THashMap(); mm.put("0", null); assertTrue(mm.values().remove(null)); } public void testSizeAfterEntrySetRemove() throws Exception { THashMap mm = new THashMap(); mm.put("0", null); Map.Entry ee = (Map.Entry)mm.entrySet().iterator().next(); assertTrue(ee.getKey().equals("0")); assertNull(ee.getValue()); assertTrue("remove on entrySet() returned false", mm.entrySet().remove(ee)); assertEquals(0, mm.size()); } public void testEntrySetRemoveSameKeyDifferentValues() throws Exception { THashMap mm1 = new THashMap(); mm1.put("0","abc"); THashMap mm2 = new THashMap(); mm2.put("0","123"); Map.Entry ee = (Map.Entry)mm1.entrySet().iterator().next(); assertEquals(1, mm2.size()); assertTrue(! mm2.entrySet().contains(ee)); assertTrue(! mm2.entrySet().remove(ee)); } public void testSizeAfterMultipleReplacingPuts() throws Exception { THashMap mm = new THashMap(); mm.put("key", "a"); assertEquals(1, mm.size()); mm.put("key", "b"); assertEquals(1, mm.size()); } public void testSerializable() throws Exception { THashMap mm = new THashMap(); mm.put("a","b"); mm.put("b","c"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(mm); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); THashMap mm2 = (THashMap)ois.readObject(); assertEquals(mm, mm2); } public void testSerializablePrimitives() throws Exception { TIntIntHashMap mm = new TIntIntHashMap(); mm.put(1, -1); mm.put(0, 0); mm.put(127, 68888); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(mm); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); TIntIntHashMap mm2 = (TIntIntHashMap)ois.readObject(); assertEquals(mm, mm2); } public void testRetainEntries() throws Exception { THashMap mm = new THashMap(); mm.put("a", "b"); mm.put("c", "b"); mm.put("d", "b"); mm.retainEntries(new TObjectObjectProcedure() { public boolean execute(Object key, Object val) { return key.equals("c"); } }); assertEquals(1, mm.size()); assertTrue(mm.containsKey("c")); assertEquals("b", mm.get("c")); } public void testPutAll() throws Exception { THashMap t = new THashMap(); HashMap m = new HashMap(); m.put("one","two"); m.put("two","four"); m.put("three","six"); t.putAll(m); } public void testClone() throws Exception { TObjectIntHashMap original = new TObjectIntHashMap(); original.put( "one", 1 ); original.put( "two", 2 ); original.put( "three", 3 ); TObjectIntHashMap clone = original.clone(); assertEquals(original,clone); assertEquals(3, clone.size()); assertEquals(1, clone.get("one" )); assertEquals(2, clone.get("two" )); assertEquals(3, clone.get("three" )); original.clear(); assertEquals(3, clone.size()); assertEquals(1, clone.get("one" )); assertEquals(2, clone.get("two" )); assertEquals(3, clone.get("three" )); } public void testHashCode() throws Exception { THashMap m1 = new THashMap(); THashMap m2 = new THashMap(); m1.put(new String("foo"), new String("bar")); m2.put(new String("foo"), new String("bar")); assertEquals(m1.hashCode(), m2.hashCode()); assertEquals(m1, m2); m2.put(new String("cruft"), new String("bar")); assertTrue(m1.hashCode() != m2.hashCode()); assertTrue(! m1.equals(m2)); } public void testBadlyWrittenKey() { boolean didThrow = false; try { for (int i = 0; i < 1000; i++) { // enough to trigger a rehash map.put(new THashSetTest.Crap(), new Integer(i)); } } catch (IllegalArgumentException e) { didThrow = true; } assertTrue("expected THashMap to throw an IllegalArgumentException", didThrow); } public void testKeySetEqualsEquivalentSet() { Set set = new java.util.HashSet(); set.add("foo"); set.add("doh"); set.add("hal"); THashMap tv1 = new THashMap(); tv1.put("doh", "blah"); tv1.put("foo", "blah"); tv1.put("hal", "notblah"); assertTrue(tv1.keySet().equals(set)); } public void testNullValue() { THashMap t = new THashMap(); t.put("foo", null); t.put("bar", null); t.put("baz", null); assertEquals(Arrays.asList(new Object[] { null, null, null }), new ArrayList(t.values())); } public void testNullValueSize() { THashMap map = new THashMap(); map.put("narf",null); map.put("narf",null); assertEquals(1, map.size()); } public void testNullKey() { THashMap t = new THashMap(); t.put(null, null); assertEquals(null, t.keySet().iterator().next()); } public void testRetainEntrySet() { Map orig = new THashMap(); orig.put("one", "frodo"); orig.put("two", "bilbo"); orig.put("three", "samwise"); Map subset = new HashMap(); subset.put("two", "bilbo"); assertTrue(orig.entrySet().retainAll(subset.entrySet())); assertEquals(subset, orig); } public void testMapEntrySetHashCode() { Map m1 = new THashMap(); m1.put("one", "foo"); Map m2 = new THashMap(); m2.put("one", "foo"); Object o1 = m1.entrySet().iterator().next(); Object o2 = m1.entrySet().iterator().next(); assertTrue(o1 != o2); assertTrue(o1.equals(o2)); assertEquals(o1.hashCode(), o2.hashCode()); } public void testEqualsAndHashCode() { THashMap map1 = new THashMap(); map1.put( "Key1", null ); THashMap map2 = new THashMap(); map2.put( "Key2", "Value2" ); assertFalse( "map1.equals( map2 )", map1.equals( map2 ) ); assertFalse( "map2.equals( map1 )", map2.equals( map1 ) ); THashMap clone_map1 = map1.clone(); THashMap clone_map2 = map2.clone(); assertEquals(map1, clone_map1); assertEquals(map1.hashCode(), clone_map1.hashCode()); assertEquals(map2, clone_map2); assertEquals(map2.hashCode(), clone_map2.hashCode()); } /** * Test case for bug #1428614. * http://sourceforge.net/tracker/index.php?func=detail&aid=1428614&group_id=39235&atid=424682 */ public void testRemoveValue() { THashMap map = new THashMap(); map.put( "one", "a" ); map.put( "two", "a" ); map.put( "three", "b" ); assertEquals( 3, map.size() ); map.values().remove( "a" ); assertEquals( 2, map.size() ); } /** * This test case arose out of a problem that was ultimately caused by the * implementation if THashMap.removeAt(int) being incorrect (the super implementation * was being called before the local implementation which caused problems when * auto-compaction occurred). So, it's a little wiggy, but since the case was useful * once, I figure I'll leave it in. - RDE */ public void testProblematicRemove() { int[] to_add = new int[] { 9707851,1432929,7941420,8698105,9178562,14368620,2165498,5759024, 4160722,1835074,5570057,15866937,1774305,7645103,11340758,14962053, 10326974,5153366,8644308,10981652,2484113,8790215,13765491,15579334, 16644662,3538325,10183070,2491991,6963721,1406388,14845099,7614579, 1630785,11417789,988981,12372702,11197485,6115155,185310,10733210, 4444363,4256211,12877269,2178642,8551718,15095256,922983,10434400, 15511986,8792944,9301853,6147907,13778707,2822511,8760514,1112301, 4624291,8406178,1708017,834479,16113199,13501060,477791,10737091, 2568325,14839924,4523777,13566852,15722007,15406704,932352,127549, 13010531,10540591,5100961,288048,9396085,12844726,8887992,12932686, 10827776,16751176,15337379,10192984,1341540,15470105,9555179,2394843, 1595902,12345969,14884594,313940,8348091,15293845,16706146,13500767, 12331344,3959435,7796580,7077998,9458485,4648605,14396291,14246507, 13404097,14988605,3600161,9280290,12842832,10606027,14355582,1136752, 12921165,1749219,5457859,9197696,421256,73503,10633537,6952660, 58264,6164651,9993341,1386282,12470635,12982240,4816459,159250, 8949093,16447937,2290043,1828537,13148199,9084516,10802630,13549340, 6609445,2995162,8040282,9333002,9580969,16406600,12194236,14835440, 13041360,8604473,12565810,1988729,4355359,1535580,5149176,5324752, 3438993,1660570,8691895,5474195,15334260,8105437,13879037,11351030, 3039475,14625682,10849417,11379670,14640675,11176427,4513965,16428465, 10578701,8072595,15538803,6526027,10283251,8507206,5188636,14223982, 3920972,15659969,12922874,13689914,3658005,8379437,5247277,9938991, 10659712,10678905,14485926,10786998,2488171,9881794,5651833,14538812, 10444169,11922157,5403811,6785775,13794224,11958753,16494451,12313218, 1297763,1126021,345418,528188,2114627,6400133,8307281,490653, 8793363,16336633,10653219,2214875,13551003,1001246,397033,12381376, 5991449,1443593,2622811,7847125,944151,13889218,14686341,6939782, 1712728,12902341,4138467,13656813,973555,4767079,9100632,13222220, 11641873,9082629,12639233,11258141,2146301,1867442,12719413,16679909, 8734589,1606713,9501535,6761395,6693929,13647363,9914313,15335895, 2021653,4068909,2228794,12603329,11807792,12665538,395494,3299447, 5119086,2917420,10055436,4831656,3927888,14447609,4329094,13077467, 11461522,14594477,6481991,8367571,7156844,9223013,6482120,10542896, 10286402,11125093,14144872,16495825,1844776,860068,9980169,14877755, 2804551,8894974,12849678,8215338,15490728,3843485,5184218,7071904, 7703600,4633458,11481528,15295069,3736219,14297843,3787634,6015173, 14290065,7290758,11764335,3688927,7991532,12075598,606202,4674522, 13772937,6515326,14974617,3385263,4587760,15178512,7689244,15015527, 3087738,3683764,5107535,10120404,6225460,8588999,4151219,9885848, 6691152,518908,13918089,13393004,13093729,16338349,5945377,15632500, 4230314,13832167,12139768,5361165,11457892,3916190,2387780,325816, 6621694,7540927,5271271,10565439,3281837,11138623,6663214,737100, 6864802,16592415,14615312,4342441,2525512,16706191,14258395,11878990, 1320531,14696398,8201398,16077183,12155328,15225360,6533378,16390602, 11750387,4144864,3744598,4136761,1775074,3787875,10061327,3165792, 6921717,84292,7420530,11805441,6704350,4234280,13377633,6417611, 81563,11879309,6692731,10285066,5452490,2848306,6094584,6772150, 2899899,805004,7273360,4566720,13878010,10871921,3724097,11896809, 15586671,5744620,13731591,16250661,8560290,8169917,7059338,14615241, 3149669,4383295,1292178,7919990,846550,896930,8769114,11437924, 3854132,16345157,2929809,186157,8183120,10860321,10092509,7157818, 8817522,2944051,4664124,6791689,12517547,12905829,12435281,5992485, 2074096,13062653,14148480,10024647,7455154,6534752,5933059,9930860, 8221561,2639915,10098755,11468155,8638604,15770467,7790866,11694410, 2868248,5710862,15709,12374346,5274287,10913198,9607083,2330533, 11262155,2500209,10878393,11834918,15572289,15669880,11713730,8818293, 15907500,12427744,13540318,5978200,13640927,2411696,16408949,1331989, 5941655,3414928,16619879,6441500,15706705,9881210,12620326,12259629, 6605901,10543825,9125515,12001189,8309409,2696396,3070853,5120614, 11830622,10490623,4149060,7141756,7297762,12039919,4930206,16095035, 10203610,12162006,10028034,14040149,1250372,9943013,11150309,1752285, 6641241,532227,2891993,2146459,4523080,1843838,1876388,12071882, 5253689,266407,14770216,7346541,9785383,12662763,4087061,5312086, 8667965,5935475,214509,14935237,12603345,12069351,13056011,3177187, 13886924,9688141,5714168,5238287,9839924,6586077,12908278,3257673, 7665358,16208962,12373914,14796394,11098653,5975276,14839805,2522300, 13055068,4113411,11984808,1418893,6924381,11314606,11633137,13235995, 8277143,14057346,5064134,2097065,13223254,12242045,13059400,9799866, 4430809,11327935,769464,13938921,11178479,5438437,1550013,12839250, 727385,11354068,3772220,15394227,9336140,11988768,860366,14994301, 15440057,7845075,46465,9200550,14833083,6980643,604527,10080643, 9045195,4244693,3844932,12717539,1960282,12786813,8615113,6833198, 5522541,5791657,15755268,3994917,158446,12203633,5002730,10253904, 1809471,11479213,9928035,11072909,9512807,11660261,16127120,12596061, 7086362,15820414,8387982,14653636,10912742,1941253,11740079,15457795, 3976572,10595620,7217556,6197451,7618490,258825,4780842,5534349, 2921202,6513404,16229803,10332843,3138363,15681804,10802604,13113540, 13757900,5443555,3681765,5063855,14185653,14039650,9644178,5024611, 8918836,11231866,13523137,2425209,8636320,10944802,3891863,12961644, 10984042,9100512,11218774,11581954,8646320,11234763,11887145,4171898, 5109569,10742219,4859349,16381539,10419813,5223261,8955000,15061357, 1607571,7136846,8670269,11099382,1451676,4261185,12586581,15531576, 2504976,7105767,6413040,7144290,16334106,1741877,16270583,7852246, 3119103,10743199,4558377,7878745,12289371,3163084,11735282,1935864, 5055074,820851,5185654,14442671,5212885,2344949,1892708,1153520, 9541794,12306031,14732248,6743381,5920025,8969603,8847687,6622806, 9462942,12451035,2336870,327996,9713350,9963027,11991923,3562944, 4520396,7065629,2905597,12675100,10094378,5011336,3908274,3572588, 15618069,13341879,9470980,13327842,8432408,6344466,12241360,1543979, 12081229,11363884,983612,6025413,1848571,14318469,14906334,13381442, 3327004,15286722,14443922,9462145,15828870,16292084,128023,4199307, 12797648,6169450,6767468,8100201,9756312,10612295,2273164,3350998, 15889011,3661060,9395406,1435793,5752767,16441805,16677778,6475274, 12909030,15902971,3415473,9004053,645884,515610,8824322,16574526, 15956463,13265827,6333169,6924814,1812983,3392856,14761092,4985619, 7893816,13931135,14548854,11444226,9118923,1875105,7285192,2101733, 7801836,11517693,2349183,5939167,11937456,10886500,13866155,12947589, 9640186,5047153,1901666,715551,13790692,2933460,11212664,9563015, 16642428,16334427,7140601,4655671,15711153,750565,15067249,16737043, 12684416,15673315,2341376,8935324,3134061,10483409,337177,13018877, 16599994,7782302,1977121,10593779,9842381,14330646,1456639,3774065, 12844377,3016177,8933870,12263851,10455534,1612109,16302350,4895080, 12932155,1905228,10253063,4458040,16024500,15902756,16584305,12528008, 4171461,14536742,9219403,12927168,1979395,15257546,10619265,1967594, 1467515,2028519,2032612,3707709,4887462,2337860,183801,2152077, 15066473,3694942,8424967,15508266,13386596,6059869,10531128,13828874, 7119662,5064756,12552069,5922533,802911,5645620,10781530,11246590, 9323418,16275234,2144845,10962831,4925357,1704524,9227431,13641289, 8489002,1225340,8659144,8671408,13461400,4992933,13370774,8568931, 2412794,1312411,12429994,1025208,478829,11399895,2242158,2332498, 10717459,8151843,5288043,7235700,9162569,14017735,10412273,12712138, 11844638,11163643,7756823,9956164,14078510,8442139,2116890,10881649, 16223710,8592664,15408035,6522496,1261635,14685232,5071601,10144049, 967751,7873356,5595700,10647000,15126220,1237821,321796,6173902, 14476409,1830511,12766190,14322080,8483740,13438254,1854079,6215655, 11575352,15129118,16393883,16560142,9079559,11379168,6198702,11864074, 2282933,16547051,7156233,15740343,4809601,2344447,10219155,4977972, 13592880,184650,16420038,3165940,9418081,13446140,179241,9394692, 6213074,1752099,3516715,16081239,13222615,1499877,9066661,12702088, 10706447,7629231,13016955,1069166,1089471,6809842,15634321,1288782, 1183469,9576844,14191973,2814257,4260748,5239952,4277681,4629271, 8220928,8766876,7388663,13090704,15838538,11015909,7814987,14448125, 13000849,15596437,2104764,8398024,15653431,3695833,6613072,13626967, 2665818,9249819,4040305,8029033,4822667,3844052,14708928,690088 }; int[] to_remove = new int[] { 9707851,7941420,9178562,2165498,4160722,5570057,1774305,11340758, 10326974,8644308 }; for( int i = 0 ; i < to_add.length; i++ ) { Integer obj = new Integer( to_add[ i ] ); map.put( obj, obj ); } for( int i = 0; i < to_remove.length; i++ ) { Integer obj = new Integer( to_remove[ i ] ); map.remove( obj ); } } public void testIterable() { Map m = new THashMap(); m.put( "One", Integer.valueOf( 1 ) ); m.put( "Two", Integer.valueOf( 2 ) ); for( String s : m.keySet() ) { assertTrue(s.equals("One") || s.equals("Two" )); } for( Integer i : m.values() ) { assertTrue(i.intValue() == 1 || i.intValue() == 2); } } public void testGetOverRemovedObjectBug() { Map m = new THashMap( new TObjectHashingStrategy() { public int computeHashCode(BadHashInteger object) { return object.hashCode(); } public boolean equals(BadHashInteger o1, BadHashInteger o2) { return o1.value == o2.value; } } ); m.put( new BadHashInteger( 1 ), "one" ); m.put( new BadHashInteger( 2 ), "two" ); m.remove( new BadHashInteger( 1 ) ); assertEquals( 1, m.size() ); // Blow up here? assertEquals( "two", m.get( new BadHashInteger( 2 ) ) ); } public void testReaddBug() { Map m = new THashMap( new TObjectHashingStrategy() { public int computeHashCode(Integer object) { return object.intValue(); } public boolean equals(Integer o1, Integer o2) { return o1.intValue() == o2.intValue(); } } ); m.put( new Integer( 1 ), "one" ); assertEquals(1, m.size()); m.remove( new Integer( 1 ) ); assertEquals(0, m.size()); m.put( new Integer( 1 ), "one" ); assertEquals(1, m.size()); } public void testToString() { Map map = new THashMap(); map.put( "One", "1" ); map.put( "Two", "2" ); String to_string = map.toString(); assertTrue( to_string, to_string.equals( "{One=1,Two=2}" ) || to_string.equals( "{Two=2,One=1}" ) ); } private static class BadHashInteger { private final int value; BadHashInteger( int value ) { this.value = value; } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BadHashInteger that = (BadHashInteger) o; if (value != that.value) return false; return true; } public int hashCode() { return 0; } } } // THashMapTests trove-2.1.0/test/gnu/trove/SerializationTest.java0000644000175000017500000006757211241347111021100 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001-2006, 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 junit.framework.TestCase; import java.io.*; import java.util.Map; import java.util.Set; import gnu.trove.decorator.*; /** * */ public class SerializationTest extends TestCase { // If non-null, we'll save the serialized objects so we can tets migration private static File serialized_object_output_dir = null; static { if ( System.getProperty( "trove.test.serialization_output_dir" ) != null ) { serialized_object_output_dir = new File( System.getProperty( "trove.test.serialization_output_dir" ) ); if ( !serialized_object_output_dir.exists() && !serialized_object_output_dir.mkdirs() ) { System.err.println( "Unable to access or create serialization test " + "output dir (" + serialized_object_output_dir + ") " ); serialized_object_output_dir = null; } System.out.println( "Serialized objects will be written to " + serialized_object_output_dir ); } } public SerializationTest( String name ) { super( name ); } public void testP2PMap() { // Long-long TLongLongHashMap llmap = new TLongLongHashMap(); Map llmap_dec = Decorators.wrap( llmap ); assertTrue( serializesCorrectly( llmap, "p2p-ll-1" ) ); assertTrue( serializesCorrectly( llmap_dec, "p2p-ll-1d" ) ); llmap.put( 0, 1 ); assertTrue( serializesCorrectly( llmap, "p2p-ll-2" ) ); assertTrue( serializesCorrectly( llmap_dec, "p2p-ll-2d" ) ); llmap.put( Long.MIN_VALUE, Long.MIN_VALUE ); assertTrue( serializesCorrectly( llmap, "p2p-ll-3" ) ); assertTrue( serializesCorrectly( llmap_dec, "p2p-ll-3d" ) ); llmap.put( Long.MAX_VALUE, Long.MAX_VALUE ); assertTrue( serializesCorrectly( llmap, "p2p-ll-4" ) ); assertTrue( serializesCorrectly( llmap_dec, "p2p-ll-4d" ) ); // Int-int TIntIntHashMap iimap = new TIntIntHashMap(); Map iimap_dec = Decorators.wrap( iimap ); assertTrue( serializesCorrectly( iimap, "p2p-ii-1" ) ); assertTrue( serializesCorrectly( iimap_dec, "p2p-ii-1d" ) ); iimap.put( 0, 1 ); assertTrue( serializesCorrectly( iimap, "p2p-ii-2" ) ); assertTrue( serializesCorrectly( iimap_dec, "p2p-ii-2d" ) ); iimap.put( Integer.MIN_VALUE, Integer.MIN_VALUE ); assertTrue( serializesCorrectly( iimap, "p2p-ii-3" ) ); assertTrue( serializesCorrectly( iimap_dec, "p2p-ii-3d" ) ); iimap.put( Integer.MAX_VALUE, Integer.MAX_VALUE ); assertTrue( serializesCorrectly( iimap, "p2p-ii-4" ) ); assertTrue( serializesCorrectly( iimap_dec, "p2p-ii-4d" ) ); // Double-double TDoubleDoubleHashMap ddmap = new TDoubleDoubleHashMap(); Map ddmap_dec = Decorators.wrap( ddmap ); assertTrue( serializesCorrectly( ddmap, "p2p-dd-1" ) ); assertTrue( serializesCorrectly( ddmap_dec, "p2p-dd-1d" ) ); ddmap.put( 0, 1 ); assertTrue( serializesCorrectly( ddmap, "p2p-dd-2" ) ); assertTrue( serializesCorrectly( ddmap_dec, "p2p-dd-2d" ) ); ddmap.put( Double.MIN_VALUE, Double.MIN_VALUE ); assertTrue( serializesCorrectly( ddmap, "p2p-dd-3" ) ); assertTrue( serializesCorrectly( ddmap_dec, "p2p-dd-3d" ) ); ddmap.put( Double.MAX_VALUE, Double.MAX_VALUE ); assertTrue( serializesCorrectly( ddmap, "p2p-dd-4" ) ); assertTrue( serializesCorrectly( ddmap_dec, "p2p-dd-4d" ) ); ddmap.put( Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( ddmap, "p2p-dd-5" ) ); assertTrue( serializesCorrectly( ddmap_dec, "p2p-dd-5d" ) ); ddmap.put( Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( ddmap, "p2p-dd-6" ) ); assertTrue( serializesCorrectly( ddmap_dec, "p2p-dd-6d" ) ); // NOTE: trove doesn't deal well with NaN // ddmap.put( Double.NaN, Double.NaN ); // assertTrue( serializesCorrectly( ddmap ) ); // Float-float TFloatFloatHashMap ffmap = new TFloatFloatHashMap(); Map ffmap_dec = Decorators.wrap( ffmap ); assertTrue( serializesCorrectly( ffmap, "p2p-ff-1" ) ); assertTrue( serializesCorrectly( ffmap_dec, "p2p-ff-1d" ) ); ffmap.put( 0, 1 ); assertTrue( serializesCorrectly( ffmap, "p2p-ff-2" ) ); assertTrue( serializesCorrectly( ffmap_dec, "p2p-ff-2d" ) ); ffmap.put( Float.MIN_VALUE, Float.MIN_VALUE ); assertTrue( serializesCorrectly( ffmap, "p2p-ff-3" ) ); assertTrue( serializesCorrectly( ffmap_dec, "p2p-ff-3d" ) ); ffmap.put( Float.MAX_VALUE, Float.MAX_VALUE ); assertTrue( serializesCorrectly( ffmap, "p2p-ff-4" ) ); assertTrue( serializesCorrectly( ffmap_dec, "p2p-ff-4d" ) ); ffmap.put( Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( ffmap, "p2p-ff-5" ) ); assertTrue( serializesCorrectly( ffmap_dec, "p2p-ff-5d" ) ); ffmap.put( Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( ffmap, "p2p-ff-6" ) ); assertTrue( serializesCorrectly( ffmap_dec, "p2p-ff-6d" ) ); // NOTE: trove doesn't deal well with NaN // ffmap.put( Float.NaN, Float.NaN ); // assertTrue( serializesCorrectly( ffmap ) ); } public void testP2OMap() { // Long-long TLongObjectHashMap lomap = new TLongObjectHashMap(); Map lomap_dec = Decorators.wrap( lomap ); assertTrue( serializesCorrectly( lomap, "p2o-l-1" ) ); assertTrue( serializesCorrectly( lomap_dec, "p2o-l-1d" ) ); lomap.put( 0, Long.valueOf( 1 ) ); assertTrue( serializesCorrectly( lomap, "p2o-l-2" ) ); assertTrue( serializesCorrectly( lomap_dec, "p2o-l-2d" ) ); lomap.put( Long.MIN_VALUE, Long.valueOf( Long.MIN_VALUE ) ); assertTrue( serializesCorrectly( lomap, "p2o-l-3" ) ); assertTrue( serializesCorrectly( lomap_dec, "p2o-l-3d" ) ); lomap.put( Long.MAX_VALUE, Long.valueOf( Long.MAX_VALUE ) ); assertTrue( serializesCorrectly( lomap, "p2o-l-4" ) ); assertTrue( serializesCorrectly( lomap_dec, "p2o-l-4d" ) ); // Int-int TIntObjectHashMap iomap = new TIntObjectHashMap(); Map iomap_dec = Decorators.wrap( iomap ); assertTrue( serializesCorrectly( iomap, "p2o-i-1" ) ); assertTrue( serializesCorrectly( iomap_dec, "p2o-i-1d" ) ); iomap.put( 0, Integer.valueOf( 1 ) ); assertTrue( serializesCorrectly( iomap, "p2o-i-2" ) ); assertTrue( serializesCorrectly( iomap_dec, "p2o-i-2d" ) ); iomap.put( Integer.MIN_VALUE, Integer.valueOf( Integer.MIN_VALUE ) ); assertTrue( serializesCorrectly( iomap, "p2o-i-3" ) ); assertTrue( serializesCorrectly( iomap_dec, "p2o-i-3d" ) ); iomap.put( Integer.MAX_VALUE, Integer.valueOf( Integer.MAX_VALUE ) ); assertTrue( serializesCorrectly( iomap, "p2o-i-4" ) ); assertTrue( serializesCorrectly( iomap_dec, "p2o-i-4d" ) ); // Double-double TDoubleObjectHashMap domap = new TDoubleObjectHashMap(); Map domap_dec = Decorators.wrap( domap ); assertTrue( serializesCorrectly( domap, "p2o-d-1" ) ); assertTrue( serializesCorrectly( domap_dec, "p2o-d-1d" ) ); domap.put( 0, Double.valueOf( 1 ) ); assertTrue( serializesCorrectly( domap, "p2o-d-2" ) ); assertTrue( serializesCorrectly( domap_dec, "p2o-d-2d" ) ); domap.put( Double.MIN_VALUE, Double.valueOf( Double.MIN_VALUE ) ); assertTrue( serializesCorrectly( domap, "p2o-d-3" ) ); assertTrue( serializesCorrectly( domap_dec, "p2o-d-3d" ) ); domap.put( Double.MAX_VALUE, Double.valueOf( Double.MAX_VALUE ) ); assertTrue( serializesCorrectly( domap, "p2o-d-4" ) ); assertTrue( serializesCorrectly( domap_dec, "p2o-d-4d" ) ); domap.put( Double.POSITIVE_INFINITY, Double.valueOf( Double.POSITIVE_INFINITY ) ); assertTrue( serializesCorrectly( domap, "p2o-d-5" ) ); assertTrue( serializesCorrectly( domap_dec, "p2o-d-5d" ) ); domap.put( Double.NEGATIVE_INFINITY, Double.valueOf( Double.NEGATIVE_INFINITY ) ); assertTrue( serializesCorrectly( domap, "p2o-d-6" ) ); assertTrue( serializesCorrectly( domap_dec, "p2o-d-6d" ) ); // NOTE: trove doesn't deal well with NaN // ddmap.put( Double.NaN, Double.NaN ); // assertTrue( serializesCorrectly( ddmap ) ); // Float-float TFloatObjectHashMap fomap = new TFloatObjectHashMap(); Map fomap_dec = Decorators.wrap( fomap ); assertTrue( serializesCorrectly( fomap, "p2o-f-1" ) ); assertTrue( serializesCorrectly( fomap_dec, "p2o-f-1d" ) ); fomap.put( 0, Float.valueOf( 1 ) ); assertTrue( serializesCorrectly( fomap, "p2o-f-2" ) ); assertTrue( serializesCorrectly( fomap_dec, "p2o-f-2d" ) ); fomap.put( Float.MIN_VALUE, Float.valueOf( Float.MIN_VALUE ) ); assertTrue( serializesCorrectly( fomap, "p2o-f-3" ) ); assertTrue( serializesCorrectly( fomap_dec, "p2o-f-3d" ) ); fomap.put( Float.MAX_VALUE, Float.valueOf( Float.MAX_VALUE ) ); assertTrue( serializesCorrectly( fomap, "p2o-f-4" ) ); assertTrue( serializesCorrectly( fomap_dec, "p2o-f-4d" ) ); fomap.put( Float.POSITIVE_INFINITY, Float.valueOf( Float.POSITIVE_INFINITY ) ); assertTrue( serializesCorrectly( fomap, "p2o-f-5" ) ); assertTrue( serializesCorrectly( fomap_dec, "p2o-f-5d" ) ); fomap.put( Float.NEGATIVE_INFINITY, Float.valueOf( Float.NEGATIVE_INFINITY ) ); assertTrue( serializesCorrectly( fomap, "p2o-f-6" ) ); assertTrue( serializesCorrectly( fomap_dec, "p2o-f-6d" ) ); // NOTE: trove doesn't deal well with NaN // ffmap.put( Float.NaN, Float.NaN ); // assertTrue( serializesCorrectly( ffmap ) ); } public void testO2PMap() { // Long-long TObjectLongHashMap olmap = new TObjectLongHashMap(); Map olmap_dec = Decorators.wrap( olmap ); assertTrue( serializesCorrectly( olmap, "o2p-l-1" ) ); assertTrue( serializesCorrectly( olmap_dec, "o2p-l-1d" ) ); olmap.put( Long.valueOf( 0 ), 1 ); assertTrue( serializesCorrectly( olmap, "o2p-l-2" ) ); assertTrue( serializesCorrectly( olmap_dec, "o2p-l-2d" ) ); olmap.put( Long.valueOf( Long.MIN_VALUE ), Long.MIN_VALUE ); assertTrue( serializesCorrectly( olmap, "o2p-l-3" ) ); assertTrue( serializesCorrectly( olmap_dec, "o2p-l-3d" ) ); olmap.put( Long.valueOf( Long.MAX_VALUE ), Long.MAX_VALUE ); assertTrue( serializesCorrectly( olmap, "o2p-l-4" ) ); assertTrue( serializesCorrectly( olmap_dec, "o2p-l-4d" ) ); // Int-int TObjectIntHashMap oimap = new TObjectIntHashMap(); Map oimap_dec = Decorators.wrap( oimap ); assertTrue( serializesCorrectly( oimap, "o2p-i-1" ) ); assertTrue( serializesCorrectly( oimap_dec, "o2p-i-1d" ) ); oimap.put( Integer.valueOf( 0 ), 1 ); assertTrue( serializesCorrectly( oimap, "o2p-i-2" ) ); assertTrue( serializesCorrectly( oimap_dec, "o2p-i-2d" ) ); oimap.put( Integer.valueOf( Integer.MIN_VALUE ), Integer.MIN_VALUE ); assertTrue( serializesCorrectly( oimap, "o2p-i-3" ) ); assertTrue( serializesCorrectly( oimap_dec, "o2p-i-3d" ) ); oimap.put( Integer.valueOf( Integer.MAX_VALUE ), Integer.MAX_VALUE ); assertTrue( serializesCorrectly( oimap, "o2p-i-4" ) ); assertTrue( serializesCorrectly( oimap_dec, "o2p-i-4d" ) ); // Double-double TObjectDoubleHashMap odmap = new TObjectDoubleHashMap(); Map odmap_dec = Decorators.wrap( odmap ); assertTrue( serializesCorrectly( odmap, "o2p-d-1" ) ); assertTrue( serializesCorrectly( odmap_dec, "o2p-d-1d" ) ); odmap.put( Double.valueOf( 0 ), 1 ); assertTrue( serializesCorrectly( odmap, "o2p-d-2" ) ); assertTrue( serializesCorrectly( odmap_dec, "o2p-d-2d" ) ); odmap.put( Double.valueOf( Double.MIN_VALUE ), Double.MIN_VALUE ); assertTrue( serializesCorrectly( odmap, "o2p-d-3" ) ); assertTrue( serializesCorrectly( odmap_dec, "o2p-d-3d" ) ); odmap.put( Double.valueOf( Double.MAX_VALUE ), Double.MAX_VALUE ); assertTrue( serializesCorrectly( odmap, "o2p-d-4" ) ); assertTrue( serializesCorrectly( odmap_dec, "o2p-d-4d" ) ); odmap.put( Double.valueOf( Double.POSITIVE_INFINITY ), Double.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( odmap, "o2p-d-5" ) ); assertTrue( serializesCorrectly( odmap_dec, "o2p-d-5d" ) ); odmap.put( Double.valueOf( Double.NEGATIVE_INFINITY ), Double.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( odmap, "o2p-d-6" ) ); assertTrue( serializesCorrectly( odmap_dec, "o2p-d-6d" ) ); // NOTE: trove doesn't deal well with NaN // ddmap.put( Double.NaN, Double.NaN ); // assertTrue( serializesCorrectly( ddmap ) ); // Float-float TObjectFloatHashMap ofmap = new TObjectFloatHashMap(); Map ofmap_dec = Decorators.wrap( ofmap ); assertTrue( serializesCorrectly( ofmap, "o2p-f-1" ) ); assertTrue( serializesCorrectly( ofmap_dec, "o2p-f-1d" ) ); ofmap.put( Float.valueOf( 0 ), 1 ); assertTrue( serializesCorrectly( ofmap, "o2p-f-2" ) ); assertTrue( serializesCorrectly( ofmap_dec, "o2p-f-2d" ) ); ofmap.put( Float.valueOf( Float.MIN_VALUE ), Float.MIN_VALUE ); assertTrue( serializesCorrectly( ofmap, "o2p-f-3" ) ); assertTrue( serializesCorrectly( ofmap_dec, "o2p-f-3d" ) ); ofmap.put( Float.valueOf( Float.MAX_VALUE ), Float.MAX_VALUE ); assertTrue( serializesCorrectly( ofmap, "o2p-f-4" ) ); assertTrue( serializesCorrectly( ofmap_dec, "o2p-f-4d" ) ); ofmap.put( Float.valueOf( Float.POSITIVE_INFINITY ), Float.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( ofmap, "o2p-f-5" ) ); assertTrue( serializesCorrectly( ofmap_dec, "o2p-f-5d" ) ); ofmap.put( Float.valueOf( Float.NEGATIVE_INFINITY ), Float.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( ofmap, "o2p-f-6" ) ); assertTrue( serializesCorrectly( ofmap_dec, "o2p-f-6d" ) ); // NOTE: trove doesn't deal well with NaN // ffmap.put( Float.NaN, Float.NaN ); // assertTrue( serializesCorrectly( ffmap ) ); } public void testList() { // Long-long TLongArrayList llist = new TLongArrayList(); assertTrue( serializesCorrectly( llist, "list-l-1" ) ); llist.add( 0 ); llist.add( 1 ); assertTrue( serializesCorrectly( llist, "list-l-2" ) ); llist.add( Long.MIN_VALUE ); assertTrue( serializesCorrectly( llist, "list-l-3" ) ); llist.add( Long.MAX_VALUE ); assertTrue( serializesCorrectly( llist, "list-l-4" ) ); // Int-int TIntArrayList ilist = new TIntArrayList(); assertTrue( serializesCorrectly( ilist, "list-i-1" ) ); ilist.add( 0 ); ilist.add( 1 ); assertTrue( serializesCorrectly( ilist, "list-i-2" ) ); ilist.add( Integer.MIN_VALUE ); assertTrue( serializesCorrectly( ilist, "list-i-3" ) ); ilist.add( Integer.MAX_VALUE ); assertTrue( serializesCorrectly( ilist, "list-i-4" ) ); // Double-double TDoubleArrayList dlist = new TDoubleArrayList(); assertTrue( serializesCorrectly( dlist, "list-d-1" ) ); dlist.add( 0 ); dlist.add( 1 ); assertTrue( serializesCorrectly( dlist, "list-d-2" ) ); dlist.add( Double.MIN_VALUE ); assertTrue( serializesCorrectly( dlist, "list-d-3" ) ); dlist.add( Double.MAX_VALUE ); assertTrue( serializesCorrectly( dlist, "list-d-4" ) ); // NOTE: trove doesn't deal well with NaN // ddmap.add( Double.NaN, Double.NaN ); // assertTrue( serializesCorrectly( ddmap ) ); dlist.add( Double.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( dlist, "list-d-5" ) ); dlist.add( Double.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( dlist, "list-d-6" ) ); // Float-float TFloatArrayList flist = new TFloatArrayList(); assertTrue( serializesCorrectly( flist, "list-f-1" ) ); flist.add( 0 ); flist.add( 1 ); assertTrue( serializesCorrectly( flist, "list-f-2" ) ); flist.add( Float.MIN_VALUE ); assertTrue( serializesCorrectly( flist, "list-f-3" ) ); flist.add( Float.MAX_VALUE ); assertTrue( serializesCorrectly( flist, "list-f-4" ) ); flist.add( Float.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( flist, "list-f-5" ) ); flist.add( Float.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( flist, "list-f-6" ) ); // NOTE: trove doesn't deal well with NaN // ffmap.add( Float.NaN ); // assertTrue( serializesCorrectly( ffmap ) ); } public void testSet() { // Long-long TLongHashSet llist = new TLongHashSet(); Set llist_dec = Decorators.wrap( llist ); assertTrue( serializesCorrectly( llist, "set-l-1" ) ); assertTrue( serializesCorrectly( llist_dec, "set-l-1d" ) ); llist.add( 0 ); llist.add( 1 ); assertTrue( serializesCorrectly( llist, "set-l-2" ) ); assertTrue( serializesCorrectly( llist_dec, "set-l-2d" ) ); llist.add( Long.MIN_VALUE ); assertTrue( serializesCorrectly( llist, "set-l-3" ) ); assertTrue( serializesCorrectly( llist_dec, "set-l-3d" ) ); llist.add( Long.MAX_VALUE ); assertTrue( serializesCorrectly( llist, "set-l-4" ) ); assertTrue( serializesCorrectly( llist_dec, "set-l-4d" ) ); // Int-int TIntHashSet ilist = new TIntHashSet(); Set ilist_dec = Decorators.wrap( ilist ); assertTrue( serializesCorrectly( ilist, "set-i-1" ) ); assertTrue( serializesCorrectly( ilist_dec, "set-i-1d" ) ); ilist.add( 0 ); ilist.add( 1 ); assertTrue( serializesCorrectly( ilist, "set-i-2" ) ); assertTrue( serializesCorrectly( ilist_dec, "set-i-2d" ) ); ilist.add( Integer.MIN_VALUE ); assertTrue( serializesCorrectly( ilist, "set-i-3" ) ); assertTrue( serializesCorrectly( ilist_dec, "set-i-3d" ) ); ilist.add( Integer.MAX_VALUE ); assertTrue( serializesCorrectly( ilist, "set-i-4" ) ); assertTrue( serializesCorrectly( ilist_dec, "set-i-4d" ) ); // Double-double TDoubleHashSet dlist = new TDoubleHashSet(); Set dlist_dec = Decorators.wrap( dlist ); assertTrue( serializesCorrectly( dlist, "set-d-1" ) ); assertTrue( serializesCorrectly( dlist_dec, "set-d-1d" ) ); dlist.add( 0 ); dlist.add( 1 ); assertTrue( serializesCorrectly( dlist, "set-d-2" ) ); assertTrue( serializesCorrectly( dlist_dec, "set-d-2d" ) ); dlist.add( Double.MIN_VALUE ); assertTrue( serializesCorrectly( dlist, "set-d-3" ) ); assertTrue( serializesCorrectly( dlist_dec, "set-d-3d" ) ); dlist.add( Double.MAX_VALUE ); assertTrue( serializesCorrectly( dlist, "set-d-4" ) ); assertTrue( serializesCorrectly( dlist_dec, "set-d-4d" ) ); dlist.add( Double.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( dlist, "set-d-5" ) ); assertTrue( serializesCorrectly( dlist_dec, "set-d-5d" ) ); dlist.add( Double.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( dlist, "set-d-6" ) ); assertTrue( serializesCorrectly( dlist_dec, "set-d-6d" ) ); // NOTE: trove doesn't deal well with NaN // ddmap.add( Double.NaN, Double.NaN ); // assertTrue( serializesCorrectly( ddmap ) ); // Float-float TFloatHashSet flist = new TFloatHashSet(); Set flist_dec = Decorators.wrap( flist ); assertTrue( serializesCorrectly( flist, "set-f-1" ) ); assertTrue( serializesCorrectly( flist_dec, "set-f-1d" ) ); flist.add( 0 ); flist.add( 1 ); assertTrue( serializesCorrectly( flist, "set-f-2" ) ); assertTrue( serializesCorrectly( flist_dec, "set-f-2d" ) ); flist.add( Float.MIN_VALUE ); assertTrue( serializesCorrectly( flist, "set-f-3" ) ); assertTrue( serializesCorrectly( flist_dec, "set-f-3d" ) ); flist.add( Float.MAX_VALUE ); assertTrue( serializesCorrectly( flist, "set-f-4" ) ); assertTrue( serializesCorrectly( flist_dec, "set-f-4d" ) ); flist.add( Float.POSITIVE_INFINITY ); assertTrue( serializesCorrectly( flist, "set-f-5" ) ); assertTrue( serializesCorrectly( flist_dec, "set-f-5d" ) ); flist.add( Float.NEGATIVE_INFINITY ); assertTrue( serializesCorrectly( flist, "set-f-6" ) ); assertTrue( serializesCorrectly( flist_dec, "set-f-6d" ) ); // NOTE: trove doesn't deal well with NaN // ffmap.add( Float.NaN ); // assertTrue( serializesCorrectly( ffmap ) ); } public void testLinkedList() { TLinkedList list = new TLinkedList(); list.add( new LinkedNode( 0 ) ); list.add( new LinkedNode( 1 ) ); list.add( new LinkedNode( 2 ) ); list.add( new LinkedNode( 3 ) ); assertTrue( serializesCorrectly( list, "linkedlist-1" ) ); } // See Tracker #1955103 - Hashing Strategy Not Retained After Serialization public void testHashingStrategy() { THashMap m = new THashMap( new CaseInsensitiveHashingStrategy() ); m.put("hello", "world"); assertTrue( m.containsKey( "hello" ) ); assertTrue( m.containsKey( "Hello" ) ); try { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream( bytesOut ); out.writeObject( m ); ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( bytesOut.toByteArray() ) ); //noinspection unchecked m = ( THashMap ) in.readObject(); } catch( Exception ex ) { ex.printStackTrace(); fail( ex.toString() ); } assertTrue( m.containsKey( "hello" ) ); assertTrue( m.containsKey( "Hello" ) ); } /** * @param test_name Name used to refer to the serialized instance. If a test * output dir is specified (see constructor), a file will be * created with this name. */ private boolean serializesCorrectly( Object obj, String test_name ) { assert obj instanceof Externalizable : obj + " is not Externalizable"; ObjectOutputStream oout = null; ObjectInputStream oin = null; try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); oout = new ObjectOutputStream( bout ); oout.writeObject( obj ); oout.close(); ByteArrayInputStream bin = new ByteArrayInputStream( bout.toByteArray() ); oin = new ObjectInputStream( bin ); Object new_obj = oin.readObject(); if ( !obj.equals( new_obj ) ) { System.err.println( "Non-matching serialized objects (in-VM test):" ); System.err.println( " Original: " + obj ); System.err.println( " Deserialized: " + new_obj ); return false; } if ( obj instanceof THash ) { assertEquals( ( ( THash ) obj ).getAutoCompactionFactor(), ( ( THash ) new_obj ).getAutoCompactionFactor(), 0.0 ); } oin.close(); if ( serialized_object_output_dir != null ) { try { File file = new File( serialized_object_output_dir, test_name + ".obj" ); ObjectOutputStream test_out = new ObjectOutputStream( new FileOutputStream( file ) ); test_out.writeObject( obj ); test_out.close(); } catch( IOException ex ) { ex.printStackTrace(); fail( "Unable to write to test file: " + test_name ); } } // Look for previous versions int version = 0; for( ; ; version++ ) { InputStream stream = SerializationTest.class.getResourceAsStream( "old_serialized_versions/" + version + "/" + test_name + ".obj" ); if ( stream == null ) break; System.out.println( "Testing " + test_name + " against version " + version + "..." ); oin = new ObjectInputStream( stream ); new_obj = oin.readObject(); if ( !obj.equals( new_obj ) ) { System.err.println( "Non-matching serialized objects (version " + version + "):" ); System.err.println( " Original: " + obj ); System.err.println( " Deserialized: " + new_obj ); return false; } } return true; } catch( Exception ex ) { ex.printStackTrace(); return false; } finally { if ( oout != null ) { try { oout.close(); } catch( IOException ex ) { // ignore } } if ( oin != null ) { try { oin.close(); } catch( IOException ex ) { // ignore } } } } private static class LinkedNode extends TLinkableAdapter { private final int value; LinkedNode( int value ) { this.value = value; } public boolean equals( Object o ) { if ( this == o ) return true; if ( o == null || getClass() != o.getClass() ) return false; LinkedNode that = ( LinkedNode ) o; if ( value != that.value ) return false; return true; } public int hashCode() { return value; } } static class CaseInsensitiveHashingStrategy implements TObjectHashingStrategy { public int computeHashCode(String s) { return s.toLowerCase().hashCode(); } public boolean equals(String a, String b) { return a.equalsIgnoreCase(b); } } } trove-2.1.0/test/gnu/trove/PrimeFinderTest.java0000644000175000017500000000265411241347111020455 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001-2006, 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 junit.framework.*; /** * * Created: Sun Nov 4 11:37:24 2001 * * @author Eric D. Friedman * @version $Id: PrimeFinderTest.java,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public class PrimeFinderTest extends TestCase { public PrimeFinderTest(String name) { super(name); } public void testPrimeFinder() throws Exception { int r = PrimeFinder.nextPrime(999999); assertEquals(1070981,r); } } // PrimeFinderTests trove-2.1.0/test/gnu/trove/P2PHashMapTest.java0000644000175000017500000002371611241347111020116 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2006-2008, Rob Eden 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 gnu.trove.decorator.TByteIntHashMapDecorator; import junit.framework.TestCase; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.Arrays; /** * */ public class P2PHashMapTest extends TestCase { final byte KEY_ONE = ( byte ) 100; final byte KEY_TWO = ( byte ) 101; public P2PHashMapTest( String name ) { super( name ); } public void testKeys() { TByteIntHashMap map = new TByteIntHashMap(); map.put( KEY_ONE, 1 ); map.put( KEY_TWO, 2 ); assertEquals( 2, map.size() ); byte[] keys = map.keys( new byte[ map.size() ] ); assertEquals( 2, keys.length ); TByteArrayList keys_list = new TByteArrayList( keys ); assertTrue( keys_list.contains( KEY_ONE ) ); assertTrue( keys_list.contains( KEY_TWO ) ); byte[] keys2 = map.keys(); assertEquals( 2, keys2.length ); TByteArrayList keys_list2 = new TByteArrayList( keys2 ); assertTrue( keys_list2.contains( KEY_ONE ) ); assertTrue( keys_list2.contains( KEY_TWO ) ); } public void testDecorator() { TByteIntHashMap map = new TByteIntHashMap(); map.put( KEY_ONE, 1 ); map.put( KEY_TWO, 2 ); Map decorator = new TByteIntHashMapDecorator( map ); assertEquals( 2, decorator.size() ); assertEquals( Integer.valueOf( 1 ), decorator.get( Byte.valueOf( KEY_ONE ) ) ); assertEquals( Integer.valueOf( 2 ), decorator.get( Byte.valueOf( KEY_TWO ) ) ); Set decorator_keys = decorator.keySet(); assertEquals( 2, decorator_keys.size() ); Iterator it = decorator_keys.iterator(); int count = 0; while( it.hasNext() ) { count++; System.out.println(it.next()); } assertEquals( 2, count ); assertSame(map, ( ( TByteIntHashMapDecorator ) decorator ).getMap() ); } public void testIterator() { TByteIntHashMap map = new TByteIntHashMap(); TByteIntIterator iterator = map.iterator(); assertFalse( iterator.hasNext() ); map.put( KEY_ONE, 1 ); map.put( KEY_TWO, 2 ); iterator = map.iterator(); assertTrue( iterator.hasNext() ); iterator.advance(); assertTrue( iterator.hasNext() ); iterator.advance(); assertFalse( iterator.hasNext() ); } public void testAdjustValue() { TByteIntHashMap map = new TByteIntHashMap(); map.put( KEY_ONE, 1 ); boolean changed = map.adjustValue( KEY_ONE, 1 ); assertTrue(changed); assertEquals( 2, map.get( KEY_ONE ) ); changed = map.adjustValue( KEY_ONE, 5 ); assertTrue(changed); assertEquals( 7, map.get( KEY_ONE ) ); changed = map.adjustValue( KEY_ONE, -3 ); assertTrue(changed); assertEquals( 4, map.get( KEY_ONE ) ); changed = map.adjustValue( KEY_TWO, 1 ); assertFalse(changed); assertFalse(map.containsKey( KEY_TWO )); } public void testAdjustOrPutValue() { TByteIntHashMap map = new TByteIntHashMap(); map.put( KEY_ONE, 1 ); long new_value = map.adjustOrPutValue( KEY_ONE, 1, 100 ); assertEquals(2, new_value); assertEquals( 2, map.get( KEY_ONE ) ); new_value = map.adjustOrPutValue( KEY_ONE, 5, 100 ); assertEquals(7, new_value); assertEquals( 7, map.get( KEY_ONE ) ); new_value = map.adjustOrPutValue( KEY_ONE, -3, 100 ); assertEquals(4, new_value); assertEquals( 4, map.get( KEY_ONE ) ); new_value = map.adjustOrPutValue( KEY_TWO, 1, 100 ); assertEquals(100, new_value); assertTrue(map.containsKey( KEY_TWO )); assertEquals( 100, map.get( KEY_TWO ) ); new_value = map.adjustOrPutValue( KEY_TWO, 1, 100 ); assertEquals(101, new_value); assertEquals( 101, map.get( KEY_TWO ) ); } /** * Test for tracking issue #1204014. +0.0 and -0.0 have different bit patterns, but * should be counted the same as keys in a map. Checks for doubles and floats. */ public void testFloatZeroHashing() { TDoubleObjectHashMap po_double_map = new TDoubleObjectHashMap(); TDoubleIntHashMap pp_double_map = new TDoubleIntHashMap(); TFloatObjectHashMap po_float_map = new TFloatObjectHashMap(); TFloatIntHashMap pp_float_map = new TFloatIntHashMap(); final double zero_double = 0.0; final double negative_zero_double = -zero_double; final float zero_float = 0.0f; final float negative_zero_float = -zero_float; // Sanity check... make sure I'm really creating two different values. final String zero_bits_double = Long.toBinaryString( Double.doubleToLongBits(zero_double) ); final String negative_zero_bits_double = Long.toBinaryString( Double.doubleToLongBits(negative_zero_double) ); assertFalse( zero_bits_double + " == " + negative_zero_bits_double, zero_bits_double.equals( negative_zero_bits_double ) ); final String zero_bits_float = Integer.toBinaryString( Float.floatToIntBits( zero_float ) ); final String negative_zero_bits_float = Integer.toBinaryString( Float.floatToIntBits( negative_zero_float ) ); assertFalse( zero_bits_float + " == " + negative_zero_bits_float, zero_bits_float.equals( negative_zero_bits_float ) ); po_double_map.put(zero_double, "Zero" ); po_double_map.put(negative_zero_double, "Negative Zero" ); pp_double_map.put(zero_double, 0 ); pp_double_map.put(negative_zero_double, -1 ); po_float_map.put(zero_float, "Zero" ); po_float_map.put(negative_zero_float, "Negative Zero" ); pp_float_map.put(zero_float, 0 ); pp_float_map.put(negative_zero_float, -1 ); assertEquals( 1, po_double_map.size() ); assertEquals( po_double_map.get(zero_double), "Negative Zero" ); assertEquals( po_double_map.get(negative_zero_double), "Negative Zero" ); assertEquals( 1, pp_double_map.size() ); assertEquals( pp_double_map.get(zero_double), -1 ); assertEquals( pp_double_map.get(negative_zero_double), -1 ); assertEquals( 1, po_float_map.size() ); assertEquals( po_float_map.get(zero_float), "Negative Zero" ); assertEquals( po_float_map.get(negative_zero_float), "Negative Zero" ); assertEquals( 1, pp_float_map.size() ); assertEquals( pp_float_map.get(zero_float), -1 ); assertEquals( pp_float_map.get(negative_zero_float), -1 ); po_double_map.put(zero_double, "Zero" ); pp_double_map.put(zero_double, 0 ); po_float_map.put(zero_float, "Zero" ); pp_float_map.put(zero_float, 0 ); assertEquals( 1, po_double_map.size() ); assertEquals( po_double_map.get(zero_double), "Zero" ); assertEquals( po_double_map.get(negative_zero_double), "Zero" ); assertEquals( 1, pp_double_map.size() ); assertEquals( pp_double_map.get(zero_double), 0 ); assertEquals( pp_double_map.get(negative_zero_double), 0 ); assertEquals( 1, po_float_map.size() ); assertEquals( po_float_map.get(zero_float), "Zero" ); assertEquals( po_float_map.get(negative_zero_float), "Zero" ); assertEquals( 1, pp_float_map.size() ); assertEquals( pp_float_map.get(zero_float), 0 ); assertEquals( pp_float_map.get(negative_zero_float), 0 ); } public void testPutIfAbsent() { TIntIntHashMap map = new TIntIntHashMap(); map.put( 1, 10 ); map.put( 2, 20 ); map.put( 3, 30 ); assertEquals( 10, map.putIfAbsent( 1, 111 ) ); assertEquals( 10, map.get( 1 ) ); assertEquals( 0, map.putIfAbsent( 9, 90 ) ); assertEquals( 90, map.get( 9 ) ); } public void testBug2037709() { TIntIntHashMap m = new TIntIntHashMap(); for (int i = 0; i < 10; i++) { m.put(i, i); } int sz = m.size(); assertEquals(10, sz); int[] keys = new int[sz]; m.keys(keys); boolean[] seen = new boolean[sz]; Arrays.fill( seen, false ); for (int i = 0; i < 10; i++) { seen[ keys[ i ] ] = true; } for (int i = 0; i < 10; i++) { if (!seen[ i ]) { TestCase.fail("Missing key for: " + i); } } } public void testPutAll() throws Exception { TIntIntHashMap t = new TIntIntHashMap(); TIntIntHashMap m = new TIntIntHashMap(); m.put(1, 2); m.put(2, 4); m.put(3, 6); t.put(4, 5); assertEquals(1, t.size()); t.putAll(m); assertEquals(4, t.size()); assertEquals(4, t.get(2)); } public void testToString() { TIntIntHashMap m = new TIntIntHashMap(); m.put(11, 1); m.put(22, 2); String to_string = m.toString(); assertTrue(to_string, to_string.equals("{11=1,22=2}") || to_string.equals("{22=2,11=1}")); } } trove-2.1.0/test/gnu/trove/P2OHashMapTest.java0000644000175000017500000001033511241347111020106 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2007-2008, Rob Eden 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 junit.framework.TestCase; import java.util.Arrays; import java.util.List; /** * */ public class P2OHashMapTest extends TestCase { public P2OHashMapTest( String name ) { super( name ); } public void testGetValues() { TIntObjectHashMap map = new TIntObjectHashMap(); map.put( 1, "one" ); map.put( 2, "two" ); map.put( 3, "three" ); map.put( 4, "four" ); // Exact size String[] template = new String[ map.size() ]; String[] values = map.getValues( template ); assertSame( template, values ); List list = Arrays.asList( values ); assertTrue( list.contains( "one" ) ); assertTrue( list.contains( "two" ) ); assertTrue( list.contains( "three" ) ); assertTrue( list.contains( "four" ) ); // Zero length template = new String[ 0 ]; values = map.getValues( template ); assertNotSame( template, values ); list = Arrays.asList( values ); assertTrue( list.contains( "one" ) ); assertTrue( list.contains( "two" ) ); assertTrue( list.contains( "three" ) ); assertTrue( list.contains( "four" ) ); // Longer than needed template = new String[ 10 ]; values = map.getValues( template ); assertSame( template, values ); list = Arrays.asList( values ); assertTrue( list.contains( "one" ) ); assertTrue( list.contains( "two" ) ); assertTrue( list.contains( "three" ) ); assertTrue( list.contains( "four" ) ); } public void testPutIfAbsent() { TIntObjectHashMap map = new TIntObjectHashMap(); map.put( 1, "One" ); map.put( 2, "Two" ); map.put( 3, "Three" ); assertEquals( "One", map.putIfAbsent( 1, "Two" ) ); assertEquals( "One", map.get( 1 ) ); assertNull( map.putIfAbsent( 9, "Nine" ) ); assertEquals( "Nine", map.get( 9 ) ); } public void testBug2037709() { TIntObjectHashMap m = new TIntObjectHashMap(); for (int i = 0; i < 10; i++) { m.put(i, String.valueOf(i)); } int sz = m.size(); assertEquals(10, sz); int[] keys = new int[sz]; m.keys(keys); boolean[] seen = new boolean[sz]; Arrays.fill( seen, false ); for (int i = 0; i < 10; i++) { seen[ keys[ i ] ] = true; } for (int i = 0; i < 10; i++) { if (!seen[ i ]) { TestCase.fail("Missing key for: " + i); } } } public void testPutAll() throws Exception { TIntObjectHashMap t = new TIntObjectHashMap(); TIntObjectHashMap m = new TIntObjectHashMap(); m.put(1, "two"); m.put(2, "four"); m.put(3, "six"); t.put(4, "five"); assertEquals(1, t.size()); t.putAll(m); assertEquals(4, t.size()); assertEquals("four", t.get(2)); } public void testToString() { TIntObjectHashMap m = new TIntObjectHashMap(); m.put(11, "One"); m.put(22, "Two"); String to_string = m.toString(); assertTrue(to_string, to_string.equals("{11=One,22=Two}") || to_string.equals("{22=Two,11=One}")); } } trove-2.1.0/test/gnu/trove/O2PHashMapTest.java0000644000175000017500000002601311241347111020106 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001-2006, 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 gnu.trove.decorator.TObjectIntHashMapDecorator; import junit.framework.TestCase; import java.util.*; /** * */ public class O2PHashMapTest extends TestCase { public O2PHashMapTest( String name ) { super( name ); } public void testKeys() { TObjectIntHashMap map = new TObjectIntHashMap(); map.put( "one", 1 ); map.put( "two", 2 ); assertEquals( 2, map.size() ); String[] keys = map.keys( new String[ map.size() ] ); assertEquals( 2, keys.length ); List keys_list = Arrays.asList( keys ); assertTrue( keys_list.contains( "one" ) ); assertTrue( keys_list.contains( "two" ) ); Object[] keys2 = map.keys(); assertEquals( 2, keys2.length ); List keys_list2 = Arrays.asList( keys2 ); assertTrue( keys_list2.contains( "one" ) ); assertTrue( keys_list2.contains( "two" ) ); } public void testDecorator() { TObjectIntHashMap map = new TObjectIntHashMap(); map.put( "one", 1 ); map.put( "two", 2 ); Map decorator = new TObjectIntHashMapDecorator( map ); assertEquals( 2, decorator.size() ); assertEquals( Integer.valueOf( 1 ), decorator.get( "one" ) ); assertEquals( Integer.valueOf( 2 ), decorator.get( "two" ) ); Set decorator_keys = decorator.keySet(); assertEquals( 2, decorator_keys.size() ); Iterator it = decorator_keys.iterator(); int count = 0; while( it.hasNext() ) { count++; System.out.println(it.next()); } assertEquals( 2, count ); assertSame(map, ( ( TObjectIntHashMapDecorator ) decorator ).getMap() ); } public void testIterator() { TObjectIntHashMap map = new TObjectIntHashMap(); TObjectIntIterator iterator = map.iterator(); assertFalse( iterator.hasNext() ); map.put( "one", 1 ); map.put( "two", 2 ); iterator = map.iterator(); assertTrue( iterator.hasNext() ); iterator.advance(); assertTrue( iterator.hasNext() ); iterator.advance(); assertFalse( iterator.hasNext() ); } public void testIteratorRemoval() { TObjectIntHashMap map = new TObjectIntHashMap(); map.put( "one", 1 ); map.put( "two", 2 ); map.put( "three", 3 ); map.put( "four", 4 ); map.put( "five", 5 ); map.put( "six", 6 ); map.put( "seven", 7 ); map.put( "eight", 8 ); map.put( "nine", 9 ); map.put( "ten", 10 ); TObjectIntIterator iterator = map.iterator(); while( map.size() > 5 && iterator.hasNext() ) { iterator.advance(); iterator.remove(); } assertEquals( 5, map.size() ); iterator = map.iterator(); assertTrue( iterator.hasNext() ); iterator.advance(); assertTrue( iterator.hasNext() ); iterator.advance(); assertTrue( iterator.hasNext() ); iterator.advance(); assertTrue( iterator.hasNext() ); iterator.advance(); assertTrue( iterator.hasNext() ); iterator.advance(); assertFalse( iterator.hasNext() ); iterator = map.iterator(); while( iterator.hasNext() ) { iterator.advance(); iterator.remove(); } assertEquals( 0, map.size() ); } public void testIteratorRemoval2() { TIntObjectHashMap map = new TIntObjectHashMap(10000, 0.5f); for( int pass = 0; pass < 10; pass++ ) { System.out.println("Test"); Random r = new Random(); System.out.println("ADD"); for (int i = 0; i <= 10000; i++) { map.put(r.nextInt(), "Test" + i); } System.out.println("REMOVE"); TIntObjectIterator iterator = map.iterator(); while (map.size() > 5000 && iterator.hasNext()) { iterator.advance(); iterator.remove(); } } } public void testAdjustValue() { TObjectIntHashMap map = new TObjectIntHashMap(); map.put( "one", 1 ); boolean changed = map.adjustValue( "one", 1 ); assertTrue(changed); assertEquals( 2, map.get( "one" ) ); changed = map.adjustValue( "one", 5 ); assertTrue(changed); assertEquals( 7, map.get( "one" ) ); changed = map.adjustValue( "one", -3 ); assertTrue(changed); assertEquals( 4, map.get( "one" ) ); changed = map.adjustValue( "two", 1 ); assertFalse(changed); assertFalse(map.containsKey( "two" )); } public void testAdjustOrPutValue() { TObjectIntHashMap map = new TObjectIntHashMap(); map.put( "one", 1 ); long new_value = map.adjustOrPutValue( "one", 1, 100 ); assertEquals(2, new_value); assertEquals( 2, map.get( "one" ) ); new_value = map.adjustOrPutValue( "one", 5, 100 ); assertEquals(7, new_value); assertEquals( 7, map.get( "one" ) ); new_value = map.adjustOrPutValue( "one", -3, 100 ); assertEquals(4, new_value); assertEquals( 4, map.get( "one" ) ); new_value = map.adjustOrPutValue( "two", 1, 100 ); assertEquals(100, new_value); assertTrue(map.containsKey( "two" )); assertEquals( 100, map.get( "two" ) ); new_value = map.adjustOrPutValue( "two", 1, 100 ); assertEquals(101, new_value); assertEquals( 101, map.get( "two" ) ); } public void testRetain() { TObjectIntHashMap map = new TObjectIntHashMap(); map.put( "one", 1 ); map.put( "two", 2 ); map.put( "three", 3 ); map.put( "four", 4 ); map.put( "five", 5 ); map.put( "six", 6 ); map.put( "seven", 7 ); map.put( "eight", 8 ); map.put( "nine", 9 ); map.put( "ten", 10 ); System.out.println("Start retain..."); map.retainEntries( new TObjectIntProcedure() { public boolean execute(String a, int b) { if ( b <= 5 ) return false; if ( b > 8 ) return false; return true; } } ); System.out.println("... end retain"); assertEquals( 3, map.size() ); assertFalse( map.containsKey( "one" ) ); assertFalse( map.containsKey( "two" ) ); assertFalse( map.containsKey( "three" ) ); assertFalse( map.containsKey( "four" ) ); assertFalse( map.containsKey( "five" ) ); assertTrue( map.containsKey( "six" ) ); assertTrue( map.containsKey( "seven" ) ); assertTrue( map.containsKey( "eight" ) ); assertFalse( map.containsKey( "nine" ) ); assertFalse( map.containsKey( "ten" ) ); map.put( "eleven", 11 ); map.put( "twelve", 12 ); map.put( "thirteen", 13 ); map.put( "fourteen", 14 ); map.put( "fifteen", 15 ); map.put( "sixteen", 16 ); map.put( "seventeen", 17 ); map.put( "eighteen", 18 ); map.put( "nineteen", 19 ); map.put( "twenty", 20 ); System.out.println("Start retain..."); map.retainEntries( new TObjectIntProcedure() { public boolean execute(String a, int b) { if ( b <= 15 ) return false; return true; } } ); System.out.println("... end retain"); assertEquals( 5, map.size() ); assertFalse( map.containsKey( "one" ) ); assertFalse( map.containsKey( "two" ) ); assertFalse( map.containsKey( "three" ) ); assertFalse( map.containsKey( "four" ) ); assertFalse( map.containsKey( "five" ) ); assertFalse( map.containsKey( "six" ) ); assertFalse( map.containsKey( "seven" ) ); assertFalse( map.containsKey( "eight" ) ); assertFalse( map.containsKey( "nine" ) ); assertFalse( map.containsKey( "ten" ) ); assertFalse( map.containsKey( "eleven" ) ); assertFalse( map.containsKey( "twelve" ) ); assertFalse( map.containsKey( "thirteen" ) ); assertFalse( map.containsKey( "fourteen" ) ); assertFalse( map.containsKey( "fifteen" ) ); assertTrue( map.containsKey( "sixteen" ) ); assertTrue( map.containsKey( "seventeen" ) ); assertTrue( map.containsKey( "eighteen" ) ); assertTrue( map.containsKey( "nineteen" ) ); assertTrue( map.containsKey( "twenty" ) ); System.out.println("Start retain..."); map.retainEntries( new TObjectIntProcedure() { public boolean execute(String a, int b) { return false; } } ); System.out.println("... end retain"); System.out.println("Retain test done"); assertEquals( 0, map.size() ); } public void testPutIfAbsent() { TObjectIntHashMap map = new TObjectIntHashMap(); map.put( "One", 1 ); map.put( "Two", 2 ); map.put( "Three", 3 ); assertEquals( 1, map.putIfAbsent( "One", 2 ) ); assertEquals( 1, map.get( "One" ) ); assertEquals( 0, map.putIfAbsent( "Nine", 9 ) ); assertEquals( 9, map.get( "Nine" ) ); } public void testPutAll() throws Exception { TObjectIntHashMap t = new TObjectIntHashMap(); TObjectIntHashMap m = new TObjectIntHashMap(); m.put("one", 2); m.put("two", 4); m.put("three", 6); t.put("four", 5); assertEquals(1, t.size()); t.putAll(m); assertEquals(4, t.size()); assertEquals(4, t.get("two")); } public void testToString() { TObjectIntHashMap m = new TObjectIntHashMap(); m.put("One", 11); m.put("Two", 22); String to_string = m.toString(); assertTrue(to_string, to_string.equals("{One=11,Two=22}") || to_string.equals("{Two=22,One=11}")); } } trove-2.1.0/test/gnu/trove/TLongIntHashMapTester.java0000644000175000017500000000206011241347111021527 0ustar mkochmkoch/* * Copyright(c) 2008, MQSoftware, Inc. * All rights reserved. */ package gnu.trove; public class TLongIntHashMapTester { public static void main(String[] args) { System.out.println("Int max: " + Integer.MAX_VALUE); System.out.println("Long value: " + 4000000000L); int array_size = Integer.MAX_VALUE - Integer.parseInt( args[ 0 ] ); System.out.print("Allocating map: " + array_size + "..."); long time = System.currentTimeMillis(); TLongIntHashMap map = new TLongIntHashMap( array_size ); System.out.println("done: " + ( System.currentTimeMillis() - time ) ); int i = 0; time = System.currentTimeMillis(); for (long l = 0; l < 4000000000L; l++) { map.put(l, i++); if ((l % 10000000) == 0) { long newTime = System.currentTimeMillis(); System.out.println("l=" + l / 1000000 + "Mio in " + (newTime - time) + "ms" ); time = newTime; } } } }trove-2.1.0/lib/0000755000175000017500000000000011261456734012414 5ustar mkochmkochtrove-2.1.0/javadocs/0000755000175000017500000000000011261456734013440 5ustar mkochmkochtrove-2.1.0/AUTHORS0000644000175000017500000000071511241347112012704 0ustar mkochmkochEric D. Friedman Rob Eden Please do NOT email bug reports or feature requests. Instead use the very fine bug tracking system and feature request service on SourceForge: http://sourceforge.net/projects/trove4j/ I'll read your issue just as quickly, and the project's issues will remain out in the open where everyone can see them. I also monitor the project fora, so feel free to use those too. trove-2.1.0/README.txt0000644000175000017500000001134211241347112013330 0ustar mkochmkoch GNU Trove: High performance collections for Java. Objectives The GNU Trove library has two objectives: 1. Provide "free" (as in "free speech" and "free beer"), fast, lightweight implementations of the java.util Collections API. These implementations are designed to be pluggable replacements for their JDK equivalents. 2. Whenever possible, provide the same collections support for primitive types. This gap in the JDK is often addressed by using the "wrapper" classes (java.lang.Integer, java.lang.Float, etc.) with Object-based collections. For most applications, however, collections which store primitives directly will require less space and yield significant performance gains. Hashtable techniques The Trove maps/sets use open addressing instead of the chaining approach taken by the JDK hashtables. This eliminates the need to create Map.Entry wrappper objects for every item in a table and so reduces the O (big-oh) in the performance of the hashtable algorithm. The size of the tables used in Trove's maps/sets is always a prime number, improving the probability of an optimal distribution of entries across the table, and so reducing the likelihood of performance-degrading collisions. Trove sets are not backed by maps, and so using a THashSet does not result in the allocation of an unused "values" array. Hashing strategies Trove's maps/sets support the use of custom hashing strategies, allowing you to tune collections based on characteristics of the input data. This feature also allows you to define hash functions when it is not feasible to override Object.hashCode(). For example, the java.lang.String class is final, and its implementation of hashCode() takes O(n) time to complete. In some applications, however, it may be possible for a custom hashing function to save time by skipping portions of the string that are invariant. Using java.util.HashMap, it is not possible to use Java language arrays as keys. For example, this code: char[] foo, bar; foo = new char[] {'a','b','c'}; bar = new char[] {'a','b','c'}; System.out.println(foo.hashCode() == bar.hashCode() ? "equal" : "not equal" ); System.out.println(foo.equals(bar) ? "equal" : "not equal"); produces this output: not equal not equal And so an entry stored in a java.util.HashMap with foo as a key could not be retrieved with bar, since there is no way to override hashCode() or equals() on language array objects. In a gnu.trove.THashMap, however, you can implement a TObjectHashingStrategy to enable hashing on arrays: class CharArrayStrategy implements TObjectHashingStrategy { public int computeHashCode(Object o) { char[] c = (char[])o; // use the shift-add-xor class of string hashing functions // cf. Ramakrishna and Zobel, "Performance in Practice of String Ha shing Functions" int h = 31; // seed chosen at random for (int i = 0; i < c.length; i++) { // could skip invariants h = h ^ ((h << 5) + (h >> 2) + c[i]); // L=5, R=2 works well fo r ASCII input } return h; } public boolean equals(Object o1, Object o2) { char[] c1 = (char[])o1; char[] c2 = (char[])o2; if (c1.length != c2.length) { // could drop this check for fixed-le ngth keys return false; } for (int i = 0, len = c1.length; i < len; i++) { // could skip inva riants if (c1[i] != c2[i]) { return false; } } return true; } } Iterators in primitive collections As of release 0.1.7, Trove's primitive mappings include access through Iterators as well as procedures and functions. The API documentation on those classes contains several examples showing how these can be used effectively and explaining why their semantics differ from those of java.util.Iterator. Miscellaneous N.B. using Map.entrySet on a Trove Map is supported, but not encouraged. The reason is that this API requires the creation of the Map.Entry Objects that all other parts of Trove manage to avoid. An alternative is to implement the appropriate Procedure interface and use it to invoke the Map's forEachEntry API. Map.keySet and Map.values are not similarly encumbered; nevertheless, the forEachKey, forEachValue, and transformValues APIs will yield slightly better performance at the cost of compatibility with the interface of java.util.Map. _________________________________________________________________ Last modified: Mon Sep 23 18:22:39 PDT 2002 trove-2.1.0/build.xml0000644000175000017500000002735011241347112013461 0ustar mkochmkoch Builds the Trove4j library trove-2.1.0/README-license.txt0000644000175000017500000000154511241347112014754 0ustar mkochmkochThe Trove library is licensed under the Lesser GNU Public License, which is included with the distribution in a file called LICENSE.txt. Other license arrangements are possible, for a fee: contact ericdf@users.sourceforge.net for terms/pricing. The PrimeFinder and HashFunctions classes in Trove are subject to the following license restrictions: Copyright (c) 1999 CERN - European Organization for Nuclear Research. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. CERN makes no representations about the suitability of this software for any purpose. It is provided "as is" without expressed or implied warranty. trove-2.1.0/ChangeLog0000644000175000017500000004155711241347112013417 0ustar mkochmkoch--- 2.1.0 --- No substantial changes. --- 2.1.0 a3 --- Bugs fixed: - [ 2685774 ] THashMap serialization bug in 2.0.4 --- 2.1.0 a2 --- Bugs fixed: - [ 2166456 ] clone() for TObjectHashMap is inefficient - [ 2166768 ] add toString() method to maps. Thanks to Ozgur Aydinli. - [ 2688770 ] TxxxArrayList serializes full capacity instead of full size - [ 2687519 ] Primitive Lists hashCode is calculated w/o regard for order - Fixed issues related to removing items multiple times from TLinkedList and using removeFirst/Last when no items are in the list. New Features - [ 2126522 ] add putAll() to the HashMaps. Thanks to Ozgur Aydinli. --- 2.1.0 a1 --- Bugs fixed: - [ 2143564 ] THashSet serialization - [ 1960418 ] Decorators serialization - [ 2127841 ] Use .valueOf on wrap/unwrap in T#K##V#HashMapDecorator New Features: - Added "Dectorators" class for easier creation of decorator classes. - [ 2152149 ] Improve performance by avoiding Math/StrictMath (thanks to Mark Beevers) --- 2.0.5 a1 --- Bugs fixed: - [ 2037709 ] bug in .keys([]) method New Features: - added keys(e[]) method to P2O maps (TIntObjectHashMap, etc.) --- 2.0.4 --- Bugs fixed: - [ 1959853 ] @return for put and putIfAbsent is incorrect --- 2.0.4 rc1 --- Bugs Fixed: - [ 1952509 ] Replace StringBuffer with StringBuilder - [ 1952508 ] pufIfAbsent for maps - [ 1955103 ] Hashing Strategy Not Retained After Serialization --- 2.0.4 a2 --- Bugs fixed: - Correct an error in TLinkedList that caused nodes to not be properly linked when using addAfter(T,T). --- 2.0.4 a1 --- Bugs fixed: - [ 1946240 ] THash.ensureCapacity(...) bug --- 2.0.3 --- Bugs Fixed: - [ 1932929 ] add toString() methods to THashSet and THashMap - Switched to Arrays.fill (which seems to be slightly faster) for clearing --- 2.0.2 --- Bugs Fixed: - [ 1821911 ] get(0) doesn't throw exception when TLinkedList is empty - [ 1800288 ] Trivial typo fixes --- 2.0.1 --- Bugs Fixed: - Fixed implementation of PArrayList.min() and .max(). --- 2.0.1 rc1 --- New Features: [ 1778999 ] Publish a source-JAR with future releases Misc: - Switched version from 2.1 to 2.0.1. --- 2.0.1 ALPHA 3 (previously: 2.1 ALPHA 3) --- Bugs Fixed: [ 1764177 ] bug in binary search --- 2.0.1 ALPHA 2 (previously: 2.1 ALPHA 2) --- New Features: [ 1748566 ] add T[] getValues(T[] a) Bugs Fixed: - Corrected hashcode computation for longs. Should result in better lookup performance. --- 2.0.1 ALPHA 1 (previously: 2.1 ALPHA 1) --- New Features: [ 1741864 ] add TLinkedList addAfter method Bugs Fixed: [ 1738760 ] T*HashMap.retainEntries should suspend automatic compaction. - Corrected hashcode computation for longs. Should result in better lookup performance. Misc: - Added an assertion in HashFunctions to throw an assertion if a value of NaN is used in a lookup/insert/delete from a map. - Added TLinkedList.getNext() and getPrevious() methods. --- 2.0 --- Unchanged from 2.0rc1 --- 2.0rc1 --- New Features: [ 1606090 ] adjustOrPutValue [ 1604073 ] Generate primitive stacks [ 1632250 ] Do maps implement Iterable [ 1670933 ] Provide access to stack native arrays [ 1690743 ] Add subList(begin, end) to ArrayLists Added forEach(TObjectProcedure) method to TLinkedList Bugs Fixed: [ 1640353 ] Generator fails on multiple file systems [ 1676866 ] Not handling REMOVED flag correctly in TObjectHash.index(T) [ 1642768 ] Exception removing from iterator when auto-compact occurs --- 2.0a2 --- New Features: [ 779039 ] expose decorator's set/map Bugs Fixed: [ 1428614 ] THashMap.values().remove() can remove multiple mappings [ 1506751 ] TxxxArrayList.toNativeArray(offset, len) is broken [ 1606095 ] Critical Iterator Error --- 2.0a1 --- This release adds support for generics, which were introduced in JSE 1.5. Starting with this release, JSE 1.5 or greater is required in order to run Trove. Special thanks to JetBrains for their initial work providing generics support. Also added in this release is automatic compaction, such that manually calling compact() is no longer necessary (although it may still provide performance benefits in certain situations). Compactions are by default performed automatically when a certain number of removes are performed based on the size of the set or map. The compaction factor can be specified via THash.setAutoCompactionFactor(float) (the default compaction factor is set to match the load factor). So, for example, if a map is created with an initial capacity of 10 and a load factory of 0.5, a compaction will be performed after 5 removes. If a size is later grown to 1000, then a compaction will occur after 500 removes. When a set/map is rehashed, the time to next compaction is reset. NOTE: auto-compaction can be disabled by setting the autoCompactionFactory (via THash.setAutoCompactionFactor) to zero. Manually compacting a collection will also reset the auto-compaction counter, so that manually compacting more often than auto-compaction wants to occur effectively also disables auto-compaction. NOTE: while manually calling compact() is no longer strictly necessary, results should always be verified in your application to ensure that the auto-compaction scheme and the compaction factors work well for your individual scenario. Support for more primitve types has been introduced. Object serialization has been changed to use Externalization. Unfortunately this means that objects serialized with earlier versions cannot be read by this release. The up-side is that this gives enough flexibility to ensure that we won't need to break serialization again. The other benefit is that the output is more efficient/compact and readable... especially when used with XML serialization mechanisms such as XStream. New Features: [ 918059 ] should rehash when below low water mark upon remove [ 1153656 ] generics? Bugs Fixed: [ 1518795 ] NullPointerException in TLinkedList's removeFirst()/Last() [ 1277703 ] make T**HashMap serializable [ 1417563 ] TLinkedList.add(int,Object) bug [ 1518823 ] another TLinkedList.add(int,Object) bug [ 1461458 ] THashMap.equals(..) method is not consistent [ 1571435 ] Error in cloning of TObjectXXXHashMap instances --- 1.1b5 --- Bugs fixed: [ 1391359 ] Duplicate iteration in THashSet.toArray(Object[]) removed the duplication [ 1382196 ] THashMap.entrySet().retainAll() implemented missing methods on elements of entrySet, refactored retainAll to use retainEntries, which saves a bunch of allocations [ 1378868 ] CVS has junit.jar checked in as ASCII flipped on '-kb' for this file [ 1193416 ] TByteArrayList throws ArrayIndexOutOfBoundsException wrongly fixed off by one error --- 1.1b4 --- Accepted patch for feature request 926921 - adds support for short, byte collections. Also adds support for null object keys. THIS WILL BREAK SERIALIZATION. A big thanks to Steven Lunt for putting this patch together. Added testSerializablePrimitives unit test to validate that behavior reported in 1113420 does work as it's supposed to. Fixed doc problem reported in 939016 Fixed 995597, missing serial version IDs. NOTE: THashMap, THashSet and TLinkedList have IDs generated by serialver and are believed to be b/w compatible. The generated collections, however, are NOT reverse compatible versions and so will break archived collections created with earlier versions of trove. Fixed 937977 -- primitive array lists were not doing a true deep clone of the underlying array. This is fixed --- 1.1b3 --- Fixed 918045 -- bug in *Decorator classes made it impossible to subclass the decorators and make those subclasses cloneable. Thanks to Steve Lunt for the bug report. --- 1.1b2 --- Fixed 901135 -- bug in T*Hash.insertionIndex() methods that prevented us from reclaiming the very first REMOVED slot if that's what the first hash landed upon. In applications that do lots of adds/removes, this would have led to unnecessary rehashing. With this fix, you can add(1), remove(1), and then re add(1) and the same slot will be used. Thanks to matlun for reporting the problem. --- 1.1b1 --- fixed a bug in decorator equals methods (845890) fixed a memory leak for certain usage patterns (843772) corrected some javadoc defects (846286) minor tuning of T*ArrayList toString() added clone() methods to decorator classes. Thanks to Steve Lunt for the bug report. implemented equals()/hashCode() on THashMap.KeyView and (by extension) subclasses. This allows the test in THashMapTests.testKeySetEqualsEquivalentSet to pass. fix 787515 -- bug in T*ArrayList.set(int, *[], int, int) --- 1.0.2 --- revamped versioning scheme added hashCode implementation to collections so that they can appear in collections too. added check+exception to detect violations of the equals() <-> hashCode() contract specified in java.lang.Object's api. --- 0.1.8 --- Added gnu.trove.decorator package, with Decorator classes that wrap trove's primitive maps and sets for conformance with the java.util.{Map,Set} APIs. --- 0.1.7 --- Added iterators to the primitive maps and sets. Note that semantics differ from those of java.util.Iterator, so RTFM. Added hashing strategy interfaces to allow users to implement custom hashing schemes for optimal distribution for specific data sets. Fixed bug 602376 -- ClassCastException n THashMap.putAll Made all collections implement Cloneable. primitive collections clone deeply; Object collections produce shallow clones. --- 0.1.6 --- Minor bug fix release. Two bugs in TIntArrayList have been fixed. Thanks to Jessica P. Hekman for reporting them. One of these prevented toNativeArray from working correctly in certain circumstances; the other problem was with the depth of cloning operations. One enhancement to TintArrayList has been made -- serialized instances are now compact -- previous versions relied on serialization behavior of the backing array, which included empty slots and so wasted space. Serialization of sets/maps has been modified as follows: previously all of the writeObject methods used a local implementation of the TXXXProcedure for writing out the data in a particular collection. These have been replaced by a single class (SerializationProcedure) which implements all of the appropriate interfaces. This reduces the number of .class files in the trove jar --- 0.1.5 --- added retainEntries methods to all Map classes. These methods accept procedure objects of the appropriate sort and use the return value of those procedures to determine whether or not a particular entry in the map should be retained. This is useful for applying a cutoff in a map without copying data: TIntIntHashMap map = new TIntIntHashMap(); // load up map map.retainEntries(new TIntIntProcedure() { public boolean execute(int key, int val) { return val > 3; // retain only those mappings with val > 3 } }); It can also be used if you want to reduce one map to the intersection between it and another map: THashMap map1 = new THashMap(); THashMap map2 = new THashMap(); // load up both maps map1.retainEntries(new TObjectObjectProcedure() { public boolean execute(Object key, Object val) { return map2.containsKey(key); // retain the intersection with map2 } }); --- 0.1.4 --- added increment() and adjustValue() methods to maps with primitive values. These are useful in the all-too-common case where you need a map for the purposes of counting the number of times a key is seen. These methods are handy because you don't have to do a "containsKey" test prior to every increment() call. Instead, you can check the return status (true if an existing mapping was modified) and if it is false, then insert the mapping with the initial value: TIntIntHashMap map = TIntIntHashMap(); int key, val; key = keyFromSomeWhere(); val = valFromSomeWhere(); if (! map.increment(key)) map.put(key, 0); increment is implemented in terms of adjustValue, which allows you to specify the amount by which the primitive value associated with a particular key should be adjusted. Thanks to Jason Baldridge for the idea. --- 0.1.3 --- bug fix in TLinkedList ListIterator implementation: fixed remove() behavior so that it correctly removes the last element returned by either next() or previous(). Added several tests to suite to verify that list iterator does what it's supposed to do in accordance with the collections API docs. --- 0.1.2 --- bug fix in primitive hash sets: toArray now produces a correct return value of size set.size(). Previously it generated an ArrayIndexOutOfBoundsException. Thanks to Tobias Henle for finding this. revised class hierarchy so that all primitive hashing collections are derived from TPrimitiveHash, which extends THash. Object hashing collections are derived from TObjectHash. As part of this change, the byte[] flags were pushed down to TPrimitiveHash, and TObjectHash was revised so that it no longer needs a byte[] array to track the state of the table. This has an appreciable impact on the total size of Object hashing collections: a set of 1,000 Integers used to take 69% of the memory needed for a JDK set; it now takes only 62%. removed slots can now be re-used in all hashing collections. If the search for an insertion index does not find that the key is already present in the map, insertionIndex implementations will now return the index of the first REMOVED or FREE slot. This means that tables which undergo a pattern of insertions/deletions without radical changes in size will not trigger as many rehashes as before. revised hashing algorithm so that the second hash function is only executed when necessary and so that FREE or FULL w/identical content slots can be found with a minimum of effort. --- 0.1.1 --- made the initial capacity of lists used for return values in grep/inverseGrep be the default capacity rather than the size of the list-being-grepped. This saves space when a small list is grepped from a larger list. added reset and resetQuick methods to *ArrayList implementations so that lists can be cleared while retaining their current capacity. changed *ArrayList toNativeArray() method behavior so that a List of 0 length can return a native array of 0 length (previously this would have thrown an exception) revamped *ArrayList insert/remove implementations so that edits are done in place instead of with a temporary array. minor performance tweak in THashIterator --- 0.1.0 --- Added primitive ArrayList implementations. --- 0.0.9 --- Made all collections implement java.io.Serializable Made all collections implement equals() so that they compare their contents instead of doing collection object identity. Made TLinkable extend java.io.Serializable Changed secondary hash function to reflect Knuth's observation about the desirability of using an odd value. Added trimToSize() and ensureCapacity() methods (finally) implemented loadFactor, with default of 0.5, per Knuth. Note that load/capacity/size are handled differently than in the Javasoft implementations. Specifically, if you ask for a collection of capacity X, Trove will give you one that can hold X elements without rehashing; Javasoft's implementation does not do this. --- 0.0.8 --- Fixes for several user-reported bugs. Unit tests have been added to demonstrate that each of these is actually fixed. 485440 Null in keys() from TObjectDoubleHashMap size/free were being updated even when a map.put() was really a replaement for an existing mapping. 485829 null values not handled correctly 485831 null values cause exceptions 485834 null values cause NullPointerException made Maps that hold Object values behave correctly (no NPE) when doing comparisons with null objects, since null values are legal. 485837 entrySet comparison semantics are wrong made entrySet check both key and value when doing comparisons. --- 0.0.7 --- new package: gnu.trove.benchmark replaced gnu.trove.Benchmark with benchmark package. This now produces formatted reports that include OS/JVM specs. Changed benchmarking approach so that timestamps are only taken at the beginning/end of the full repetition count for an operation. This reduces the variability caused by calling System.currentTimeMillis() more than once in the same second. Added memory profiler which produces a report with the memory requirements for trove/javasoft collections of the same objects. build.xml modified jar task so that the benchmark package is not included in the jar file or the javadoc set. Only the framework classes get jarred up; developers can run the benchmarks by using the output/classes directory instead. TObjectHash Based on profiling results, replaced calls to HashFunctions.hash(obj) with direct invocation of obj.hashCode() to save a method call. This is probably inlined by hotspot compilers, but my profiler doesn't work with those. TObjectHash.HashIterator Based on bytecode examination, replaced a putfield/getfield combo with a putfield/dup_x. This saves three opcodes in a method which gets called a lot (moveToNextIndex()). PrimeFinder/HashFunctions finalized both classes and all methods. trove-2.1.0/src/0000755000175000017500000000000011241347110012416 5ustar mkochmkochtrove-2.1.0/src/gnu/0000755000175000017500000000000011241347110013207 5ustar mkochmkochtrove-2.1.0/src/gnu/trove/0000755000175000017500000000000011261456735014366 5ustar mkochmkochtrove-2.1.0/src/gnu/trove/THashIterator.java0000644000175000017500000000671211241347110017740 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.util.ConcurrentModificationException; import java.util.Iterator; import java.util.NoSuchElementException; /** * Implements all iterator functions for the hashed object set. * Subclasses may override objectAtIndex to vary the object * returned by calls to next() (e.g. for values, and Map.Entry * objects). * *

Note that iteration is fastest if you forego the calls to * hasNext in favor of checking the size of the structure * yourself and then call next() that many times: * *

 * Iterator i = collection.iterator();
 * for (int size = collection.size(); size-- > 0;) {
 *   Object o = i.next();
 * }
 * 
* *

You may, of course, use the hasNext(), next() idiom too if * you aren't in a performance critical spot.

* */ abstract class THashIterator extends TIterator implements Iterator { private final TObjectHash _object_hash; /** * Create an instance of THashIterator over the values of the TObjectHash */ public THashIterator(TObjectHash hash) { super(hash); _object_hash = hash; } /** * Moves the iterator to the next Object and returns it. * * @return an Object value * @exception ConcurrentModificationException if the structure * was changed using a method that isn't on this iterator. * @exception NoSuchElementException if this is called on an * exhausted iterator. */ public V next() { moveToNextIndex(); return objectAtIndex(_index); } /** * Returns the index of the next value in the data structure * or a negative value if the iterator is exhausted. * * @return an int value * @exception ConcurrentModificationException if the underlying * collection's size has been modified since the iterator was * created. */ protected final int nextIndex() { if (_expectedSize != _hash.size()) { throw new ConcurrentModificationException(); } Object[] set = _object_hash._set; int i = _index; while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) ; return i; } /** * Returns the object at the specified index. Subclasses should * implement this to return the appropriate object for the given * index. * * @param index the index of the value to return. * @return an Object value */ abstract protected V objectAtIndex(int index); } // THashIterator trove-2.1.0/src/gnu/trove/TLinkedList.java0000644000175000017500000005306211241347110017405 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.*; import java.util.AbstractSequentialList; import java.util.ListIterator; import java.util.NoSuchElementException; /** * A LinkedList implementation which holds instances of type * TLinkable. * *

Using this implementation allows you to get java.util.LinkedList * behavior (a doubly linked list, with Iterators that support insert * and delete operations) without incurring the overhead of creating * Node wrapper objects for every element in your list.

* *

The requirement to achieve this time/space gain is that the * Objects stored in the List implement the TLinkable * interface.

* *

The limitations are that you cannot put the same object into * more than one list or more than once in the same list. You must * also ensure that you only remove objects that are actually in the * list. That is, if you have an object A and lists l1 and l2, you * must ensure that you invoke List.remove(A) on the correct list. It * is also forbidden to invoke List.remove() with an unaffiliated * TLinkable (one that belongs to no list): this will destroy the list * you invoke it on.

* *

* Created: Sat Nov 10 15:25:10 2001 *

* * @author Eric D. Friedman * @version $Id: TLinkedList.java,v 1.15 2009/03/31 19:43:14 robeden Exp $ * @see gnu.trove.TLinkable */ public class TLinkedList extends AbstractSequentialList implements Externalizable { static final long serialVersionUID = 1L; /** the head of the list */ protected T _head; /** the tail of the list */ protected T _tail; /** the number of elements in the list */ protected int _size = 0; /** * Creates a new TLinkedList instance. * */ public TLinkedList() { super(); } /** * Returns an iterator positioned at index. Assuming * that the list has a value at that index, calling next() will * retrieve and advance the iterator. Assuming that there is a * value before index in the list, calling previous() * will retrieve it (the value at index - 1) and move the iterator * to that position. So, iterating from front to back starts at * 0; iterating from back to front starts at size(). * * @param index an int value * @return a ListIterator value */ public ListIterator listIterator(int index) { return new IteratorImpl(index); } /** * Returns the number of elements in the list. * * @return an int value */ public int size() { return _size; } /** * Inserts linkable at index index in the list. * All values > index are shifted over one position to accommodate * the new addition. * * @param index an int value * @param linkable an object of type TLinkable */ public void add(int index, T linkable) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("index:" + index); } insert(index,linkable); } /** * Appends linkable to the end of the list. * * @param linkable an object of type TLinkable * @return always true */ public boolean add(T linkable) { insert(_size, linkable); return true; } /** * Inserts linkable at the head of the list. * * @param linkable an object of type TLinkable */ public void addFirst(T linkable) { insert(0, linkable); } /** * Adds linkable to the end of the list. * * @param linkable an object of type TLinkable */ public void addLast(T linkable) { insert(size(), linkable); } /** * Empties the list. * */ public void clear() { if (null != _head) { for (TLinkable link = _head.getNext(); link != null; link = link.getNext()) { TLinkable prev = link.getPrevious(); prev.setNext(null); link.setPrevious(null); } _head = _tail = null; } _size = 0; } /** * Copies the list's contents into a native array. This will be a * shallow copy: the Tlinkable instances in the Object[] array * have links to one another: changing those will put this list * into an unpredictable state. Holding a reference to one * element in the list will prevent the others from being garbage * collected unless you clear the next/previous links. Caveat * programmer! * * @return an Object[] value */ public Object[] toArray() { Object[] o = new Object[_size]; int i = 0; for (TLinkable link = _head; link != null; link = link.getNext()) { o[i++] = link; } return o; } /** * Copies the list to a native array, destroying the next/previous * links as the copy is made. This list will be emptied after the * copy (as if clear() had been invoked). The Object[] array * returned will contain TLinkables that do not hold * references to one another and so are less likely to be the * cause of memory leaks. * * @return an Object[] value */ public Object[] toUnlinkedArray() { Object[] o = new Object[_size]; int i = 0; for (T link = _head, tmp = null; link != null; i++) { o[i] = link; tmp = link; link = (T) link.getNext(); tmp.setNext(null); // clear the links tmp.setPrevious(null); } _size = 0; // clear the list _head = _tail = null; return o; } /** * A linear search for o in the list. * * @param o an Object value * @return a boolean value */ public boolean contains(Object o) { for (TLinkable link = _head; link != null; link = link.getNext()) { if (o.equals(link)) { return true; } } return false; } /** * {@inheritDoc} */ @Override public T get(int index) { // Blow out for bogus values if (index < 0 || index >= _size ) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + _size); } // Determine if it's better to get there from the front or the back if (index > (_size >> 1)) { int position = _size - 1; T node = _tail; while ( position > index ) { node = ( T ) node.getPrevious(); position--; } return node; } else { int position = 0; T node = _head; while( position < index ) { node = ( T ) node.getNext(); position++; } return node; } } /** * Returns the head of the list * * @return an Object value */ public T getFirst() { return _head; } /** * Returns the tail of the list. * * @return an Object value */ public T getLast() { return _tail; } /** * Return the node following the given node. This method exists for two reasons: *
    *
  1. It's really not recommended that the methods implemented by TLinkable be * called directly since they're used internally by this class.
  2. *
  3. This solves problems arising from generics when working with the linked * objects directly.
  4. *
*

* NOTE: this should only be used with nodes contained in the list. The results are * undefined with anything else. */ public T getNext( T current ) { return ( T ) current.getNext(); } /** * Return the node preceding the given node. This method exists for two reasons: *

    *
  1. It's really not recommended that the methods implemented by TLinkable be * called directly since they're used internally by this class.
  2. *
  3. This solves problems arising from generics when working with the linked * objects directly.
  4. *
*

* NOTE: this should only be used with nodes contained in the list. The results are * undefined with anything else. */ public T getPrevious( T current ) { return ( T ) current.getPrevious(); } /** * Remove and return the first element in the list. * * @return an Object value */ public T removeFirst() { T o = _head; if ( o == null ) return null; T n = (T) o.getNext(); o.setNext(null); if (null != n) { n.setPrevious(null); } _head = n; if (--_size == 0) { _tail = null; } return o; } /** * Remove and return the last element in the list. * * @return an Object value */ public T removeLast() { T o = _tail; if ( o == null ) return null; T prev = (T) o.getPrevious(); o.setPrevious(null); if (null != prev) { prev.setNext(null); } _tail = prev; if (--_size == 0) { _head = null; } return o; } /** * Implementation of index-based list insertions. * * @param index an int value * @param linkable an object of type TLinkable */ protected void insert(int index, T linkable) { T newLink = linkable; if (_size == 0) { _head = _tail = newLink; // first insertion } else if (index == 0) { newLink.setNext(_head); // insert at front _head.setPrevious(newLink); _head = newLink; } else if (index == _size) { // insert at back _tail.setNext(newLink); newLink.setPrevious(_tail); _tail = newLink; } else { T node = get(index); T before = (T) node.getPrevious(); if (before != null) before.setNext(linkable); linkable.setPrevious(before); linkable.setNext(node); node.setPrevious(linkable); } _size++; } /** * Removes the specified element from the list. Note that * it is the caller's responsibility to ensure that the * element does, in fact, belong to this list and not another * instance of TLinkedList. * * @param o a TLinkable element already inserted in this list. * @return true if the element was a TLinkable and removed */ public boolean remove(Object o) { if (o instanceof TLinkable) { T p, n; TLinkable link = (TLinkable)o; p = (T) link.getPrevious(); n = (T) link.getNext(); if (n == null && p == null ) { // emptying the list // It's possible this object is not something that's in the list. So, // make sure it's the head if it doesn't point to anything. This solves // problems caused by removing something multiple times. if (o != _head) return false; _head = _tail = null; } else if (n == null) { // this is the tail // make previous the new tail link.setPrevious(null); p.setNext(null); _tail = p; } else if (p == null) { // this is the head // make next the new head link.setNext(null); n.setPrevious(null); _head = n; } else { // somewhere in the middle p.setNext(n); n.setPrevious(p); link.setNext(null); link.setPrevious(null); } _size--; // reduce size of list return true; } else { return false; } } /** * Inserts newElement into the list immediately before current. * All elements to the right of and including current are shifted * over. * * @param current a TLinkable value currently in the list. * @param newElement a TLinkable value to be added to * the list. */ public void addBefore(T current, T newElement) { if (current == _head) { addFirst(newElement); } else if (current == null) { addLast(newElement); } else { TLinkable p = current.getPrevious(); newElement.setNext(current); p.setNext(newElement); newElement.setPrevious(p); current.setPrevious(newElement); _size++; } } /** * Inserts newElement into the list immediately after current. * All elements to the left of and including current are shifted * over. * * @param current a TLinkable value currently in the list. * @param newElement a TLinkable value to be added to * the list. */ public void addAfter(T current, T newElement) { if (current == _tail) { addLast(newElement); } else if (current == null) { addFirst(newElement); } else { TLinkable n = current.getNext(); newElement.setPrevious(current); newElement.setNext(n); current.setNext(newElement); n.setPrevious(newElement); _size++; } } /** * Executes procedure for each entry in the list. * * @param procedure a TObjectProcedure value * @return false if the loop over the values terminated because * the procedure returned false for some value. */ public boolean forEachValue(TObjectProcedure procedure) { T node = _head; while ( node != null ) { boolean keep_going = procedure.execute( node ); if ( !keep_going ) return false; node = ( T ) node.getNext(); } return true; } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte(0); // NUMBER OF ENTRIES out.writeInt(_size); // HEAD out.writeObject(_head); // TAIL out.writeObject(_tail); } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIED _size = in.readInt(); // HEAD _head = (T) in.readObject(); // TAIL _tail = (T) in.readObject(); } /** * A ListIterator that supports additions and deletions. * */ protected final class IteratorImpl implements ListIterator { private int _nextIndex = 0; private T _next; private T _lastReturned; /** * Creates a new Iterator instance positioned at * index. * * @param position an int value */ IteratorImpl(int position) { if (position < 0 || position > _size) { throw new IndexOutOfBoundsException(); } _nextIndex = position; if (position == 0) { _next = _head; } else if (position == _size) { _next = null; } else if (position < (_size >> 1)) { int pos = 0; for (_next = _head; pos < position; pos++) { _next = (T) _next.getNext(); } } else { int pos = _size - 1; for (_next = _tail; pos > position; pos--) { _next = (T) _next.getPrevious(); } } } /** * Insert linkable at the current position of the iterator. * Calling next() after add() will return the added object. * * @param linkable an object of type TLinkable */ public final void add(T linkable) { _lastReturned = null; _nextIndex++; if (_size == 0) { TLinkedList.this.add(linkable); } else { TLinkedList.this.addBefore(_next, linkable); } } /** * True if a call to next() will return an object. * * @return a boolean value */ public final boolean hasNext() { return _nextIndex != _size; } /** * True if a call to previous() will return a value. * * @return a boolean value */ public final boolean hasPrevious() { return _nextIndex != 0; } /** * Returns the value at the Iterator's index and advances the * iterator. * * @return an Object value * @exception NoSuchElementException if there is no next element */ public final T next() { if (_nextIndex == _size) { throw new NoSuchElementException(); } _lastReturned = _next; _next = (T) _next.getNext(); _nextIndex++; return _lastReturned; } /** * returns the index of the next node in the list (the * one that would be returned by a call to next()). * * @return an int value */ public final int nextIndex() { return _nextIndex; } /** * Returns the value before the Iterator's index and moves the * iterator back one index. * * @return an Object value * @exception NoSuchElementException if there is no previous element. */ public final T previous() { if (_nextIndex == 0) { throw new NoSuchElementException(); } if (_nextIndex == _size) { _lastReturned = _next = _tail; } else { _lastReturned = _next = (T) _next.getPrevious(); } _nextIndex--; return _lastReturned; } /** * Returns the previous element's index. * * @return an int value */ public final int previousIndex() { return _nextIndex - 1; } /** * Removes the current element in the list and shrinks its * size accordingly. * * @exception IllegalStateException neither next nor previous * have been invoked, or remove or add have been invoked after * the last invocation of next or previous. */ public final void remove() { if (_lastReturned == null) { throw new IllegalStateException("must invoke next or previous before invoking remove"); } if (_lastReturned != _next) { _nextIndex--; } _next = (T) _lastReturned.getNext(); TLinkedList.this.remove(_lastReturned); _lastReturned = null; } /** * Replaces the current element in the list with * linkable * * @param linkable an object of type TLinkable */ public final void set(T linkable) { if (_lastReturned == null) { throw new IllegalStateException(); } T l = linkable; // need to check both, since this could be the only // element in the list. if (_lastReturned == _head) { _head = l; } if (_lastReturned == _tail) { _tail = l; } swap(_lastReturned, l); _lastReturned = l; } /** * Replace from with to in the list. * * @param from a TLinkable value * @param to a TLinkable value */ private void swap(T from, T to) { T p = (T) from.getPrevious(); T n = (T) from.getNext(); if (null != p) { to.setPrevious(p); p.setNext(to); } if (null != n) { to.setNext(n); n.setPrevious(to); } from.setNext(null); from.setPrevious(null); } } } // TLinkedList trove-2.1.0/src/gnu/trove/THashMap.java0000644000175000017500000006024111241347110016661 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.*; import java.util.*; /** * An implementation of the Map interface which uses an open addressed * hash table to store its contents. * * Created: Sun Nov 4 08:52:45 2001 * * @author Eric D. Friedman * @version $Id: THashMap.java,v 1.33 2008/05/08 17:42:55 robeden Exp $ */ public class THashMap extends TObjectHash implements Map, Externalizable { static final long serialVersionUID = 1L; /** the values of the map */ protected transient V[] _values; /** * Creates a new THashMap instance with the default * capacity and load factor. */ public THashMap() { super(); } /** * Creates a new THashMap instance with the default * capacity and load factor. * @param strategy used to compute hash codes and to compare objects. */ public THashMap(TObjectHashingStrategy strategy) { super(strategy); } /** * Creates a new THashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value */ public THashMap(int initialCapacity) { super(initialCapacity); } /** * Creates a new THashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare objects. */ public THashMap(int initialCapacity, TObjectHashingStrategy strategy) { super(initialCapacity, strategy); } /** * Creates a new THashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value */ public THashMap(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Creates a new THashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value * @param strategy used to compute hash codes and to compare objects. */ public THashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { super(initialCapacity, loadFactor, strategy); } /** * Creates a new THashMap instance which contains the * key/value pairs in map. * * @param map a Map value */ public THashMap(Map map) { this(map.size()); putAll(map); } /** * Creates a new THashMap instance which contains the * key/value pairs in map. * * @param map a Map value * @param strategy used to compute hash codes and to compare objects. */ public THashMap(Map map, TObjectHashingStrategy strategy) { this(map.size(), strategy); putAll(map); } /** * @return a shallow clone of this collection */ public THashMap clone() { THashMap m = (THashMap)super.clone(); m._values = this._values.clone(); return m; } /** * initialize the value array of the map. * * @param initialCapacity an int value * @return an int value */ protected int setUp(int initialCapacity) { int capacity; capacity = super.setUp(initialCapacity); //noinspection unchecked _values = (V[]) new Object[capacity]; return capacity; } /** * Inserts a key/value pair into the map. * * @param key an Object value * @param value an Object value * @return the previous value associated with key, * or {@code null} if none was found. */ public V put(K key, V value) { int index = insertionIndex(key); return doPut(key, value, index); } /** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an Object value * @param value an Object value * @return the previous value associated with key, * or {@code null} if none was found. */ public V putIfAbsent(K key, V value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); } private V doPut(K key, V value, int index) { V previous = null; Object oldKey; boolean isNewMapping = true; if (index < 0) { index = -index -1; previous = _values[index]; isNewMapping = false; } oldKey = _set[index]; _set[index] = key; _values[index] = value; if (isNewMapping) { postInsertHook(oldKey == FREE); } return previous; } /** * Compares this map with another map for equality of their stored * entries. * * @param other an Object value * @return a boolean value */ public boolean equals(Object other) { if (! (other instanceof Map)) { return false; } Map that = (Map)other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); } public int hashCode() { HashProcedure p = new HashProcedure(); forEachEntry(p); return p.getHashCode(); } public String toString() { final StringBuilder buf = new StringBuilder("{"); forEachEntry(new TObjectObjectProcedure() { private boolean first = true; public boolean execute(K key, V value) { if ( first ) first = false; else buf.append( "," ); buf.append(key); buf.append("="); buf.append(value); return true; } }); buf.append("}"); return buf.toString(); } private final class HashProcedure implements TObjectObjectProcedure { private int h = 0; public int getHashCode() { return h; } public final boolean execute(K key, V value) { h += _hashingStrategy.computeHashCode(key) ^ (value == null ? 0 : value.hashCode()); return true; } } private static final class EqProcedure implements TObjectObjectProcedure { private final Map _otherMap; EqProcedure(Map otherMap) { _otherMap = otherMap; } public final boolean execute(K key, V value) { // Check to make sure the key is there. This avoids problems that come up with // null values. Since it is only caused in that cause, only do this when the // value is null (to avoid extra work). if (value == null && !_otherMap.containsKey(key)) return false; V oValue = _otherMap.get(key); return oValue == value || (oValue != null && oValue.equals(value)); } } /** * Executes procedure for each key in the map. * * @param procedure a TObjectProcedure value * @return false if the loop over the keys terminated because * the procedure returned false for some key. */ public boolean forEachKey(TObjectProcedure procedure) { return forEach(procedure); } /** * Executes procedure for each value in the map. * * @param procedure a TObjectProcedure value * @return false if the loop over the values terminated because * the procedure returned false for some value. */ public boolean forEachValue(TObjectProcedure procedure) { V[] values = _values; Object[] set = _set; for (int i = values.length; i-- > 0;) { if (set[i] != FREE && set[i] != REMOVED && ! procedure.execute(values[i])) { return false; } } return true; } /** * Executes procedure for each key/value entry in the * map. * * @param procedure a TObjectObjectProcedure value * @return false if the loop over the entries terminated because * the procedure returned false for some entry. */ public boolean forEachEntry(TObjectObjectProcedure procedure) { Object[] keys = _set; V[] values = _values; for (int i = keys.length; i-- > 0;) { if (keys[i] != FREE && keys[i] != REMOVED && ! procedure.execute((K) keys[i],values[i])) { return false; } } return true; } /** * Retains only those entries in the map for which the procedure * returns a true value. * * @param procedure determines which entries to keep * @return true if the map was modified. */ public boolean retainEntries(TObjectObjectProcedure procedure) { boolean modified = false; Object[] keys = _set; V[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for (int i = keys.length; i-- > 0;) { if (keys[i] != FREE && keys[i] != REMOVED && ! procedure.execute((K) keys[i],values[i])) { removeAt(i); modified = true; } } } finally { reenableAutoCompaction(true); } return modified; } /** * Transform the values in this map using function. * * @param function a TObjectFunction value */ public void transformValues(TObjectFunction function) { V[] values = _values; Object[] set = _set; for (int i = values.length; i-- > 0;) { if (set[i] != FREE && set[i] != REMOVED) { values[i] = function.execute(values[i]); } } } /** * rehashes the map to the new capacity. * * @param newCapacity an int value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; Object oldKeys[] = _set; V oldVals[] = _values; _set = new Object[newCapacity]; Arrays.fill(_set, FREE); _values = (V[]) new Object[newCapacity]; for (int i = oldCapacity; i-- > 0;) { if(oldKeys[i] != FREE && oldKeys[i] != REMOVED) { Object o = oldKeys[i]; int index = insertionIndex((K) o); if (index < 0) { throwObjectContractViolation(_set[(-index -1)], o); } _set[index] = o; _values[index] = oldVals[i]; } } } /** * retrieves the value for key * * @param key an Object value * @return the value of key or null if no such mapping exists. */ public V get(Object key) { int index = index((K) key); return index < 0 ? null : _values[index]; } /** * Empties the map. * */ public void clear() { if (size() == 0) return; // optimization super.clear(); Arrays.fill(_set, 0, _set.length, FREE); Arrays.fill(_values, 0, _values.length, null); } /** * Deletes a key/value pair from the map. * * @param key an Object value * @return an Object value */ public V remove(Object key) { V prev = null; int index = index((K) key); if (index >= 0) { prev = _values[index]; removeAt(index); // clear key,state; adjust size } return prev; } /** * removes the mapping at index from the map. * * @param index an int value */ protected void removeAt(int index) { _values[index] = null; super.removeAt(index); // clear key, state; adjust size } /** * Returns a view on the values of the map. * * @return a Collection value */ public Collection values() { return new ValueView(); } /** * returns a Set view on the keys of the map. * * @return a Set value */ public Set keySet() { return new KeyView(); } /** * Returns a Set view on the entries of the map. * * @return a Set value */ public Set> entrySet() { return new EntryView(); } /** * checks for the presence of val in the values of the map. * * @param val an Object value * @return a boolean value */ public boolean containsValue(Object val) { Object[] set = _set; V[] vals = _values; // special case null values so that we don't have to // perform null checks before every call to equals() if (null == val) { for (int i = vals.length; i-- > 0;) { if ((set[i] != FREE && set[i] != REMOVED) && val == vals[i]) { return true; } } } else { for (int i = vals.length; i-- > 0;) { if ((set[i] != FREE && set[i] != REMOVED) && (val == vals[i] || val.equals(vals[i]))) { return true; } } } // end of else return false; } /** * checks for the present of key in the keys of the map. * * @param key an Object value * @return a boolean value */ public boolean containsKey(Object key) { return contains(key); } /** * copies the key/value mappings in map into this map. * * @param map a Map value */ public void putAll(Map map) { ensureCapacity(map.size()); // could optimize this for cases when map instanceof THashMap for (Iterator> i = map.entrySet().iterator(); i.hasNext();) { Map.Entry e = i.next(); put(e.getKey(),e.getValue()); } } /** * a view onto the values of the map. * */ protected class ValueView extends MapBackedView { public Iterator iterator() { return new THashIterator(THashMap.this) { protected V objectAtIndex(int index) { return _values[index]; } }; } public boolean containsElement(V value) { return containsValue(value); } public boolean removeElement(V value) { Object[] values = _values; Object[] set = _set; for (int i = values.length; i-- > 0;) { if ((set[i] != FREE && set[i] != REMOVED) && value == values[i] || (null != values[i] && values[i].equals(value))) { removeAt(i); return true; } } return false; } } /** * a view onto the entries of the map. * */ protected class EntryView extends MapBackedView> { private final class EntryIterator extends THashIterator> { EntryIterator(THashMap map) { super(map); } public Entry objectAtIndex(final int index) { return new Entry((K) _set[index], _values[index], index); } } public Iterator> iterator() { return new EntryIterator(THashMap.this); } public boolean removeElement(Map.Entry entry) { // have to effectively reimplement Map.remove here // because we need to return true/false depending on // whether the removal took place. Since the Entry's // value can be null, this means that we can't rely // on the value of the object returned by Map.remove() // to determine whether a deletion actually happened. // // Note also that the deletion is only legal if // both the key and the value match. Object val; int index; K key = keyForEntry(entry); index = index(key); if (index >= 0) { val = valueForEntry(entry); if (val == _values[index] || (null != val && val.equals(_values[index]))) { removeAt(index); // clear key,state; adjust size return true; } } return false; } public boolean containsElement(Map.Entry entry) { Object val = get(keyForEntry(entry)); Object entryValue = entry.getValue(); return entryValue == val || (null != val && val.equals(entryValue)); } protected V valueForEntry(Map.Entry entry) { return entry.getValue(); } protected K keyForEntry(Map.Entry entry) { return entry.getKey(); } } private abstract class MapBackedView extends AbstractSet implements Set, Iterable { public abstract Iterator iterator(); public abstract boolean removeElement(E key); public abstract boolean containsElement(E key); public boolean contains(Object key) { return containsElement((E) key); } public boolean remove(Object o) { return removeElement((E) o); } public boolean containsAll(Collection collection) { for (Iterator i = collection.iterator(); i.hasNext();) { if (! contains(i.next())) { return false; } } return true; } public void clear() { THashMap.this.clear(); } public boolean add(E obj) { throw new UnsupportedOperationException(); } public int size() { return THashMap.this.size(); } public Object[] toArray() { Object[] result = new Object[size()]; Iterator e = iterator(); for (int i=0; e.hasNext(); i++) result[i] = e.next(); return result; } public T[] toArray(T[] a) { int size = size(); if (a.length < size) a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); Iterator it = iterator(); Object[] result = a; for (int i=0; i size) { a[size] = null; } return a; } public boolean isEmpty() { return THashMap.this.isEmpty(); } public boolean addAll(Collection collection) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection collection) { boolean changed = false; Iterator i = iterator(); while (i.hasNext()) { if (! collection.contains(i.next())) { i.remove(); changed = true; } } return changed; } } /** * a view onto the keys of the map. */ protected class KeyView extends MapBackedView { public Iterator iterator() { return new TObjectHashIterator(THashMap.this); } public boolean removeElement(K key) { return null != THashMap.this.remove(key); } public boolean containsElement(K key) { return THashMap.this.contains(key); } } final class Entry implements Map.Entry { private K key; private V val; private final int index; Entry(final K key, V value, final int index) { this.key = key; this.val = value; this.index = index; } void setKey(K aKey) { this.key = aKey; } void setValue0(V aValue) { this.val = aValue; } public K getKey() { return key; } public V getValue() { return val; } public V setValue(V o) { if (_values[index] != val) { throw new ConcurrentModificationException(); } _values[index] = o; o = val; // need to return previous value val = o; // update this entry's value, in case // setValue is called again return o; } public boolean equals(Object o) { if (o instanceof Map.Entry) { Map.Entry e1 = this; Map.Entry e2 = (Map.Entry) o; return (e1.getKey()==null ? e2.getKey()==null : e1.getKey().equals(e2.getKey())) && (e1.getValue()==null ? e2.getValue()==null : e1.getValue().equals(e2.getValue())); } return false; } public int hashCode() { return (getKey()==null ? 0 : getKey().hashCode()) ^ (getValue()==null ? 0 : getValue().hashCode()); } } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 1 ); // NOTE: Super was not written in version 0 super.writeExternal( out ); // NUMBER OF ENTRIES out.writeInt( _size ); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure( out ); if (! forEachEntry(writeProcedure)) { throw writeProcedure.exception; } } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION byte version = in.readByte(); // NOTE: super was not written in version 0 if ( version != 0 ) super.readExternal( in ); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { //noinspection unchecked K key = (K) in.readObject(); //noinspection unchecked V val = (V) in.readObject(); put(key, val); } } } // THashMap trove-2.1.0/src/gnu/trove/TPrimitiveIterator.java0000644000175000017500000000517311241347110021025 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.util.ConcurrentModificationException; /** * Implements all iterator functions for the hashed object set. * Subclasses may override objectAtIndex to vary the object * returned by calls to next() (e.g. for values, and Map.Entry * objects). * *

Note that iteration is fastest if you forego the calls to * hasNext in favor of checking the size of the structure * yourself and then call next() that many times: * *

 * Iterator i = collection.iterator();
 * for (int size = collection.size(); size-- > 0;) {
 *   Object o = i.next();
 * }
 * 
* *

You may, of course, use the hasNext(), next() idiom too if * you aren't in a performance critical spot.

* */ abstract class TPrimitiveIterator extends TIterator { /** the collection on which this iterator operates. */ protected final TPrimitiveHash _hash; /** * Creates a TPrimitiveIterator for the specified collection. */ public TPrimitiveIterator(TPrimitiveHash hash) { super(hash); _hash = hash; } /** * Returns the index of the next value in the data structure * or a negative value if the iterator is exhausted. * * @return an int value * @exception ConcurrentModificationException if the underlying collection's * size has been modified since the iterator was created. */ protected final int nextIndex() { if (_expectedSize != _hash.size()) { throw new ConcurrentModificationException(); } byte[] states = _hash._states; int i = _index; while (i-- > 0 && (states[i] != TPrimitiveHash.FULL)) ; return i; } } // TPrimitiveIterator trove-2.1.0/src/gnu/trove/TObjectFunction.java0000644000175000017500000000266711241347110020264 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; /** * Interface for functions that accept and return one Object reference. * * Created: Mon Nov 5 22:19:36 2001 * * @author Eric D. Friedman * @version $Id: TObjectFunction.java,v 1.3 2006/11/10 23:27:56 robeden Exp $ */ public interface TObjectFunction { /** * Execute this function with value * * @param value an Object input * @return an Object result */ public R execute(T value); }// TObjectFunction trove-2.1.0/src/gnu/trove/ToObjectArrayProcedure.java0000644000175000017500000000303511241347110021573 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; /** * A procedure which stores each value it receives into a target array. * * Created: Sat Jan 12 10:13:42 2002 * * @author Eric D. Friedman * @version $Id: ToObjectArrayProcedure.java,v 1.2 2006/11/10 23:27:57 robeden Exp $ */ final class ToObjectArrayProcedure implements TObjectProcedure { private final T[] target; private int pos = 0; public ToObjectArrayProcedure(final T[] target) { this.target = target; } public final boolean execute(T value) { target[pos++] = value; return true; } } // ToObjectArrayProcedure trove-2.1.0/src/gnu/trove/TObjectIdentityHashingStrategy.java0000644000175000017500000000406111241347110023303 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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; /** * This object hashing strategy uses the System.identityHashCode * method to provide identity hash codes. These are identical to the * value produced by Object.hashCode(), even when the type of the * object being hashed overrides that method. * * Created: Sat Aug 17 11:13:15 2002 * * @author Eric Friedman * @version $Id: TObjectIdentityHashingStrategy.java,v 1.4 2007/06/11 15:26:44 robeden Exp $ */ public final class TObjectIdentityHashingStrategy implements TObjectHashingStrategy { /** * Delegates hash code computation to the System.identityHashCode(Object) method. * * @param object for which the hashcode is to be computed * @return the hashCode */ public final int computeHashCode(T object) { return System.identityHashCode(object); } /** * Compares object references for equality. * * @param o1 an Object value * @param o2 an Object value * @return true if o1 == o2 */ public final boolean equals(T o1, T o2) { return o1 == o2; } } // TObjectIdentityHashingStrategy trove-2.1.0/src/gnu/trove/TIterator.java0000644000175000017500000000653411241347110017136 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.util.ConcurrentModificationException; import java.util.NoSuchElementException; /** * Abstract iterator class for THash implementations. This class provides some * of the common iterator operations (hasNext(), remove()) and allows subclasses * to define the mechanism(s) for advancing the iterator and returning data. * * @author Eric D. Friedman * @version $Id: TIterator.java,v 1.3 2007/06/29 20:03:10 robeden Exp $ */ abstract class TIterator { /** the data structure this iterator traverses */ protected final THash _hash; /** the number of elements this iterator believes are in the * data structure it accesses. */ protected int _expectedSize; /** the index used for iteration. */ protected int _index; /** * Create an instance of TIterator over the specified THash. */ public TIterator(THash hash) { _hash = hash; _expectedSize = _hash.size(); _index = _hash.capacity(); } /** * Returns true if the iterator can be advanced past its current * location. * * @return a boolean value */ public boolean hasNext() { return nextIndex() >= 0; } /** * Removes the last entry returned by the iterator. * Invoking this method more than once for a single entry * will leave the underlying data structure in a confused * state. */ public void remove() { if (_expectedSize != _hash.size()) { throw new ConcurrentModificationException(); } // Disable auto compaction during the remove. This is a workaround for bug 1642768. try { _hash.tempDisableAutoCompaction(); _hash.removeAt(_index); } finally { _hash.reenableAutoCompaction( false ); } _expectedSize--; } /** * Sets the internal index so that the `next' object * can be returned. */ protected final void moveToNextIndex() { // doing the assignment && < 0 in one line shaves // 3 opcodes... if ((_index = nextIndex()) < 0) { throw new NoSuchElementException(); } } /** * Returns the index of the next value in the data structure * or a negative value if the iterator is exhausted. * * @return an int value */ abstract protected int nextIndex(); } // TIterator trove-2.1.0/src/gnu/trove/TObjectHashingStrategy.java0000644000175000017500000000426711241347110021601 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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.Serializable; /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use object values, values provided by the java runtime, * or a custom strategy when computing hashcodes. * * Created: Sat Aug 17 10:52:32 2002 * * @author Eric Friedman * @version $Id: TObjectHashingStrategy.java,v 1.3 2007/06/11 15:26:44 robeden Exp $ */ public interface TObjectHashingStrategy extends Serializable { /** * Computes a hash code for the specified object. Implementors * can use the object's own hashCode method, the Java * runtime's identityHashCode, or a custom scheme. * * @param object for which the hashcode is to be computed * @return the hashCode */ int computeHashCode(T object); /** * Compares o1 and o2 for equality. Strategy implementors may use * the objects' own equals() methods, compare object references, * or implement some custom scheme. * * @param o1 an Object value * @param o2 an Object value * @return true if the objects are equal according to this strategy. */ boolean equals(T o1, T o2); } // TObjectHashingStrategy trove-2.1.0/src/gnu/trove/TObjectProcedure.java0000644000175000017500000000311011241347110020407 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; /** * Interface for procedures with one Object parameter. * * Created: Mon Nov 5 21:45:49 2001 * * @author Eric D. Friedman * @version $Id: TObjectProcedure.java,v 1.4 2007/11/01 16:08:14 robeden Exp $ */ public interface TObjectProcedure { /** * Executes this procedure. A false return value indicates that * the application executing this procedure should not invoke this * procedure again. * * @param object an Object value * @return true if additional invocations of the procedure are * allowed. */ public boolean execute(T object); }// TObjectProcedure trove-2.1.0/src/gnu/trove/PrimeFinder.java0000644000175000017500000001421311241347110017416 0ustar mkochmkoch// Copyright (c) 1999 CERN - European Organization for Nuclear Research. // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies and // that both that copyright notice and this permission notice appear in // supporting documentation. CERN makes no representations about the // suitability of this software for any purpose. It is provided "as is" // without expressed or implied warranty. package gnu.trove; import java.util.Arrays; /* * Modified for Trove to use the java.util.Arrays sort/search * algorithms instead of those provided with colt. */ /** * Used to keep hash table capacities prime numbers. * Not of interest for users; only for implementors of hashtables. * *

Choosing prime numbers as hash table capacities is a good idea * to keep them working fast, particularly under hash table * expansions. * *

However, JDK 1.2, JGL 3.1 and many other toolkits do nothing to * keep capacities prime. This class provides efficient means to * choose prime capacities. * *

Choosing a prime is O(log 300) (binary search in a list * of 300 ints). Memory requirements: 1 KB static memory. * * @author wolfgang.hoschek@cern.ch * @version 1.0, 09/24/99 */ public final class PrimeFinder { /** * The largest prime this class can generate; currently equal to * Integer.MAX_VALUE. */ public static final int largestPrime = Integer.MAX_VALUE; //yes, it is prime. /** * The prime number list consists of 11 chunks. * * Each chunk contains prime numbers. * * A chunk starts with a prime P1. The next element is a prime * P2. P2 is the smallest prime for which holds: P2 >= 2*P1. * * The next element is P3, for which the same holds with respect * to P2, and so on. * * Chunks are chosen such that for any desired capacity >= 1000 * the list includes a prime number <= desired capacity * 1.11. * * Therefore, primes can be retrieved which are quite close to any * desired capacity, which in turn avoids wasting memory. * * For example, the list includes * 1039,1117,1201,1277,1361,1439,1523,1597,1759,1907,2081. * * So if you need a prime >= 1040, you will find a prime <= * 1040*1.11=1154. * * Chunks are chosen such that they are optimized for a hashtable * growthfactor of 2.0; * * If your hashtable has such a growthfactor then, after initially * "rounding to a prime" upon hashtable construction, it will * later expand to prime capacities such that there exist no * better primes. * * In total these are about 32*10=320 numbers -> 1 KB of static * memory needed. * * If you are stingy, then delete every second or fourth chunk. */ private static final int[] primeCapacities = { //chunk #0 largestPrime, //chunk #1 5,11,23,47,97,197,397,797,1597,3203,6421,12853,25717,51437,102877,205759, 411527,823117,1646237,3292489,6584983,13169977,26339969,52679969,105359939, 210719881,421439783,842879579,1685759167, //chunk #2 433,877,1759,3527,7057,14143,28289,56591,113189,226379,452759,905551,1811107, 3622219,7244441,14488931,28977863,57955739,115911563,231823147,463646329,927292699, 1854585413, //chunk #3 953,1907,3821,7643,15287,30577,61169,122347,244703,489407,978821,1957651,3915341, 7830701,15661423,31322867,62645741,125291483,250582987,501165979,1002331963, 2004663929, //chunk #4 1039,2081,4177,8363,16729,33461,66923,133853,267713,535481,1070981,2141977,4283963, 8567929,17135863,34271747,68543509,137087021,274174111,548348231,1096696463, //chunk #5 31,67,137,277,557,1117,2237,4481,8963,17929,35863,71741,143483,286973,573953, 1147921,2295859,4591721,9183457,18366923,36733847,73467739,146935499,293871013, 587742049,1175484103, //chunk #6 599,1201,2411,4831,9677,19373,38747,77509,155027,310081,620171,1240361,2480729, 4961459,9922933,19845871,39691759,79383533,158767069,317534141,635068283,1270136683, //chunk #7 311,631,1277,2557,5119,10243,20507,41017,82037,164089,328213,656429,1312867, 2625761,5251529,10503061,21006137,42012281,84024581,168049163,336098327,672196673, 1344393353, //chunk #8 3,7,17,37,79,163,331,673,1361,2729,5471,10949,21911,43853,87719,175447,350899, 701819,1403641,2807303,5614657,11229331,22458671,44917381,89834777,179669557, 359339171,718678369,1437356741, //chunk #9 43,89,179,359,719,1439,2879,5779,11579,23159,46327,92657,185323,370661,741337, 1482707,2965421,5930887,11861791,23723597,47447201,94894427,189788857,379577741, 759155483,1518310967, //chunk #10 379,761,1523,3049,6101,12203,24407,48817,97649,195311,390647,781301,1562611, 3125257,6250537,12501169,25002389,50004791,100009607,200019221,400038451,800076929, 1600153859 }; static { //initializer // The above prime numbers are formatted for human readability. // To find numbers fast, we sort them once and for all. Arrays.sort(primeCapacities); } /** * Returns a prime number which is >= desiredCapacity * and very close to desiredCapacity (within 11% if * desiredCapacity >= 1000). * * @param desiredCapacity the capacity desired by the user. * @return the capacity which should be used for a hashtable. */ public static final int nextPrime(int desiredCapacity) { int i = Arrays.binarySearch(primeCapacities, desiredCapacity); if (i<0) { // desired capacity not found, choose next prime greater // than desired capacity i = -i -1; // remember the semantics of binarySearch... } return primeCapacities[i]; } } trove-2.1.0/src/gnu/trove/TLinkable.java0000644000175000017500000000371411241347110017063 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.Serializable; /** * Interface for Objects which can be inserted into a TLinkedList. * *

* Created: Sat Nov 10 15:23:41 2001 *

* * @author Eric D. Friedman * @version $Id: TLinkable.java,v 1.2 2001/12/03 00:16:25 ericdf Exp $ * @see gnu.trove.TLinkedList */ public interface TLinkable extends Serializable { /** * Returns the linked list node after this one. * * @return a TLinkable value */ public TLinkable getNext(); /** * Returns the linked list node before this one. * * @return a TLinkable value */ public TLinkable getPrevious(); /** * Sets the linked list node after this one. * * @param linkable a TLinkable value */ public void setNext(TLinkable linkable); /** * Sets the linked list node before this one. * * @param linkable a TLinkable value */ public void setPrevious(TLinkable linkable); }// TLinkable trove-2.1.0/src/gnu/trove/TObjectHash.java0000644000175000017500000003257111241347110017357 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.util.Arrays; import java.io.ObjectOutput; import java.io.IOException; import java.io.ObjectInput; /** * An open addressed hashing implementation for Object types. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: TObjectHash.java,v 1.27 2009/06/01 22:14:44 robeden Exp $ */ abstract public class TObjectHash extends THash implements TObjectHashingStrategy { static final long serialVersionUID = -3461112548087185871L; /** the set of Objects */ protected transient Object[] _set; /** the strategy used to hash objects in this collection. */ protected TObjectHashingStrategy _hashingStrategy; protected static final Object REMOVED = new Object(), FREE = new Object(); /** * Creates a new TObjectHash instance with the * default capacity and load factor. */ public TObjectHash() { super(); this._hashingStrategy = this; } /** * Creates a new TObjectHash instance with the * default capacity and load factor and a custom hashing strategy. * * @param strategy used to compute hash codes and to compare objects. */ public TObjectHash(TObjectHashingStrategy strategy) { super(); this._hashingStrategy = strategy; } /** * Creates a new TObjectHash instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. * * @param initialCapacity an int value */ public TObjectHash(int initialCapacity) { super(initialCapacity); this._hashingStrategy = this; } /** * Creates a new TObjectHash instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. Uses the specified custom * hashing strategy. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare objects. */ public TObjectHash(int initialCapacity, TObjectHashingStrategy strategy) { super(initialCapacity); this._hashingStrategy = strategy; } /** * Creates a new TObjectHash 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. */ public TObjectHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); this._hashingStrategy = this; } /** * Creates a new TObjectHash instance with a prime * value at or near the specified capacity and load factor. Uses * the specified custom hashing strategy. * * @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 objects. */ public TObjectHash(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { super(initialCapacity, loadFactor); this._hashingStrategy = strategy; } /** * @return a shallow clone of this collection */ public TObjectHash clone() { TObjectHash h = (TObjectHash)super.clone(); h._set = (Object[])this._set.clone(); return h; } protected int capacity() { return _set.length; } protected void removeAt(int index) { _set[index] = REMOVED; super.removeAt(index); } /** * initializes the Object set of this hash table. * * @param initialCapacity an int value * @return an int value */ protected int setUp(int initialCapacity) { int capacity; capacity = super.setUp(initialCapacity); _set = new Object[capacity]; Arrays.fill(_set,FREE); return capacity; } /** * Executes procedure for each element in the set. * * @param procedure a TObjectProcedure value * @return false if the loop over the set terminated because * the procedure returned false for some value. */ public boolean forEach(TObjectProcedure procedure) { Object[] set = _set; for (int i = set.length; i-- > 0;) { if (set[i] != FREE && set[i] != REMOVED && ! procedure.execute((T) set[i])) { return false; } } return true; } /** * Searches the set for obj * * @param obj an Object value * @return a boolean value */ public boolean contains(Object obj) { return index((T) obj) >= 0; } /** * Locates the index of obj. * * @param obj an Object value * @return the index of obj or -1 if it isn't in the set. */ protected int index(T obj) { final TObjectHashingStrategy hashing_strategy = _hashingStrategy; final Object[] set = _set; final int length = set.length; final int hash = hashing_strategy.computeHashCode(obj) & 0x7fffffff; int index = hash % length; Object cur = set[index]; if ( cur == FREE ) return -1; // NOTE: here it has to be REMOVED or FULL (some user-given value) if ( cur == REMOVED || ! hashing_strategy.equals((T) cur, obj)) { // see Knuth, p. 529 final int probe = 1 + (hash % (length - 2)); do { index -= probe; if (index < 0) { index += length; } cur = set[index]; } while (cur != FREE && (cur == REMOVED || ! _hashingStrategy.equals((T) cur, obj))); } return cur == FREE ? -1 : index; } /** * Locates the index at which obj can be inserted. if * there is already a value equal()ing obj in the set, * returns that value's index as -index - 1. * * @param obj an Object value * @return the index of a FREE slot at which obj can be inserted * or, if obj is already stored in the hash, the negative value of * that index, minus 1: -index -1. */ protected int insertionIndex(T obj) { final TObjectHashingStrategy hashing_strategy = _hashingStrategy; final Object[] set = _set; final int length = set.length; final int hash = hashing_strategy.computeHashCode(obj) & 0x7fffffff; int index = hash % length; Object cur = set[index]; if (cur == FREE) { return index; // empty, all done } else if (cur != REMOVED && hashing_strategy.equals((T) cur, obj)) { return -index -1; // already stored } else { // already FULL or REMOVED, must probe // compute the double hash final int probe = 1 + (hash % (length - 2)); // if the slot we landed on is FULL (but not removed), probe // until we find an empty slot, a REMOVED slot, or an element // equal to the one we are trying to insert. // finding an empty slot means that the value is not present // and that we should use that slot as the insertion point; // finding a REMOVED slot means that we need to keep searching, // however we want to remember the offset of that REMOVED slot // so we can reuse it in case a "new" insertion (i.e. not an update) // is possible. // finding a matching value means that we've found that our desired // key is already in the table if (cur != REMOVED) { // starting at the natural offset, probe until we find an // offset that isn't full. do { index -= probe; if (index < 0) { index += length; } cur = set[index]; } while (cur != FREE && cur != REMOVED && ! hashing_strategy.equals((T) cur, obj)); } // if the index we found was removed: continue probing until we // locate a free location or an element which equal()s the // one we have. if (cur == REMOVED) { int firstRemoved = index; while (cur != FREE && (cur == REMOVED || ! hashing_strategy.equals((T) cur, obj))) { index -= probe; if (index < 0) { index += length; } cur = set[index]; } // NOTE: cur cannot == REMOVED in this block return (cur != FREE) ? -index -1 : firstRemoved; } // if it's full, the key is already stored // NOTE: cur cannot equal REMOVE here (would have retuned already (see above) return (cur != FREE) ? -index -1 : index; } } /** * This is the default implementation of TObjectHashingStrategy: * it delegates hashing to the Object's hashCode method. * * @param o for which the hashcode is to be computed * @return the hashCode * @see Object#hashCode() */ public final int computeHashCode(T o) { return o == null ? 0 : o.hashCode(); } /** * This is the default implementation of TObjectHashingStrategy: * it delegates equality comparisons to the first parameter's * equals() method. * * @param o1 an Object value * @param o2 an Object value * @return true if the objects are equal * @see Object#equals(Object) */ public final boolean equals(T o1, T o2) { return o1 == null ? o2 == null : o1.equals(o2); } /** * Convenience methods for subclasses to use in throwing exceptions about * badly behaved user objects employed as keys. We have to throw an * IllegalArgumentException with a rather verbose message telling the * user that they need to fix their object implementation to conform * to the general contract for java.lang.Object. * * @param o1 the first of the equal elements with unequal hash codes. * @param o2 the second of the equal elements with unequal hash codes. * @exception IllegalArgumentException the whole point of this method. */ protected final void throwObjectContractViolation(Object o1, Object o2) throws IllegalArgumentException { throw new IllegalArgumentException("Equal objects must have equal hashcodes. " + "During rehashing, Trove discovered that " + "the following two objects claim to be " + "equal (as in java.lang.Object.equals()) " + "but their hashCodes (or those calculated by " + "your TObjectHashingStrategy) are not equal." + "This violates the general contract of " + "java.lang.Object.hashCode(). See bullet point two " + "in that method's documentation. " + "object #1 =" + o1 + "; object #2 =" + o2); } @Override public void writeExternal( ObjectOutput out ) throws IOException { super.writeExternal( out ); // VERSION out.writeByte( 0 ); // HASHING STRATEGY if ( _hashingStrategy == this ) out.writeObject( null ); else out.writeObject( _hashingStrategy ); } @Override public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { super.readExternal( in ); // VERSION in.readByte(); // HASHING STRATEGY //noinspection unchecked _hashingStrategy = ( TObjectHashingStrategy ) in.readObject(); if ( _hashingStrategy == null ) _hashingStrategy = this; } } // TObjectHash trove-2.1.0/src/gnu/trove/TObjectHashIterator.java0000644000175000017500000000270511241347110021065 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; /** * * Created: Wed Nov 28 21:30:53 2001 * * @author Eric D. Friedman * @version $Id: TObjectHashIterator.java,v 1.2 2006/11/10 23:27:56 robeden Exp $ */ class TObjectHashIterator extends THashIterator { protected final TObjectHash _objectHash; public TObjectHashIterator(TObjectHash hash) { super(hash); _objectHash = hash; } protected E objectAtIndex(int index) { return (E)_objectHash._set[index]; } } // TObjectHashIterator trove-2.1.0/src/gnu/trove/THashSet.java0000644000175000017500000002760111241347110016702 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.*; import java.util.Collection; import java.util.Iterator; import java.util.Set; import java.util.Arrays; import java.lang.reflect.Array; /** * An implementation of the Set interface that uses an * open-addressed hash table to store its contents. * * Created: Sat Nov 3 10:38:17 2001 * * @author Eric D. Friedman * @version $Id: THashSet.java,v 1.21 2008/10/07 20:33:56 robeden Exp $ */ public class THashSet extends TObjectHash implements Set, Iterable, Externalizable { static final long serialVersionUID = 1L; /** * Creates a new THashSet instance with the default * capacity and load factor. */ public THashSet() { super(); } /** * Creates a new THashSet instance with the default * capacity and load factor. * * @param strategy used to compute hash codes and to compare objects. */ public THashSet(TObjectHashingStrategy strategy) { super(strategy); } /** * Creates a new THashSet instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value */ public THashSet(int initialCapacity) { super(initialCapacity); } /** * Creates a new THashSet instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare objects. */ public THashSet(int initialCapacity, TObjectHashingStrategy strategy) { super(initialCapacity, strategy); } /** * Creates a new THashSet instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value */ public THashSet(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Creates a new THashSet instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value * @param strategy used to compute hash codes and to compare objects. */ public THashSet(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { super(initialCapacity, loadFactor, strategy); } /** * Creates a new THashSet instance containing the * elements of collection. * * @param collection a Collection value */ public THashSet(Collection collection) { this(collection.size()); addAll(collection); } /** * Creates a new THashSet instance containing the * elements of collection. * * @param collection a Collection value * @param strategy used to compute hash codes and to compare objects. */ public THashSet(Collection collection, TObjectHashingStrategy strategy) { this(collection.size(), strategy); addAll(collection); } /** * Inserts a value into the set. * * @param obj an Object value * @return true if the set was modified by the add operation */ public boolean add(E obj) { int index = insertionIndex(obj); if (index < 0) { return false; // already present in set, nothing to add } Object old = _set[index]; _set[index] = obj; postInsertHook(old == FREE); return true; // yes, we added something } public boolean equals(Object other) { if (! (other instanceof Set)) { return false; } Set that = (Set)other; if (that.size() != this.size()) { return false; } return containsAll(that); } public int hashCode() { HashProcedure p = new HashProcedure(); forEach(p); return p.getHashCode(); } private final class HashProcedure implements TObjectProcedure { private int h = 0; public int getHashCode() { return h; } public final boolean execute(E key) { h += _hashingStrategy.computeHashCode(key); return true; } } /** * Expands the set to accommodate new values. * * @param newCapacity an int value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; Object oldSet[] = _set; _set = new Object[newCapacity]; Arrays.fill(_set, FREE); for (int i = oldCapacity; i-- > 0;) { if(oldSet[i] != FREE && oldSet[i] != REMOVED) { E o = (E) oldSet[i]; int index = insertionIndex(o); if (index < 0) { // everyone pays for this because some people can't RTFM throwObjectContractViolation(_set[(-index -1)], o); } _set[index] = o; } } } /** * Returns a new array containing the objects in the set. * * @return an Object[] value */ public Object[] toArray() { Object[] result = new Object[size()]; forEach(new ToObjectArrayProcedure(result)); return result; } /** * Returns a typed array of the objects in the set. * * @param a an Object[] value * @return an Object[] value */ public T[] toArray(T[] a) { int size = size(); if (a.length < size) a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); forEach(new ToObjectArrayProcedure(a)); // If this collection fits in the specified array with room to // spare (i.e., the array has more elements than this // collection), the element in the array immediately following // the end of the collection is set to null. This is useful in // determining the length of this collection only if the // caller knows that this collection does not contain any null // elements.) if (a.length > size) { a[size] = null; } return a; } /** * Empties the set. */ public void clear() { super.clear(); Arrays.fill(_set, 0, _set.length, FREE); } /** * Removes obj from the set. * * @param obj an Object value * @return true if the set was modified by the remove operation. */ public boolean remove(Object obj) { int index = index((E) obj); if (index >= 0) { removeAt(index); return true; } return false; } /** * Creates an iterator over the values of the set. The iterator * supports element deletion. * * @return an Iterator value */ public Iterator iterator() { return new TObjectHashIterator(this); } /** * Tests the set to determine if all of the elements in * collection are present. * * @param collection a Collection value * @return true if all elements were present in the set. */ public boolean containsAll(Collection collection) { for (Iterator i = collection.iterator(); i.hasNext();) { if (! contains(i.next())) { return false; } } return true; } /** * Adds all of the elements in collection to the set. * * @param collection a Collection value * @return true if the set was modified by the add all operation. */ public boolean addAll(Collection collection) { boolean changed = false; int size = collection.size(); ensureCapacity(size); Iterator it = collection.iterator(); while (size-- > 0) { if (add(it.next())) { changed = true; } } return changed; } /** * Removes all of the elements in collection from the set. * * @param collection a Collection value * @return true if the set was modified by the remove all operation. */ public boolean removeAll(Collection collection) { boolean changed = false; int size = collection.size(); Iterator it; it = collection.iterator(); while (size-- > 0) { if (remove(it.next())) { changed = true; } } return changed; } /** * Removes any values in the set which are not contained in * collection. * * @param collection a Collection value * @return true if the set was modified by the retain all operation */ public boolean retainAll(Collection collection) { boolean changed = false; int size = size(); Iterator it; it = iterator(); while (size-- > 0) { if (! collection.contains(it.next())) { it.remove(); changed = true; } } return changed; } public String toString() { final StringBuilder buf = new StringBuilder("{"); forEach(new TObjectProcedure() { private boolean first = true; public boolean execute(Object value) { if ( first ) first = false; else buf.append( "," ); buf.append(value); return true; } }); buf.append("}"); return buf.toString(); } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 1 ); // NOTE: Super was not written in version 0 super.writeExternal( out ); // NUMBER OF ENTRIES out.writeInt( _size ); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure( out ); if (! forEach(writeProcedure)) { throw writeProcedure.exception; } } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION byte version = in.readByte(); // NOTE: super was not written in version 0 if ( version != 0 ) super.readExternal( in ); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { E val = (E) in.readObject(); add(val); } } } // THashSet trove-2.1.0/src/gnu/trove/package.html0000644000175000017500000001272111241347110016632 0ustar mkochmkoch GNU Trove API Documentation

GNU Trove: High performance collections for Java.

Objectives

The GNU Trove library has two objectives:

  1. Provide "free" (as in "free speech" and "free beer"), fast, lightweight implementations of the java.util Collections API. These implementations are designed to be pluggable replacements for their JDK equivalents.
  2. Whenever possible, provide the same collections support for primitive types. This gap in the JDK is often addressed by using the "wrapper" classes (java.lang.Integer, java.lang.Float, etc.) with Object-based collections. For most applications, however, collections which store primitives directly will require less space and yield significant performance gains.

Hashtable techniques

The Trove maps/sets use open addressing instead of the chaining approach taken by the JDK hashtables. This eliminates the need to create Map.Entry wrappper objects for every item in a table and so reduces the O (big-oh) in the performance of the hashtable algorithm. The size of the tables used in Trove's maps/sets is always a prime number, improving the probability of an optimal distribution of entries across the table, and so reducing the the likelihood of performance-degrading collisions. Trove sets are not backed by maps, and so using a THashSet does not result in the allocation of an unused "values" array.

Hashing strategies

Trove's maps/sets support the use of custom hashing strategies, allowing you to tune collections based on characteristics of the input data. This feature also allows you to define hash functions when it is not feasible to override Object.hashCode(). For example, the java.lang.String class is final, and its implementation of hashCode() takes O(n) time to complete. In some applications, however, it may be possible for a custom hashing function to save time by skipping portions of the string that are invariant.

Using java.util.HashMap, it is not possible to use Java language arrays as keys. For example, this code:

    char[] foo, bar;
    foo = new char[] {'a','b','c'};
    bar = new char[] {'a','b','c'};
    System.out.println(foo.hashCode() == bar.hashCode() ? "equal" : "not equal");
    System.out.println(foo.equals(bar) ? "equal" : "not equal");
    
produces this output:
    not equal
    not equal
    
And so an entry stored in a java.util.HashMap with foo as a key could not be retrieved with bar, since there is no way to override hashCode() or equals() on language array objects.

In a gnu.trove.THashMap, however, you can implement a TObjectHashingStrategy to enable hashing on arrays:

    class CharArrayStrategy implements TObjectHashingStrategy {
        public int computeHashCode(Object o) {
            char[] c = (char[])o;
            // use the shift-add-xor class of string hashing functions
            // cf. Ramakrishna and Zobel, "Performance in Practice of String Hashing Functions"
            int h = 31; // seed chosen at random
            for (int i = 0; i < c.length; i++) { // could skip invariants
                h = h ^ ((h << 5) + (h >> 2) + c[i]); // L=5, R=2 works well for ASCII input
            }
            return h;
        }

        public boolean equals(Object o1, Object o2) {
            char[] c1 = (char[])o1;
            char[] c2 = (char[])o2;
            if (c1.length != c2.length) { // could drop this check for fixed-length keys
                return false;
            }
            for (int i = 0, len = c1.length; i < len; i++) { // could skip invariants
                if (c1[i] != c2[i]) {
                    return false;
                }
            }
            return true;
        }
    }
    

Iterators in primitive collections

As of release 0.1.7, Trove's primitive mappings include access through Iterators as well as procedures and functions. The API documentation on those classes contains several examples showing how these can be used effectively and explaining why their semantics differ from those of java.util.Iterator.

Miscellaneous

N.B. using Map.entrySet on a Trove Map is supported, but not encouraged. The reason is that this API requires the creation of the Map.Entry Objects that all other parts of Trove manage to avoid. An alternative is to implement the appropriate Procedure interface and use it to invoke the Map's forEachEntry API. Map.keySet and Map.values are not similarly encumbered; nevertheless, the forEachKey, forEachValue, and transformValues APIs will yield slightly better performance at the cost of compatibility with the interface of java.util.Map.


Last modified: Mon Sep 23 18:22:39 PDT 2002 trove-2.1.0/src/gnu/trove/THash.java0000644000175000017500000003157211241347110016230 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.Externalizable; import java.io.ObjectOutput; import java.io.IOException; import java.io.ObjectInput; /** * Base class for hashtables that use open addressing to resolve * collisions. * * Created: Wed Nov 28 21:11:16 2001 * * @author Eric D. Friedman * @author Rob Eden (auto-compaction) * * @version $Id: THash.java,v 1.14 2008/10/08 16:39:10 robeden Exp $ */ abstract public class THash implements Cloneable, Externalizable { static final long serialVersionUID = -1792948471915530295L; /** the load above which rehashing occurs. */ protected static final float DEFAULT_LOAD_FACTOR = 0.5f; /** the default initial capacity for the hash table. This is one * less than a prime value because one is added to it when * searching for a prime capacity to account for the free slot * required by open addressing. Thus, the real default capacity is * 11. */ protected static final int DEFAULT_INITIAL_CAPACITY = 10; /** the current number of occupied slots in the hash. */ protected transient int _size; /** the current number of free slots in the hash. */ protected transient int _free; /** Determines how full the internal table can become before * rehashing is required. This must be a value in the range: 0.0 < * loadFactor < 1.0. The default value is 0.5, which is about as * large as you can get in open addressing without hurting * performance. Cf. Knuth, Volume 3., Chapter 6. */ protected float _loadFactor; /** * The maximum number of elements allowed without allocating more * space. */ protected int _maxSize; /** * The number of removes that should be performed before an auto-compaction occurs. */ protected int _autoCompactRemovesRemaining; /** * The auto-compaction factor for the table. * * @see #setAutoCompactionFactor */ protected float _autoCompactionFactor; /** * @see #tempDisableAutoCompaction */ private transient boolean _autoCompactTemporaryDisable = false; /** * Creates a new THash instance with the default * capacity and load factor. */ public THash() { this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR); } /** * Creates a new THash instance with a prime capacity * at or near the specified capacity and with the default load * factor. * * @param initialCapacity an int value */ public THash(int initialCapacity) { this(initialCapacity, DEFAULT_LOAD_FACTOR); } /** * Creates a new THash instance with a prime capacity * at or near the minimum needed to hold initialCapacity * elements with load factor loadFactor without triggering * a rehash. * * @param initialCapacity an int value * @param loadFactor a float value */ public THash(int initialCapacity, float loadFactor) { super(); _loadFactor = loadFactor; // Through testing, the load factor (especially the default load factor) has been // found to be a pretty good starting auto-compaction factor. _autoCompactionFactor = loadFactor; setUp(HashFunctions.fastCeil(initialCapacity / loadFactor)); } public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException cnse) { return null; // it's supported } } /** * Tells whether this set is currently holding any elements. * * @return a boolean value */ public boolean isEmpty() { return 0 == _size; } /** * Returns the number of distinct elements in this collection. * * @return an int value */ public int size() { return _size; } /** * @return the current physical capacity of the hash table. */ abstract protected int capacity(); /** * Ensure that this hashtable has sufficient capacity to hold * desiredCapacity additional elements without * requiring a rehash. This is a tuning method you can call * before doing a large insert. * * @param desiredCapacity an int value */ public void ensureCapacity(int desiredCapacity) { if (desiredCapacity > (_maxSize - size())) { rehash(PrimeFinder.nextPrime(HashFunctions.fastCeil( (desiredCapacity + size()) / _loadFactor) + 1)); computeMaxSize(capacity()); } } /** * Compresses the hashtable to the minimum prime size (as defined * by PrimeFinder) that will hold all of the elements currently in * the table. If you have done a lot of remove * operations and plan to do a lot of queries or insertions or * iteration, it is a good idea to invoke this method. Doing so * will accomplish two things: * *
    *
  1. You'll free memory allocated to the table but no * longer needed because of the remove()s.
  2. * *
  3. You'll get better query/insert/iterator performance * because there won't be any REMOVED slots to skip * over when probing for indices in the table.
  4. *
*/ public void compact() { // need at least one free spot for open addressing rehash(PrimeFinder.nextPrime(HashFunctions.fastCeil(size()/_loadFactor) + 1)); computeMaxSize(capacity()); // If auto-compaction is enabled, re-determine the compaction interval if ( _autoCompactionFactor != 0 ) { computeNextAutoCompactionAmount(size()); } } /** * The auto-compaction factor controls whether and when a table performs a * {@link #compact} automatically after a certain number of remove operations. * If the value is non-zero, the number of removes that need to occur for * auto-compaction is the size of table at the time of the previous compaction * (or the initial capacity) multiplied by this factor. *

* Setting this value to zero will disable auto-compaction. */ public void setAutoCompactionFactor( float factor ) { if ( factor < 0 ) { throw new IllegalArgumentException( "Factor must be >= 0: " + factor ); } _autoCompactionFactor = factor; } /** * @see #setAutoCompactionFactor */ public float getAutoCompactionFactor() { return _autoCompactionFactor; } /** * This simply calls {@link #compact compact}. It is included for * symmetry with other collection classes. Note that the name of this * method is somewhat misleading (which is why we prefer * compact) as the load factor may require capacity above * and beyond the size of this collection. * * @see #compact */ public final void trimToSize() { compact(); } /** * Delete the record at index. Reduces the size of the * collection by one. * * @param index an int value */ protected void removeAt(int index) { _size--; // If auto-compaction is enabled, see if we need to compact if ( _autoCompactionFactor != 0 ) { _autoCompactRemovesRemaining--; if ( !_autoCompactTemporaryDisable && _autoCompactRemovesRemaining <= 0 ) { // Do the compact // NOTE: this will cause the next compaction interval to be calculated compact(); } } } /** * Empties the collection. */ public void clear() { _size = 0; _free = capacity(); } /** * initializes the hashtable to a prime capacity which is at least * initialCapacity + 1. * * @param initialCapacity an int value * @return the actual capacity chosen */ protected int setUp(int initialCapacity) { int capacity; capacity = PrimeFinder.nextPrime(initialCapacity); computeMaxSize(capacity); computeNextAutoCompactionAmount(initialCapacity); return capacity; } /** * Rehashes the set. * * @param newCapacity an int value */ protected abstract void rehash(int newCapacity); /** * Temporarily disables auto-compaction. MUST be followed by calling * {@link #reenableAutoCompaction}. */ protected void tempDisableAutoCompaction() { _autoCompactTemporaryDisable = true; } /** * Re-enable auto-compaction after it was disabled via * {@link #tempDisableAutoCompaction()}. * * @param check_for_compaction True if compaction should be performed if needed * before returning. If false, no compaction will be * performed. */ protected void reenableAutoCompaction( boolean check_for_compaction ) { _autoCompactTemporaryDisable = false; if ( check_for_compaction && _autoCompactRemovesRemaining <= 0 && _autoCompactionFactor != 0 ) { // Do the compact // NOTE: this will cause the next compaction interval to be calculated compact(); } } /** * Computes the values of maxSize. There will always be at least * one free slot required. * * @param capacity an int value */ private void computeMaxSize(int capacity) { // need at least one free slot for open addressing _maxSize = Math.min(capacity - 1, (int) (capacity * _loadFactor)); _free = capacity - _size; // reset the free element count } /** * Computes the number of removes that need to happen before the next auto-compaction * will occur. */ private void computeNextAutoCompactionAmount( int size ) { if ( _autoCompactionFactor != 0 ) { // NOTE: doing the round ourselves has been found to be faster than using // Math.round. _autoCompactRemovesRemaining = ( int ) ( ( size * _autoCompactionFactor ) + 0.5f ); } } /** * After an insert, this hook is called to adjust the size/free * values of the set and to perform rehashing if necessary. */ protected final void postInsertHook(boolean usedFreeSlot) { if (usedFreeSlot) { _free--; } // rehash whenever we exhaust the available space in the table if (++_size > _maxSize || _free == 0) { // choose a new capacity suited to the new state of the table // if we've grown beyond our maximum size, double capacity; // if we've exhausted the free spots, rehash to the same capacity, // which will free up any stale removed slots for reuse. int newCapacity = _size > _maxSize ? PrimeFinder.nextPrime(capacity() << 1) : capacity(); rehash(newCapacity); computeMaxSize(capacity()); } } protected int calculateGrownCapacity() { return capacity() << 1; } public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte( 0 ); // LOAD FACTOR out.writeFloat( _loadFactor ); // AUTO COMPACTION LOAD FACTOR out.writeFloat( _autoCompactionFactor ); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // LOAD FACTOR float old_factor = _loadFactor; _loadFactor = in.readFloat(); // AUTO COMPACTION LOAD FACTOR _autoCompactionFactor = in.readFloat(); // If we change the laod factor from the default, re-setup if ( old_factor != _loadFactor ) { setUp((int)Math.ceil(DEFAULT_INITIAL_CAPACITY / _loadFactor)); } } }// THash trove-2.1.0/src/gnu/trove/HashFunctions.java0000644000175000017500000000551111241347110017767 0ustar mkochmkoch// Copyright (c) 1999 CERN - European Organization for Nuclear Research. // Permission to use, copy, modify, distribute and sell this software and // its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies and that // both that copyright notice and this permission notice appear in // supporting documentation. CERN makes no representations about the // suitability of this software for any purpose. It is provided "as is" // without expressed or implied warranty. package gnu.trove; /** * Provides various hash functions. * * @author wolfgang.hoschek@cern.ch * @version 1.0, 09/24/99 */ public final class HashFunctions { /** * Returns a hashcode for the specified value. * * @return a hash code value for the specified value. */ public static int hash(double value) { assert !Double.isNaN(value) : "Values of NaN are not supported."; long bits = Double.doubleToLongBits(value); return (int)(bits ^ (bits >>> 32)); //return (int) Double.doubleToLongBits(value*663608941.737); //this avoids excessive hashCollisions in the case values are //of the form (1.0, 2.0, 3.0, ...) } /** * Returns a hashcode for the specified value. * * @return a hash code value for the specified value. */ public static int hash(float value) { assert !Float.isNaN(value) : "Values of NaN are not supported."; return Float.floatToIntBits(value*663608941.737f); // this avoids excessive hashCollisions in the case values are // of the form (1.0, 2.0, 3.0, ...) } /** * Returns a hashcode for the specified value. * * @return a hash code value for the specified value. */ public static int hash(int value) { // Multiply by prime to make sure hash can't be negative (see Knuth v3, p. 515-516) return value * 31; } /** * Returns a hashcode for the specified value. * * @return a hash code value for the specified value. */ public static int hash(long value) { // Multiply by prime to make sure hash can't be negative (see Knuth v3, p. 515-516) return ((int)(value ^ (value >>> 32))) * 31; } /** * Returns a hashcode for the specified object. * * @return a hash code value for the specified object. */ public static int hash(Object object) { return object==null ? 0 : object.hashCode(); } /** * In profiling, it has been found to be faster to have our own local implementation * of "ceil" rather than to call to {@link Math#ceil(double)}. */ static int fastCeil( float v ) { int possible_result = ( int ) v; if ( v - possible_result > 0 ) possible_result++; return possible_result; } } trove-2.1.0/src/gnu/trove/TPrimitiveHash.java0000644000175000017500000001032311241347110020110 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; /** * The base class for hashtables of primitive values. Since there is * no notion of object equality for primitives, it isn't possible to * use a `REMOVED' object to track deletions in an open-addressed table. * So, we have to resort to using a parallel `bookkeeping' array of bytes, * in which flags can be set to indicate that a particular slot in the * hash table is FREE, FULL, or REMOVED. * * Created: Fri Jan 11 18:55:16 2002 * * @author Eric D. Friedman * @version $Id: TPrimitiveHash.java,v 1.5 2008/10/08 16:39:10 robeden Exp $ */ abstract public class TPrimitiveHash extends THash { /** flags indicating whether each position in the hash is * FREE, FULL, or REMOVED */ protected transient byte[] _states; /* constants used for state flags */ /** flag indicating that a slot in the hashtable is available */ protected static final byte FREE = 0; /** flag indicating that a slot in the hashtable is occupied */ protected static final byte FULL = 1; /** flag indicating that the value of a slot in the hashtable * was deleted */ protected static final byte REMOVED = 2; /** * Creates a new THash instance with the default * capacity and load factor. */ public TPrimitiveHash() { super(); } /** * Creates a new TPrimitiveHash instance with a prime * capacity at or near the specified capacity and with the default * load factor. * * @param initialCapacity an int value */ public TPrimitiveHash(int initialCapacity) { this(initialCapacity, DEFAULT_LOAD_FACTOR); } /** * Creates a new TPrimitiveHash instance with a prime * capacity at or near the minimum needed to hold * initialCapacity elements with load factor * loadFactor without triggering a rehash. * * @param initialCapacity an int value * @param loadFactor a float value */ public TPrimitiveHash(int initialCapacity, float loadFactor) { super(); _loadFactor = loadFactor; setUp(HashFunctions.fastCeil(initialCapacity / loadFactor)); } public Object clone() { TPrimitiveHash h = (TPrimitiveHash)super.clone(); h._states = (byte[])this._states.clone(); return h; } /** * Returns the capacity of the hash table. This is the true * physical capacity, without adjusting for the load factor. * * @return the physical capacity of the hash table. */ protected int capacity() { return _states.length; } /** * Delete the record at index. * * @param index an int value */ protected void removeAt(int index) { _states[index] = REMOVED; super.removeAt(index); } /** * initializes the hashtable to a prime capacity which is at least * initialCapacity + 1. * * @param initialCapacity an int value * @return the actual capacity chosen */ protected int setUp(int initialCapacity) { int capacity; capacity = super.setUp(initialCapacity); _states = new byte[capacity]; return capacity; } } // TPrimitiveHash trove-2.1.0/src/gnu/trove/generate/0000755000175000017500000000000011261456735016160 5ustar mkochmkochtrove-2.1.0/src/gnu/trove/generate/PArrayList.template0000644000175000017500000006510711241347110021740 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Arrays; import java.util.Random; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * A resizable, array-backed list of #e# primitives. * * Created: Sat Dec 29 14:21:12 2001 * * @author Eric D. Friedman * @author Rob Eden */ public class T#E#ArrayList implements Externalizable, Cloneable { static final long serialVersionUID = 1L; /** the data of the list */ protected #e#[] _data; /** the index after the last entry in the list */ protected int _pos; /** the default capacity for new lists */ protected static final int DEFAULT_CAPACITY = 10; /** * Creates a new T#E#ArrayList instance with the * default capacity. */ public T#E#ArrayList() { this(DEFAULT_CAPACITY); } /** * Creates a new T#E#ArrayList instance with the * specified capacity. * * @param capacity an int value */ public T#E#ArrayList(int capacity) { _data = new #e#[capacity]; _pos = 0; } /** * Creates a new T#E#ArrayList instance whose * capacity is the greater of the length of values and * DEFAULT_CAPACITY and whose initial contents are the specified * values. * * @param values an #e#[] value */ public T#E#ArrayList(#e#[] values) { this(Math.max(values.length, DEFAULT_CAPACITY)); add(values); } // sizing /** * Grow the internal array as needed to accommodate the specified * number of elements. The size of the array #e#s on each * resize unless capacity requires more than twice the * current capacity. * * @param capacity an int value */ public void ensureCapacity(int capacity) { if (capacity > _data.length) { int newCap = Math.max(_data.length << 1, capacity); #e#[] tmp = new #e#[newCap]; System.arraycopy(_data, 0, tmp, 0, _data.length); _data = tmp; } } /** * Returns the number of values in the list. * * @return the number of values in the list. */ public int size() { return _pos; } /** * Tests whether this list contains any values. * * @return true if the list is empty. */ public boolean isEmpty() { return _pos == 0; } /** * Sheds any excess capacity above and beyond the current size of * the list. */ public void trimToSize() { if (_data.length > size()) { #e#[] tmp = new #e#[size()]; toNativeArray(tmp, 0, tmp.length); _data = tmp; } } // modifying /** * Adds val to the end of the list, growing as needed. * * @param val an #e# value */ public void add(#e# val) { ensureCapacity(_pos + 1); _data[_pos++] = val; } /** * Adds the values in the array vals to the end of the * list, in order. * * @param vals an #e#[] value */ public void add(#e#[] vals) { add(vals, 0, vals.length); } /** * Adds a subset of the values in the array vals to the * end of the list, in order. * * @param vals an #e#[] value * @param offset the offset at which to start copying * @param length the number of values to copy. */ public void add(#e#[] vals, int offset, int length) { ensureCapacity(_pos + length); System.arraycopy(vals, offset, _data, _pos, length); _pos += length; } /** * Inserts value into the list at offset. All * values including and to the right of offset are shifted * to the right. * * @param offset an int value * @param value an #e# value */ public void insert(int offset, #e# value) { if (offset == _pos) { add(value); return; } ensureCapacity(_pos + 1); // shift right System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); // insert _data[offset] = value; _pos++; } /** * Inserts the array of values into the list at * offset. All values including and to the right of * offset are shifted to the right. * * @param offset an int value * @param values an #e#[] value */ public void insert(int offset, #e#[] values) { insert(offset, values, 0, values.length); } /** * Inserts a slice of the array of values into the list * at offset. All values including and to the right of * offset are shifted to the right. * * @param offset an int value * @param values an #e#[] value * @param valOffset the offset in the values array at which to * start copying. * @param len the number of values to copy from the values array */ public void insert(int offset, #e#[] values, int valOffset, int len) { if (offset == _pos) { add(values, valOffset, len); return; } ensureCapacity(_pos + len); // shift right System.arraycopy(_data, offset, _data, offset + len, _pos - offset); // insert System.arraycopy(values, valOffset, _data, offset, len); _pos += len; } /** * Returns the value at the specified offset. * * @param offset an int value * @return an #e# value */ public #e# get(int offset) { if (offset >= _pos) { throw new ArrayIndexOutOfBoundsException(offset); } return _data[offset]; } /** * Returns the value at the specified offset without doing any * bounds checking. * * @param offset an int value * @return an #e# value */ public #e# getQuick(int offset) { return _data[offset]; } /** * Sets the value at the specified offset. * * @param offset an int value * @param val an #e# value */ public void set(int offset, #e# val) { if (offset >= _pos) { throw new ArrayIndexOutOfBoundsException(offset); } _data[offset] = val; } /** * Sets the value at the specified offset and returns the * previously stored value. * * @param offset an int value * @param val an #e# value * @return the value previously stored at offset. */ public #e# getSet(int offset, #e# val) { if (offset >= _pos) { throw new ArrayIndexOutOfBoundsException(offset); } #e# old = _data[offset]; _data[offset] = val; return old; } /** * Replace the values in the list starting at offset with * the contents of the values array. * * @param offset the first offset to replace * @param values the source of the new values */ public void set(int offset, #e#[] values) { set(offset, values, 0, values.length); } /** * Replace the values in the list starting at offset with * length values from the values array, starting * at valOffset. * * @param offset the first offset to replace * @param values the source of the new values * @param valOffset the first value to copy from the values array * @param length the number of values to copy */ public void set(int offset, #e#[] values, int valOffset, int length) { if (offset < 0 || offset + length > _pos) { throw new ArrayIndexOutOfBoundsException(offset); } System.arraycopy(values, valOffset, _data, offset, length); } /** * Sets the value at the specified offset without doing any bounds * checking. * * @param offset an int value * @param val an #e# value */ public void setQuick(int offset, #e# val) { _data[offset] = val; } /** * Flushes the internal state of the list, resetting the capacity * to the default. */ public void clear() { clear(DEFAULT_CAPACITY); } /** * Flushes the internal state of the list, setting the capacity of * the empty list to capacity. * * @param capacity an int value */ public void clear(int capacity) { _data = new #e#[capacity]; _pos = 0; } /** * Sets the size of the list to 0, but does not change its * capacity. This method can be used as an alternative to the * {@link #clear clear} method if you want to recyle a list without * allocating new backing arrays. * * @see #clear */ public void reset() { _pos = 0; fill((#e#)0); } /** * Sets the size of the list to 0, but does not change its * capacity. This method can be used as an alternative to the * {@link #clear clear} method if you want to recyle a list * without allocating new backing arrays. This method differs * from {@link #reset reset} in that it does not clear the old * values in the backing array. Thus, it is possible for {@link * #getQuick getQuick} to return stale data if this method is used * and the caller is careless about bounds checking. * * @see #reset * @see #clear * @see #getQuick */ public void resetQuick() { _pos = 0; } /** * Removes the value at offset from the list. * * @param offset an int value * @return the value previously stored at offset. */ public #e# remove(int offset) { #e# old = get(offset); remove(offset, 1); return old; } /** * Removes length values from the list, starting at * offset * * @param offset an int value * @param length an int value */ public void remove(int offset, int length) { if (offset < 0 || offset >= _pos) { throw new ArrayIndexOutOfBoundsException(offset); } if (offset == 0) { // data at the front System.arraycopy(_data, length, _data, 0, _pos - length); } else if (_pos - length == offset) { // no copy to make, decrementing pos "deletes" values at // the end } else { // data in the middle System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); } _pos -= length; // no need to clear old values beyond _pos, because this is a // primitive collection and 0 takes as much room as any other // value } /** * Transform each value in the list using the specified function. * * @param function a T#E#Function value */ public void transformValues(T#E#Function function) { for (int i = _pos; i-- > 0;) { _data[i] = function.execute(_data[i]); } } /** * Reverse the order of the elements in the list. */ public void reverse() { reverse(0, _pos); } /** * Reverse the order of the elements in the range of the list. * * @param from the inclusive index at which to start reversing * @param to the exclusive index at which to stop reversing */ public void reverse(int from, int to) { if (from == to) { return; // nothing to do } if (from > to) { throw new IllegalArgumentException("from cannot be greater than to"); } for (int i = from, j = to - 1; i < j; i++, j--) { swap(i, j); } } /** * Shuffle the elements of the list using the specified random * number generator. * * @param rand a Random value */ public void shuffle(Random rand) { for (int i = _pos; i-- > 1;) { swap(i, rand.nextInt(i)); } } /** * Swap the values at offsets i and j. * * @param i an offset into the data array * @param j an offset into the data array */ private final void swap(int i, int j) { #e# tmp = _data[i]; _data[i] = _data[j]; _data[j] = tmp; } // copying /** * Returns a clone of this list. Since this is a primitive * collection, this will be a deep clone. * * @return a deep clone of the list. */ public Object clone() { T#E#ArrayList list = null; try { list = (T#E#ArrayList) super.clone(); list._data = toNativeArray(); } catch (CloneNotSupportedException e) { // it's supported } // end of try-catch return list; } /** * Returns a sublist of this list. * * @param begin low endpoint (inclusive) of the subList. * @param end high endpoint (exclusive) of the subList. * @return sublist of this list from begin, inclusive to end, exclusive. * @throws IndexOutOfBoundsException - endpoint out of range * @throws IllegalArgumentException - endpoints out of order (end > begin) */ public T#E#ArrayList subList(int begin, int end) { if (end < begin) throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); if (begin < 0) throw new IndexOutOfBoundsException("begin index can not be < 0"); if (end > _data.length) throw new IndexOutOfBoundsException("end index < " + _data.length); T#E#ArrayList list = new T#E#ArrayList(end - begin); for (int i = begin; i < end; i++) { list.add(_data[i]); } return list; } /** * Copies the contents of the list into a native array. * * @return an #e#[] value */ public #e#[] toNativeArray() { return toNativeArray(0, _pos); } /** * Copies a slice of the list into a native array. * * @param offset the offset at which to start copying * @param len the number of values to copy. * @return an #e#[] value */ public #e#[] toNativeArray(int offset, int len) { #e#[] rv = new #e#[len]; toNativeArray(rv, offset, len); return rv; } /** * Copies a slice of the list into a native array. * * @param dest the array to copy into. * @param offset the offset of the first value to copy * @param len the number of values to copy. */ public void toNativeArray(#e#[] dest, int offset, int len) { if (len == 0) { return; // nothing to copy } if (offset < 0 || offset >= _pos) { throw new ArrayIndexOutOfBoundsException(offset); } System.arraycopy(_data, offset, dest, 0, len); } // comparing /** * Compares this list to another list, value by value. * * @param other the object to compare against * @return true if other is a T#E#ArrayList and has exactly the * same values. */ public boolean equals(Object other) { if (other == this) { return true; } else if (other instanceof T#E#ArrayList) { T#E#ArrayList that = (T#E#ArrayList)other; if (that.size() != this.size()) { return false; } else { for (int i = _pos; i-- > 0;) { if (this._data[i] != that._data[i]) { return false; } } return true; } } else { return false; } } public int hashCode() { int h = 0; for (int i = _pos; i-- > 0;) { h = 37 * h + HashFunctions.hash(_data[i]); } return h; } // procedures /** * Applies the procedure to each value in the list in ascending * (front to back) order. * * @param procedure a T#E#Procedure value * @return true if the procedure did not terminate prematurely. */ public boolean forEach(T#E#Procedure procedure) { for (int i = 0; i < _pos; i++) { if (! procedure.execute(_data[i])) { return false; } } return true; } /** * Applies the procedure to each value in the list in descending * (back to front) order. * * @param procedure a T#E#Procedure value * @return true if the procedure did not terminate prematurely. */ public boolean forEachDescending(T#E#Procedure procedure) { for (int i = _pos; i-- > 0;) { if (! procedure.execute(_data[i])) { return false; } } return true; } // sorting /** * Sort the values in the list (ascending) using the Sun quicksort * implementation. * * @see java.util.Arrays#sort */ public void sort() { Arrays.sort(_data, 0, _pos); } /** * Sort a slice of the list (ascending) using the Sun quicksort * implementation. * * @param fromIndex the index at which to start sorting (inclusive) * @param toIndex the index at which to stop sorting (exclusive) * @see java.util.Arrays#sort */ public void sort(int fromIndex, int toIndex) { Arrays.sort(_data, fromIndex, toIndex); } // filling /** * Fills every slot in the list with the specified value. * * @param val the value to use when filling */ public void fill(#e# val) { Arrays.fill(_data, 0, _pos, val); } /** * Fills a range in the list with the specified value. * * @param fromIndex the offset at which to start filling (inclusive) * @param toIndex the offset at which to stop filling (exclusive) * @param val the value to use when filling */ public void fill(int fromIndex, int toIndex, #e# val) { if (toIndex > _pos) { ensureCapacity(toIndex); _pos = toIndex; } Arrays.fill(_data, fromIndex, toIndex, val); } // searching /** * Performs a binary search for value in the entire list. * Note that you must @{link #sort sort} the list before * doing a search. * * @param value the value to search for * @return the absolute offset in the list of the value, or its * negative insertion point into the sorted list. */ public int binarySearch(#e# value) { return binarySearch(value, 0, _pos); } /** * Performs a binary search for value in the specified * range. Note that you must @{link #sort sort} the list * or the range before doing a search. * * @param value the value to search for * @param fromIndex the lower boundary of the range (inclusive) * @param toIndex the upper boundary of the range (exclusive) * @return the absolute offset in the list of the value, or its * negative insertion point into the sorted list. */ public int binarySearch(#e# value, int fromIndex, int toIndex) { if (fromIndex < 0) { throw new ArrayIndexOutOfBoundsException(fromIndex); } if (toIndex > _pos) { throw new ArrayIndexOutOfBoundsException(toIndex); } int low = fromIndex; int high = toIndex - 1; while (low <= high) { int mid = (low + high) >>> 1; #e# midVal = _data[mid]; if (midVal < value) { low = mid + 1; } else if (midVal > value) { high = mid - 1; } else { return mid; // value found } } return -(low + 1); // value not found. } /** * Searches the list front to back for the index of * value. * * @param value an #e# value * @return the first offset of the value, or -1 if it is not in * the list. * @see #binarySearch for faster searches on sorted lists */ public int indexOf(#e# value) { return indexOf(0, value); } /** * Searches the list front to back for the index of * value, starting at offset. * * @param offset the offset at which to start the linear search * (inclusive) * @param value an #e# value * @return the first offset of the value, or -1 if it is not in * the list. * @see #binarySearch for faster searches on sorted lists */ public int indexOf(int offset, #e# value) { for (int i = offset; i < _pos; i++) { if (_data[i] == value) { return i; } } return -1; } /** * Searches the list back to front for the last index of * value. * * @param value an #e# value * @return the last offset of the value, or -1 if it is not in * the list. * @see #binarySearch for faster searches on sorted lists */ public int lastIndexOf(#e# value) { return lastIndexOf(_pos, value); } /** * Searches the list back to front for the last index of * value, starting at offset. * * @param offset the offset at which to start the linear search * (exclusive) * @param value an #e# value * @return the last offset of the value, or -1 if it is not in * the list. * @see #binarySearch for faster searches on sorted lists */ public int lastIndexOf(int offset, #e# value) { for (int i = offset; i-- > 0;) { if (_data[i] == value) { return i; } } return -1; } /** * Searches the list for value * * @param value an #e# value * @return true if value is in the list. */ public boolean contains(#e# value) { return lastIndexOf(value) >= 0; } /** * Searches the list for values satisfying condition in * the manner of the *nix grep utility. * * @param condition a condition to apply to each element in the list * @return a list of values which match the condition. */ public T#E#ArrayList grep(T#E#Procedure condition) { T#E#ArrayList list = new T#E#ArrayList(); for (int i = 0; i < _pos; i++) { if (condition.execute(_data[i])) { list.add(_data[i]); } } return list; } /** * Searches the list for values which do not satisfy * condition. This is akin to *nix grep -v. * * @param condition a condition to apply to each element in the list * @return a list of values which do not match the condition. */ public T#E#ArrayList inverseGrep(T#E#Procedure condition) { T#E#ArrayList list = new T#E#ArrayList(); for (int i = 0; i < _pos; i++) { if (! condition.execute(_data[i])) { list.add(_data[i]); } } return list; } /** * Finds the maximum value in the list. * * @return the largest value in the list. * @exception IllegalStateException if the list is empty */ public #e# max() { if (size() == 0) { throw new IllegalStateException("cannot find maximum of an empty list"); } #e# max = #EMIN#; for (int i = 0; i < _pos; i++ ) { if ( _data[i] > max ) { max = _data[i]; } } return max; } /** * Finds the minimum value in the list. * * @return the smallest value in the list. * @exception IllegalStateException if the list is empty */ public #e# min() { if (size() == 0) { throw new IllegalStateException("cannot find minimum of an empty list"); } #e# min = #EMAX#; for (int i = 0; i < _pos; i++ ) { if ( _data[i] < min ) { min = _data[i]; } } return min; } // stringification /** * Returns a String representation of the list, front to back. * * @return a String value */ public String toString() { final StringBuilder buf = new StringBuilder("{"); for (int i = 0, end = _pos - 1; i < end; i++) { buf.append(_data[i]); buf.append(", "); } if (size() > 0) { buf.append(_data[_pos - 1]); } buf.append("}"); return buf.toString(); } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 1 ); // POSITION out.writeInt( _pos ); // ENTRIES int len = _pos; out.writeInt( _pos ); // Written twice for backwards compatability with // version 0 for( int i = 0; i < len; i++ ) { out.write#E#( _data[ i ] ); } } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // POSITION _pos = in.readInt(); // ENTRIES int len = in.readInt(); _data = new #e#[ len ]; for( int i = 0; i < len; i++ ) { _data[ i ] = in.read#E#(); } } } // T#E#ArrayList trove-2.1.0/src/gnu/trove/generate/Generate.java0000644000175000017500000004410611241347110020542 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.generate; import java.io.*; import java.util.regex.Pattern; import java.util.Arrays; import java.util.Map; import java.util.HashMap; import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * Generates classes that are created from templates. The "*.template" files must be in * the classpath (because Class.getResource() is used to load the files). */ public class Generate { private static final String P2P_MAP_DECORATOR_NAME = "P2PMapDecorator.template"; private static final String DECORATORS_CLASS_TEMP = "Decorators.template"; private static final WrapperInfo[] WRAPPERS = new WrapperInfo[] { new WrapperInfo( "double", "Double", "POSITIVE_INFINITY", "NEGATIVE_INFINITY" ), new WrapperInfo( "float", "Float", "POSITIVE_INFINITY", "NEGATIVE_INFINITY" ), new WrapperInfo( "int", "Integer", "MAX_VALUE", "MIN_VALUE" ), new WrapperInfo( "long", "Long", "MAX_VALUE", "MIN_VALUE" ), new WrapperInfo( "byte", "Byte", "MAX_VALUE", "MIN_VALUE" ), new WrapperInfo( "short", "Short", "MAX_VALUE", "MIN_VALUE" ) }; public static void main(String[] args) throws IOException { if ( args.length == 0 ) { System.out.println( "Usage: Generate " ); return; } File input_path = new File(args[ 0 ]); File output_path = new File(args[ 1 ]); System.out.println("File: " + output_path.getAbsolutePath()); if (!output_path.exists()) { System.err.println("\"" + output_path + "\" does not exist"); return; } generateP2PMapDecorators(input_path,output_path); // Decorators generate("P2OMapDecorator.template", "decorator/T", "ObjectHashMapDecorator.java", input_path, output_path); generate("O2PMapDecorator.template", "decorator/TObject", "HashMapDecorator.java", input_path, output_path); generate("PHashSetDecorator.template", "decorator/T", "HashSetDecorator.java", input_path, output_path); generateDecoratorsClass(input_path, output_path); // Iterators generate("O2PIterator.template", "TObject", "Iterator.java", input_path, output_path); generate("P2OIterator.template", "T", "ObjectIterator.java", input_path, output_path); generateP2P("P2PIterator.template", "T", "Iterator.java", input_path, output_path); generate("PIterator.template", "T", "Iterator.java", input_path, output_path); // Procedures generate("O2PProcedure.template", "TObject", "Procedure.java", input_path, output_path); generate("P2OProcedure.template", "T", "ObjectProcedure.java", input_path, output_path); generateP2P("P2PProcedure.template", "T", "Procedure.java", input_path, output_path); generate("PProcedure.template", "T", "Procedure.java", input_path, output_path); // Functions generate("PFunction.template", "T", "Function.java", input_path, output_path); // Hashing Strategy interfaces generate("PHashingStrategy.template", "T", "HashingStrategy.java", input_path, output_path); // Hash abstract classes generate("PHash.template", "T", "Hash.java", input_path, output_path); // HashMaps generate("P2OHashMap.template", "T", "ObjectHashMap.java", input_path, output_path); generate("O2PHashMap.template", "TObject", "HashMap.java", input_path, output_path); generateP2P("P2PHashMap.template", "T", "HashMap.java", input_path, output_path); // ArrayLists generate( "PArrayList.template", "T", "ArrayList.java", input_path, output_path); // HashSets generate( "PHashSet.template", "T", "HashSet.java", input_path, output_path); // Stacks generate( "PStack.template", "T", "Stack.java", input_path, output_path); System.out.println( "Generation complete." ); } private static void generate(String templateName, String pathPrefix, String pathSuffix, File input_path, File output_path) throws IOException { String template = readFile(templateName, input_path); for (int i = 0; i < WRAPPERS.length; i++) { WrapperInfo info = WRAPPERS[ i ]; String e = info.primitive; String ET = info.class_name; String E = shortInt(ET); String EMAX = info.max_value; String EMIN = info.min_value; String out = template; out = Pattern.compile("#e#").matcher(out).replaceAll(e); out = Pattern.compile("#E#").matcher(out).replaceAll(E); out = Pattern.compile("#ET#").matcher(out).replaceAll(ET); out = Pattern.compile("#EMAX#").matcher(out).replaceAll(EMAX); out = Pattern.compile("#EMIN#").matcher(out).replaceAll(EMIN); String outFile = pathPrefix + E + pathSuffix; writeFile(outFile, out, output_path); } } private static void generateP2P(String templateName, String pathPrefix, String pathSuffix, File input_path, File output_path) throws IOException { String template = readFile(templateName, input_path); for (int i = 0; i < WRAPPERS.length; i++) { WrapperInfo info = WRAPPERS[ i ]; String e = info.primitive; String ET = info.class_name; String E = shortInt(ET); String EMAX = info.max_value; String EMIN = info.min_value; for (int j = 0; j < WRAPPERS.length; j++) { String out = template; out = Pattern.compile("#e#").matcher(out).replaceAll(e); out = Pattern.compile("#E#").matcher(out).replaceAll(E); out = Pattern.compile("#ET#").matcher(out).replaceAll(ET); out = Pattern.compile("#EMAX#").matcher(out).replaceAll(EMAX); out = Pattern.compile("#EMIN#").matcher(out).replaceAll(EMIN); WrapperInfo jinfo = WRAPPERS[ j ]; String f = jinfo.primitive; String FT = jinfo.class_name; String F = shortInt(FT); String FMAX = jinfo.max_value; String FMIN = jinfo.min_value; out = Pattern.compile("#f#").matcher(out).replaceAll(f); out = Pattern.compile("#F#").matcher(out).replaceAll(F); out = Pattern.compile("#FT#").matcher(out).replaceAll(FT); out = Pattern.compile("#FMAX#").matcher(out).replaceAll(FMAX); out = Pattern.compile("#FMIN#").matcher(out).replaceAll(FMIN); String outFile = pathPrefix + E + F + pathSuffix; writeFile(outFile, out, output_path); } } } private static void generateP2PMapDecorators(File input_path, File output_path) throws IOException { String template = readFile(P2P_MAP_DECORATOR_NAME, input_path); for (int i = 0; i < WRAPPERS.length; i++) { WrapperInfo info = WRAPPERS[ i ]; String k = info.primitive; String KT = info.class_name; String K = shortInt(KT); String KMAX = info.max_value; String KMIN = info.min_value; for (int j = 0; j < WRAPPERS.length; j++) { WrapperInfo jinfo = WRAPPERS[ j ]; String v = jinfo.primitive; String VT = jinfo.class_name; String V = shortInt(VT); String VMAX = jinfo.max_value; String VMIN = jinfo.min_value; String out = template; out = Pattern.compile("#v#").matcher(out).replaceAll(v); out = Pattern.compile("#V#").matcher(out).replaceAll(V); out = Pattern.compile("#k#").matcher(out).replaceAll(k); out = Pattern.compile("#K#").matcher(out).replaceAll(K); out = Pattern.compile("#KT#").matcher(out).replaceAll(KT); out = Pattern.compile("#VT#").matcher(out).replaceAll(VT); out = Pattern.compile("#KMAX#").matcher(out).replaceAll(KMAX); out = Pattern.compile("#VMAX#").matcher(out).replaceAll(VMAX); out = Pattern.compile("#KMIN#").matcher(out).replaceAll(KMIN); out = Pattern.compile("#VMIN#").matcher(out).replaceAll(VMIN); String outFile = "decorator/T" + K + V + "HashMapDecorator.java"; writeFile(outFile, out, output_path); } } } private static void generateDecoratorsClass(File input_path, File output_path) throws IOException { String raw_template = readFile(DECORATORS_CLASS_TEMP, input_path); // NOTE: don't try to use trove here... it ain't built yet! :-) Map replicated_content = new HashMap(); // Find the replicated content blocks in the template. For ease, read this line // by line. String processed_template = null; BufferedReader reader = new BufferedReader(new StringReader(raw_template)); String line; StringBuilder buffer = new StringBuilder(); boolean in_replicated_block = false; boolean need_newline = false; while ((line = reader.readLine()) != null) { if (!in_replicated_block && line.startsWith("====START_REPLICATED_CONTENT #")) { in_replicated_block = true; need_newline = false; if (processed_template == null) { processed_template = buffer.toString(); } buffer = new StringBuilder(); } else if (in_replicated_block && line.startsWith("=====END_REPLICATED_CONTENT #")) { int number_start_index = "=====END_REPLICATED_CONTENT #".length(); int number_end_index = line.indexOf("=", number_start_index); String number = line.substring(number_start_index, number_end_index); Integer number_obj = new Integer(number); replicated_content.put(number_obj, buffer.toString()); in_replicated_block = false; need_newline = false; } else { if (need_newline) { buffer.append(System.getProperty("line.separator")); } else need_newline = true; buffer.append(line); } } for (Map.Entry entry : replicated_content.entrySet()) { // Replace the markers in the replicated content StringBuilder entry_buffer = new StringBuilder(); boolean first_loop = true; for (int i = 0; i < WRAPPERS.length; i++) { WrapperInfo info = WRAPPERS[ i ]; String k = info.primitive; String KT = info.class_name; String K = shortInt(KT); String KMAX = info.max_value; String KMIN = info.min_value; for (int j = 0; j < WRAPPERS.length; j++) { WrapperInfo jinfo = WRAPPERS[ j ]; String v = jinfo.primitive; String VT = jinfo.class_name; String V = shortInt(VT); String VMAX = jinfo.max_value; String VMIN = jinfo.min_value; String out = entry.getValue(); String before_e = out; out = Pattern.compile("#e#").matcher(out).replaceAll(k); out = Pattern.compile("#E#").matcher(out).replaceAll(K); out = Pattern.compile("#ET#").matcher(out).replaceAll(KT); out = Pattern.compile("#EMAX#").matcher(out).replaceAll(KMAX); out = Pattern.compile("#EMIN#").matcher(out).replaceAll(KMIN); boolean uses_e = !out.equals(before_e); // If we use "e" (instead of "k" & "v", then we don't need the inner // map. Yeah, this is ugly I know... but it works. if (uses_e && j != 0) break; out = Pattern.compile("#v#").matcher(out).replaceAll(v); out = Pattern.compile("#V#").matcher(out).replaceAll(V); out = Pattern.compile("#VT#").matcher(out).replaceAll(VT); out = Pattern.compile("#VMAX#").matcher(out).replaceAll(VMAX); out = Pattern.compile("#VMIN#").matcher(out).replaceAll(VMIN); out = Pattern.compile("#k#").matcher(out).replaceAll(k); out = Pattern.compile("#K#").matcher(out).replaceAll(K); out = Pattern.compile("#KT#").matcher(out).replaceAll(KT); out = Pattern.compile("#KMAX#").matcher(out).replaceAll(KMAX); out = Pattern.compile("#KMIN#").matcher(out).replaceAll(KMIN); if (first_loop) first_loop = false; else { entry_buffer.append(System.getProperty("line.separator")); entry_buffer.append(System.getProperty("line.separator")); } entry_buffer.append(out); } } processed_template = Pattern.compile("#REPLICATED" + entry.getKey() + "#").matcher( processed_template).replaceAll(entry_buffer.toString()); } writeFile("Decorators.java", processed_template, output_path); } private static void writeFile(String file, String out, File output_path) throws IOException { File destination = new File(output_path.getPath() + "/" + file); File parent = destination.getParentFile(); parent.mkdirs(); // Write to a temporary file File temp = File.createTempFile("trove", "gentemp", new File("output")); FileWriter writer = new FileWriter(temp); writer.write(out); writer.close(); // Now determine if it should be moved to the final location final boolean need_to_move; if (destination.exists()) { boolean matches; try { MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] current_file = digest(destination, digest); byte[] new_file = digest(temp, digest); matches = Arrays.equals(current_file, new_file); } catch (NoSuchAlgorithmException ex) { System.err.println("WARNING: Couldn't load digest algorithm to compare " + "new and old template. Generation will be forced." ); matches = false; } need_to_move = !matches; } else need_to_move = true; // Now move it if we need to move it if (need_to_move) { destination.delete(); if (!temp.renameTo(destination)) { throw new IOException("ERROR writing: " + destination); } else System.out.println("Wrote: " + destination); } else { System.out.println("Skipped: " + destination); temp.delete(); } } private static byte[] digest(File file, MessageDigest digest) throws IOException { digest.reset(); byte[] buffer = new byte[1024]; FileInputStream in = new FileInputStream(file); try { int read = in.read(buffer); while (read >= 0) { digest.update(buffer, 0, read); read = in.read(buffer); } return digest.digest(); } finally { try { in.close(); } catch (IOException ex) { // ignore } } } private static String shortInt(String type) { return type.equals("Integer") ? "Int" : type; } private static String readFile(String name, File input_path) throws IOException { File file = new File( input_path, name ); if ( !file.exists() ) { throw new NullPointerException("Couldn't find: " + file); } BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); StringBuilder out = new StringBuilder(); while (true) { String line = reader.readLine(); if (line == null) break; out.append(line); out.append("\n"); } return out.toString(); } finally { if ( reader != null ) { try { reader.close(); } catch( IOException ex ) { // ignore } } } } private static class WrapperInfo { final String primitive; final String class_name; final String max_value; final String min_value; WrapperInfo(String primitive, String class_name, String max_value, String min_value) { this.primitive = primitive; this.class_name = class_name; this.max_value = class_name + "." + max_value; this.min_value = class_name + "." + min_value; } } } trove-2.1.0/src/gnu/trove/generate/O2PMapDecorator.template0000644000175000017500000002514611241347110022606 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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.decorator; import gnu.trove.TObject#E#HashMap; import gnu.trove.TObject#E#Iterator; import java.io.*; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Wrapper class to make a TObject#E#HashMap conform to the java.util.Map API. * This class simply decorates an underlying TObject#E#HashMap and translates the Object-based * APIs into their Trove primitive analogs. *

*

* Note that wrapping and unwrapping primitive values is extremely inefficient. If * possible, users of this class should override the appropriate methods in this class * and use a table of canonical values. *

*

* Created: Mon Sep 23 22:07:40 PDT 2002 * * @author Eric D. Friedman */ public class TObject#E#HashMapDecorator extends AbstractMap implements Map, Externalizable, Cloneable { /** * the wrapped primitive map */ protected TObject#E#HashMap _map; /** * FOR EXTERNALIZATION ONLY!! */ public TObject#E#HashMapDecorator() {} /** * Creates a wrapper that decorates the specified primitive map. */ public TObject#E#HashMapDecorator(TObject#E#HashMap map) { super(); this._map = map; } /** * Returns a reference to the map wrapped by this decorator. */ public TObject#E#HashMap getMap() { return _map; } /** * Clones the underlying trove collection and returns the clone wrapped in a new * decorator instance. This is a shallow clone except where primitives are * concerned. * * @return a copy of the receiver */ public TObject#E#HashMapDecorator clone() { try { TObject#E#HashMapDecorator copy = (TObject#E#HashMapDecorator) super.clone(); copy._map = (TObject#E#HashMap)_map.clone(); return copy; } catch (CloneNotSupportedException e) { // assert(false); throw new InternalError(); // we are cloneable, so this does not happen } } /** * Inserts a key/value pair into the map. * * @param key an Object value * @param value an Object value * @return the previous value associated with key, * or Integer(0) if none was found. */ public #ET# put(V key, #ET# value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Retrieves the value for key * * @param key an Object value * @return the value of key or null if no such mapping exists. */ public #ET# get(Object key) { V k = unwrapKey(key); #e# v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an Object value * @return the removed value, or Integer(0) if it was not found in the map */ public #ET# remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a Set value */ public Set> entrySet() { return new AbstractSet>() { public int size() { return _map.size(); } public boolean isEmpty() { return TObject#E#HashMapDecorator.this.isEmpty(); } public boolean contains(Object o) { if (o instanceof Map.Entry) { Object k = ((Map.Entry) o).getKey(); Object v = ((Map.Entry) o).getValue(); return TObject#E#HashMapDecorator.this.containsKey(k) && TObject#E#HashMapDecorator.this.get(k).equals(v); } else { return false; } } public Iterator> iterator() { return new Iterator>() { private final TObject#E#Iterator it = _map.iterator(); public Map.Entry next() { it.advance(); final V key = wrapKey(it.key()); final #ET# v = wrapValue(it.value()); return new Map.Entry() { private #ET# val = v; public boolean equals(Object o) { return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) && ((Map.Entry) o).getValue().equals(val); } public V getKey() { return key; } public #ET# getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public #ET# setValue(#ET# value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(#ET# o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection> c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { TObject#E#HashMapDecorator.this.clear(); } }; } /** * Checks for the presence of val in the values of the map. * * @param val an Object value * @return a boolean value */ public boolean containsValue(Object val) { return _map.containsValue(unwrapValue(val)); } /** * Checks for the present of key in the keys of the map. * * @param key an Object value * @return a boolean value */ public boolean containsKey(Object key) { return _map.containsKey(unwrapKey(key)); } /** * Returns the number of entries in the map. * * @return the map's size. */ public int size() { return this._map.size(); } /** * Indicates whether map has any entries. * * @return true if the map is empty */ public boolean isEmpty() { return size() == 0; } /** * Copies the key/value mappings in map into this map. * Note that this will be a deep copy, as storage is by * primitive value. * * @param map a Map value */ public void putAll(Map map) { Iterator> it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Entry e = it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param o key in the underlying map * @return an Object representation of the key */ protected final V wrapKey(Object o) { return (V) o; } /** * Unwraps a key * * @param key wrapped key * @return an unwrapped representation of the key */ protected final V unwrapKey(Object key) { return (V) key; } /** * Wraps a value * * @param k value in the underlying map * @return an Object representation of the value */ protected #ET# wrapValue(#e# k) { return #ET#.valueOf(k); } /** * Unwraps a value * * @param value wrapped value * @return an unwrapped representation of the value */ protected #e# unwrapValue(Object value) { return ((#ET#) value).#e#Value(); } // Implements Externalizable public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP _map = (TObject#E#HashMap) in.readObject(); } // Implements Externalizable public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // MAP out.writeObject(_map); } } // TObject#E#HashMapDecorator trove-2.1.0/src/gnu/trove/generate/P2OProcedure.template0000644000175000017500000000344511241347110022154 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Interface for procedures that take two parameters of type #e# and Object. * * Created: Mon Nov 5 22:03:30 2001 * * @author Eric D. Friedman * @version $Id: P2OProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public interface T#E#ObjectProcedure { /** * Executes this procedure. A false return value indicates that * the application executing this procedure should not invoke this * procedure again. * * @param a a #e# value * @param b an Object value * @return true if additional invocations of the procedure are * allowed. */ public boolean execute(#e# a, T b); }// T#E#ObjectProcedure trove-2.1.0/src/gnu/trove/generate/PHashingStrategy.template0000644000175000017500000000363411241347110023127 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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.Serializable; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use an optimal strategy when computing hashcodes. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: PHashingStrategy.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public interface T#E#HashingStrategy extends Serializable { /** * Computes a hash code for the specified #e#. Implementors * can use the #e#'s own value or a custom scheme designed to * minimize collisions for a known set of input. * * @param val #e# for which the hashcode is to be computed * @return the hashCode */ public int computeHashCode(#e# val); } // T#E#HashingStrategy trove-2.1.0/src/gnu/trove/generate/O2PIterator.template0000644000175000017500000001304411241347110022011 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.util.ConcurrentModificationException; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Iterator for maps of type Object and #e#. *

*

The iterator semantics for Trove's primitive maps is slightly different * from those defined in java.util.Iterator, but still well within * the scope of the pattern, as defined by Gamma, et al.

*

*

This iterator does not implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to advance() and then retrieve either the key(), * the value() or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.

*

*

In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.

*

*

Here are some sample scenarios for this class of iterator:

*

*

 * // accessing keys/values through an iterator:
 * for (TObject#E#Iterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     doSomethingWithValue(it.value());
 *   }
 * }
 * 
*

*

 * // modifying values in-place through iteration:
 * for (TObject#E#Iterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     it.setValue(newValueForKey(it.key()));
 *   }
 * }
 * 
*

*

 * // deleting entries during iteration:
 * for (TObject#E#Iterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     it.remove();
 *   }
 * }
 * 
*

*

 * // faster iteration by avoiding hasNext():
 * TObject#E#Iterator iterator = map.iterator();
 * for (int i = map.size(); i-- > 0;) {
 *   iterator.advance();
 *   doSomethingWithKeyAndValue(iterator.key(), iterator.value());
 * }
 * 
* * @author Eric D. Friedman * @version $Id: O2PIterator.template,v 1.3 2007/01/22 16:56:39 robeden Exp $ */ public class TObject#E#Iterator extends TIterator { private final TObject#E#HashMap _map; public TObject#E#Iterator(TObject#E#HashMap map) { super(map); this._map = map; } /** * Returns the index of the next value in the data structure * or a negative value if the iterator is exhausted. * * @return an #e# value */ protected final int nextIndex() { if (_expectedSize != _hash.size()) { throw new ConcurrentModificationException(); } Object[] set = _map._set; int i = _index; while (i-- > 0 && (set[i] == null || set[i] == TObjectHash.REMOVED || set[i] == TObjectHash.FREE)) ; return i; } /** * Moves the iterator forward to the next entry in the underlying map. * * @throws java.util.NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must advance() the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public K key() { return (K) _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must advance() the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public #e# value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must advance() the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public #e# setValue(#e# val) { #e# old = value(); _map._values[_index] = val; return old; } }// TObject#E#Iterator trove-2.1.0/src/gnu/trove/generate/O2PHashMap.template0000644000175000017500000004424611241347110021551 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.ObjectInput; import java.io.ObjectOutput; import java.io.Externalizable; import java.util.Arrays; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * An open addressed Map implementation for Object keys and #e# values. * * Created: Sun Nov 4 08:52:45 2001 * * @author Eric D. Friedman */ public class TObject#E#HashMap extends TObjectHash implements Externalizable { static final long serialVersionUID = 1L; private final TObject#E#Procedure PUT_ALL_PROC = new TObject#E#Procedure() { public boolean execute(K key, #e# value) { put(key, value); return true; } }; /** the values of the map */ protected transient #e#[] _values; /** * Creates a new TObject#E#HashMap instance with the default * capacity and load factor. */ public TObject#E#HashMap() { super(); } /** * Creates a new TObject#E#HashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value */ public TObject#E#HashMap(int initialCapacity) { super(initialCapacity); } /** * Creates a new TObject#E#HashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value */ public TObject#E#HashMap(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Creates a new TObject#E#HashMap instance with the default * capacity and load factor. * @param strategy used to compute hash codes and to compare keys. */ public TObject#E#HashMap(TObjectHashingStrategy strategy) { super(strategy); } /** * Creates a new TObject#E#HashMap instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare keys. */ public TObject#E#HashMap(int initialCapacity, TObjectHashingStrategy strategy) { super(initialCapacity, strategy); } /** * Creates a new TObject#E#HashMap 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 TObject#E#HashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { super(initialCapacity, loadFactor, strategy); } /** * @return an iterator over the entries in this map */ public TObject#E#Iterator iterator() { return new TObject#E#Iterator(this); } /** * initializes the hashtable to a prime capacity which is at least * initialCapacity + 1. * * @param initialCapacity an int value * @return the actual capacity chosen */ protected int setUp(int initialCapacity) { int capacity; capacity = super.setUp(initialCapacity); _values = new #e#[capacity]; return capacity; } /** * Inserts a key/value pair into the map. * * @param key an Object value * @param value an #e# value * @return the previous value associated with key, * or (#e#)0 if none was found. */ public #e# put(K key, #e# value) { int index = insertionIndex(key); return doPut(key, value, index); } /** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an Object value * @param value an #e# value * @return the previous value associated with key, * or (#e#)0 if none was found. */ public #e# putIfAbsent(K key, #e# value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); } private #e# doPut(K key, #e# value, int index) { #e# previous = (#e#)0; boolean isNewMapping = true; if (index < 0) { index = -index -1; previous = _values[index]; isNewMapping = false; } K oldKey = (K) _set[index]; _set[index] = key; _values[index] = value; if (isNewMapping) { postInsertHook(oldKey == FREE); } return previous; } /** * Put all the entries from the given map into this map. * * @param map The map from which entries will be obtained to put into this map. */ public void putAll(TObject#E#HashMap map){ map.forEachEntry(PUT_ALL_PROC); } /** * rehashes the map to the new capacity. * * @param newCapacity an int value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; K oldKeys[] = (K[]) _set; #e# oldVals[] = _values; _set = new Object[newCapacity]; Arrays.fill(_set, FREE); _values = new #e#[newCapacity]; for (int i = oldCapacity; i-- > 0;) { if(oldKeys[i] != FREE && oldKeys[i] != REMOVED) { K o = oldKeys[i]; int index = insertionIndex(o); if (index < 0) { throwObjectContractViolation(_set[(-index -1)], o); } _set[index] = o; _values[index] = oldVals[i]; } } } /** * retrieves the value for key * * @param key an Object value * @return the value of key or (#e#)0 if no such mapping exists. */ public #e# get(K key) { int index = index(key); return index < 0 ? (#e#)0 : _values[index]; } /** * Empties the map. * */ public void clear() { super.clear(); Object[] keys = _set; #e#[] vals = _values; Arrays.fill(_set, 0, _set.length, FREE); Arrays.fill(_values, 0, _values.length, (#e#) 0); } /** * Deletes a key/value pair from the map. * * @param key an Object value * @return an #e# value or (#e#)0 if no such mapping exists. */ public #e# remove(K key) { #e# prev = (#e#)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 Object value * @return a boolean value */ public boolean equals(Object other) { if (! (other instanceof TObject#E#HashMap)) { return false; } TObject#E#HashMap that = (TObject#E#HashMap)other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); } /** * {@inheritDoc} */ @Override public TObject#E#HashMap clone() { TObject#E#HashMap clone = ( TObject#E#HashMap ) super.clone(); clone._values = new #e#[_values.length]; System.arraycopy( _values, 0, clone._values, 0, clone._values.length ); return clone; } private static final class EqProcedure implements TObject#E#Procedure { private final TObject#E#HashMap _otherMap; EqProcedure(TObject#E#HashMap otherMap) { _otherMap = otherMap; } public final boolean execute(Object key, #e# value) { int index = _otherMap.index(key); if (index >= 0 && eq(value, _otherMap.get(key))) { return true; } return false; } /** * Compare two #e#s for equality. */ private final boolean eq(#e# v1, #e# v2) { return v1 == v2; } } /** * removes the mapping at index from the map. * * @param index an int value */ protected void removeAt(int index) { _values[index] = 0; super.removeAt(index); // clear key, state; adjust size } /** * Returns the values of the map. * * @return a Collection value */ public #e#[] getValues() { #e#[] vals = new #e#[size()]; #e#[] v = _values; Object[] keys = _set; for (int i = v.length, j = 0; i-- > 0;) { if (keys[i] != FREE && keys[i] != REMOVED) { vals[j++] = v[i]; } } return vals; } /** * returns the keys of the map. * * @return a Set value */ public Object[] keys() { Object[] keys = new Object[size()]; K[] k = (K[]) _set; for (int i = k.length, j = 0; i-- > 0;) { if (k[i] != FREE && k[i] != REMOVED) { keys[j++] = k[i]; } } return keys; } /** * returns the keys of the map. * * @param a the array into which the elements of the list are to * be stored, if it is big enough; otherwise, a new array of the * same runtime type is allocated for this purpose. * @return a Set value */ public K[] keys(K[] a) { int size = size(); if (a.length < size) { a = (K[]) java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size); } K[] k = (K[]) _set; for (int i = k.length, j = 0; i-- > 0;) { if (k[i] != FREE && k[i] != REMOVED) { a[j++] = k[i]; } } return a; } /** * checks for the presence of val in the values of the map. * * @param val an #e# value * @return a boolean value */ public boolean containsValue(#e# val) { Object[] keys = _set; #e#[] vals = _values; for (int i = vals.length; i-- > 0;) { if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { return true; } } return false; } /** * checks for the present of key in the keys of the map. * * @param key an Object value * @return a boolean value */ public boolean containsKey(K key) { return contains(key); } /** * Executes procedure for each key in the map. * * @param procedure a TObjectProcedure value * @return false if the loop over the keys terminated because * the procedure returned false for some key. */ public boolean forEachKey(TObjectProcedure procedure) { return forEach(procedure); } /** * Executes procedure for each value in the map. * * @param procedure a T#E#Procedure value * @return false if the loop over the values terminated because * the procedure returned false for some value. */ public boolean forEachValue(T#E#Procedure procedure) { Object[] keys = _set; #e#[] values = _values; for (int i = values.length; i-- > 0;) { if (keys[i] != FREE && keys[i] != REMOVED && ! procedure.execute(values[i])) { return false; } } return true; } /** * Executes procedure for each key/value entry in the * map. * * @param procedure a TOObject#E#Procedure value * @return false if the loop over the entries terminated because * the procedure returned false for some entry. */ public boolean forEachEntry(TObject#E#Procedure procedure) { K[] keys = (K[]) _set; #e#[] values = _values; for (int i = keys.length; i-- > 0;) { if (keys[i] != FREE && keys[i] != REMOVED && ! procedure.execute(keys[i],values[i])) { return false; } } return true; } /** * Retains only those entries in the map for which the procedure * returns a true value. * * @param procedure determines which entries to keep * @return true if the map was modified. */ public boolean retainEntries(TObject#E#Procedure procedure) { boolean modified = false; K[] keys = (K[]) _set; #e#[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for (int i = keys.length; i-- > 0;) { if (keys[i] != FREE && keys[i] != REMOVED && ! procedure.execute(keys[i],values[i])) { removeAt(i); modified = true; } } } finally { reenableAutoCompaction(true); } return modified; } /** * Transform the values in this map using function. * * @param function a T#E#Function value */ public void transformValues(T#E#Function function) { Object[] keys = _set; #e#[] values = _values; for (int i = values.length; i-- > 0;) { if (keys[i] != null && keys[i] != REMOVED) { values[i] = function.execute(values[i]); } } } /** * Increments the primitive value mapped to key by 1 * * @param key the key of the value to increment * @return true if a mapping was found and modified. */ public boolean increment(K key) { return adjustValue(key, (#e#)1); } /** * Adjusts the primitive value mapped to key. * * @param key the key of the value to increment * @param amount the amount to adjust the value by. * @return true if a mapping was found and modified. */ public boolean adjustValue(K key, #e# amount) { int index = index(key); if (index < 0) { return false; } else { _values[index] += amount; return true; } } /** * Adjusts the primitive value mapped to the key if the key is present in the map. * Otherwise, the initial_value is put in the map. * * @param key the key of the value to increment * @param adjust_amount the amount to adjust the value by * @param put_amount the value put into the map if the key is not initial present * * @return the value present in the map after the adjustment or put operation * * @since 2.0b1 */ public #e# adjustOrPutValue(final K key, final #e# adjust_amount, final #e# put_amount ) { int index = insertionIndex(key); final boolean isNewMapping; final #e# newValue; if (index < 0) { index = -index -1; newValue = ( _values[index] += adjust_amount ); isNewMapping = false; } else { newValue = ( _values[index] = put_amount ); isNewMapping = true; } K oldKey = (K) _set[index]; _set[index] = key; if ( isNewMapping ) { postInsertHook(oldKey == FREE); } return newValue; } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 0 ); // NUMBER OF ENTRIES out.writeInt( _size ); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure( out ); if (! forEachEntry(writeProcedure)) { throw writeProcedure.exception; } } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { K key = (K) in.readObject(); #e# val = in.read#E#(); put(key, val); } } public String toString() { final StringBuilder buf = new StringBuilder("{"); forEachEntry(new TObject#E#Procedure() { private boolean first = true; public boolean execute(K key, #e# value) { if ( first ) first = false; else buf.append( "," ); buf.append(key); buf.append("="); buf.append(value); return true; } }); buf.append("}"); return buf.toString(); } } // TObject#E#HashMap trove-2.1.0/src/gnu/trove/generate/P2PIterator.template0000644000175000017500000001170411241347110022013 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Iterator for maps of type #e# and #f#. * *

The iterator semantics for Trove's primitive maps is slightly different * from those defined in java.util.Iterator, but still well within * the scope of the pattern, as defined by Gamma, et al.

* *

This iterator does not implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to advance() and then retrieve either the key(), * the value() or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.

* *

In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.

* *

Here are some sample scenarios for this class of iterator:

* *
 * // accessing keys/values through an iterator:
 * for (T#E##F#Iterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     doSomethingWithValue(it.value());
 *   }
 * }
 * 
* *
 * // modifying values in-place through iteration:
 * for (T#E##F#Iterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     it.setValue(newValueForKey(it.key()));
 *   }
 * }
 * 
* *
 * // deleting entries during iteration:
 * for (T#E##F#Iterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     it.remove();
 *   }
 * }
 * 
* *
 * // faster iteration by avoiding hasNext():
 * T#E##F#Iterator iterator = map.iterator();
 * for (int i = map.size(); i-- > 0;) {
 *   iterator.advance();
 *   doSomethingWithKeyAndValue(iterator.key(), iterator.value());
 * }
 * 
* * @author Eric D. Friedman * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public class T#E##F#Iterator extends TPrimitiveIterator { /** the collection being iterated over */ private final T#E##F#HashMap _map; /** * Creates an iterator over the specified map */ public T#E##F#Iterator(T#E##F#HashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @throws java.util.NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must advance() the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public #e# key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must advance() the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public #f# value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must advance() the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public #f# setValue(#f# val) { #f# old = value(); _map._values[_index] = val; return old; } }// T#E##F#Iterator trove-2.1.0/src/gnu/trove/generate/PHashSetDecorator.template0000644000175000017500000001511011241347110023215 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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.decorator; import gnu.trove.T#E#HashSet; import gnu.trove.T#E#Iterator; import java.io.*; import java.util.AbstractSet; import java.util.Iterator; import java.util.Set; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Wrapper class to make a T#E#HashSet conform to the java.util.Set API. * This class simply decorates an underlying T#E#HashSet and translates the Object-based * APIs into their Trove primitive analogs. *

*

* Note that wrapping and unwrapping primitive values is extremely inefficient. If * possible, users of this class should override the appropriate methods in this class * and use a table of canonical values. *

*

* Created: Tue Sep 24 22:08:17 PDT 2002 * * @author Eric D. Friedman */ public class T#E#HashSetDecorator extends AbstractSet<#ET#> implements Set<#ET#>, Externalizable { /** the wrapped primitive set */ protected T#E#HashSet _set; /** * FOR EXTERNALIZATION ONLY!! */ public T#E#HashSetDecorator() {} /** * Creates a wrapper that decorates the specified primitive set. */ public T#E#HashSetDecorator(T#E#HashSet set) { super(); this._set = set; } /** * Returns a reference to the set wrapped by this decorator. */ public T#E#HashSet getSet() { return _set; } /** * Clones the underlying trove collection and returns the clone wrapped in a new * decorator instance. This is a shallow clone except where primitives are * concerned. * * @return a copy of the receiver */ public T#E#HashSetDecorator clone() { try { T#E#HashSetDecorator copy = (T#E#HashSetDecorator) super.clone(); copy._set = (T#E#HashSet) _set.clone(); return copy; } catch (CloneNotSupportedException e) { // assert(false); throw new InternalError(); // we are cloneable } } /** * Inserts a value into the set. * * @param value true if the set was modified by the insertion */ public boolean add(#ET# value) { return _set.add(unwrap(value)); } /** * Compares this set with another set for equality of their stored * entries. * * @param other an Object value * @return true if the sets are identical */ public boolean equals(Object other) { if (_set.equals(other)) { return true; // comparing two trove sets } else if (other instanceof Set) { Set that = (Set) other; if (that.size() != _set.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Iterator it = that.iterator(); for (int i = that.size(); i-- > 0;) { Object val = it.next(); if (val instanceof #ET#) { #e# v = unwrap(val); if (_set.contains(v)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other set } } return true; // all entries match } } else { return false; } } /** * Empties the set. */ public void clear() { this._set.clear(); } /** * Deletes a value from the set. * * @param value an Object value * @return true if the set was modified */ public boolean remove(Object value) { return _set.remove(unwrap(value)); } /** * Creates an iterator over the values of the set. * * @return an iterator with support for removals in the underlying set */ public Iterator<#ET#> iterator() { return new Iterator<#ET#>() { private final T#E#Iterator it = _set.iterator(); public #ET# next() { return wrap(it.next()); } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } /** * Returns the number of entries in the set. * * @return the set's size. */ public int size() { return this._set.size(); } /** * Indicates whether set has any entries. * * @return true if the set is empty */ public boolean isEmpty() { return size() == 0; } /** * Wraps a value * * @param k value in the underlying set * @return an Object representation of the value */ protected #ET# wrap(#e# k) { return #ET#.valueOf(k); } /** * Unwraps a value * * @param value wrapped value * @return an unwrapped representation of the value */ protected #e# unwrap(Object value) { return ((#ET#) value).#e#Value(); } // Implements Externalizable public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SET _set = (T#E#HashSet) in.readObject(); } // Implements Externalizable public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // SET out.writeObject(_set); } } // T#E#HashSetDecorator trove-2.1.0/src/gnu/trove/generate/PStack.template0000644000175000017500000000637211241347110021072 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; /** * A stack of #e# primitives, backed by a T#E#ArrayList. * * @author Eric D. Friedman, Rob Eden * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $ */ public class T#E#Stack { /** the list used to hold the stack values. */ protected T#E#ArrayList _list; public static final int DEFAULT_CAPACITY = T#E#ArrayList.DEFAULT_CAPACITY; /** * Creates a new T#E#Stack instance with the default * capacity. */ public T#E#Stack() { this(DEFAULT_CAPACITY); } /** * Creates a new T#E#Stack instance with the * specified capacity. * * @param capacity the initial depth of the stack */ public T#E#Stack(int capacity) { _list = new T#E#ArrayList(capacity); } /** * Pushes the value onto the top of the stack. * * @param val an #e# value */ public void push(#e# val) { _list.add(val); } /** * Removes and returns the value at the top of the stack. * * @return an #e# value */ public #e# pop() { return _list.remove(_list.size() - 1); } /** * Returns the value at the top of the stack. * * @return an #e# value */ public #e# peek() { return _list.get(_list.size() - 1); } /** * Returns the current depth of the stack. */ public int size() { return _list.size(); } /** * Clears the stack, reseting its capacity to the default. */ public void clear() { _list.clear(DEFAULT_CAPACITY); } /** * Clears the stack without releasing its internal capacity allocation. */ public void reset() { _list.reset(); } /** * Copies the contents of the stack into a native array. Note that this will NOT * pop them out of the stack. * * @return an #e#[] value */ public #e#[] toNativeArray() { return _list.toNativeArray(); } /** * Copies a slice of the list into a native array. Note that this will NOT * pop them out of the stack. * * @param dest the array to copy into. */ public void toNativeArray(#e#[] dest) { _list.toNativeArray(dest, 0, size()); } } // T#E#Stack trove-2.1.0/src/gnu/trove/generate/Decorators.template0000644000175000017500000000507111241347110022005 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2008, Robert D. Eden 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.util.*; import gnu.trove.decorator.*; /** * This is a static utility class that provides functions for simplifying creation of * decorators. * * @author Robert D. Eden * @since Trove 2.1 */ public class Decorators { // Hide the constructor private Decorators() {} #REPLICATED1# #REPLICATED2# #REPLICATED3# #REPLICATED4# } ====START_REPLICATED_CONTENT #1==== /** * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. */ public static Map<#KT#,#VT#> wrap( T#K##V#HashMap map ) { return new T#K##V#HashMapDecorator( map ); } =====END_REPLICATED_CONTENT #1===== ====START_REPLICATED_CONTENT #2==== /** * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. */ public static Map wrap( TObject#E#HashMap map ) { return new TObject#E#HashMapDecorator( map ); } =====END_REPLICATED_CONTENT #2===== ====START_REPLICATED_CONTENT #3==== /** * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. */ public static Map<#ET#,T> wrap( T#E#ObjectHashMap map ) { return new T#E#ObjectHashMapDecorator( map ); } =====END_REPLICATED_CONTENT #3===== ====START_REPLICATED_CONTENT #4==== /** * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} * interface. */ public static Set<#ET#> wrap( T#E#HashSet set ) { return new T#E#HashSetDecorator( set ); } =====END_REPLICATED_CONTENT #4=====trove-2.1.0/src/gnu/trove/generate/P2PProcedure.template0000644000175000017500000000342711241347110022155 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Interface for procedures that take two parameters of type #e# and #f#. * * Created: Mon Nov 5 22:03:30 2001 * * @author Eric D. Friedman * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public interface T#E##F#Procedure { /** * Executes this procedure. A false return value indicates that * the application executing this procedure should not invoke this * procedure again. * * @param a a #e# value * @param b a #f# value * @return true if additional invocations of the procedure are * allowed. */ public boolean execute(#e# a, #f# b); }// T#E##F#Procedure trove-2.1.0/src/gnu/trove/generate/P2PHashMap.template0000644000175000017500000004460611241347110021552 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.ObjectInput; import java.io.ObjectOutput; import java.io.Externalizable; import java.util.Arrays; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * An open addressed Map implementation for #e# keys and #f# values. * * Created: Sun Nov 4 08:52:45 2001 * * @author Eric D. Friedman */ public class T#E##F#HashMap extends T#E#Hash implements Externalizable { static final long serialVersionUID = 1L; private final T#E##F#Procedure PUT_ALL_PROC = new T#E##F#Procedure() { public boolean execute(#e# key, #f# value) { put(key, value); return true; } }; /** the values of the map */ protected transient #f#[] _values; /** * Creates a new T#E##F#HashMap instance with the default * capacity and load factor. */ public T#E##F#HashMap() { super(); } /** * Creates a new T#E##F#HashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value */ public T#E##F#HashMap(int initialCapacity) { super(initialCapacity); } /** * Creates a new T#E##F#HashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value */ public T#E##F#HashMap(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Creates a new T#E##F#HashMap instance with the default * capacity and load factor. * @param strategy used to compute hash codes and to compare keys. */ public T#E##F#HashMap(T#E#HashingStrategy strategy) { super(strategy); } /** * Creates a new T#E##F#HashMap instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare keys. */ public T#E##F#HashMap(int initialCapacity, T#E#HashingStrategy strategy) { super(initialCapacity, strategy); } /** * Creates a new T#E##F#HashMap 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 T#E##F#HashMap(int initialCapacity, float loadFactor, T#E#HashingStrategy strategy) { super(initialCapacity, loadFactor, strategy); } /** * @return a deep clone of this collection */ public Object clone() { T#E##F#HashMap m = (T#E##F#HashMap)super.clone(); m._values = (#f#[])this._values.clone(); return m; } /** * @return a T#E##F#Iterator with access to this map's keys and values */ public T#E##F#Iterator iterator() { return new T#E##F#Iterator(this); } /** * initializes the hashtable to a prime capacity which is at least * initialCapacity + 1. * * @param initialCapacity an int value * @return the actual capacity chosen */ protected int setUp(int initialCapacity) { int capacity; capacity = super.setUp(initialCapacity); _values = new #f#[capacity]; return capacity; } /** * Inserts a key/value pair into the map. * * @param key an #e# value * @param value an #f# value * @return the previous value associated with key, * or (#e#)0 if none was found. */ public #f# put(#e# key, #f# value) { int index = insertionIndex(key); return doPut(key, value, index); } /** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an #e# value * @param value an #f# value * @return the previous value associated with key, * or (#e#)0 if none was found. */ public #f# putIfAbsent(#e# key, #f# value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); } private #f# doPut(#e# key, #f# value, int index) { byte previousState; #f# previous = (#f#)0; 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; } /** * Put all the entries from the given map into this map. * * @param map The map from which entries will be obtained to put into this map. */ public void putAll(T#E##F#HashMap map){ map.forEachEntry(PUT_ALL_PROC); } /** * rehashes the map to the new capacity. * * @param newCapacity an int value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; #e# oldKeys[] = _set; #f# oldVals[] = _values; byte oldStates[] = _states; _set = new #e#[newCapacity]; _values = new #f#[newCapacity]; _states = new byte[newCapacity]; for (int i = oldCapacity; i-- > 0;) { if(oldStates[i] == FULL) { #e# o = oldKeys[i]; int index = insertionIndex(o); _set[index] = o; _values[index] = oldVals[i]; _states[index] = FULL; } } } /** * retrieves the value for key * * @param key an #e# value * @return the value of key or (#e#)0 if no such mapping exists. */ public #f# get(#e# key) { int index = index(key); return index < 0 ? (#f#)0 : _values[index]; } /** * Empties the map. * */ public void clear() { super.clear(); #e#[] keys = _set; #f#[] vals = _values; byte[] states = _states; Arrays.fill(_set, 0, _set.length, (#e#) 0); Arrays.fill(_values, 0, _values.length, (#f#) 0); Arrays.fill(_states, 0, _states.length, FREE); } /** * Deletes a key/value pair from the map. * * @param key an #e# value * @return an #f# value, or (#e#)0 if no mapping for key exists */ public #f# remove(#e# key) { #f# prev = (#f#)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 Object value * @return a boolean value */ public boolean equals(Object other) { if (! (other instanceof T#E##F#HashMap)) { return false; } T#E##F#HashMap that = (T#E##F#HashMap)other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); } public int hashCode() { HashProcedure p = new HashProcedure(); forEachEntry(p); return p.getHashCode(); } private final class HashProcedure implements T#E##F#Procedure { private int h = 0; public int getHashCode() { return h; } public final boolean execute(#e# key, #f# value) { h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); return true; } } private static final class EqProcedure implements T#E##F#Procedure { private final T#E##F#HashMap _otherMap; EqProcedure(T#E##F#HashMap otherMap) { _otherMap = otherMap; } public final boolean execute(#e# key, #f# value) { int index = _otherMap.index(key); if (index >= 0 && eq(value, _otherMap.get(key))) { return true; } return false; } /** * Compare two #f#s for equality. */ private final boolean eq(#f# v1, #f# v2) { return v1 == v2; } } /** * removes the mapping at index from the map. * * @param index an int value */ protected void removeAt(int index) { _values[index] = (#f#)0; super.removeAt(index); // clear key, state; adjust size } /** * Returns the values of the map. * * @return a Collection value */ public #f#[] getValues() { #f#[] vals = new #f#[size()]; #f#[] v = _values; byte[] states = _states; for (int i = v.length, j = 0; i-- > 0;) { if (states[i] == FULL) { vals[j++] = v[i]; } } return vals; } /** * returns the keys of the map. * * @return a Set value */ public #e#[] keys() { #e#[] keys = new #e#[size()]; #e#[] k = _set; byte[] states = _states; for (int i = k.length, j = 0; i-- > 0;) { if (states[i] == FULL) { keys[j++] = k[i]; } } return keys; } /** * returns the keys of the map. * * @param a the array into which the elements of the list are to * be stored, if it is big enough; otherwise, a new array of the * same type is allocated for this purpose. * @return a Set value */ public #e#[] keys(#e#[] a) { int size = size(); if (a.length < size) { a = (#e#[]) java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size); } #e#[] k = (#e#[]) _set; byte[] states = _states; for (int i = k.length, j = 0; i-- > 0;) { if (states[i] == FULL) { a[j++] = k[i]; } } return a; } /** * checks for the presence of val in the values of the map. * * @param val an #f# value * @return a boolean value */ public boolean containsValue(#f# val) { byte[] states = _states; #f#[] vals = _values; for (int i = vals.length; i-- > 0;) { if (states[i] == FULL && val == vals[i]) { return true; } } return false; } /** * checks for the present of key in the keys of the map. * * @param key an #e# value * @return a boolean value */ public boolean containsKey(#e# key) { return contains(key); } /** * Executes procedure for each key in the map. * * @param procedure a T#E#Procedure value * @return false if the loop over the keys terminated because * the procedure returned false for some key. */ public boolean forEachKey(T#E#Procedure procedure) { return forEach(procedure); } /** * Executes procedure for each value in the map. * * @param procedure a T#F#Procedure value * @return false if the loop over the values terminated because * the procedure returned false for some value. */ public boolean forEachValue(T#F#Procedure procedure) { byte[] states = _states; #f#[] values = _values; for (int i = values.length; i-- > 0;) { if (states[i] == FULL && ! procedure.execute(values[i])) { return false; } } return true; } /** * Executes procedure for each key/value entry in the * map. * * @param procedure a TO#E##F#Procedure value * @return false if the loop over the entries terminated because * the procedure returned false for some entry. */ public boolean forEachEntry(T#E##F#Procedure procedure) { byte[] states = _states; #e#[] keys = _set; #f#[] values = _values; for (int i = keys.length; i-- > 0;) { if (states[i] == FULL && ! procedure.execute(keys[i],values[i])) { return false; } } return true; } /** * Retains only those entries in the map for which the procedure * returns a true value. * * @param procedure determines which entries to keep * @return true if the map was modified. */ public boolean retainEntries(T#E##F#Procedure procedure) { boolean modified = false; byte[] states = _states; #e#[] keys = _set; #f#[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for (int i = keys.length; i-- > 0;) { if (states[i] == FULL && ! procedure.execute(keys[i],values[i])) { removeAt(i); modified = true; } } } finally { reenableAutoCompaction(true); } return modified; } /** * Transform the values in this map using function. * * @param function a T#F#Function value */ public void transformValues(T#F#Function function) { byte[] states = _states; #f#[] values = _values; for (int i = values.length; i-- > 0;) { if (states[i] == FULL) { values[i] = function.execute(values[i]); } } } /** * Increments the primitive value mapped to key by 1 * * @param key the key of the value to increment * @return true if a mapping was found and modified. */ public boolean increment(#e# key) { return adjustValue(key, (#f#)1); } /** * Adjusts the primitive value mapped to key. * * @param key the key of the value to increment * @param amount the amount to adjust the value by. * @return true if a mapping was found and modified. */ public boolean adjustValue(#e# key, #f# amount) { int index = index(key); if (index < 0) { return false; } else { _values[index] += amount; return true; } } /** * Adjusts the primitive value mapped to the key if the key is present in the map. * Otherwise, the initial_value is put in the map. * * @param key the key of the value to increment * @param adjust_amount the amount to adjust the value by * @param put_amount the value put into the map if the key is not initial present * * @return the value present in the map after the adjustment or put operation * * @since 2.0b1 */ public #f# adjustOrPutValue(final #e# key, final #f# adjust_amount, final #f# put_amount ) { int index = insertionIndex(key); final boolean isNewMapping; final #f# newValue; if (index < 0) { index = -index -1; newValue = ( _values[index] += adjust_amount ); isNewMapping = false; } else { newValue = ( _values[index] = put_amount ); isNewMapping = true; } byte previousState = _states[index]; _set[index] = key; _states[index] = FULL; if ( isNewMapping ) { postInsertHook(previousState == FREE); } return newValue; } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 0 ); // NUMBER OF ENTRIES out.writeInt( _size ); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure( out ); if (! forEachEntry(writeProcedure)) { throw writeProcedure.exception; } } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { #e# key = in.read#E#(); #f# val = in.read#F#(); put(key, val); } } public String toString() { final StringBuilder buf = new StringBuilder("{"); forEachEntry(new T#E##F#Procedure() { private boolean first = true; public boolean execute(#e# key, #f# value) { if ( first ) first = false; else buf.append( "," ); buf.append(key); buf.append("="); buf.append(value); return true; } }); buf.append("}"); return buf.toString(); } } // T#E##F#HashMap trove-2.1.0/src/gnu/trove/generate/PHash.template0000644000175000017500000002273211241347110020706 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * An open addressed hashing implementation for #e# primitives. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: PHash.template,v 1.2 2007/06/29 22:39:46 robeden Exp $ */ abstract public class T#E#Hash extends TPrimitiveHash implements T#E#HashingStrategy { /** the set of #e#s */ protected transient #e#[] _set; /** strategy used to hash values in this collection */ protected T#E#HashingStrategy _hashingStrategy; /** * Creates a new T#E#Hash instance with the default * capacity and load factor. */ public T#E#Hash() { super(); this._hashingStrategy = this; } /** * Creates a new T#E#Hash instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. * * @param initialCapacity an int value */ public T#E#Hash(int initialCapacity) { super(initialCapacity); this._hashingStrategy = this; } /** * Creates a new T#E#Hash 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. */ public T#E#Hash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); this._hashingStrategy = this; } /** * Creates a new T#E#Hash instance with the default * capacity and load factor. * @param strategy used to compute hash codes and to compare keys. */ public T#E#Hash(T#E#HashingStrategy strategy) { super(); this._hashingStrategy = strategy; } /** * Creates a new T#E#Hash instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare keys. */ public T#E#Hash(int initialCapacity, T#E#HashingStrategy strategy) { super(initialCapacity); this._hashingStrategy = strategy; } /** * Creates a new T#E#Hash 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 T#E#Hash(int initialCapacity, float loadFactor, T#E#HashingStrategy strategy) { super(initialCapacity, loadFactor); this._hashingStrategy = strategy; } /** * @return a deep clone of this collection */ public Object clone() { T#E#Hash h = (T#E#Hash)super.clone(); h._set = (#e#[])this._set.clone(); return h; } /** * initializes the hashtable to a prime capacity which is at least * initialCapacity + 1. * * @param initialCapacity an int value * @return the actual capacity chosen */ protected int setUp(int initialCapacity) { int capacity; capacity = super.setUp(initialCapacity); _set = new #e#[capacity]; return capacity; } /** * Searches the set for val * * @param val an #e# value * @return a boolean value */ public boolean contains(#e# val) { return index(val) >= 0; } /** * Executes procedure for each element in the set. * * @param procedure a TObjectProcedure value * @return false if the loop over the set terminated because * the procedure returned false for some value. */ public boolean forEach(T#E#Procedure procedure) { byte[] states = _states; #e#[] set = _set; for (int i = set.length; i-- > 0;) { if (states[i] == FULL && ! procedure.execute(set[i])) { return false; } } return true; } /** * Releases the element currently stored at index. * * @param index an int value */ protected void removeAt(int index) { _set[index] = (#e#)0; super.removeAt(index); } /** * Locates the index of val. * * @param val an #e# value * @return the index of val or -1 if it isn't in the set. */ protected int index(#e# val) { int hash, probe, index, length; final byte[] states = _states; final #e#[] set = _set; length = states.length; hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; if (states[index] != FREE && (states[index] == REMOVED || set[index] != val)) { // see Knuth, p. 529 probe = 1 + (hash % (length - 2)); do { index -= probe; if (index < 0) { index += length; } } while (states[index] != FREE && (states[index] == REMOVED || set[index] != val)); } return states[index] == FREE ? -1 : index; } /** * Locates the index at which val can be inserted. if * there is already a value equal()ing val in the set, * returns that value as a negative integer. * * @param val an #e# value * @return an int value */ protected int insertionIndex(#e# val) { int hash, probe, index, length; final byte[] states = _states; final #e#[] set = _set; length = states.length; hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; if (states[index] == FREE) { return index; // empty, all done } else if (states[index] == FULL && set[index] == val) { return -index -1; // already stored } else { // already FULL or REMOVED, must probe // compute the double hash probe = 1 + (hash % (length - 2)); // if the slot we landed on is FULL (but not removed), probe // until we find an empty slot, a REMOVED slot, or an element // equal to the one we are trying to insert. // finding an empty slot means that the value is not present // and that we should use that slot as the insertion point; // finding a REMOVED slot means that we need to keep searching, // however we want to remember the offset of that REMOVED slot // so we can reuse it in case a "new" insertion (i.e. not an update) // is possible. // finding a matching value means that we've found that our desired // key is already in the table if (states[index] != REMOVED) { // starting at the natural offset, probe until we find an // offset that isn't full. do { index -= probe; if (index < 0) { index += length; } } while (states[index] == FULL && set[index] != val); } // if the index we found was removed: continue probing until we // locate a free location or an element which equal()s the // one we have. if (states[index] == REMOVED) { int firstRemoved = index; while (states[index] != FREE && (states[index] == REMOVED || set[index] != val)) { index -= probe; if (index < 0) { index += length; } } return states[index] == FULL ? -index -1 : firstRemoved; } // if it's full, the key is already stored return states[index] == FULL ? -index -1 : index; } } /** * Default implementation of T#E#HashingStrategy: * delegates hashing to HashFunctions.hash(#e#). * * @param val the value to hash * @return the hashcode. */ public final int computeHashCode(#e# val) { return HashFunctions.hash(val); } } // T#E#Hash trove-2.1.0/src/gnu/trove/generate/P2PMapDecorator.template0000644000175000017500000002511311241347110022601 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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.decorator; import gnu.trove.T#K##V#HashMap; import gnu.trove.T#K##V#Iterator; import java.io.*; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Wrapper class to make a T#K##V#HashMap conform to the java.util.Map API. * This class simply decorates an underlying T#K##V#HashMap and translates the Object-based * APIs into their Trove primitive analogs. *

*

* Note that wrapping and unwrapping primitive values is extremely inefficient. If * possible, users of this class should override the appropriate methods in this class * and use a table of canonical values. *

*

* Created: Mon Sep 23 22:07:40 PDT 2002 * * @author Eric D. Friedman * @author Rob Eden */ public class T#K##V#HashMapDecorator extends AbstractMap<#KT#, #VT#> implements Map<#KT#, #VT#>, Externalizable, Cloneable { /** the wrapped primitive map */ protected T#K##V#HashMap _map; /** * FOR EXTERNALIZATION ONLY!! */ public T#K##V#HashMapDecorator() {} /** * Creates a wrapper that decorates the specified primitive map. */ public T#K##V#HashMapDecorator(T#K##V#HashMap map) { super(); this._map = map; } /** * Returns a reference to the map wrapped by this decorator. */ public T#K##V#HashMap getMap() { return _map; } /** * Clones the underlying trove collection and returns the clone wrapped in a new * decorator instance. This is a shallow clone except where primitives are * concerned. * * @return a copy of the receiver */ public T#K##V#HashMapDecorator clone() { try { T#K##V#HashMapDecorator copy = (T#K##V#HashMapDecorator) super.clone(); copy._map = (T#K##V#HashMap)_map.clone(); return copy; } catch (CloneNotSupportedException e) { // assert(false); throw new InternalError(); // we are cloneable, so this does not happen } } /** * Inserts a key/value pair into the map. * * @param key an Object value * @param value an Object value * @return the previous value associated with key, * or #VT#(0) if none was found. */ public #VT# put(#KT# key, #VT# value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Retrieves the value for key * * @param key an Object value * @return the value of key or null if no such mapping exists. */ public #VT# get(#KT# key) { #k# k = unwrapKey(key); #v# v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an Object value * @return the removed value, or #VT#(0) if it was not found in the map */ public #VT# remove(#KT# key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a Set value */ public Set> entrySet() { return new AbstractSet>() { public int size() { return _map.size(); } public boolean isEmpty() { return T#K##V#HashMapDecorator.this.isEmpty(); } public boolean contains(Object o) { if (o instanceof Map.Entry) { Object k = ((Map.Entry) o).getKey(); Object v = ((Map.Entry) o).getValue(); return T#K##V#HashMapDecorator.this.containsKey(k) && T#K##V#HashMapDecorator.this.get(k).equals(v); } else { return false; } } public Iterator> iterator() { return new Iterator>() { private final T#K##V#Iterator it = _map.iterator(); public Map.Entry<#KT#,#VT#> next() { it.advance(); final #KT# key = wrapKey(it.key()); final #VT# v = wrapValue(it.value()); return new Map.Entry<#KT#,#VT#>() { private #VT# val = v; public boolean equals(Object o) { return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) && ((Map.Entry) o).getValue().equals(val); } public #KT# getKey() { return key; } public #VT# getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public #VT# setValue(#VT# value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(#VT# o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection> c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { T#K##V#HashMapDecorator.this.clear(); } }; } /** * Checks for the presence of val in the values of the map. * * @param val an Object value * @return a boolean value */ public boolean containsValue(Object val) { return _map.containsValue(unwrapValue(val)); } /** * Checks for the present of key in the keys of the map. * * @param key an Object value * @return a boolean value */ public boolean containsKey(Object key) { return _map.containsKey(unwrapKey(key)); } /** * Returns the number of entries in the map. * * @return the map's size. */ public int size() { return this._map.size(); } /** * Indicates whether map has any entries. * * @return true if the map is empty */ public boolean isEmpty() { return size() == 0; } /** * Copies the key/value mappings in map into this map. * Note that this will be a deep copy, as storage is by * primitive value. * * @param map a Map value */ public void putAll(Map map) { Iterator> it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Entry e = it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param k key in the underlying map * @return an Object representation of the key */ protected #KT# wrapKey(#k# k) { return #KT#.valueOf(k); } /** * Unwraps a key * * @param key wrapped key * @return an unwrapped representation of the key */ protected #k# unwrapKey(Object key) { return ((#KT#)key).#k#Value(); } /** * Wraps a value * * @param k value in the underlying map * @return an Object representation of the value */ protected #VT# wrapValue(#v# k) { return #VT#.valueOf(k); } /** * Unwraps a value * * @param value wrapped value * @return an unwrapped representation of the value */ protected #v# unwrapValue(Object value) { return ((#VT#)value).#v#Value(); } // Implements Externalizable public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP _map = (T#K##V#HashMap) in.readObject(); } // Implements Externalizable public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // MAP out.writeObject(_map); } } // T#K##V#HashMapDecorator trove-2.1.0/src/gnu/trove/generate/P2OIterator.template0000644000175000017500000001212311241347110022006 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Iterator for maps of type #e# and Object. *

*

The iterator semantics for Trove's primitive maps is slightly different * from those defined in java.util.Iterator, but still well within * the scope of the pattern, as defined by Gamma, et al.

*

*

This iterator does not implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to advance() and then retrieve either the key(), * the value() or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.

*

*

In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.

*

*

Here are some sample scenarios for this class of iterator:

*

*

 * // accessing keys/values through an iterator:
 * for (T#E#ObjectIterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     doSomethingWithValue(it.value());
 *   }
 * }
 * 
*

*

 * // modifying values in-place through iteration:
 * for (T#E#ObjectIterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     it.setValue(newValueForKey(it.key()));
 *   }
 * }
 * 
*

*

 * // deleting entries during iteration:
 * for (T#E#ObjectIterator it = map.iterator();
 *      it.hasNext();) {
 *   it.advance();
 *   if (satisfiesCondition(it.key()) {
 *     it.remove();
 *   }
 * }
 * 
*

*

 * // faster iteration by avoiding hasNext():
 * T#E#ObjectIterator iterator = map.iterator();
 * for (int i = map.size(); i-- > 0;) {
 *   iterator.advance();
 *   doSomethingWithKeyAndValue(iterator.key(), iterator.value());
 * }
 * 
* * @author Eric D. Friedman * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public class T#E#ObjectIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final T#E#ObjectHashMap _map; /** * Creates an iterator over the specified map */ public T#E#ObjectIterator(T#E#ObjectHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @throws java.util.NoSuchElementException * if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must advance() the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public #e# key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must advance() the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public V value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must advance() the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public V setValue(V val) { V old = value(); _map._values[_index] = val; return old; } }// T#E#ObjectIterator trove-2.1.0/src/gnu/trove/generate/P2OHashMap.template0000644000175000017500000004441511241347110021547 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.ObjectInput; import java.io.ObjectOutput; import java.io.Externalizable; import java.util.Arrays; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * An open addressed Map implementation for #e# keys and Object values. * * Created: Sun Nov 4 08:52:45 2001 * * @author Eric D. Friedman */ public class T#E#ObjectHashMap extends T#E#Hash implements Externalizable { static final long serialVersionUID = 1L; private final T#E#ObjectProcedure PUT_ALL_PROC = new T#E#ObjectProcedure() { public boolean execute(#e# key, V value) { put(key, value); return true; } }; /** the values of the map */ protected transient V[] _values; /** * Creates a new T#E#ObjectHashMap instance with the default * capacity and load factor. */ public T#E#ObjectHashMap() { super(); } /** * Creates a new T#E#ObjectHashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value */ public T#E#ObjectHashMap(int initialCapacity) { super(initialCapacity); } /** * Creates a new T#E#ObjectHashMap instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value */ public T#E#ObjectHashMap(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Creates a new T#E#ObjectHashMap instance with the default * capacity and load factor. * @param strategy used to compute hash codes and to compare keys. */ public T#E#ObjectHashMap(T#E#HashingStrategy strategy) { super(strategy); } /** * Creates a new T#E#ObjectHashMap instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare keys. */ public T#E#ObjectHashMap(int initialCapacity, T#E#HashingStrategy strategy) { super(initialCapacity, strategy); } /** * Creates a new T#E#ObjectHashMap 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 T#E#ObjectHashMap(int initialCapacity, float loadFactor, T#E#HashingStrategy strategy) { super(initialCapacity, loadFactor, strategy); } /** * @return a deep clone of this collection */ public T#E#ObjectHashMap clone() { T#E#ObjectHashMap m = (T#E#ObjectHashMap)super.clone(); m._values = (V[]) this._values.clone(); return m; } /** * @return a T#E#ObjectIterator with access to this map's keys and values */ public T#E#ObjectIterator iterator() { return new T#E#ObjectIterator(this); } /** * initializes the hashtable to a prime capacity which is at least * initialCapacity + 1. * * @param initialCapacity an int value * @return the actual capacity chosen */ protected int setUp(int initialCapacity) { int capacity; capacity = super.setUp(initialCapacity); _values = (V[]) new Object[capacity]; return capacity; } /** * Inserts a key/value pair into the map. * * @param key an #e# value * @param value an Object value * @return the previous value associated with key, * or {@code null} if none was found. */ public V put(#e# key, V value) { int index = insertionIndex(key); return doPut(key, value, index); } /** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an #e# value * @param value an Object value * @return the previous value associated with key, * or {@code null} if none was found. */ public V putIfAbsent(#e# key, V value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); } private V doPut(#e# key, V value, int index) { byte previousState; V previous = null; 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; } /** * Put all the entries from the given map into this map. * * @param map The map from which entries will be obtained to put into this map. */ public void putAll(T#E#ObjectHashMap map){ map.forEachEntry(PUT_ALL_PROC); } /** * rehashes the map to the new capacity. * * @param newCapacity an int value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; #e# oldKeys[] = _set; V oldVals[] = _values; byte oldStates[] = _states; _set = new #e#[newCapacity]; _values = (V[]) new Object[newCapacity]; _states = new byte[newCapacity]; for (int i = oldCapacity; i-- > 0;) { if(oldStates[i] == FULL) { #e# o = oldKeys[i]; int index = insertionIndex(o); _set[index] = o; _values[index] = oldVals[i]; _states[index] = FULL; } } } /** * retrieves the value for key * * @param key an #e# value * @return the value of key or (#e#)0 if no such mapping exists. */ public V get(#e# key) { int index = index(key); return index < 0 ? null : _values[index]; } /** * Empties the map. * */ public void clear() { super.clear(); #e#[] keys = _set; Object[] vals = _values; byte[] states = _states; Arrays.fill(_set, 0, _set.length, (#e#) 0); Arrays.fill(_values, 0, _values.length, null); Arrays.fill(_states, 0, _states.length, FREE); } /** * Deletes a key/value pair from the map. * * @param key an #e# value * @return an Object value or (#e#)0 if no such mapping exists. */ public V remove(#e# key) { V prev = null; 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 Object value * @return a boolean value */ public boolean equals(Object other) { if (! (other instanceof T#E#ObjectHashMap)) { return false; } T#E#ObjectHashMap that = (T#E#ObjectHashMap)other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); } public int hashCode() { HashProcedure p = new HashProcedure(); forEachEntry(p); return p.getHashCode(); } private final class HashProcedure implements T#E#ObjectProcedure { private int h = 0; public int getHashCode() { return h; } public final boolean execute(#e# key, Object value) { h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); return true; } } private static final class EqProcedure implements T#E#ObjectProcedure { private final T#E#ObjectHashMap _otherMap; EqProcedure(T#E#ObjectHashMap otherMap) { _otherMap = otherMap; } public final boolean execute(#e# key, Object value) { int index = _otherMap.index(key); if (index >= 0 && eq(value, _otherMap.get(key))) { return true; } return false; } /** * Compare two objects for equality. */ private final boolean eq(Object o1, Object o2) { return o1 == o2 || ((o1 != null) && o1.equals(o2)); } } /** * removes the mapping at index from the map. * * @param index an int value */ protected void removeAt(int index) { _values[index] = null; super.removeAt(index); // clear key, state; adjust size } /** * Returns the values of the map. * * @return a Collection value * * @see #getValues(Object[]) */ public Object[] getValues() { Object[] vals = new Object[size()]; V[] v = _values; byte[] states = _states; for (int i = v.length, j = 0; i-- > 0;) { if (states[i] == FULL) { vals[j++] = v[i]; } } return vals; } /** * Return the values of the map; the runtime type of the returned array is that of * the specified array. * * @param a the array into which the elements of this collection are to be * stored, if it is big enough; otherwise, a new array of the same * runtime type is allocated for this purpose. * @return an array containing the elements of this collection * * @throws ArrayStoreException the runtime type of the specified array is * not a supertype of the runtime type of every element in this * collection. * @throws NullPointerException if the specified array is null. * * @see #getValues() */ public T[] getValues( T[] a ) { if (a.length < _size) { a = (T[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), _size); } V[] v = _values; byte[] states = _states; for (int i = v.length, j = 0; i-- > 0;) { if (states[i] == FULL) { a[j++] = (T) v[i]; } } return a; } /** * returns the keys of the map. * * @return a Set value */ public #e#[] keys() { #e#[] keys = new #e#[size()]; #e#[] k = _set; byte[] states = _states; for (int i = k.length, j = 0; i-- > 0;) { if (states[i] == FULL) { keys[j++] = k[i]; } } return keys; } /** * returns the keys of the map. * * @param a the array into which the elements of the list are to * be stored, if it is big enough; otherwise, a new array of the * same type is allocated for this purpose. * @return a Set value */ public #e#[] keys(#e#[] a) { int size = size(); if (a.length < size) { a = (#e#[]) java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size); } #e#[] k = (#e#[]) _set; byte[] states = _states; for (int i = k.length, j = 0; i-- > 0;) { if (states[i] == FULL) { a[j++] = k[i]; } } return a; } /** * checks for the presence of val in the values of the map. * * @param val an Object value * @return a boolean value */ public boolean containsValue(V val) { byte[] states = _states; V[] vals = _values; // special case null values so that we don't have to // perform null checks before every call to equals() if (null == val) { for (int i = vals.length; i-- > 0;) { if (states[i] == FULL && val == vals[i]) { return true; } } } else { for (int i = vals.length; i-- > 0;) { if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { return true; } } } // end of else return false; } /** * checks for the present of key in the keys of the map. * * @param key an #e# value * @return a boolean value */ public boolean containsKey(#e# key) { return contains(key); } /** * Executes procedure for each key in the map. * * @param procedure a T#E#Procedure value * @return false if the loop over the keys terminated because * the procedure returned false for some key. */ public boolean forEachKey(T#E#Procedure procedure) { return forEach(procedure); } /** * Executes procedure for each value in the map. * * @param procedure a TObjectProcedure value * @return false if the loop over the values terminated because * the procedure returned false for some value. */ public boolean forEachValue(TObjectProcedure procedure) { byte[] states = _states; V[] values = _values; for (int i = values.length; i-- > 0;) { if (states[i] == FULL && ! procedure.execute(values[i])) { return false; } } return true; } /** * Executes procedure for each key/value entry in the * map. * * @param procedure a TO#E#ObjectProcedure value * @return false if the loop over the entries terminated because * the procedure returned false for some entry. */ public boolean forEachEntry(T#E#ObjectProcedure procedure) { byte[] states = _states; #e#[] keys = _set; V[] values = _values; for (int i = keys.length; i-- > 0;) { if (states[i] == FULL && ! procedure.execute(keys[i],values[i])) { return false; } } return true; } /** * Retains only those entries in the map for which the procedure * returns a true value. * * @param procedure determines which entries to keep * @return true if the map was modified. */ public boolean retainEntries(T#E#ObjectProcedure procedure) { boolean modified = false; byte[] states = _states; #e#[] keys = _set; V[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for (int i = keys.length; i-- > 0;) { if (states[i] == FULL && ! procedure.execute(keys[i],values[i])) { removeAt(i); modified = true; } } } finally { reenableAutoCompaction(true); } return modified; } /** * Transform the values in this map using function. * * @param function a TObjectFunction value */ public void transformValues(TObjectFunction function) { byte[] states = _states; V[] values = _values; for (int i = values.length; i-- > 0;) { if (states[i] == FULL) { values[i] = function.execute(values[i]); } } } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 0 ); // NUMBER OF ENTRIES out.writeInt( _size ); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure( out ); if (! forEachEntry(writeProcedure)) { throw writeProcedure.exception; } } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { #e# key = in.read#E#(); V val = (V) in.readObject(); put(key, val); } } public String toString() { final StringBuilder buf = new StringBuilder("{"); forEachEntry(new T#E#ObjectProcedure() { private boolean first = true; public boolean execute(#e# key, Object value) { if ( first ) first = false; else buf.append( "," ); buf.append(key); buf.append("="); buf.append(value); return true; } }); buf.append("}"); return buf.toString(); } } // T#E#ObjectHashMap trove-2.1.0/src/gnu/trove/generate/PIterator.template0000644000175000017500000000363011241347110021610 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Iterator for #e# collections. * * @author Eric D. Friedman * @version $Id: PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public class T#E#Iterator extends TPrimitiveIterator { /** the collection on which the iterator operates */ private final T#E#Hash _hash; /** * Creates a T#E#Iterator for the elements in the specified collection. */ public T#E#Iterator(T#E#Hash hash) { super(hash); this._hash = hash; } /** * Advances the iterator to the next element in the underlying collection * and returns it. * * @return the next #e# in the collection * @exception NoSuchElementException if the iterator is already exhausted */ public #e# next() { moveToNextIndex(); return _hash._set[_index]; } }// T#E#Iterator trove-2.1.0/src/gnu/trove/generate/O2PProcedure.template0000644000175000017500000000344511241347110022154 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Interface for procedures that take two parameters of type Object and #e#. * * Created: Mon Nov 5 22:03:30 2001 * * @author Eric D. Friedman * @version $Id: O2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public interface TObject#E#Procedure { /** * Executes this procedure. A false return value indicates that * the application executing this procedure should not invoke this * procedure again. * * @param a an Object value * @param b a #e# value * @return true if additional invocations of the procedure are * allowed. */ public boolean execute(K a, #e# b); }// TObject#E#Procedure trove-2.1.0/src/gnu/trove/generate/PProcedure.template0000644000175000017500000000333011241347110021744 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Interface for procedures with one #e# parameter. * * Created: Mon Nov 5 21:45:49 2001 * * @author Eric D. Friedman * @version $Id: PProcedure.template,v 1.2 2007/11/01 16:08:14 robeden Exp $ */ public interface T#E#Procedure { /** * Executes this procedure. A false return value indicates that * the application executing this procedure should not invoke this * procedure again. * * @param value a value of type #e# * @return true if additional invocations of the procedure are * allowed. */ public boolean execute(#e# value); }// T#E#Procedure trove-2.1.0/src/gnu/trove/generate/PHashSet.template0000644000175000017500000002465611241347110021371 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.ObjectInput; import java.io.ObjectOutput; import java.io.Externalizable; import java.util.Arrays; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * An open addressed set implementation for #e# primitives. * * @author Eric D. Friedman * @author Rob Eden */ public class T#E#HashSet extends T#E#Hash implements Externalizable { static final long serialVersionUID = 1L; /** * Creates a new T#E#HashSet instance with the default * capacity and load factor. */ public T#E#HashSet() { super(); } /** * Creates a new T#E#HashSet instance with a prime * capacity equal to or greater than initialCapacity and * with the default load factor. * * @param initialCapacity an int value */ public T#E#HashSet(int initialCapacity) { super(initialCapacity); } /** * Creates a new T#E#HashSet instance with a prime * capacity equal to or greater than initialCapacity and * with the specified load factor. * * @param initialCapacity an int value * @param loadFactor a float value */ public T#E#HashSet(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Creates a new T#E#HashSet instance containing the * elements of array. * * @param array an array of #e# primitives */ public T#E#HashSet(#e#[] array) { this(array.length); addAll(array); } /** * Creates a new T#E#Hash instance with the default * capacity and load factor. * @param strategy used to compute hash codes and to compare keys. */ public T#E#HashSet(T#E#HashingStrategy strategy) { super(strategy); } /** * Creates a new T#E#Hash instance whose capacity * is the next highest prime above initialCapacity + 1 * unless that value is already prime. * * @param initialCapacity an int value * @param strategy used to compute hash codes and to compare keys. */ public T#E#HashSet(int initialCapacity, T#E#HashingStrategy strategy) { super(initialCapacity, strategy); } /** * Creates a new T#E#Hash 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 T#E#HashSet(int initialCapacity, float loadFactor, T#E#HashingStrategy strategy) { super(initialCapacity, loadFactor, strategy); } /** * Creates a new T#E#HashSet instance containing the * elements of array. * * @param array an array of #e# primitives * @param strategy used to compute hash codes and to compare keys. */ public T#E#HashSet(#e#[] array, T#E#HashingStrategy strategy) { this(array.length, strategy); addAll(array); } /** * @return a T#E#Iterator with access to the values in this set */ public T#E#Iterator iterator() { return new T#E#Iterator(this); } /** * Inserts a value into the set. * * @param val an #e# value * @return true if the set was modified by the add operation */ public boolean add(#e# val) { int index = insertionIndex(val); if (index < 0) { return false; // already present in set, nothing to add } byte previousState = _states[index]; _set[index] = val; _states[index] = FULL; postInsertHook(previousState == FREE); return true; // yes, we added something } /** * Expands the set to accommodate new values. * * @param newCapacity an int value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; #e# oldSet[] = _set; byte oldStates[] = _states; _set = new #e#[newCapacity]; _states = new byte[newCapacity]; for (int i = oldCapacity; i-- > 0;) { if(oldStates[i] == FULL) { #e# o = oldSet[i]; int index = insertionIndex(o); _set[index] = o; _states[index] = FULL; } } } /** * Returns a new array containing the values in the set. * * @return an #e#[] value */ public #e#[] toArray() { #e#[] result = new #e#[size()]; #e#[] set = _set; byte[] states = _states; for (int i = states.length, j = 0; i-- > 0;) { if (states[i] == FULL) { result[j++] = set[i]; } } return result; } /** * Empties the set. */ public void clear() { super.clear(); #e#[] set = _set; byte[] states = _states; for (int i = set.length; i-- > 0;) { set[i] = (#e#)0; states[i] = FREE; } } /** * Compares this set with another set for equality of their stored * entries. * * @param other an Object value * @return a boolean value */ public boolean equals(Object other) { if (! (other instanceof T#E#HashSet)) { return false; } final T#E#HashSet that = (T#E#HashSet)other; if (that.size() != this.size()) { return false; } return forEach(new T#E#Procedure() { public final boolean execute(#e# value) { return that.contains(value); } }); } public int hashCode() { HashProcedure p = new HashProcedure(); forEach(p); return p.getHashCode(); } private final class HashProcedure implements T#E#Procedure { private int h = 0; public int getHashCode() { return h; } public final boolean execute(#e# key) { h += _hashingStrategy.computeHashCode(key); return true; } } /** * Removes val from the set. * * @param val an #e# value * @return true if the set was modified by the remove operation. */ public boolean remove(#e# val) { int index = index(val); if (index >= 0) { removeAt(index); return true; } return false; } /** * Tests the set to determine if all of the elements in * array are present. * * @param array an array of #e# primitives. * @return true if all elements were present in the set. */ public boolean containsAll(#e#[] array) { for (int i = array.length; i-- > 0;) { if (! contains(array[i])) { return false; } } return true; } /** * Adds all of the elements in array to the set. * * @param array an array of #e# primitives. * @return true if the set was modified by the add all operation. */ public boolean addAll(#e#[] array) { boolean changed = false; for (int i = array.length; i-- > 0;) { if (add(array[i])) { changed = true; } } return changed; } /** * Removes all of the elements in array from the set. * * @param array an array of #e# primitives. * @return true if the set was modified by the remove all operation. */ public boolean removeAll(#e#[] array) { boolean changed = false; for (int i = array.length; i-- > 0;) { if (remove(array[i])) { changed = true; } } return changed; } /** * Removes any values in the set which are not contained in * array. * * @param array an array of #e# primitives. * @return true if the set was modified by the retain all operation */ public boolean retainAll(#e#[] array) { boolean changed = false; Arrays.sort(array); #e#[] set = _set; byte[] states = _states; for (int i = set.length; i-- > 0;) { if (states[i] == FULL && (Arrays.binarySearch(array,set[i]) < 0)) { remove(set[i]); changed = true; } } return changed; } public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 0 ); // NUMBER OF ENTRIES out.writeInt( _size ); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure(out); if (! forEach(writeProcedure)) { throw writeProcedure.exception; } } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); // ENTRIES setUp(size); while (size-- > 0) { #e# val = in.read#E#(); add(val); } } } // T#E#HashSet trove-2.1.0/src/gnu/trove/generate/P2OMapDecorator.template0000644000175000017500000002446511241347110022611 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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.decorator; import gnu.trove.T#E#ObjectHashMap; import gnu.trove.T#E#ObjectIterator; import java.io.*; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Wrapper class to make a T#E#ObjectHashMap conform to the java.util.Map API. * This class simply decorates an underlying T#E#ObjectHashMap and translates the Object-based * APIs into their Trove primitive analogs. *

*

* Note that wrapping and unwrapping primitive values is extremely inefficient. If * possible, users of this class should override the appropriate methods in this class * and use a table of canonical values. *

*

* Created: Mon Sep 23 22:07:40 PDT 2002 * * @author Eric D. Friedman */ public class T#E#ObjectHashMapDecorator extends AbstractMap<#ET#, V> implements Map<#ET#, V>, Externalizable, Cloneable { /** * the wrapped primitive map */ protected T#E#ObjectHashMap _map; /** * FOR EXTERNALIZATION ONLY!! */ public T#E#ObjectHashMapDecorator() {} /** * Creates a wrapper that decorates the specified primitive map. */ public T#E#ObjectHashMapDecorator(T#E#ObjectHashMap map) { super(); this._map = map; } /** * Returns a reference to the map wrapped by this decorator. */ public T#E#ObjectHashMap getMap() { return _map; } /** * Clones the underlying trove collection and returns the clone wrapped in a new * decorator instance. This is a shallow clone except where primitives are * concerned. * * @return a copy of the receiver */ public T#E#ObjectHashMapDecorator clone() { try { T#E#ObjectHashMapDecorator copy = (T#E#ObjectHashMapDecorator) super.clone(); copy._map = (T#E#ObjectHashMap)_map.clone(); return copy; } catch (CloneNotSupportedException e) { // assert(false); throw new InternalError(); // we are cloneable, so this does not happen } } /** * Inserts a key/value pair into the map. * * @param key an Object value * @param value an Object value * @return the previous value associated with key, * or Integer(0) if none was found. */ public V put(#ET# key, V value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Retrieves the value for key * * @param key an Object value * @return the value of key or null if no such mapping exists. */ public V get(Object key) { return _map.get(unwrapKey(key)); } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an Object value * @return the removed value, or Integer(0) if it was not found in the map */ public V remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a Set value */ public Set> entrySet() { return new AbstractSet>() { public int size() { return _map.size(); } public boolean isEmpty() { return T#E#ObjectHashMapDecorator.this.isEmpty(); } public boolean contains(Object o) { if (o instanceof Map.Entry) { Object k = ((Map.Entry) o).getKey(); Object v = ((Map.Entry) o).getValue(); return T#E#ObjectHashMapDecorator.this.containsKey(k) && T#E#ObjectHashMapDecorator.this.get(k).equals(v); } else { return false; } } public Iterator> iterator() { return new Iterator>() { private final T#E#ObjectIterator it = _map.iterator(); public Map.Entry<#ET#,V> next() { it.advance(); final #ET# key = wrapKey(it.key()); final V v = wrapValue(it.value()); return new Map.Entry<#ET#,V>() { private V val = v; public boolean equals(Object o) { return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) && ((Map.Entry) o).getValue().equals(val); } public #ET# getKey() { return key; } public V getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public V setValue(V value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(Map.Entry<#ET#,V> o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection> c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { T#E#ObjectHashMapDecorator.this.clear(); } }; } /** * Checks for the presence of val in the values of the map. * * @param val an Object value * @return a boolean value */ public boolean containsValue(Object val) { return _map.containsValue(unwrapValue((V) val)); } /** * Checks for the present of key in the keys of the map. * * @param key an Object value * @return a boolean value */ public boolean containsKey(Object key) { return _map.containsKey(unwrapKey(key)); } /** * Returns the number of entries in the map. * * @return the map's size. */ public int size() { return this._map.size(); } /** * Indicates whether map has any entries. * * @return true if the map is empty */ public boolean isEmpty() { return size() == 0; } /** * Copies the key/value mappings in map into this map. * Note that this will be a deep copy, as storage is by * primitive value. * * @param map a Map value */ public void putAll(Map map) { Iterator> it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Entry e = it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param k key in the underlying map * @return an Object representation of the key */ protected #ET# wrapKey(#e# k) { return #ET#.valueOf(k); } /** * Unwraps a key * * @param key wrapped key * @return an unwrapped representation of the key */ protected #e# unwrapKey(Object key) { return ((#ET#)key).#e#Value(); } /** * Wraps a value * * @param o value in the underlying map * @return an Object representation of the value */ protected final V wrapValue(V o) { return o; } /** * Unwraps a value * * @param value wrapped value * @return an unwrapped representation of the value */ protected final V unwrapValue(V value) { return value; } // Implements Externalizable public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP _map = (T#E#ObjectHashMap) in.readObject(); } // Implements Externalizable public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // MAP out.writeObject(_map); } } // T#E#ObjectHashMapDecorator trove-2.1.0/src/gnu/trove/generate/PFunction.template0000644000175000017500000000307611241347110021610 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Interface for functions that accept and return one #e# primitive. * * Created: Mon Nov 5 22:19:36 2001 * * @author Eric D. Friedman * @version $Id: PFunction.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ */ public interface T#E#Function { /** * Execute this function with value * * @param value a #e# input * @return a #e# result */ public #e# execute(#e# value); }// T#E#Function trove-2.1.0/src/gnu/trove/decorator/0000755000175000017500000000000011261456735016350 5ustar mkochmkochtrove-2.1.0/src/gnu/trove/decorator/package.html0000644000175000017500000000303711241347110020614 0ustar mkochmkoch GNU Trove API Documentation

GNU Trove: Decorators for java.util.{Map,Set} compatability

The classes in this package serve to wrap the Trove primitive collections so that they can be used in operations that require a java.util.Map or java.util.Set.

This is form of adaptation is extremely inefficient and so should only be undertaken as a last resort or when you don't care about performance (in which case Trove is probably not appropriate anyway).

The general pattern here is that you "wrap" a Trove collection with the appropriate decorator object to obtain a java.util.Map or Set. The implementations do not retain references to the Objects they accept/return (all calls are delegated to the underlying trove collection), so you should not rely on object identity within those collections.

You may extend the decorator classes to use canonical values if your dataset permits. For some applications, this will help reduce the cost of (un)wrapping primitive values. Note, however, that such datasets are probably small/restricted enough that you should again ask yourself whether Trove is appropriate in the first place. Caveat programmer. Last modified: Mon Sep 23 22:55:32 PDT 2002 trove-2.1.0/src/gnu/trove/TObjectObjectProcedure.java0000644000175000017500000000321211241347110021541 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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; /** * Interface for procedures that take two Object parameters. * * Created: Mon Nov 5 22:03:30 2001 * * @author Eric D. Friedman * @version $Id: TObjectObjectProcedure.java,v 1.3 2006/11/10 23:27:57 robeden Exp $ */ public interface TObjectObjectProcedure { /** * Executes this procedure. A false return value indicates that * the application executing this procedure should not invoke this * procedure again. * * @param a an Object value * @param b an Object value * @return true if additional invocations of the procedure are * allowed. */ public boolean execute(K a, V b); }// TObjectObjectProcedure trove-2.1.0/src/gnu/trove/SerializationProcedure.java0000644000175000017500000004250111241347110021701 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, 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.ObjectOutput; /** * Implementation of the variously typed procedure interfaces that supports * writing the arguments to the procedure out on an ObjectOutputStream. * In the case of two-argument procedures, the arguments are written out * in the order received. * *

* Any IOException is trapped here so that it can be rethrown in a writeObject * method. *

* * Created: Sun Jul 7 00:14:18 2002 * * @author Eric D. Friedman * @version $Id: SerializationProcedure.java,v 1.5 2006/11/10 23:27:54 robeden Exp $ */ class SerializationProcedure implements TDoubleDoubleProcedure, TDoubleFloatProcedure, TDoubleIntProcedure, TDoubleLongProcedure, TDoubleShortProcedure, TDoubleByteProcedure, TDoubleObjectProcedure, TDoubleProcedure, TFloatDoubleProcedure, TFloatFloatProcedure, TFloatIntProcedure, TFloatLongProcedure, TFloatShortProcedure, TFloatByteProcedure, TFloatObjectProcedure, TFloatProcedure, TIntDoubleProcedure, TIntFloatProcedure, TIntIntProcedure, TIntLongProcedure, TIntShortProcedure, TIntByteProcedure, TIntObjectProcedure, TIntProcedure, TLongDoubleProcedure, TLongFloatProcedure, TLongIntProcedure, TLongLongProcedure, TLongShortProcedure, TLongByteProcedure, TLongObjectProcedure, TLongProcedure, TShortDoubleProcedure, TShortFloatProcedure, TShortIntProcedure, TShortLongProcedure, TShortShortProcedure, TShortByteProcedure, TShortObjectProcedure, TShortProcedure, TByteDoubleProcedure, TByteFloatProcedure, TByteIntProcedure, TByteLongProcedure, TByteShortProcedure, TByteByteProcedure, TByteObjectProcedure, TByteProcedure, TObjectDoubleProcedure, TObjectFloatProcedure, TObjectIntProcedure, TObjectLongProcedure, TObjectShortProcedure, TObjectByteProcedure, TObjectObjectProcedure, TObjectProcedure { private final ObjectOutput stream; IOException exception; SerializationProcedure ( ObjectOutput stream) { this.stream = stream; } public boolean execute(byte val) { try { stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short val) { try { stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int val) { try { stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double val) { try { stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long val) { try { stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float val) { try { stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object val) { try { stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object key, Object val) { try { stream.writeObject(key); stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object key, byte val) { try { stream.writeObject(key); stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object key, short val) { try { stream.writeObject(key); stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object key, int val) { try { stream.writeObject(key); stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object key, long val) { try { stream.writeObject(key); stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object key, double val) { try { stream.writeObject(key); stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(Object key, float val) { try { stream.writeObject(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int key, byte val) { try { stream.writeInt(key); stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int key, short val) { try { stream.writeInt(key); stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int key, Object val) { try { stream.writeInt(key); stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int key, int val) { try { stream.writeInt(key); stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int key, long val) { try { stream.writeInt(key); stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int key, double val) { try { stream.writeInt(key); stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(int key, float val) { try { stream.writeInt(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long key, Object val) { try { stream.writeLong(key); stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long key, byte val) { try { stream.writeLong(key); stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long key, short val) { try { stream.writeLong(key); stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long key, int val) { try { stream.writeLong(key); stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long key, long val) { try { stream.writeLong(key); stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long key, double val) { try { stream.writeLong(key); stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(long key, float val) { try { stream.writeLong(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double key, Object val) { try { stream.writeDouble(key); stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double key, byte val) { try { stream.writeDouble(key); stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double key, short val) { try { stream.writeDouble(key); stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double key, int val) { try { stream.writeDouble(key); stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double key, long val) { try { stream.writeDouble(key); stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double key, double val) { try { stream.writeDouble(key); stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(double key, float val) { try { stream.writeDouble(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float key, Object val) { try { stream.writeFloat(key); stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float key, byte val) { try { stream.writeFloat(key); stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float key, short val) { try { stream.writeFloat(key); stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float key, int val) { try { stream.writeFloat(key); stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float key, long val) { try { stream.writeFloat(key); stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float key, double val) { try { stream.writeFloat(key); stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(float key, float val) { try { stream.writeFloat(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(byte key, Object val) { try { stream.writeByte(key); stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(byte key, byte val) { try { stream.writeByte(key); stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(byte key, short val) { try { stream.writeByte(key); stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(byte key, int val) { try { stream.writeByte(key); stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(byte key, long val) { try { stream.writeByte(key); stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(byte key, double val) { try { stream.writeByte(key); stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(byte key, float val) { try { stream.writeByte(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short key, Object val) { try { stream.writeShort(key); stream.writeObject(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short key, byte val) { try { stream.writeShort(key); stream.writeByte(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short key, short val) { try { stream.writeShort(key); stream.writeShort(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short key, int val) { try { stream.writeShort(key); stream.writeInt(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short key, long val) { try { stream.writeShort(key); stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short key, double val) { try { stream.writeShort(key); stream.writeDouble(val); } catch (IOException e) { this.exception = e; return false; } return true; } public boolean execute(short key, float val) { try { stream.writeShort(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; } }// SerializationProcedure trove-2.1.0/src/gnu/trove/TLinkableAdapter.java0000644000175000017500000000426611241347110020367 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Jason Baldridge 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; /** * Adapter for TLinkable interface which implements the interface and can * therefore be extended trivially to create TLinkable objects without * having to implement the obvious. * *

* Created: Thurs Nov 15 16:25:00 2001 *

* * @author Jason Baldridge * @version $Id: TLinkableAdapter.java,v 1.1 2006/11/10 23:27:56 robeden Exp $ * @see gnu.trove.TLinkedList */ public class TLinkableAdapter implements TLinkable { TLinkable _previous, _next; /** * Returns the linked list node after this one. * * @return a TLinkable value */ public TLinkable getNext() { return _next; } /** * Returns the linked list node before this one. * * @return a TLinkable value */ public TLinkable getPrevious() { return _previous; } /** * Sets the linked list node after this one. * * @param linkable a TLinkable value */ public void setNext(TLinkable linkable) { _next = linkable; } /** * Sets the linked list node before this one. * * @param linkable a TLinkable value */ public void setPrevious(TLinkable linkable) { _previous = linkable; } } trove-2.1.0/src/gnu/trove/benchmark/0000755000175000017500000000000011261456735016320 5ustar mkochmkochtrove-2.1.0/src/gnu/trove/benchmark/CompactionBenchmark.java0000644000175000017500000000630611241347110023057 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2006, Rob Eden 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.benchmark; import gnu.trove.TIntObjectHashMap; import java.util.Random; /** * */ public class CompactionBenchmark { public static void main( String[] args ) { float compact_factor; if ( args.length > 0 ) compact_factor = Float.parseFloat( args[ 0 ] ); else compact_factor = 0.5f; System.out.println( "Compact factor: " + compact_factor ); int[] primitives = new int[ 1000000 ]; for( int i = 0; i < primitives.length; i++ ) { primitives[ i ] = i; } Integer[] objects = new Integer[ primitives.length ]; for( int i = 0; i < primitives.length; i++ ) { objects[ i ] = new Integer( primitives[ i ] ); } TIntObjectHashMap map = new TIntObjectHashMap() { @Override public void compact() { super.compact(); System.out.print( "c" ); } }; map.setAutoCompactionFactor( compact_factor ); Random rand = new Random(); final boolean manual_compaction = compact_factor == 0; long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; long total = 0; for( int i = 0; i < 50; i++ ) { long time = System.currentTimeMillis(); runTest( primitives, objects, map, rand ); if ( manual_compaction ) map.compact(); time = System.currentTimeMillis() - time; System.out.println( time ); total += time; min = Math.min( time, min ); max = Math.max( time, max ); } System.out.println( "----------------------" ); System.out.println( "Avg: " + ( total / 100.0 ) ); System.out.println( "Min: " + min ); System.out.println( "Max: " + max ); } private static void runTest( int[] primitives, Integer[] objects, TIntObjectHashMap map, Random rand ) { for( int i = 0; i < 250000; i++ ) { int index = rand.nextInt( primitives.length ); map.put( primitives[ index ], objects[ index ] ); } for( int i = 0; i < 250000; i++ ) { int index = rand.nextInt( primitives.length ); map.remove( primitives[ index ] ); } } } trove-2.1.0/src/gnu/trove/benchmark/Timer.java0000644000175000017500000000214511241347110020225 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; public interface Timer { public Operation getOperation(); public long theirs(); public long ours(); public Result run(); } trove-2.1.0/src/gnu/trove/benchmark/Reporter.java0000644000175000017500000000233711241347110020752 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; interface Reporter { void report(Result result); void start(); void finish(); public static final String[] ENV_PROPS = { "java.vm.name", "java.runtime.version", "os.name", "os.arch", "os.version" }; } trove-2.1.0/src/gnu/trove/benchmark/Operation.java0000644000175000017500000000211411241347110021101 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; public interface Operation { public void theirs(); public void ours(); public int getIterationCount(); } trove-2.1.0/src/gnu/trove/benchmark/MemoryUsage.java0000644000175000017500000001651611241347110021411 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; import gnu.trove.*; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; public class MemoryUsage { public static long sizeOf(Creator c) { long size= 0; Object[] objects = new Object[100]; try { Object primer = c.create(); long startingMemoryUse = getUsedMemory(); for (int i = 0; i < objects.length; i++) { objects[i] = c.create(); } long endingMemoryUse = getUsedMemory(); float approxSize = (endingMemoryUse - startingMemoryUse) / 100f; size = Math.round(approxSize); } catch (Exception e) { e.printStackTrace(); } return size; } private static long getUsedMemory() { gc(); long totalMemory = Runtime.getRuntime().totalMemory(); gc(); long freeMemory = Runtime.getRuntime().freeMemory(); long usedMemory = totalMemory - freeMemory; return usedMemory; } private static void gc() { try { System.gc(); Thread.currentThread().sleep(100); System.runFinalization(); Thread.currentThread().sleep(100); System.gc(); Thread.currentThread().sleep(100); System.runFinalization(); Thread.currentThread().sleep(100); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { try { MemoryComparator set = new MemoryComparator(new TroveSetCreator(), new JavasoftSetCreator(), "Compare size of Set implementation: 1,000 Integer objects measured in bytes"); set.compare(); set = null; MemoryComparator list = new MemoryComparator(new TroveListCreator(), new JavasoftListCreator(), "Compare size of LinkedList implementation: 1,000 TLinkableAdaptor objects measured in bytes"); list.compare(); list = null; MemoryComparator list2 = new MemoryComparator(new TroveIntArrayListCreator(), new JavasoftIntegerArrayListCreator(), "Compare size of int/IntegerArrayList implementation: 1,000 ints measured in bytes"); list2.compare(); list2 = null; MemoryComparator map = new MemoryComparator(new TroveMapCreator(), new JavasoftMapCreator(), "Compare size of Map implementation: 1,000 Integer->Integer mappings measured in bytes"); map.compare(); } catch (Exception e) { e.printStackTrace(); } System.exit(0); } static class MemoryComparator { Creator trove, javasoft; String description; MemoryComparator(Creator trove, Creator javasoft, String description) { this.trove = trove; this.javasoft = javasoft; this.description = description; } public void compare() { gc(); long j = sizeOf(javasoft); gc(); long t = sizeOf(trove); long p = Math.round(t * 100 / j * 100) / 100; System.out.println("--------------------------"); System.out.println(description); System.out.println("javasoft: " + j); System.out.println("trove: " + t); System.out.println("trove's collection requires " + p + "% of the memory needed by javasoft's collection"); } } interface Creator { Object create(); } static class TroveIntArrayListCreator implements Creator { public Object create() { TIntArrayList list = new TIntArrayList(); for (int i = 0; i < 1000; i++) { list.add(i); } list.trimToSize(); return list; } } static class JavasoftIntegerArrayListCreator implements Creator { public Object create() { ArrayList list = new ArrayList(); for (int i = 0; i < 1000; i++) { Integer x = new Integer(i); list.add(x); } list.trimToSize(); return list; } } static class TroveMapCreator implements Creator { public Object create() { THashMap map = new THashMap(); for (int i = 0; i < 1000; i++) { Integer x = new Integer(i); map.put(x,x); } return map; } } static class JavasoftMapCreator implements Creator { public Object create() { HashMap map = new HashMap(); for (int i = 0; i < 1000; i++) { Integer x = new Integer(i); map.put(x,x); } return map; } } static class TroveSetCreator implements Creator { public Object create() { THashSet map = new THashSet(); for (int i = 0; i < 1000; i++) { Integer x = new Integer(i); map.add(x); } return map; } } static class JavasoftSetCreator implements Creator { public Object create() { HashSet map = new HashSet(); for (int i = 0; i < 1000; i++) { Integer x = new Integer(i); map.add(x); } return map; } } static class TroveListCreator implements Creator { public Object create() { TLinkedList list = new TLinkedList(); for (int i = 0; i < 1000; i++) { TLinkableAdapter a = new TLinkableAdapter(); list.add(a); } return list; } } static class JavasoftListCreator implements Creator { public Object create() { LinkedList list = new LinkedList(); for (int i = 0; i < 1000; i++) { TLinkableAdapter a = new TLinkableAdapter(); list.add(a); } return list; } } } trove-2.1.0/src/gnu/trove/benchmark/Repeater.java0000644000175000017500000000371511241347110020720 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; class Repeater implements Timer { int _count; Operation _operation; Repeater(Operation o) { _count = o.getIterationCount(); _operation = o; } public Result run() { long theirs = theirs(); long ours = ours(); Result r = new Result(); r.setTheirs(theirs); r.setOurs(ours); r.setIterations(_count); r.setDescription(_operation.toString()); return r; } public long theirs() { long then = System.currentTimeMillis(); for (int i = 0; i < _count; i++) { _operation.theirs(); } long now = System.currentTimeMillis(); return (now -then); } public long ours() { long then = System.currentTimeMillis(); for (int i = 0; i < _count; i++) { _operation.ours(); } long now = System.currentTimeMillis(); return (now -then); } public Operation getOperation() { return _operation; } } trove-2.1.0/src/gnu/trove/benchmark/Result.java0000644000175000017500000000666011241347110020431 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; /** * * Created: Thu Nov 22 20:47:16 2001 * * @author Eric D. Friedman * @version $Id: Result.java,v 1.3 2008/05/07 19:26:31 robeden Exp $ */ class Result { long theirs; long ours; int iterations; String description; /** * Gets the value of theirs * * @return the value of theirs */ public long getTheirs() { return this.theirs; } /** * Sets the value of theirs * * @param argTheirs Value to assign to this.theirs */ public void setTheirs(long argTheirs){ this.theirs = argTheirs; } /** * Gets the value of ours * * @return the value of ours */ public long getOurs() { return this.ours; } /** * Sets the value of ours * * @param argOurs Value to assign to this.ours */ public void setOurs(long argOurs){ this.ours = argOurs; } /** * Gets the value of theirAvg * * @return the value of theirAvg */ public long getTheirAvg() { return theirs / iterations; } /** * Gets the value of ourAvg * * @return the value of ourAvg */ public long getOurAvg() { return ours / iterations; } /** * Gets the value of iterations * * @return the value of iterations */ public int getIterations() { return this.iterations; } /** * Sets the value of iterations * * @param argIterations Value to assign to this.iterations */ public void setIterations(int argIterations){ this.iterations = argIterations; } /** * Gets the value of description * * @return the value of description */ public String getDescription() { return this.description; } /** * Sets the value of description * * @param argDescription Value to assign to this.description */ public void setDescription(String argDescription){ this.description = argDescription; } public String toString() { StringBuilder b = new StringBuilder(); b.append(getDescription() + "\n"); b.append("Iterations: " + getIterations() + "\n"); b.append("Their total (msec): " + getTheirs() + "\n"); b.append("Our total (msec): " + getOurs() + "\n"); b.append("Their average (msec): " + getTheirAvg() + "\n"); b.append("Our average (msec): " + getOurAvg() + "\n"); return b.toString(); } } trove-2.1.0/src/gnu/trove/benchmark/XMLReporter.java0000644000175000017500000000523211241347110021330 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; import java.io.*; /** * * Created: Thu Nov 22 20:49:24 2001 * * @author Eric D. Friedman * @version $Id: XMLReporter.java,v 1.2 2006/11/10 23:27:59 robeden Exp $ */ class XMLReporter implements Reporter { PrintWriter out; XMLReporter() { this.out = new PrintWriter(new OutputStreamWriter(System.out), true); } XMLReporter(PrintWriter out) { this.out = out; } public void report(Result result) { out.println(""); out.print(""); out.print(result.getDescription()); out.println(""); out.print(""); out.print(result.getIterations()); out.println(""); out.print(""); out.print(result.getTheirs()); out.println(""); out.print(""); out.print(result.getTheirAvg()); out.println(""); out.print(""); out.print(result.getOurs()); out.println(""); out.print(""); out.print(result.getOurAvg()); out.println(""); out.println(""); } public void start() { out.println(""); out.println(""); out.print(""); for (int i = 0; i < ENV_PROPS.length; i++) { String key = ENV_PROPS[i]; out.print(System.getProperty(key)); out.print(" "); } out.println(""); } public void finish() { out.println(""); } } trove-2.1.0/src/gnu/trove/benchmark/Main.java0000644000175000017500000003425511241347110020040 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; import gnu.trove.*; import java.util.*; /** * * Created: Sat Nov 3 18:17:56 2001 * * @author Eric D. Friedman * @version $Id: Main.java,v 1.5 2006/12/11 21:03:48 robeden Exp $ */ public class Main { static final int ITERATIONS = 25; static final int SET_SIZE = 100000; static final List dataset = new ArrayList(SET_SIZE); static { for (int i = 0; i < SET_SIZE; i++) { dataset.add(new Integer(i)); } } public static Operation getSetOperation() { return new Operation() { public void theirs() { Set s = new HashSet(SET_SIZE); for (Iterator i = dataset.iterator(); i.hasNext();) { s.add(i.next()); } } public void ours() { Set s = new THashSet(SET_SIZE); for (Iterator i = dataset.iterator(); i.hasNext();) { s.add(i.next()); } } public String toString() { return "compares " + dataset.size() + " Set.add() operations"; } public int getIterationCount() { return ITERATIONS; } }; } public static Operation getLinkedListAddOp() { try { Class.forName( "gnu.trove.TLinkableAdapter" ); } catch( Throwable t ) { return new Operation() { public int getIterationCount() { return 1; } public void ours() {} public void theirs() {} public String toString() { return "(**UNAVAILABLE**) compares " + dataset.size() + " LinkedList.add() operations"; } }; } final List data = new ArrayList(100000); for (int i = 0; i < 100000; i++) { data.add(new TLinkableAdapter()); } return new Operation() { public void theirs() { List l = new LinkedList(); for (Iterator i = data.iterator(); i.hasNext();) { l.add(i.next()); } } public void ours() { List l = new TLinkedList(); for (Iterator i = data.iterator(); i.hasNext();) { l.add(i.next()); } } public String toString() { return "compares " + dataset.size() + " LinkedList.add() operations"; } public int getIterationCount() { return ITERATIONS; } }; } static Operation getContainsOp() { final Set theirs = new HashSet(dataset.size()); theirs.addAll(dataset); final Set ours = new THashSet(dataset.size()); ours.addAll(dataset); return new Operation() { public void theirs() { for (int i = 0; i < dataset.size(); i += 5) { theirs.contains(dataset.get(i)); } } public void ours() { for (int i = 0; i < dataset.size(); i += 5) { ours.contains(dataset.get(i)); } } public String toString() { return "compares " + dataset.size() / 5 + " Set.contains() operations"; } public int getIterationCount() { return ITERATIONS; } }; } static Operation getRandomSetContainsOp() { final Set theirs = new HashSet(SET_SIZE); final Set ours = new THashSet(SET_SIZE); Random rand = new Random(9999L); for (int i = 0; i < SET_SIZE; i++) { Integer x = new Integer(rand.nextInt()); theirs.add(x); ours.add(x); } Random rand2 = new Random(9998L); final List query = new ArrayList(SET_SIZE); int match = 0; for (int i = 0; i < SET_SIZE; i++) { Integer x = new Integer(rand.nextInt()); query.add(x); if (theirs.contains(x)) { match++; } } final int success = match; return new Operation() { public void theirs() { for (Iterator i = query.iterator(); i.hasNext();) { theirs.contains(i.next()); } } public void ours() { for (Iterator i = query.iterator(); i.hasNext();) { ours.contains(i.next()); } } public String toString() { return "compares " + SET_SIZE + " Set.contains() operations. " + success + " are actually present in set"; } public int getIterationCount() { return ITERATIONS; } }; } static Operation getMapPutOp() { return new Operation() { public void theirs() { Map theirs = new HashMap(dataset.size()); for (Iterator i = dataset.iterator();i.hasNext();) { Object o = i.next(); theirs.put(o,o); } } public void ours() { Map ours = new THashMap(dataset.size()); for (Iterator i = dataset.iterator();i.hasNext();) { Object o = i.next(); ours.put(o,o); } } public String toString() { return "compares " + dataset.size() + " Map.put() operations"; } public int getIterationCount() { return ITERATIONS; } }; } static Operation getIterationOp() { final Map theirMap = new HashMap(dataset.size()); final Map ourMap = new THashMap(dataset.size()); for (Iterator i = dataset.iterator();i.hasNext();) { Object o = i.next(); theirMap.put(o,o); ourMap.put(o,o); } return new Operation() { public void theirs() { Map m = theirMap; Iterator i = m.keySet().iterator(); for (int size = m.size(); size-- > 0;) { Object o = i.next(); } } public void ours() { Map m = ourMap; Iterator i = m.keySet().iterator(); for (int size = m.size(); size-- > 0;) { Object o = i.next(); } } public String toString() { return "compares Iterator.next() over " + dataset.size() + " map keys"; } public int getIterationCount() { return ITERATIONS; } }; } static Operation getIterationWithHasNextOp() { final Map theirMap = new HashMap(dataset.size()); final Map ourMap = new THashMap(dataset.size()); for (Iterator i = dataset.iterator();i.hasNext();) { Object o = i.next(); theirMap.put(o,o); ourMap.put(o,o); } return new Operation() { public void theirs() { Map m = theirMap; Iterator i = m.keySet().iterator(); while (i.hasNext()) { Object o = i.next(); } } public void ours() { Map m = ourMap; Iterator i = m.keySet().iterator(); while (i.hasNext()) { Object o = i.next(); } } public String toString() { return "compares Iterator.hasNext()/ Iterator.next() over " + theirMap.size() + " keys"; } public int getIterationCount() { return ITERATIONS; } }; } static Operation getIntMapPut() { return new Operation() { public void theirs() { } public void ours() { TIntIntHashMap ours = new TIntIntHashMap(SET_SIZE); for (int i = dataset.size(); i-- > 0;) { ours.put(i,i); } } public String toString() { return dataset.size() + " entry primitive int map.put timing run; no basis for comparison"; } public int getIterationCount() { return ITERATIONS; } }; } static Operation getSumSetOperation() { final Set theirSet = new HashSet(dataset.size()); final THashSet ourSet = new THashSet(dataset.size()); theirSet.addAll(dataset); ourSet.addAll(dataset); final TObjectProcedure proc = new TObjectProcedure() { int sum = 0; public boolean execute(Object o) { sum += ((Integer)o).intValue(); return true; } }; return new Operation() { public void theirs() { int sum = 0; for (Iterator i = theirSet.iterator(); i.hasNext();) { sum += ((Integer)i.next()).intValue(); } } public void ours() { ourSet.forEach(proc); } public String toString() { return "sums a " + theirSet.size() + " element Set of Integer objects. Their approach uses Iterator.hasNext()/next(); ours uses THashSet.forEach(TObjectProcedure)"; } public int getIterationCount() { return ITERATIONS; } }; } // This is an internal test comparing the old method using adjustValue() & put() to the // new adjustOrPutValue() method. static Operation getAdjustCompareOp() { final TObjectIntHashMap theirs = new TObjectIntHashMap(); final TObjectIntHashMap ours = new TObjectIntHashMap(); for( int i = 0; i < SET_SIZE; i++ ) { if ( ( i % 1000 ) == 0 ) { Integer int_obj = dataset.get( i ); theirs.put( int_obj, int_obj.intValue() ); ours.put( int_obj, int_obj.intValue() ); } } return new Operation() { public void theirs() { int size = dataset.size(); for( int i = 0; i < size; i++ ) { Integer key = dataset.get(i); if ( !theirs.adjustValue(key, 1) ) { theirs.put(key,1); } } } public void ours() { int size = dataset.size(); for( int i = 0; i < size; i++ ) { theirs.adjustOrPutValue(dataset.get(i), 1, 1); } } public String toString() { return "compares adjustValue & put vs. adjustOrPutValue"; } public int getIterationCount() { return ITERATIONS; } }; } public static void main (String[] args) { Operation op; Timer t; Reporter reporter; reporter = new TextReporter(); reporter.start(); // NOTE: this is internal only // op = getAdjustCompareOp(); // 10 times // t = new Repeater(op); // reporter.report(t.run()); op = getRandomSetContainsOp(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getSumSetOperation(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getIterationWithHasNextOp(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getIterationOp(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getLinkedListAddOp(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getIntMapPut(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getMapPutOp(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getContainsOp(); // 10 times t = new Repeater(op); reporter.report(t.run()); op = getSetOperation(); // 10 times t = new Repeater(op); reporter.report(t.run()); reporter.finish(); } } // Main trove-2.1.0/src/gnu/trove/benchmark/Test.java0000644000175000017500000000255511241347110020071 0ustar mkochmkoch/* * Copyright(c) 2008, MQSoftware, Inc. * All rights reserved. */ package gnu.trove.benchmark; import gnu.trove.THashMap; import gnu.trove.THashSet; /** * */ public class Test { public static void main(String[] args) { final int KEYS = 50000 * 10; final int ELEMENTS = 50000; final THashMap map = new THashMap(); // map.setAutoCompactionFactor(0); final THashSet keys = new THashSet(KEYS); // keys.setAutoCompactionFactor(0); while (keys.size() != KEYS) { final Integer k = (int) (Math.random() * 100000000); keys.add(k); } final Object[] keysA = keys.toArray(); int addKey = 0; int removeKey = 0; for (int i = 1; i < ELEMENTS; ++i) { map.put(keysA[ addKey++ ], null); } System.out.println("Map size: " + map.size()); final long start = System.currentTimeMillis(); for (int i = 1; i < 1000000; ++i) { map.put(keysA[ addKey++ ], null); if (addKey >= KEYS) { addKey = 0; } map.remove(keysA[ removeKey++ ]); if (removeKey >= KEYS) { removeKey = 0; } } System.out.println("Map size: " + map.size() + ", total time " + (System.currentTimeMillis() - start) + "ms" ); } } trove-2.1.0/src/gnu/trove/benchmark/TextReporter.java0000644000175000017500000000347011241347110021616 0ustar mkochmkoch/////////////////////////////////////////////////////////////////////////////// // 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.benchmark; import java.io.*; class TextReporter implements Reporter { PrintWriter out; TextReporter() { this(new PrintWriter(new OutputStreamWriter(System.out),true)); } TextReporter(PrintWriter out) { this.out = out; } public void report(Result result) { out.print(result); out.println("--------------------------------"); } public void start() { out.println("--------------------------------"); out.println("GNU Trove Benchmark suite"); out.println("--------------------------------"); for (int i = 0; i < ENV_PROPS.length; i++) { String key = ENV_PROPS[i]; out.println(key + "=" + System.getProperty(key)); } out.println("--------------------------------"); } public void finish() { out.println("done"); } } trove-2.1.0/LICENSE.txt0000644000175000017500000006355011241347112013465 0ustar mkochmkoch GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it!