You can subscribe to this list here.
2002 |
Jan
(14) |
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
(3) |
Jul
(3) |
Aug
(6) |
Sep
(14) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(1) |
Feb
|
Mar
(7) |
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
(2) |
Sep
(3) |
Oct
|
Nov
(7) |
Dec
(3) |
2004 |
Jan
|
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(4) |
Dec
|
2005 |
Jan
|
Feb
|
Mar
(11) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(7) |
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(29) |
Dec
(16) |
2007 |
Jan
(11) |
Feb
(6) |
Mar
(12) |
Apr
(2) |
May
|
Jun
(16) |
Jul
(9) |
Aug
(5) |
Sep
|
Oct
(4) |
Nov
(8) |
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
(23) |
Jun
|
Jul
|
Aug
(5) |
Sep
|
Oct
(11) |
Nov
(2) |
Dec
(3) |
2009 |
Jan
|
Feb
(2) |
Mar
(15) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(65) |
Sep
(180) |
Oct
(52) |
Nov
(33) |
Dec
|
2010 |
Jan
(5) |
Feb
(3) |
Mar
(24) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(49) |
Oct
|
Nov
|
Dec
|
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:18
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/src/gnu/trove Added Files: Tag: TROVE_3_WORKING Builder.java Log Message: Builder pattern initial implementation and associated changes. --- NEW FILE: Builder.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2008, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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.impl.Constants; /** * Configuration object to allow setting of all of the optional parameters * for the various Trove collections and maps and keep the constructors * manageable. */ public class Builder<K, V> { private int initial_capacity; private float load_factor; private K no_entry_key; private V no_entry_value; /** * Use the default values when none are provided. Individal constructors * for primitive classes will use the appropriate default key and value for * their primitive type. */ public Builder() { initial_capacity = Constants.DEFAULT_CAPACITY; load_factor = Constants.DEFAULT_LOAD_FACTOR; no_entry_key = null; no_entry_value = null; } /** * Provide the values for all of the optional information to be provided * to the constructors. Primitive collections should use the appropriate * Value class for each type. The <tt>no_entry_key</tt> parameter is only * used by the various Trove maps. * * @param initial_capacity the initial capacity desired. * @param load_factor the load factor to use (when applicable) * @param no_entry_key the value to use for invalid keys (only applies to Maps) * @param no_entry_value the value to use to non-existing values in maps and all other collections. */ public Builder( int initial_capacity, float load_factor, K no_entry_key, V no_entry_value ) { this.initial_capacity = initial_capacity; if ( load_factor < 0.0f ) load_factor = 0.0f; if ( load_factor > 1.0f ) load_factor = 1.0f; this.load_factor = load_factor; this.no_entry_key = no_entry_key; this.no_entry_value = no_entry_value; } /** * Get the collection's initial capacity. * * @return the initial capacity requested. */ public int getInitialCapacity() { return initial_capacity; } /** * Set the collection's initial capacity. * * @param initial_capacity the collection's initial capacity. * @return the instance to allow for call chaining. */ public Builder<K,V> setInitialCapacity( int initial_capacity ) { this.initial_capacity = initial_capacity; return this; } /** * Get the desired load factor. * * @return a float value between 0.0f and 1.0f that is the load factor * requested. */ public float getLoadFactor() { return load_factor; } /** * Set the desired load factor. * * @param load_factor a float value between 0.0f and 1.0f * @return the instance to allow for call chaining. */ public Builder<K,V> setLoadFactor( float load_factor ) { if ( load_factor < 0.0f ) load_factor = 0.0f; if ( load_factor > 1.0f ) load_factor = 1.0f; this.load_factor = load_factor; return this; } /** * The value that represents no entry in Trove map's keySet(). * * @return the value that represents null for Keys. */ public K getNoEntryKey() { return no_entry_key; } /** * Maps with primitive keys should use the appropriate Value Object * type * * @param no_entry_key the value that represents null for Trove map's keySet(). * @return the instance to allow for call chaining. */ public Builder<K,V> setNoEntryKey( K no_entry_key ) { this.no_entry_key = no_entry_key; return this; } /** * The value that represents null in various Trove maps and collections. * * @return the value that represents null for values in maps and collections. */ public V getNoEntryValue() { return no_entry_value; } /** * The value that represents null for values in Trove maps and collections. * * @param no_entry_value the value that represents null for Trove maps and collections. * @return the instance to allow for call chaining. */ public Builder<K,V> setNoEntryValue( V no_entry_value ) { this.no_entry_value = no_entry_value; return this; } /** {@inheritDoc} */ @Override public boolean equals( Object o ) { if ( this == o ) return true; if ( o == null || getClass() != o.getClass() ) return false; Builder builder = ( Builder ) o; if ( initial_capacity != builder.initial_capacity ) return false; if ( Float.compare( builder.load_factor, load_factor ) != 0 ) return false; if ( no_entry_key != null ? !no_entry_key.equals( builder.no_entry_key ) : builder.no_entry_key != null ) return false; //noinspection simplify return !(no_entry_value != null ? !no_entry_value.equals(builder.no_entry_value) : builder.no_entry_value != null); } /** {@inheritDoc} */ @Override public int hashCode() { int result = initial_capacity; result = 31 * result + ( load_factor != +0.0f ? Float.floatToIntBits( load_factor ) : 0 ); result = 31 * result + ( no_entry_key != null ? no_entry_key.hashCode() : 0 ); result = 31 * result + ( no_entry_value != null ? no_entry_value.hashCode() : 0 ); return result; } /** {@inheritDoc} */ @Override public String toString() { return "Builder{" + "initial_capacity=" + initial_capacity + ", load_factor=" + load_factor + ", no_entry_key=" + no_entry_key + ", no_entry_value=" + no_entry_value + '}'; } } |
Update of /cvsroot/trove4j/trove/test/gnu/trove/decorator In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/test/gnu/trove/decorator Modified Files: Tag: TROVE_3_WORKING TPrimitivePrimitiveMapDecoratorTest.java TPrimitiveObjectMapDecoratorTest.java TPrimitiveSetDecoratorTest.java Log Message: Builder pattern initial implementation and associated changes. Index: TPrimitivePrimitiveMapDecoratorTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/decorator/Attic/TPrimitivePrimitiveMapDecoratorTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** TPrimitivePrimitiveMapDecoratorTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.1 --- TPrimitivePrimitiveMapDecoratorTest.java 27 Sep 2009 06:23:58 -0000 1.1.2.2 *************** *** 22,25 **** --- 22,26 ---- import gnu.trove.TDecorators; + import gnu.trove.Builder; import gnu.trove.set.TIntSet; import gnu.trove.set.hash.TIntHashSet; *************** *** 69,73 **** assertEquals( keys.length, map.size() ); ! TIntLongMap raw_capacity = new TIntLongHashMap( 20 ); for ( int i = 0; i < keys.length; i++ ) { raw_capacity.put( keys[i], vals[i] ); --- 70,77 ---- assertEquals( keys.length, map.size() ); ! Builder<Integer,Long> builder = new Builder<Integer, Long>(); ! builder.setInitialCapacity( 20 ); ! ! TIntLongMap raw_capacity = new TIntLongHashMap( builder ); for ( int i = 0; i < keys.length; i++ ) { raw_capacity.put( keys[i], vals[i] ); *************** *** 76,80 **** assertEquals( keys.length, capacity.size() ); ! TIntLongMap raw_cap_and_factor = new TIntLongHashMap( 20, 0.75f ); for ( int i = 0; i < keys.length; i++ ) { raw_cap_and_factor.put( keys[i], vals[i] ); --- 80,85 ---- assertEquals( keys.length, capacity.size() ); ! builder.setLoadFactor( 0.75f ); ! TIntLongMap raw_cap_and_factor = new TIntLongHashMap( builder ); for ( int i = 0; i < keys.length; i++ ) { raw_cap_and_factor.put( keys[i], vals[i] ); *************** *** 83,88 **** assertEquals( keys.length, cap_and_factor.size() ); ! TIntLongMap raw_fully_specified = ! new TIntLongHashMap( 20, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); for ( int i = 0; i < keys.length; i++ ) { raw_fully_specified.put( keys[i], vals[i] ); --- 88,94 ---- assertEquals( keys.length, cap_and_factor.size() ); ! builder.setInitialCapacity( 20 ).setLoadFactor( 0.5f ); ! builder.setNoEntryKey( Integer.MIN_VALUE ).setNoEntryValue( Long.MIN_VALUE ); ! TIntLongMap raw_fully_specified = new TIntLongHashMap( builder ); for ( int i = 0; i < keys.length; i++ ) { raw_fully_specified.put( keys[i], vals[i] ); *************** *** 95,99 **** assertEquals( keys.length, fully_specified.size() ); ! TIntLongMap raw_arrays = new TIntLongHashMap( keys, vals ); Map<Integer,Long> arrays = TDecorators.wrap( raw_arrays ); assertEquals( keys.length, arrays.size() ); --- 101,105 ---- assertEquals( keys.length, fully_specified.size() ); ! TIntLongMap raw_arrays = new TIntLongHashMap( null, keys, vals ); Map<Integer,Long> arrays = TDecorators.wrap( raw_arrays ); assertEquals( keys.length, arrays.size() ); *************** *** 666,670 **** int element_count = 20; ! raw_map = new TIntLongHashMap( element_count, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); map = TDecorators.wrap( raw_map ); for ( int i = 0; i < element_count; i++ ) { --- 672,678 ---- int element_count = 20; ! Builder<Integer,Long> builder = ! new Builder<Integer, Long>( element_count, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); ! raw_map = new TIntLongHashMap( builder ); map = TDecorators.wrap( raw_map ); for ( int i = 0; i < element_count; i++ ) { *************** *** 967,971 **** int element_count = 20; ! raw_map = new TIntLongHashMap( 20, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); map = TDecorators.wrap( raw_map ); for ( int i = 0; i < element_count; i++ ) { --- 975,981 ---- int element_count = 20; ! Builder<Integer,Long> builder = ! new Builder<Integer, Long>( element_count, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); ! raw_map = new TIntLongHashMap( builder ); map = TDecorators.wrap( raw_map ); for ( int i = 0; i < element_count; i++ ) { *************** *** 990,995 **** Long[] vals = new Long[element_count]; TIntLongMap raw_map = ! new TIntLongHashMap( element_count, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); Map<Integer,Long> map = TDecorators.wrap( raw_map ); --- 1000,1007 ---- Long[] vals = new Long[element_count]; + Builder<Integer,Long> builder = + new Builder<Integer, Long>( 20, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); TIntLongMap raw_map = ! new TIntLongHashMap( builder ); Map<Integer,Long> map = TDecorators.wrap( raw_map ); Index: TPrimitiveObjectMapDecoratorTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/decorator/Attic/TPrimitiveObjectMapDecoratorTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** TPrimitiveObjectMapDecoratorTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.1 --- TPrimitiveObjectMapDecoratorTest.java 27 Sep 2009 06:23:58 -0000 1.1.2.2 *************** *** 24,27 **** --- 24,28 ---- import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.TDecorators; + import gnu.trove.Builder; import gnu.trove.set.TIntSet; import gnu.trove.set.hash.TIntHashSet; *************** *** 64,69 **** Map<Integer,String> map = TDecorators.wrap( raw_map ); ! TIntObjectMap<String> raw_capacity = ! new TIntObjectHashMap<String>( 20 ); for ( int i = 0; i < element_count; i++ ) { raw_capacity.put( keys[i], vals[i] ); --- 65,71 ---- Map<Integer,String> map = TDecorators.wrap( raw_map ); ! Builder<Integer,String> builder = new Builder<Integer,String>(); ! builder.setInitialCapacity( element_count ); ! TIntObjectMap<String> raw_capacity = new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { raw_capacity.put( keys[i], vals[i] ); *************** *** 72,77 **** assertEquals( map, capacity ); ! TIntObjectMap<String> raw_cap_and_factor = ! new TIntObjectHashMap<String>( 20, 0.75f ); for ( int i = 0; i < element_count; i++ ) { raw_cap_and_factor.put( keys[i], vals[i] ); --- 74,79 ---- assertEquals( map, capacity ); ! builder.setLoadFactor( 0.75f ); ! TIntObjectMap<String> raw_cap_and_factor = new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { raw_cap_and_factor.put( keys[i], vals[i] ); *************** *** 80,85 **** assertEquals( map, cap_and_factor ); ! TIntObjectMap<String> raw_fully_specified = ! new TIntObjectHashMap<String>( 20, 0.75f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { raw_fully_specified.put( keys[i], vals[i] ); --- 82,87 ---- assertEquals( map, cap_and_factor ); ! builder.setNoEntryKey( Integer.MIN_VALUE ); ! TIntObjectMap<String> raw_fully_specified = new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { raw_fully_specified.put( keys[i], vals[i] ); *************** *** 869,874 **** String[] vals = new String[element_count]; ! TIntObjectMap<String> raw_map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); Map<Integer,String> map = TDecorators.wrap( raw_map ); --- 871,878 ---- String[] vals = new String[element_count]; ! Builder<Integer,String> builder = new Builder<Integer,String>(); ! builder.setInitialCapacity( element_count ); ! builder.setNoEntryKey( Integer.MIN_VALUE ); ! TIntObjectMap<String> raw_map = new TIntObjectHashMap<String>( builder ); Map<Integer,String> map = TDecorators.wrap( raw_map ); *************** *** 951,956 **** String[] vals = new String[element_count]; ! TIntObjectMap<String> raw_map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; --- 955,962 ---- String[] vals = new String[element_count]; ! Builder<Integer,String> builder = new Builder<Integer,String>(); ! builder.setInitialCapacity( element_count ); ! builder.setNoEntryKey( Integer.MIN_VALUE ); ! TIntObjectMap<String> raw_map = new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; *************** *** 961,966 **** assertEquals( element_count, map.size() ); ! TIntObjectHashMap<String> raw_fully_specified = ! new TIntObjectHashMap<String>( 20, 0.75f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { raw_fully_specified.put( keys[i], vals[i] ); --- 967,972 ---- assertEquals( element_count, map.size() ); ! builder.setLoadFactor( 0.75f ); ! TIntObjectHashMap<String> raw_fully_specified = new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { raw_fully_specified.put( keys[i], vals[i] ); Index: TPrimitiveSetDecoratorTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/decorator/Attic/TPrimitiveSetDecoratorTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** TPrimitiveSetDecoratorTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.1 --- TPrimitiveSetDecoratorTest.java 27 Sep 2009 06:23:58 -0000 1.1.2.2 *************** *** 25,28 **** --- 25,29 ---- import gnu.trove.set.hash.TIntHashSet; import gnu.trove.TDecorators; + import gnu.trove.Builder; import java.util.*; *************** *** 68,77 **** assertTrue( "set not a copy: " + set + ", " + copy, set.equals( copy ) ); ! TIntSet raw_another = new TIntHashSet( 20 ); Set<Integer> another = TDecorators.wrap( raw_another ); another.addAll( Arrays.asList( ints ) ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); ! raw_another = new TIntHashSet( 2, 1.0f ); another = TDecorators.wrap( raw_another ); another.addAll( Arrays.asList( ints ) ); --- 69,81 ---- assertTrue( "set not a copy: " + set + ", " + copy, set.equals( copy ) ); ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( 20 ); ! TIntSet raw_another = new TIntHashSet( builder ); Set<Integer> another = TDecorators.wrap( raw_another ); another.addAll( Arrays.asList( ints ) ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); ! builder.setLoadFactor( 1.0f ); ! raw_another = new TIntHashSet( builder ); another = TDecorators.wrap( raw_another ); another.addAll( Arrays.asList( ints ) ); *************** *** 398,402 **** public void testToArrayWithParams() { int no_entry_value = Integer.MIN_VALUE; ! TIntSet raw_set = new TIntHashSet( 10, 0.5f, no_entry_value ); Set<Integer> set = TDecorators.wrap( raw_set ); --- 402,408 ---- public void testToArrayWithParams() { int no_entry_value = Integer.MIN_VALUE; ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setNoEntryValue( no_entry_value ); ! TIntSet raw_set = new TIntHashSet( builder ); Set<Integer> set = TDecorators.wrap( raw_set ); *************** *** 424,428 **** public void testRehashing() throws Exception { int size = 10000; ! TIntSet set = new TIntHashSet( 10 ); for ( int i = 0; i < size; i++ ) { set.add( i ); --- 430,434 ---- public void testRehashing() throws Exception { int size = 10000; ! TIntSet set = new TIntHashSet(); for ( int i = 0; i < size; i++ ) { set.add( i ); |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:15
|
Update of /cvsroot/trove4j/trove/src/gnu/trove/impl/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/src/gnu/trove/impl/hash Modified Files: Tag: TROVE_3_WORKING TPrimitiveHash.java Log Message: Builder pattern initial implementation and associated changes. Index: TPrimitiveHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/impl/hash/Attic/TPrimitiveHash.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** TPrimitiveHash.java 4 Sep 2009 12:32:33 -0000 1.1.2.2 --- TPrimitiveHash.java 27 Sep 2009 06:23:59 -0000 1.1.2.3 *************** *** 60,84 **** /** - * Creates a new <code>THash</code> instance with the default - * capacity and load factor. - */ - public TPrimitiveHash() { - super(); - } - - - /** - * Creates a new <code>TPrimitiveHash</code> instance with a prime - * capacity at or near the specified capacity and with the default - * load factor. - * - * @param initialCapacity an <code>int</code> value - */ - public TPrimitiveHash( int initialCapacity ) { - this( initialCapacity, DEFAULT_LOAD_FACTOR ); - } - - - /** * Creates a new <code>TPrimitiveHash</code> instance with a prime * capacity at or near the minimum needed to hold --- 60,63 ---- |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:13
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/impl/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/test/gnu/trove/impl/hash Modified Files: Tag: TROVE_3_WORKING THashTest.java Log Message: Builder pattern initial implementation and associated changes. Index: THashTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/impl/hash/Attic/THashTest.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** THashTest.java 15 Sep 2009 18:40:57 -0000 1.1.2.5 --- THashTest.java 27 Sep 2009 06:23:58 -0000 1.1.2.6 *************** *** 10,13 **** --- 10,14 ---- import gnu.trove.map.TIntObjectMap; import gnu.trove.map.TObjectIntMap; + import gnu.trove.Builder; import java.io.ByteArrayOutputStream; *************** *** 148,152 **** int cap = 20; ! TIntLongMap cap_and_factor = new TIntLongHashMap( cap, 0.75f ); TPrimitiveHash cap_and_factor_hash = (TPrimitiveHash) cap_and_factor; assertTrue( "capacity not sufficient: " + cap + ", " + cap_and_factor_hash.capacity(), --- 149,155 ---- int cap = 20; ! Builder<Integer,Long> builder = ! new Builder<Integer, Long>( cap, 0.75f, null, null ); ! TIntLongMap cap_and_factor = new TIntLongHashMap( builder ); TPrimitiveHash cap_and_factor_hash = (TPrimitiveHash) cap_and_factor; assertTrue( "capacity not sufficient: " + cap + ", " + cap_and_factor_hash.capacity(), *************** *** 154,159 **** assertEquals( 0.75f, cap_and_factor_hash._loadFactor ); ! TIntLongMap fully_specified = ! new TIntLongHashMap( cap, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); TPrimitiveHash fully_specified_hash = (TPrimitiveHash) fully_specified; assertTrue( "capacity not sufficient: " + cap + ", " + fully_specified_hash.capacity(), --- 157,162 ---- assertEquals( 0.75f, cap_and_factor_hash._loadFactor ); ! builder = new Builder<Integer, Long>( cap, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); ! TIntLongMap fully_specified = new TIntLongHashMap( builder ); TPrimitiveHash fully_specified_hash = (TPrimitiveHash) fully_specified; assertTrue( "capacity not sufficient: " + cap + ", " + fully_specified_hash.capacity(), *************** *** 170,175 **** long[] vals = new long[keys.length]; TIntLongMap original_map = ! new TIntLongHashMap( 200, 0.75f, Integer.MIN_VALUE, Long.MIN_VALUE ); for ( int i = 0; i < keys.length; i++ ) { vals[i] = keys[i] * 2; --- 173,180 ---- long[] vals = new long[keys.length]; + Builder<Integer, Long> builder = + new Builder<Integer, Long>( 200, 0.75f, Integer.MIN_VALUE, Long.MIN_VALUE ); TIntLongMap original_map = ! new TIntLongHashMap( builder ); for ( int i = 0; i < keys.length; i++ ) { vals[i] = keys[i] * 2; *************** *** 201,206 **** String[] vals = new String[keys.length]; ! TIntObjectMap<String> original_map = ! new TIntObjectHashMap<String>( 200, 0.75f, Integer.MIN_VALUE ); for ( int i = 0; i < keys.length; i++ ) { vals[i] = String.valueOf( keys[i] * 2 ); --- 206,214 ---- String[] vals = new String[keys.length]; ! Builder<Integer,String> builder = new Builder<Integer, String>(); ! builder.setInitialCapacity( 200 ); ! builder.setLoadFactor( 0.75f ); ! builder.setNoEntryKey( Integer.MIN_VALUE ); ! TIntObjectMap<String> original_map = new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < keys.length; i++ ) { vals[i] = String.valueOf( keys[i] * 2 ); |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:13
|
Update of /cvsroot/trove4j/trove/templates/gnu/trove/set/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/templates/gnu/trove/set/hash Modified Files: Tag: TROVE_3_WORKING _E_HashSet.template Log Message: Builder pattern initial implementation and associated changes. Index: _E_HashSet.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/set/hash/Attic/_E_HashSet.template,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -C2 -d -r1.1.2.7 -r1.1.2.8 *** _E_HashSet.template 18 Sep 2009 06:07:23 -0000 1.1.2.7 --- _E_HashSet.template 27 Sep 2009 06:23:59 -0000 1.1.2.8 *************** *** 27,30 **** --- 27,31 ---- import gnu.trove.impl.hash.T#E#Hash; import gnu.trove.T#E#Collection; + import gnu.trove.Builder; import java.io.IOException; *************** *** 52,55 **** --- 53,58 ---- static final long serialVersionUID = 1L; + /** a default builder object to use when none is specified. */ + private static final Builder<?, #ET#> DEFAULT_BUILDER = new Builder<Object, #ET#>(); /** *************** *** 58,87 **** */ public T#E#HashSet() { ! super(); ! } ! ! ! /** ! * Creates a new <code>T#E#HashSet</code> instance with a prime ! * capacity equal to or greater than <tt>initialCapacity</tt> and ! * with the default load factor. ! * ! * @param initialCapacity an <code>int</code> value ! */ ! public T#E#HashSet( int initialCapacity ) { ! super( initialCapacity ); ! } ! ! ! /** ! * Creates a new <code>TIntHash</code> instance with a prime ! * value at or near the specified capacity and load factor. ! * ! * @param initialCapacity used to find a prime capacity for the table. ! * @param load_factor used to calculate the threshold over which ! * rehashing takes place. ! */ ! public T#E#HashSet( int initialCapacity, float load_factor ) { ! super( initialCapacity, load_factor ); } --- 61,65 ---- */ public T#E#HashSet() { ! this( DEFAULT_BUILDER ); } *************** *** 92,104 **** * with the specified load factor. * ! * @param initial_capacity an <code>int</code> value ! * @param load_factor a <code>float</code> value ! * @param no_entry_value a <code>#e#</code> value that represents null. */ ! public T#E#HashSet( int initial_capacity, float load_factor, ! #e# no_entry_value ) { ! super( initial_capacity, load_factor, no_entry_value ); ! //noinspection RedundantCast ! if ( no_entry_value != ( #e# ) 0 ) { Arrays.fill( _set, no_entry_value ); } --- 70,86 ---- * with the specified load factor. * ! * @param builder describes the configurable parameters. */ ! public T#E#HashSet( Builder<?, ? extends #ET#> builder ) { ! super( builder.getInitialCapacity(), builder.getLoadFactor(), ! builder.getNoEntryValue() == null ? ! Constants.DEFAULT_#EC#_NO_ENTRY_VALUE : ! builder.getNoEntryValue().#e#Value() ); ! ! #e# no_entry_value = builder.getNoEntryValue() == null ? ! Constants.DEFAULT_#EC#_NO_ENTRY_VALUE : ! builder.getNoEntryValue().#e#Value(); ! ! if ( no_entry_value != 0 ) { Arrays.fill( _set, no_entry_value ); } *************** *** 113,117 **** */ public T#E#HashSet( Collection<? extends #ET#> collection ) { ! this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); addAll( collection ); } --- 95,100 ---- */ public T#E#HashSet( Collection<? extends #ET#> collection ) { ! this( new Builder<Object, #ET#>(). ! setInitialCapacity( Math.max( collection.size(), DEFAULT_CAPACITY ) ) ); addAll( collection ); } *************** *** 125,138 **** */ public T#E#HashSet( T#E#Collection collection ) { ! this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); if ( collection instanceof T#E#HashSet ) { T#E#HashSet hashset = ( T#E#HashSet ) collection; this._loadFactor = hashset._loadFactor; ! this.no_entry_value = hashset.no_entry_value; ! //noinspection RedundantCast ! if ( this.no_entry_value != ( #e# ) 0 ) { ! Arrays.fill( _set, this.no_entry_value ); ! } ! setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } addAll( collection ); --- 108,119 ---- */ public T#E#HashSet( T#E#Collection collection ) { ! this( new Builder<Object, #ET#>(). ! setInitialCapacity( Math.max( collection.size(), DEFAULT_CAPACITY ) ). ! setNoEntryValue( collection.getNoEntryValue() ) ); if ( collection instanceof T#E#HashSet ) { T#E#HashSet hashset = ( T#E#HashSet ) collection; this._loadFactor = hashset._loadFactor; ! int size = Math.max( hashset.size(), DEFAULT_CAPACITY ); ! setUp( ( int ) Math.ceil( size / _loadFactor ) ); } addAll( collection ); *************** *** 144,151 **** * elements of <tt>array</tt>. * * @param array an array of <code>#e#</code> primitives */ ! public T#E#HashSet( #e#[] array ) { ! this( Math.max( array.length, DEFAULT_CAPACITY ) ); addAll( array ); } --- 125,136 ---- * elements of <tt>array</tt>. * + * @param builder describes the configurable parameters. * @param array an array of <code>#e#</code> primitives */ ! public T#E#HashSet( Builder<?, ? extends #ET#> builder, #e#[] array ) { ! this( builder == null ? ! new Builder<Object, #ET#>(). ! setInitialCapacity( Math.max( array.length, DEFAULT_CAPACITY ) ) : ! builder ); addAll( array ); } |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:13
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/list/array In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/test/gnu/trove/list/array Modified Files: Tag: TROVE_3_WORKING TPrimitiveArrayListTest.java Log Message: Builder pattern initial implementation and associated changes. Index: TPrimitiveArrayListTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/list/array/Attic/TPrimitiveArrayListTest.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** TPrimitiveArrayListTest.java 11 Sep 2009 22:19:25 -0000 1.1.2.6 --- TPrimitiveArrayListTest.java 27 Sep 2009 06:23:59 -0000 1.1.2.7 *************** *** 17,21 **** import gnu.trove.set.hash.TIntHashSet; import gnu.trove.TIntCollection; ! --- 17,21 ---- import gnu.trove.set.hash.TIntHashSet; import gnu.trove.TIntCollection; ! import gnu.trove.Builder; *************** *** 490,494 **** } ! TIntArrayList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 490,496 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 523,527 **** public void testContainsAllTCollection() { int element_count = 20; ! TIntArrayList list = new TIntArrayList( element_count * 2 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 525,531 ---- public void testContainsAllTCollection() { int element_count = 20; ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count * 2 ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 561,565 **** int element_count = 20; int[] ints = new int[element_count]; ! TIntArrayList list = new TIntArrayList( element_count * 2 ); for ( int i = 0; i < element_count; i++ ) { ints[i] = i; --- 565,572 ---- int element_count = 20; int[] ints = new int[element_count]; ! ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count * 2 ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { ints[i] = i; *************** *** 583,587 **** } ! TIntArrayList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 590,596 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 612,616 **** } ! TIntArrayList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 621,627 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 668,672 **** } ! TIntList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 679,685 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 705,709 **** } ! TIntList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 718,724 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 743,747 **** } ! TIntList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 758,764 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 781,785 **** } ! TIntList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 798,804 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 799,803 **** // Reset the list ! list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 818,822 ---- // Reset the list ! list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 827,831 **** } ! TIntList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 846,852 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 840,844 **** // Reset the list ! list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 861,865 ---- // Reset the list ! list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 853,857 **** // Reset the list ! list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 874,878 ---- // Reset the list ! list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 881,885 **** } ! TIntList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 902,908 ---- } ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 893,897 **** // Reset the list ! list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 916,920 ---- // Reset the list ! list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 919,923 **** public void testShuffle() { int element_count = 20; ! TIntList list = new TIntArrayList( 20 ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); --- 942,948 ---- public void testShuffle() { int element_count = 20; ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! TIntArrayList list = new TIntArrayList( builder ); for ( int i = 0; i < element_count; i++ ) { list.add( i ); *************** *** 1034,1038 **** int element_count = 100; ! TIntArrayList array_list = new TIntArrayList( initial_size ); int initial_length = array_list._data.length; assertEquals( initial_size, initial_length ); --- 1059,1065 ---- int element_count = 100; ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( initial_size ); ! TIntArrayList array_list = new TIntArrayList( builder ); int initial_length = array_list._data.length; assertEquals( initial_size, initial_length ); *************** *** 1222,1226 **** public void testReset() { int element_count = 20; ! TIntArrayList a = new TIntArrayList( 20, Integer.MIN_VALUE ); for ( int i = 1; i <= element_count; i++ ) { a.add( i ); --- 1249,1256 ---- public void testReset() { int element_count = 20; ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( element_count ); ! builder.setNoEntryValue( Integer.MIN_VALUE ); ! TIntArrayList a = new TIntArrayList( builder ); for ( int i = 1; i <= element_count; i++ ) { a.add( i ); |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:13
|
Update of /cvsroot/trove4j/trove/test/gnu/trove In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/test/gnu/trove Modified Files: Tag: TROVE_3_WORKING TStackTest.java TArrayListTest.java Log Message: Builder pattern initial implementation and associated changes. Index: TStackTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/TStackTest.java,v retrieving revision 1.1.4.3 retrieving revision 1.1.4.4 diff -C2 -d -r1.1.4.3 -r1.1.4.4 *** TStackTest.java 4 Sep 2009 12:32:33 -0000 1.1.4.3 --- TStackTest.java 27 Sep 2009 06:23:59 -0000 1.1.4.4 *************** *** 57,61 **** assertEquals( 2, stack.size() ); ! TIntStack other = new TIntArrayStack( 20 ); other.push( 10 ); other.push( 20 ); --- 57,61 ---- assertEquals( 2, stack.size() ); ! TIntStack other = new TIntArrayStack(); other.push( 10 ); other.push( 20 ); *************** *** 101,105 **** public void testArrays() { int no_entry_value = Integer.MIN_VALUE; ! TIntStack stack = new TIntArrayStack(10, no_entry_value); assertEquals( no_entry_value, stack.getNoEntryValue() ); --- 101,107 ---- public void testArrays() { int no_entry_value = Integer.MIN_VALUE; ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setNoEntryValue( no_entry_value ); ! TIntStack stack = new TIntArrayStack( builder ); assertEquals( no_entry_value, stack.getNoEntryValue() ); *************** *** 177,181 **** assertEquals( 2, stack.size() ); ! TIntStack other = new TIntArrayStack( 20 ); other.push( 10 ); other.push( 20 ); --- 179,185 ---- assertEquals( 2, stack.size() ); ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( 20 ); ! TIntStack other = new TIntArrayStack( builder ); other.push( 10 ); other.push( 20 ); *************** *** 188,192 **** stack.equals( other ) ); ! TIntArrayList list = new TIntArrayList( stack.toArray() ); assertFalse( "stack should not equal list: " + stack + ", " + list, stack.equals( list ) ); --- 192,196 ---- stack.equals( other ) ); ! TIntArrayList list = new TIntArrayList( builder, stack.toArray() ); assertFalse( "stack should not equal list: " + stack + ", " + list, stack.equals( list ) ); *************** *** 202,206 **** assertEquals( 2, stack.size() ); ! TIntStack other = new TIntArrayStack( 20 ); other.push( 10 ); other.push( 20 ); --- 206,212 ---- assertEquals( 2, stack.size() ); ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( 20 ); ! TIntStack other = new TIntArrayStack( builder ); other.push( 10 ); other.push( 20 ); Index: TArrayListTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/TArrayListTest.java,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -C2 -d -r1.4.2.2 -r1.4.2.3 *** TArrayListTest.java 2 Sep 2009 21:52:33 -0000 1.4.2.2 --- TArrayListTest.java 27 Sep 2009 06:23:59 -0000 1.4.2.3 *************** *** 42,46 **** super.setUp(); ! list = new TIntArrayList( 15, Integer.MIN_VALUE ); list.add( 1 ); list.add( 2 ); --- 42,49 ---- super.setUp(); ! Builder<?,Integer> builder = new Builder<Object, Integer>(); ! builder.setInitialCapacity( 15 ); ! builder.setNoEntryValue( Integer.MIN_VALUE ); ! list = new TIntArrayList( builder ); list.add( 1 ); list.add( 2 ); |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:13
|
Update of /cvsroot/trove4j/trove/templates/gnu/trove/list/array In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/templates/gnu/trove/list/array Modified Files: Tag: TROVE_3_WORKING _E_ArrayList.template Log Message: Builder pattern initial implementation and associated changes. Index: _E_ArrayList.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/list/array/Attic/_E_ArrayList.template,v retrieving revision 1.1.2.15 retrieving revision 1.1.2.16 diff -C2 -d -r1.1.2.15 -r1.1.2.16 *** _E_ArrayList.template 11 Sep 2009 05:52:04 -0000 1.1.2.15 --- _E_ArrayList.template 27 Sep 2009 06:23:59 -0000 1.1.2.16 *************** *** 27,30 **** --- 27,31 ---- import gnu.trove.T#E#Collection; import gnu.trove.impl.*; + import gnu.trove.Builder; import java.io.Externalizable; *************** *** 46,49 **** --- 47,53 ---- static final long serialVersionUID = 1L; + /** a default builder object to use when none is specified. */ + private static final Builder<?, #ET#> DEFAULT_BUILDER = new Builder<Object, #ET#>(); + /** the data of the list */ protected #e#[] _data; *************** *** 65,81 **** @SuppressWarnings({"RedundantCast"}) public T#E#ArrayList() { ! this( DEFAULT_CAPACITY, ( #e# ) 0 ); ! } ! ! ! /** ! * Creates a new <code>T#E#ArrayList</code> instance with the ! * specified capacity. ! * ! * @param capacity an <code>int</code> value ! */ ! @SuppressWarnings({"RedundantCast"}) ! public T#E#ArrayList( int capacity ) { ! this( capacity, ( #e# ) 0 ); } --- 69,74 ---- @SuppressWarnings({"RedundantCast"}) public T#E#ArrayList() { ! //noinspection unchecked ! this( ( Builder<Object, #ET#> ) DEFAULT_BUILDER ); } *************** *** 83,97 **** /** * Creates a new <code>T#E#ArrayList</code> instance with the ! * specified capacity. * ! * @param capacity an <code>int</code> value ! * @param no_entry_value an <code>#e#</code> value that represents null. */ ! public T#E#ArrayList( int capacity, #e# no_entry_value ) { ! _data = new #e#[ capacity ]; _pos = 0; ! this.no_entry_value = no_entry_value; } /** * Creates a new <code>T#E#ArrayList</code> instance that contains --- 76,97 ---- /** * Creates a new <code>T#E#ArrayList</code> instance with the ! * specified configurable elements. * ! * @param builder describes the configurable parameters. */ ! public T#E#ArrayList( Builder<?, ? extends #ET#> builder ) { ! _data = new #e#[ builder.getInitialCapacity() ]; _pos = 0; ! no_entry_value = builder.getNoEntryValue() == null ? ! Constants.DEFAULT_#EC#_NO_ENTRY_VALUE : ! builder.getNoEntryValue().#e#Value(); ! ! //noinspection RedundantCast ! if ( no_entry_value != ( #e# ) 0 ) { ! Arrays.fill( _data, no_entry_value ); ! } } + /** * Creates a new <code>T#E#ArrayList</code> instance that contains *************** *** 101,105 **** */ public T#E#ArrayList ( T#E#Collection collection ) { ! this( collection.size() ); addAll( collection ); } --- 101,105 ---- */ public T#E#ArrayList ( T#E#Collection collection ) { ! this( new Builder<Object, #ET#>().setInitialCapacity( collection.size() ) ); addAll( collection ); } *************** *** 111,118 **** * initial contents are the specified values. * * @param values an <code>#e#[]</code> value */ ! public T#E#ArrayList( #e#[] values ) { ! this( values.length ); add( values ); } --- 111,119 ---- * initial contents are the specified values. * + * @param builder describes the configurable parameters. * @param values an <code>#e#[]</code> value */ ! public T#E#ArrayList( Builder<?, #ET#> builder, #e#[] values ) { ! this( builder == null ? DEFAULT_BUILDER : builder ); add( values ); } *************** *** 773,777 **** 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 ] ); --- 774,780 ---- throw new IndexOutOfBoundsException( "end index < " + _data.length ); } ! Builder<Object, #ET#> builder = new Builder<Object, #ET#>(); ! builder.setInitialCapacity( end - begin ).setNoEntryValue( getNoEntryValue() ); ! T#E#ArrayList list = new T#E#ArrayList( builder ); for ( int i = begin; i < end; i++ ) { list.add( _data[ i ] ); |
Update of /cvsroot/trove4j/trove/test/gnu/trove/map/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/test/gnu/trove/map/hash Modified Files: Tag: TROVE_3_WORKING TObjectPrimitiveHashMapTest.java TPrimitivePrimitiveHashMapTest.java TPrimitiveObjectHashMapTest.java Log Message: Builder pattern initial implementation and associated changes. Index: TObjectPrimitiveHashMapTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/map/hash/Attic/TObjectPrimitiveHashMapTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** TObjectPrimitiveHashMapTest.java 18 Sep 2009 21:50:08 -0000 1.1.2.2 --- TObjectPrimitiveHashMapTest.java 27 Sep 2009 06:23:58 -0000 1.1.2.3 *************** *** 861,865 **** int[] values_array = map.values(); assertEquals( element_count, values_array.length ); ! TIntList values_list = new TIntArrayList( values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); --- 861,865 ---- int[] values_array = map.values(); assertEquals( element_count, values_array.length ); ! TIntList values_list = new TIntArrayList( null, values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); *************** *** 869,873 **** values_array = map.values( new int[0] ); assertEquals( element_count, values_array.length ); ! values_list = new TIntArrayList( values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); --- 869,873 ---- values_array = map.values( new int[0] ); assertEquals( element_count, values_array.length ); ! values_list = new TIntArrayList( null, values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); *************** *** 877,881 **** values_array = map.values( new int[map.size()] ); assertEquals( element_count, values_array.length ); ! values_list = new TIntArrayList( values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); --- 877,881 ---- values_array = map.values( new int[map.size()] ); assertEquals( element_count, values_array.length ); ! values_list = new TIntArrayList( null, values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); *************** *** 885,889 **** values_array = map.values( new int[element_count * 2] ); assertEquals( element_count * 2, values_array.length ); ! values_list = new TIntArrayList( values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); --- 885,889 ---- values_array = map.values( new int[element_count * 2] ); assertEquals( element_count * 2, values_array.length ); ! values_list = new TIntArrayList( null, values_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( values_list.contains( vals[i] ) ); *************** *** 1185,1189 **** map.forEachValue( foreach ); TIntList built = foreach.getBuilt(); ! TIntList values = new TIntArrayList( map.values() ); assertEquals( values, built ); --- 1185,1189 ---- map.forEachValue( foreach ); TIntList built = foreach.getBuilt(); ! TIntList values = new TIntArrayList( null, map.values() ); assertEquals( values, built ); *************** *** 1212,1216 **** map.forEachValue( foreach_false ); built = foreach_false.getBuilt(); ! values = new TIntArrayList( map.values() ); assertEquals( 1, built.size() ); assertEquals( values.get( 0 ), built.get( 0 ) ); --- 1212,1216 ---- map.forEachValue( foreach_false ); built = foreach_false.getBuilt(); ! values = new TIntArrayList( null, map.values() ); assertEquals( 1, built.size() ); assertEquals( values.get( 0 ), built.get( 0 ) ); Index: TPrimitivePrimitiveHashMapTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/map/hash/Attic/TPrimitivePrimitiveHashMapTest.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** TPrimitivePrimitiveHashMapTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.5 --- TPrimitivePrimitiveHashMapTest.java 27 Sep 2009 06:23:58 -0000 1.1.2.6 *************** *** 41,44 **** --- 41,45 ---- import gnu.trove.TLongCollection; import gnu.trove.TIntCollection; + import gnu.trove.Builder; import junit.framework.TestCase; *************** *** 76,80 **** assertEquals( keys.length, map.size() ); ! TIntLongMap capacity = new TIntLongHashMap( 20 ); for ( int i = 0; i < keys.length; i++ ) { capacity.put( keys[i], vals[i] ); --- 77,83 ---- assertEquals( keys.length, map.size() ); ! Builder<Integer,Long> builder = new Builder<Integer, Long>(); ! builder.setInitialCapacity( 20 ); ! TIntLongMap capacity = new TIntLongHashMap( builder ); for ( int i = 0; i < keys.length; i++ ) { capacity.put( keys[i], vals[i] ); *************** *** 82,86 **** assertEquals( keys.length, capacity.size() ); ! TIntLongMap cap_and_factor = new TIntLongHashMap( 20, 0.75f ); for ( int i = 0; i < keys.length; i++ ) { cap_and_factor.put( keys[i], vals[i] ); --- 85,90 ---- assertEquals( keys.length, capacity.size() ); ! builder.setLoadFactor( 0.75f ); ! TIntLongMap cap_and_factor = new TIntLongHashMap( builder ); for ( int i = 0; i < keys.length; i++ ) { cap_and_factor.put( keys[i], vals[i] ); *************** *** 88,93 **** assertEquals( keys.length, cap_and_factor.size() ); ! TIntLongMap fully_specified = ! new TIntLongHashMap( 20, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); for ( int i = 0; i < keys.length; i++ ) { fully_specified.put( keys[i], vals[i] ); --- 92,97 ---- assertEquals( keys.length, cap_and_factor.size() ); ! builder = new Builder<Integer, Long>( 20, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE ); ! TIntLongMap fully_specified = new TIntLongHashMap( builder ); for ( int i = 0; i < keys.length; i++ ) { fully_specified.put( keys[i], vals[i] ); *************** *** 98,102 **** assertEquals( keys.length, fully_specified.size() ); ! TIntLongMap arrays = new TIntLongHashMap( keys, vals ); assertEquals( keys.length, arrays.size() ); --- 102,106 ---- assertEquals( keys.length, fully_specified.size() ); ! TIntLongMap arrays = new TIntLongHashMap( builder, keys, vals ); assertEquals( keys.length, arrays.size() ); *************** *** 314,317 **** --- 318,322 ---- // test with a java.util.Map Set<Number> java_set = new HashSet<Number>(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { java_set.add( Integer.valueOf( keys[i] ) ); *************** *** 326,330 **** // test with a TCollection ! TIntSet tintset = new TIntHashSet( keys ); assertTrue( set.containsAll( tintset ) ); tintset.add( 12 ); --- 331,335 ---- // test with a TCollection ! TIntSet tintset = new TIntHashSet( null, keys ); assertTrue( set.containsAll( tintset ) ); tintset.add( 12 ); *************** *** 354,357 **** --- 359,363 ---- // test with a java.util.Map Set<Integer> java_set = new HashSet<Integer>(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { java_set.add( Integer.valueOf( keys[i] ) ); *************** *** 400,403 **** --- 406,410 ---- // test with a java.util.Map Set<Number> java_set = new HashSet<Number>(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { java_set.add( Integer.valueOf( keys[i] ) ); *************** *** 406,409 **** --- 413,417 ---- assertEquals( keys.length, set.size() ); assertEquals( keys.length, map.size() ); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { assertTrue( set.contains( keys[i] ) ); *************** *** 415,418 **** --- 423,427 ---- assertEquals( keys.length - 1, set.size() ); assertEquals( keys.length - 1, map.size() ); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { if ( keys[i] != 42 ) { *************** *** 444,451 **** // test with a TCollection ! TIntSet tintset = new TIntHashSet( keys ); assertFalse( "set: " + set + ", collection: " + tintset, set.retainAll( tintset ) ); ! TIntCollection collection = new TIntArrayList( keys ); assertFalse( "set: " + set + ", collection: " + collection, set.retainAll( collection ) ); --- 453,460 ---- // test with a TCollection ! TIntSet tintset = new TIntHashSet( null, keys ); assertFalse( "set: " + set + ", collection: " + tintset, set.retainAll( tintset ) ); ! TIntCollection collection = new TIntArrayList( null, keys ); assertFalse( "set: " + set + ", collection: " + collection, set.retainAll( collection ) ); *************** *** 513,517 **** assertFalse( set.removeAll( java_set ) ); assertEquals( keys.length, set.size() ); ! assertEquals( keys.length, map.size() ); for ( int i = 0; i < keys.length; i++ ) { assertTrue( set.contains( keys[i] ) ); --- 522,527 ---- assertFalse( set.removeAll( java_set ) ); assertEquals( keys.length, set.size() ); ! assertEquals( keys.length, map.size() ); ! //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { assertTrue( set.contains( keys[i] ) ); *************** *** 519,522 **** --- 529,533 ---- } + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { java_set.add( Integer.valueOf( keys[i] ) ); *************** *** 527,530 **** --- 538,542 ---- assertEquals( "set: " + set, 1, set.size() ); assertEquals( "set: " + set, 1, map.size() ); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { if ( keys[i] == 42 ) { *************** *** 570,574 **** // With partial set ! tintset = new TIntHashSet( keys ); tintset.remove( 42 ); assertTrue( "set: " + set + ", collection: " + tintset, --- 582,586 ---- // With partial set ! tintset = new TIntHashSet( null, keys ); tintset.remove( 42 ); assertTrue( "set: " + set + ", collection: " + tintset, *************** *** 576,579 **** --- 588,592 ---- assertEquals( "set: " + set, 1, set.size() ); assertEquals( "set: " + set, 1, map.size() ); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { if ( keys[i] == 42 ) { *************** *** 600,604 **** // partial list ! collection = new TIntArrayList( keys ); collection.remove( 42 ); assertTrue( "set: " + set + ", collection: " + collection, --- 613,617 ---- // partial list ! collection = new TIntArrayList( null, keys ); collection.remove( 42 ); assertTrue( "set: " + set + ", collection: " + collection, *************** *** 606,609 **** --- 619,623 ---- assertEquals( "set: " + set, 1, set.size() ); assertEquals( "set: " + set, 1, map.size() ); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { if ( keys[i] == 42 ) { *************** *** 765,769 **** } ! TIntList list = new TIntArrayList( keys ); TIntSet set = map.keySet(); assertEquals( map.getNoEntryValue(), set.getNoEntryValue() ); --- 779,783 ---- } ! TIntList list = new TIntArrayList( null, keys ); TIntSet set = map.keySet(); assertEquals( map.getNoEntryValue(), set.getNoEntryValue() ); *************** *** 814,818 **** int[] keys = map.keys( new int[map.size()] ); assertEquals( 2, keys.length ); ! TIntList keys_list = new TIntArrayList( keys ); assertTrue( keys_list.contains( KEY_ONE ) ); --- 828,832 ---- int[] keys = map.keys( new int[map.size()] ); assertEquals( 2, keys.length ); ! TIntList keys_list = new TIntArrayList( null, keys ); assertTrue( keys_list.contains( KEY_ONE ) ); *************** *** 821,825 **** int[] keys2 = map.keys(); assertEquals( 2, keys2.length ); ! TIntList keys_list2 = new TIntArrayList( keys2 ); assertTrue( keys_list2.contains( KEY_ONE ) ); --- 835,839 ---- int[] keys2 = map.keys(); assertEquals( 2, keys2.length ); ! TIntList keys_list2 = new TIntArrayList( null, keys2 ); assertTrue( keys_list2.contains( KEY_ONE ) ); *************** *** 904,907 **** --- 918,922 ---- // test with a java.util.Map Set<Number> java_set = new HashSet<Number>(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < vals.length; i++ ) { java_set.add( Long.valueOf( vals[i] ) ); *************** *** 916,920 **** // test with a TCollection ! TLongSet tintset = new TLongHashSet( vals ); assertTrue( values.containsAll( tintset ) ); tintset.add( 12 ); --- 931,935 ---- // test with a TCollection ! TLongSet tintset = new TLongHashSet( null, vals ); assertTrue( values.containsAll( tintset ) ); tintset.add( 12 ); *************** *** 944,947 **** --- 959,963 ---- // test with a java.util.Map Set<Long> java_set = new HashSet<Long>(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < vals.length; i++ ) { java_set.add( Long.valueOf( vals[i] ) ); *************** *** 990,993 **** --- 1006,1010 ---- // test with a java.util.Map Set<Number> java_set = new HashSet<Number>(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < vals.length; i++ ) { java_set.add( Long.valueOf( vals[i] ) ); *************** *** 1035,1042 **** // test with a TCollection ! TLongSet tintset = new TLongHashSet( vals ); assertFalse( "values: " + values + ", collection: " + tintset, values.retainAll( tintset ) ); ! TLongCollection collection = new TLongArrayList( vals ); assertFalse( "values: " + values + ", collection: " + collection, values.retainAll( collection ) ); --- 1052,1059 ---- // test with a TCollection ! TLongSet tintset = new TLongHashSet( null, vals ); assertFalse( "values: " + values + ", collection: " + tintset, values.retainAll( tintset ) ); ! TLongCollection collection = new TLongArrayList( null, vals ); assertFalse( "values: " + values + ", collection: " + collection, values.retainAll( collection ) ); *************** *** 1110,1113 **** --- 1127,1131 ---- } + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < vals.length; i++ ) { java_set.add( Long.valueOf( vals[i] ) ); *************** *** 1118,1121 **** --- 1136,1140 ---- assertEquals( "set: " + values, 1, values.size() ); assertEquals( "set: " + values, 1, map.size() ); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < vals.length; i++ ) { if ( vals[i] == 42 * 2 ) { *************** *** 1161,1165 **** // With partial set ! tlongset = new TLongHashSet( vals ); tlongset.remove( 42 * 2 ); assertTrue( "values: " + values + ", collection: " + tlongset, --- 1180,1184 ---- // With partial set ! tlongset = new TLongHashSet( null, vals ); tlongset.remove( 42 * 2 ); assertTrue( "values: " + values + ", collection: " + tlongset, *************** *** 1191,1195 **** // partial list ! collection = new TLongArrayList( vals ); collection.remove( 42 * 2 ); assertTrue( "values: " + values + ", collection: " + collection, --- 1210,1214 ---- // partial list ! collection = new TLongArrayList( null, vals ); collection.remove( 42 * 2 ); assertTrue( "values: " + values + ", collection: " + collection, *************** *** 1297,1301 **** values.equals( values_list ) ); ! TLongList list = new TLongArrayList( vals ); values_list.sort(); list.sort(); --- 1316,1320 ---- values.equals( values_list ) ); ! TLongList list = new TLongArrayList( null, vals ); values_list.sort(); list.sort(); *************** *** 1322,1326 **** // value in map twice, in list twice. ! list = new TLongArrayList( vals ); map.put( 1, vals[0] ); values_list = new TLongArrayList( map.valueCollection() ); --- 1341,1345 ---- // value in map twice, in list twice. ! list = new TLongArrayList( null, vals ); map.put( 1, vals[0] ); values_list = new TLongArrayList( map.valueCollection() ); *************** *** 1332,1336 **** // value in the map twice, same length list, but value only in list once. ! list = new TLongArrayList( vals ); list.add( -1 ); list.sort(); --- 1351,1355 ---- // value in the map twice, same length list, but value only in list once. ! list = new TLongArrayList( null, vals ); list.add( -1 ); list.sort(); *************** *** 1371,1375 **** } ! TLongList list = new TLongArrayList( vals ); TLongCollection set = map.valueCollection(); assertEquals( map.getNoEntryValue(), set.getNoEntryValue() ); --- 1390,1394 ---- } ! TLongList list = new TLongArrayList( null, vals ); TLongCollection set = map.valueCollection(); assertEquals( map.getNoEntryValue(), set.getNoEntryValue() ); *************** *** 1420,1424 **** long[] values = map.values( new long[map.size()] ); assertEquals( 2, values.length ); ! TLongList values_list = new TLongArrayList( values ); assertTrue( values_list.contains( 1 ) ); --- 1439,1443 ---- long[] values = map.values( new long[map.size()] ); assertEquals( 2, values.length ); ! TLongList values_list = new TLongArrayList( null, values ); assertTrue( values_list.contains( 1 ) ); *************** *** 1427,1431 **** long[] values2 = map.values(); assertEquals( 2, values2.length ); ! TLongList keys_list2 = new TLongArrayList( values2 ); assertTrue( keys_list2.contains( 1 ) ); --- 1446,1450 ---- long[] values2 = map.values(); assertEquals( 2, values2.length ); ! TLongList keys_list2 = new TLongArrayList( null, values2 ); assertTrue( keys_list2.contains( 1 ) ); *************** *** 1473,1477 **** map.forEachKey( foreach ); TIntList built = foreach.getBuilt(); ! TIntList keys = new TIntArrayList( map.keys() ); assertEquals( keys, built ); --- 1492,1496 ---- map.forEachKey( foreach ); TIntList built = foreach.getBuilt(); ! TIntList keys = new TIntArrayList( null, map.keys() ); assertEquals( keys, built ); *************** *** 1498,1502 **** map.forEachKey( foreach_false ); built = foreach_false.getBuilt(); ! keys = new TIntArrayList( map.keys() ); assertEquals( 1, built.size() ); assertEquals( keys.get( 0 ), built.get( 0 ) ); --- 1517,1521 ---- map.forEachKey( foreach_false ); built = foreach_false.getBuilt(); ! keys = new TIntArrayList( null, map.keys() ); assertEquals( 1, built.size() ); assertEquals( keys.get( 0 ), built.get( 0 ) ); *************** *** 1528,1532 **** map.forEachValue( foreach ); TLongList built = foreach.getBuilt(); ! TLongList vals = new TLongArrayList( map.values() ); assertEquals( vals, built ); --- 1547,1551 ---- map.forEachValue( foreach ); TLongList built = foreach.getBuilt(); ! TLongList vals = new TLongArrayList( null, map.values() ); assertEquals( vals, built ); *************** *** 1553,1557 **** map.forEachValue( foreach_false ); built = foreach_false.getBuilt(); ! vals = new TLongArrayList( map.values() ); assertEquals( 1, built.size() ); assertEquals( vals.get( 0 ), built.get( 0 ) ); --- 1572,1576 ---- map.forEachValue( foreach_false ); built = foreach_false.getBuilt(); ! vals = new TLongArrayList( null, map.values() ); assertEquals( 1, built.size() ); assertEquals( vals.get( 0 ), built.get( 0 ) ); *************** *** 1958,1961 **** --- 1977,1981 ---- TIntLongMap unequal = new TIntLongHashMap(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < keys.length; i++ ) { unequal.put( keys[i], keys[i] ); *************** *** 1966,1969 **** --- 1986,1990 ---- int[] mismatched = {72, 49, 53, 1024, 999}; TIntLongMap mismatched_map = new TIntLongHashMap(); + //noinspection ForLoopReplaceableByForEach for ( int i = 0; i < mismatched.length; i++ ) { mismatched_map.put( mismatched[i], mismatched[i] * 37 ); Index: TPrimitiveObjectHashMapTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/map/hash/Attic/TPrimitiveObjectHashMapTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** TPrimitiveObjectHashMapTest.java 18 Sep 2009 21:50:08 -0000 1.1.2.3 --- TPrimitiveObjectHashMapTest.java 27 Sep 2009 06:23:58 -0000 1.1.2.4 *************** *** 42,46 **** import gnu.trove.set.hash.TIntHashSet; import gnu.trove.TIntCollection; ! --- 42,46 ---- import gnu.trove.set.hash.TIntHashSet; import gnu.trove.TIntCollection; ! import gnu.trove.Builder; *************** *** 67,72 **** } TIntObjectMap<String> capacity = ! new TIntObjectHashMap<String>( 20 ); for ( int i = 0; i < element_count; i++ ) { capacity.put( keys[i], vals[i] ); --- 67,74 ---- } + Builder<Integer,String> builder = new Builder<Integer, String>(); + builder.setInitialCapacity( element_count ); TIntObjectMap<String> capacity = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { capacity.put( keys[i], vals[i] ); *************** *** 74,79 **** assertEquals( map, capacity ); TIntObjectMap<String> cap_and_factor = ! new TIntObjectHashMap<String>( 20, 0.75f ); for ( int i = 0; i < element_count; i++ ) { cap_and_factor.put( keys[i], vals[i] ); --- 76,82 ---- assertEquals( map, capacity ); + builder.setLoadFactor( 0.75f ); TIntObjectMap<String> cap_and_factor = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { cap_and_factor.put( keys[i], vals[i] ); *************** *** 81,86 **** assertEquals( map, cap_and_factor ); TIntObjectMap<String> fully_specified = ! new TIntObjectHashMap<String>( 20, 0.75f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { fully_specified.put( keys[i], vals[i] ); --- 84,90 ---- assertEquals( map, cap_and_factor ); + builder.setNoEntryKey( Integer.MIN_VALUE ); TIntObjectMap<String> fully_specified = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { fully_specified.put( keys[i], vals[i] ); *************** *** 407,410 **** --- 411,415 ---- Collection<Integer> test_collection = new HashSet<Integer>(); + //noinspection ManualArrayToCollectionCopy for ( int i = 0; i < element_count; i++ ) { test_collection.add( keys[i] ); *************** *** 507,510 **** --- 512,516 ---- Collection<Integer> test_collection = new HashSet<Integer>(); + //noinspection ManualArrayToCollectionCopy for ( int i = 0; i < element_count; i++ ) { test_collection.add( keys[i] ); *************** *** 814,818 **** assertEquals( keyset.hashCode(), keyset.hashCode() ); ! TIntSet other = new TIntHashSet( keys ); other.add( 1138 ); assertTrue( keyset.hashCode() != other.hashCode() ); --- 820,824 ---- assertEquals( keyset.hashCode(), keyset.hashCode() ); ! TIntSet other = new TIntHashSet( null, keys ); other.add( 1138 ); assertTrue( keyset.hashCode() != other.hashCode() ); *************** *** 836,840 **** int[] keys_array = map.keys(); assertEquals( element_count, keys_array.length ); ! TIntList keys_list = new TIntArrayList( keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); --- 842,846 ---- int[] keys_array = map.keys(); assertEquals( element_count, keys_array.length ); ! TIntList keys_list = new TIntArrayList( null, keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); *************** *** 844,848 **** keys_array = map.keys( new int[0] ); assertEquals( element_count, keys_array.length ); ! keys_list = new TIntArrayList( keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); --- 850,854 ---- keys_array = map.keys( new int[0] ); assertEquals( element_count, keys_array.length ); ! keys_list = new TIntArrayList( null, keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); *************** *** 852,856 **** keys_array = map.keys( new int[map.size()] ); assertEquals( element_count, keys_array.length ); ! keys_list = new TIntArrayList( keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); --- 858,862 ---- keys_array = map.keys( new int[map.size()] ); assertEquals( element_count, keys_array.length ); ! keys_list = new TIntArrayList( null, keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); *************** *** 860,864 **** keys_array = map.keys( new int[element_count * 2] ); assertEquals( element_count * 2, keys_array.length ); ! keys_list = new TIntArrayList( keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); --- 866,870 ---- keys_array = map.keys( new int[element_count * 2] ); assertEquals( element_count * 2, keys_array.length ); ! keys_list = new TIntArrayList( null, keys_array ); for ( int i = 0; i < element_count; i++ ) { assertTrue( keys_list.contains( keys[i] ) ); *************** *** 1355,1360 **** int remaining = element_count / 2; ! TIntObjectHashMap<String> map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int pass = 0; pass < 10; pass++ ) { --- 1361,1368 ---- int remaining = element_count / 2; ! Builder<Integer,String> builder = new Builder<Integer, String>(); ! builder.setInitialCapacity( element_count ); ! builder.setNoEntryKey( Integer.MIN_VALUE ); ! TIntObjectHashMap<String> map = new TIntObjectHashMap<String>( builder ); for ( int pass = 0; pass < 10; pass++ ) { *************** *** 1378,1383 **** String[] vals = new String[element_count]; TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; --- 1386,1394 ---- String[] vals = new String[element_count]; + Builder<Integer,String> builder = new Builder<Integer, String>(); + builder.setInitialCapacity( element_count ); + builder.setNoEntryKey( Integer.MIN_VALUE ); TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; *************** *** 1406,1410 **** map.forEachKey( foreach ); TIntList built = foreach.getBuilt(); ! TIntList keys_list = new TIntArrayList( map.keys( new int[map.size()] ) ); assertEquals( keys_list, built ); --- 1417,1421 ---- map.forEachKey( foreach ); TIntList built = foreach.getBuilt(); ! TIntList keys_list = new TIntArrayList( null, map.keys( new int[map.size()] ) ); assertEquals( keys_list, built ); *************** *** 1433,1437 **** map.forEachKey( foreach_false ); built = foreach_false.getBuilt(); ! keys_list = new TIntArrayList( map.keys( new int[map.size()] ) ); assertEquals( 1, built.size() ); assertEquals( keys_list.get( 0 ), built.get( 0 ) ); --- 1444,1448 ---- map.forEachKey( foreach_false ); built = foreach_false.getBuilt(); ! keys_list = new TIntArrayList( null, map.keys( new int[map.size()] ) ); assertEquals( 1, built.size() ); assertEquals( keys_list.get( 0 ), built.get( 0 ) ); *************** *** 1444,1449 **** String[] vals = new String[element_count]; TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; --- 1455,1463 ---- String[] vals = new String[element_count]; + Builder<Integer,String> builder = new Builder<Integer, String>(); + builder.setInitialCapacity( element_count ); + builder.setNoEntryKey( Integer.MIN_VALUE ); TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; *************** *** 1510,1515 **** String[] vals = new String[element_count]; TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; --- 1524,1532 ---- String[] vals = new String[element_count]; + Builder<Integer,String> builder = new Builder<Integer, String>(); + builder.setInitialCapacity( element_count ); + builder.setNoEntryKey( Integer.MIN_VALUE ); TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; *************** *** 1654,1659 **** String[] vals = new String[element_count]; TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; --- 1671,1679 ---- String[] vals = new String[element_count]; + Builder<Integer,String> builder = new Builder<Integer, String>(); + builder.setInitialCapacity( element_count ); + builder.setNoEntryKey( Integer.MIN_VALUE ); TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; *************** *** 1681,1686 **** String[] vals = new String[element_count]; TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; --- 1701,1709 ---- String[] vals = new String[element_count]; + Builder<Integer,String> builder = new Builder<Integer, String>(); + builder.setInitialCapacity( element_count ); + builder.setNoEntryKey( Integer.MIN_VALUE ); TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; *************** *** 1690,1695 **** assertEquals( element_count, map.size() ); TIntObjectHashMap<String> fully_specified = ! new TIntObjectHashMap<String>( 20, 0.75f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { fully_specified.put( keys[i], vals[i] ); --- 1713,1719 ---- assertEquals( element_count, map.size() ); + builder.setLoadFactor( 0.75f ); TIntObjectHashMap<String> fully_specified = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++ ) { fully_specified.put( keys[i], vals[i] ); *************** *** 1725,1730 **** int counter = 0; TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++, counter++ ) { keys[i] = counter + 1; --- 1749,1757 ---- int counter = 0; + Builder<Integer,String> builder = new Builder<Integer, String>(); + builder.setInitialCapacity( element_count ); + builder.setNoEntryKey( Integer.MIN_VALUE ); TIntObjectMap<String> map = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++, counter++ ) { keys[i] = counter + 1; *************** *** 1743,1747 **** TIntObjectMap<String> map2 = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++, counter++ ) { keys[i] = counter + 1; --- 1770,1774 ---- TIntObjectMap<String> map2 = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++, counter++ ) { keys[i] = counter + 1; *************** *** 1753,1757 **** TIntObjectMap<String> map3 = ! new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++, counter++ ) { keys[i] = counter + 1; --- 1780,1784 ---- TIntObjectMap<String> map3 = ! new TIntObjectHashMap<String>( builder ); for ( int i = 0; i < element_count; i++, counter++ ) { keys[i] = counter + 1; |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:10
|
Update of /cvsroot/trove4j/trove/templates/gnu/trove/map/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/templates/gnu/trove/map/hash Modified Files: Tag: TROVE_3_WORKING _E_ObjectHashMap.template _K__V_HashMap.template Log Message: Builder pattern initial implementation and associated changes. Index: _E_ObjectHashMap.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/map/hash/Attic/_E_ObjectHashMap.template,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** _E_ObjectHashMap.template 18 Sep 2009 21:50:08 -0000 1.1.2.3 --- _E_ObjectHashMap.template 27 Sep 2009 06:23:59 -0000 1.1.2.4 *************** *** 34,37 **** --- 34,38 ---- import gnu.trove.set.T#E#Set; import gnu.trove.T#E#Collection; + import gnu.trove.Builder; import java.io.*; *************** *** 58,61 **** --- 59,65 ---- static final long serialVersionUID = 1L; + /** a default builder object to use when none is specified. */ + private static final Builder<#ET#, ?> DEFAULT_BUILDER = new Builder<#ET#, Object>(); + private final T#E#ObjectProcedure<V> PUT_ALL_PROC = new T#E#ObjectProcedure<V>() { public boolean execute( #e# key, V value) { *************** *** 77,108 **** */ public T#E#ObjectHashMap() { ! super(); ! } ! ! ! /** ! * Creates a new <code>T#E#ObjectHashMap</code> instance with a prime ! * capacity equal to or greater than <tt>initialCapacity</tt> and ! * with the default load factor. ! * ! * @param initialCapacity an <code>int</code> value ! */ ! public T#E#ObjectHashMap( int initialCapacity ) { ! super( initialCapacity ); ! no_entry_key = Constants.DEFAULT_#EC#_NO_ENTRY_VALUE; ! } ! ! ! /** ! * Creates a new <code>T#E#ObjectHashMap</code> instance with a prime ! * capacity equal to or greater than <tt>initialCapacity</tt> and ! * with the specified load factor. ! * ! * @param initialCapacity an <code>int</code> value ! * @param loadFactor a <code>float</code> value ! */ ! public T#E#ObjectHashMap( int initialCapacity, float loadFactor ) { ! super( initialCapacity, loadFactor ); ! no_entry_key = Constants.DEFAULT_#EC#_NO_ENTRY_VALUE; } --- 81,85 ---- */ public T#E#ObjectHashMap() { ! this( ( Builder<#ET#, V> ) DEFAULT_BUILDER ); } *************** *** 112,123 **** * 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 noEntryKey the value used to represent null in the key set. */ ! public T#E#ObjectHashMap( int initialCapacity, float loadFactor, #e# noEntryKey ) { ! super( initialCapacity, loadFactor ); ! this.no_entry_value = noEntryKey; } --- 89,103 ---- * value at or near the specified capacity and load factor. * ! * @param builder describes the configurable parameters. */ ! public T#E#ObjectHashMap( Builder<#ET#, V> builder ) { ! super( builder.getInitialCapacity(), builder.getLoadFactor(), ! builder.getNoEntryKey() == null ? ! Constants.DEFAULT_#EC#_NO_ENTRY_VALUE : ! builder.getNoEntryKey().#e#Value()); ! ! this.no_entry_value = builder.getNoEntryKey() == null ? ! Constants.DEFAULT_#EC#_NO_ENTRY_VALUE : ! builder.getNoEntryKey().#e#Value(); } *************** *** 130,134 **** */ public T#E#ObjectHashMap( T#E#ObjectMap<V> map ) { ! this( map.size(), 0.5f, map.getNoEntryKey() ); putAll( map ); } --- 110,122 ---- */ public T#E#ObjectHashMap( T#E#ObjectMap<V> map ) { ! this( new Builder<#ET#, V>(). ! setInitialCapacity( Math.max( map.size(), DEFAULT_CAPACITY ) ). ! setNoEntryKey( map.getNoEntryKey() ) ); ! if ( map instanceof T#E#ObjectHashMap ) { ! T#E#ObjectHashMap hashmap = ( T#E#ObjectHashMap ) map; ! this._loadFactor = hashmap._loadFactor; ! int size = Math.max( map.size(), DEFAULT_CAPACITY ); ! setUp( (int) Math.ceil( size / _loadFactor ) ); ! } putAll( map ); } Index: _K__V_HashMap.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/map/hash/Attic/_K__V_HashMap.template,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** _K__V_HashMap.template 15 Sep 2009 18:40:57 -0000 1.1.2.6 --- _K__V_HashMap.template 27 Sep 2009 06:23:59 -0000 1.1.2.7 *************** *** 34,37 **** --- 34,38 ---- import gnu.trove.impl.hash.*; import gnu.trove.impl.HashFunctions; + import gnu.trove.impl.Constants; import gnu.trove.*; *************** *** 50,53 **** --- 51,57 ---- static final long serialVersionUID = 1L; + /** a default builder object to use when none is specified. */ + private static final Builder<#KT#, #VT#> DEFAULT_BUILDER = new Builder<#KT#, #VT#>(); + /** the values of the map */ protected transient #v#[] _values; *************** *** 59,106 **** */ public T#K##V#HashMap() { ! super(); ! } ! ! ! /** ! * Creates a new <code>T#K##V#HashMap</code> instance with a prime ! * capacity equal to or greater than <tt>initialCapacity</tt> and ! * with the default load factor. ! * ! * @param initialCapacity an <code>int</code> value ! */ ! public T#K##V#HashMap( int initialCapacity ) { ! super( initialCapacity ); ! } ! ! ! /** ! * Creates a new <code>T#K##V#HashMap</code> instance with a prime ! * capacity equal to or greater than <tt>initialCapacity</tt> and ! * with the specified load factor. ! * ! * @param initialCapacity an <code>int</code> value ! * @param loadFactor a <code>float</code> value ! */ ! public T#K##V#HashMap( int initialCapacity, float loadFactor ) { ! super( initialCapacity, loadFactor ); } /** ! * Creates a new <code>T#K##V#HashMap</code> instance with a prime ! * capacity equal to or greater than <tt>initialCapacity</tt> and ! * with the specified load factor. * ! * @param initialCapacity an <code>int</code> value ! * @param loadFactor a <code>float</code> value ! * @param noEntryKey a <code>#k#</code> value that represents ! * <tt>null</tt> for the Key set. ! * @param noEntryValue a <code>#v#</code> value that represents ! * <tt>null</tt> for the Value set. */ ! public T#K##V#HashMap( int initialCapacity, float loadFactor, ! #k# noEntryKey, #v# noEntryValue ) { ! super( initialCapacity, loadFactor, noEntryKey, noEntryValue ); } --- 63,85 ---- */ public T#K##V#HashMap() { ! this( DEFAULT_BUILDER ); } /** ! * Creates a new <code>TIntLongHashMap</code> instance with a prime ! * capacity equal to or greater than the <tt>initialCapacity</tt> ! * specified . * ! * @param builder describes the configurable parameters. */ ! public T#K##V#HashMap( Builder<? extends #KT#, ? extends #VT#> builder ) { ! super( builder.getInitialCapacity(), builder.getLoadFactor(), ! builder.getNoEntryKey() == null ? ! Constants.DEFAULT_#KC#_NO_ENTRY_VALUE : ! builder.getNoEntryKey().#k#Value(), ! builder.getNoEntryValue() == null ? ! Constants.DEFAULT_#VC#_NO_ENTRY_VALUE : ! builder.getNoEntryValue().#v#Value() ); } *************** *** 110,118 **** * all of the entries in the map passed in. * * @param keys a <tt>#k#</tt> array containing the keys for the matching values. * @param values a <tt>#v#</tt> array containing the values. */ ! public T#K##V#HashMap( #k#[] keys, #v#[] values ) { ! super( Math.max( keys.length, values.length ) ); int size = Math.min( keys.length, values.length ); --- 89,99 ---- * all of the entries in the map passed in. * + * @param builder describes of the customizable values desired. * @param keys a <tt>#k#</tt> array containing the keys for the matching values. * @param values a <tt>#v#</tt> array containing the values. */ ! public T#K##V#HashMap( Builder<? extends #KT#, ? extends #VT#> builder, ! #k#[] keys, #v#[] values ) { ! this( builder == null ? DEFAULT_BUILDER : builder ); int size = Math.min( keys.length, values.length ); *************** *** 130,148 **** */ public T#K##V#HashMap( T#K##V#Map map ) { ! super( map.size() ); if ( map instanceof T#K##V#HashMap ) { T#K##V#HashMap hashmap = ( T#K##V#HashMap ) map; this._loadFactor = hashmap._loadFactor; ! this.no_entry_key = hashmap.no_entry_key; ! this.no_entry_value = hashmap.no_entry_value; ! //noinspection RedundantCast ! if ( this.no_entry_key != ( #k# ) 0 ) { ! Arrays.fill( _set, this.no_entry_key ); ! } ! //noinspection RedundantCast ! if ( this.no_entry_value != ( #v# ) 0 ) { ! Arrays.fill( _values, this.no_entry_value ); ! } ! setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } putAll( map ); --- 111,123 ---- */ public T#K##V#HashMap( T#K##V#Map map ) { ! this( new Builder<#KT#, #VT#>(). ! setInitialCapacity( Math.max( map.size(), DEFAULT_CAPACITY ) ). ! setNoEntryKey( map.getNoEntryKey() ). ! setNoEntryValue( map.getNoEntryValue() ) ); if ( map instanceof T#K##V#HashMap ) { T#K##V#HashMap hashmap = ( T#K##V#HashMap ) map; this._loadFactor = hashmap._loadFactor; ! int size = Math.max( map.size(), DEFAULT_CAPACITY ); ! setUp( (int) Math.ceil( size / _loadFactor ) ); } putAll( map ); |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:10
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/set/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/test/gnu/trove/set/hash Modified Files: Tag: TROVE_3_WORKING TPrimitiveHashSetTest.java Log Message: Builder pattern initial implementation and associated changes. Index: TPrimitiveHashSetTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/set/hash/Attic/TPrimitiveHashSetTest.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** TPrimitiveHashSetTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.3 --- TPrimitiveHashSetTest.java 27 Sep 2009 06:23:59 -0000 1.1.2.4 *************** *** 12,16 **** import gnu.trove.iterator.TIntIterator; import gnu.trove.procedure.TIntProcedure; ! --- 12,16 ---- import gnu.trove.iterator.TIntIterator; import gnu.trove.procedure.TIntProcedure; ! import gnu.trove.Builder; *************** *** 43,55 **** assertTrue( "set not a copy: " + set + ", " + copy, set.equals( copy ) ); ! TIntSet another = new TIntHashSet( 20 ); another.addAll( ints ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); ! another = new TIntHashSet( 2, 1.0f ); another.addAll( ints ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); ! another = new TIntHashSet( ints ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); } --- 43,59 ---- assertTrue( "set not a copy: " + set + ", " + copy, set.equals( copy ) ); ! Builder<?,Integer> builder = new Builder<Object,Integer>(); ! builder.setInitialCapacity( 20 ); ! TIntSet another = new TIntHashSet( builder ); another.addAll( ints ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); ! builder.setInitialCapacity( 2 ); ! builder.setLoadFactor( 1.0f ); ! another = new TIntHashSet( builder ); another.addAll( ints ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); ! another = new TIntHashSet( builder, ints ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); } *************** *** 385,389 **** public void testToArrayWithParams() { int no_entry_value = Integer.MIN_VALUE; ! TIntSet set = new TIntHashSet( 10, 0.5f, no_entry_value ); assertEquals( no_entry_value, set.getNoEntryValue() ); --- 389,395 ---- public void testToArrayWithParams() { int no_entry_value = Integer.MIN_VALUE; ! Builder<?,Integer> builder = new Builder<Object,Integer>(); ! builder.setNoEntryValue( no_entry_value ); ! TIntSet set = new TIntHashSet( builder ); assertEquals( no_entry_value, set.getNoEntryValue() ); *************** *** 415,419 **** public void testRehashing() throws Exception { int size = 10000; ! TIntSet set = new TIntHashSet( 10 ); for ( int i = 0; i < size; i++ ) { set.add( i ); --- 421,425 ---- public void testRehashing() throws Exception { int size = 10000; ! TIntSet set = new TIntHashSet(); for ( int i = 0; i < size; i++ ) { set.add( i ); *************** *** 488,492 **** public void testForEach() { ! TIntSet set = new TIntHashSet( 10, 0.5f ); int[] ints = {1138, 42, 86, 99, 101}; set.addAll( ints ); --- 494,498 ---- public void testForEach() { ! TIntSet set = new TIntHashSet(); int[] ints = {1138, 42, 86, 99, 101}; set.addAll( ints ); |
From: Jeff R. <uph...@us...> - 2009-09-27 06:24:10
|
Update of /cvsroot/trove4j/trove/templates/gnu/trove/stack/array In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28043/templates/gnu/trove/stack/array Modified Files: Tag: TROVE_3_WORKING _E_ArrayStack.template Log Message: Builder pattern initial implementation and associated changes. Index: _E_ArrayStack.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/stack/array/Attic/_E_ArrayStack.template,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -C2 -d -r1.1.2.9 -r1.1.2.10 *** _E_ArrayStack.template 9 Sep 2009 01:15:54 -0000 1.1.2.9 --- _E_ArrayStack.template 27 Sep 2009 06:23:59 -0000 1.1.2.10 *************** *** 24,28 **** import gnu.trove.stack.T#E#Stack; import gnu.trove.list.array.T#E#ArrayList; ! import gnu.trove.impl.*; import java.io.Externalizable; --- 24,28 ---- import gnu.trove.stack.T#E#Stack; import gnu.trove.list.array.T#E#ArrayList; ! import gnu.trove.Builder; import java.io.Externalizable; *************** *** 45,49 **** protected T#E#ArrayList _list; ! public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; --- 45,50 ---- protected T#E#ArrayList _list; ! /** a default builder object to use when none is specified. */ ! public static final Builder<?, #ET#> DEFAULT_BUILDER = new Builder<Object, #ET#>(); *************** *** 53,68 **** */ public T#E#ArrayStack() { ! this( DEFAULT_CAPACITY ); ! } ! ! ! /** ! * Creates a new <code>T#E#ArrayStack</code> instance with the ! * specified capacity. ! * ! * @param capacity the initial depth of the stack ! */ ! public T#E#ArrayStack( int capacity ) { ! _list = new T#E#ArrayList( capacity ); } --- 54,58 ---- */ public T#E#ArrayStack() { ! this( DEFAULT_BUILDER ); } *************** *** 72,80 **** * specified capacity. * ! * @param capacity the initial depth of the stack ! * @param no_entry_value value that represents null */ ! public T#E#ArrayStack( int capacity, #e# no_entry_value ) { ! _list = new T#E#ArrayList( capacity, no_entry_value ); } --- 62,69 ---- * specified capacity. * ! * @param builder describes the configurable parameters. */ ! public T#E#ArrayStack( Builder<?, #ET#> builder ) { ! _list = new T#E#ArrayList( builder ); } |
From: Rob E. <ro...@us...> - 2009-09-24 04:18:17
|
Update of /cvsroot/trove4j/trove In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18364/trove Added Files: Tag: TROVE_3_WORKING build.xml Log Message: Ant file |
From: Rob E. <ro...@us...> - 2009-09-24 04:18:16
|
Update of /cvsroot/trove4j/trove/generator_src/gnu/trove/generator In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18364/trove/generator_src/gnu/trove/generator Modified Files: Tag: TROVE_3_WORKING Generator.java Log Message: Ant file Index: Generator.java =================================================================== RCS file: /cvsroot/trove4j/trove/generator_src/gnu/trove/generator/Attic/Generator.java,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -C2 -d -r1.1.2.8 -r1.1.2.9 *** Generator.java 15 Sep 2009 01:57:42 -0000 1.1.2.8 --- Generator.java 24 Sep 2009 04:18:05 -0000 1.1.2.9 *************** *** 33,37 **** * */ ! class Generator { private static final WrapperInfo[] WRAPPERS = new WrapperInfo[]{ new WrapperInfo( "double", "Double", "POSITIVE_INFINITY", "NEGATIVE_INFINITY" ), --- 33,37 ---- * */ ! public class Generator { private static final WrapperInfo[] WRAPPERS = new WrapperInfo[]{ new WrapperInfo( "double", "Double", "POSITIVE_INFINITY", "NEGATIVE_INFINITY" ), |
From: Jeff R. <uph...@us...> - 2009-09-18 21:50:20
|
Update of /cvsroot/trove4j/trove/templates/gnu/trove/map/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4508/templates/gnu/trove/map/hash Modified Files: Tag: TROVE_3_WORKING Object_E_HashMap.template _E_ObjectHashMap.template Log Message: Add missing hashCode() to TObjectPrimitiveHashMap and test, accept null keys/values, additional test coverage to TPrimitiveObjectHashMap Index: Object_E_HashMap.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/map/hash/Attic/Object_E_HashMap.template,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** Object_E_HashMap.template 15 Sep 2009 18:40:57 -0000 1.1.2.2 --- Object_E_HashMap.template 18 Sep 2009 21:50:08 -0000 1.1.2.3 *************** *** 576,602 **** */ public boolean equals( Object other ) { ! if (! ( other instanceof TObject#E#Map ) ) { return false; } ! //noinspection unchecked ! TObject#E#Map<K> that = ( TObject#E#Map<K> ) other; ! return ( that.size() == this.size() ) && forEachEntry( new EqProcedure<K>( that ) ); } ! /** TObject#E#Procedure for use in {@link #equals(Object)} */ ! private static final class EqProcedure<K> implements TObject#E#Procedure<K> { ! private final TObject#E#Map<K> _otherMap; ! private final #e# _no_value; ! ! EqProcedure( TObject#E#Map<K> otherMap ) { ! _otherMap = otherMap; ! _no_value = otherMap.getNoEntryValue(); ! } ! ! public boolean execute( K key, #e# value ) { ! #e# other_value = _otherMap.get( key ); ! return ( other_value != _no_value ) && ( value == other_value ); } } --- 576,621 ---- */ public boolean equals( Object other ) { ! if ( ! ( other instanceof TObject#E#Map ) ) { return false; } ! TObject#E#Map that = ( TObject#E#Map ) other; ! if ( that.size() != this.size() ) { ! return false; ! } ! try { ! TObject#E#Iterator iter = this.iterator(); ! while ( iter.hasNext() ) { ! iter.advance(); ! Object key = iter.key(); ! #e# value = iter.value(); ! if ( value == no_entry_value ) { ! if ( !( that.get( key ) == that.getNoEntryValue() && that.containsKey( key ) ) ) { ! return false; ! } ! } else { ! if ( value != that.get( key ) ) { ! return false; ! } ! } ! } ! } catch ( ClassCastException ex ) { ! // unused. ! } ! return true; } ! /** {@inheritDoc} */ ! public int hashCode() { ! int hashcode = 0; ! Object[] keys = _set; ! #e#[] values = _values; ! for ( int i = values.length; i-- > 0; ) { ! if ( keys[i] != FREE && keys[i] != REMOVED ) { ! hashcode += HashFunctions.hash( values[i] ) ^ ! ( keys[i] == null ? 0 : keys[i].hashCode() ); ! } } + return hashcode; } *************** *** 907,945 **** } - @Override - public boolean equals( Object other ) { - if ( !( other instanceof T#E#Collection ) ) { - return false; - } - final T#E#Collection that = ( T#E#Collection ) other; - if ( that.size() != this.size() ) { - return false; - } - return forEach( new T#E#Procedure() { - public final boolean execute( #e# value ) { - return that.contains( value ); - } - } ); - } - - @Override - public int hashCode() { - class HashProcedure implements T#E#Procedure { - int hashcode = 0; - - public boolean execute( #e# value ) { - hashcode += HashFunctions.hash( value ); - return true; - } - - public int getHashCode() { - return hashcode; - } - } - - HashProcedure p = new HashProcedure(); - forEachValue( p ); - return p.getHashCode(); - } @Override --- 926,929 ---- Index: _E_ObjectHashMap.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/map/hash/Attic/_E_ObjectHashMap.template,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** _E_ObjectHashMap.template 15 Sep 2009 18:40:57 -0000 1.1.2.2 --- _E_ObjectHashMap.template 18 Sep 2009 21:50:08 -0000 1.1.2.3 *************** *** 508,512 **** if ( states[i] == FULL ) { hashcode += HashFunctions.hash( _set[i] ) ^ ! values[i].hashCode(); } } --- 508,512 ---- if ( states[i] == FULL ) { hashcode += HashFunctions.hash( _set[i] ) ^ ! ( values[i] == null ? 0 : values[i].hashCode() ); } } *************** *** 616,619 **** --- 616,620 ---- T#E#Iterator iter = iterator(); while ( iter.hasNext() ) { + //noinspection SuspiciousMethodCalls if ( ! collection.contains( #ET#.valueOf ( iter.next() ) ) ) { iter.remove(); *************** *** 627,631 **** public boolean retainAll( T#E#Collection collection ) { if ( this == collection ) { ! return false; } boolean modified = false; --- 628,632 ---- public boolean retainAll( T#E#Collection collection ) { if ( this == collection ) { ! return false; } boolean modified = false; *************** *** 672,675 **** --- 673,680 ---- /** {@inheritDoc} */ public boolean removeAll( T#E#Collection collection ) { + if ( collection == this ) { + clear(); + return true; + } boolean changed = false; T#E#Iterator iter = collection.iterator(); *************** *** 705,710 **** /** {@inheritDoc) */ ! public boolean equal( Object other ) { ! if (! (other instanceof T#E#Set)) { return false; } --- 710,715 ---- /** {@inheritDoc) */ ! public boolean equals( Object other ) { ! if (! ( other instanceof T#E#Set ) ) { return false; } *************** *** 723,727 **** } ! public int hashCode() { int hashcode = 0; --- 728,732 ---- } ! /** {@inheritDoc} */ public int hashCode() { int hashcode = 0; *************** *** 734,737 **** --- 739,756 ---- } + /** {@inheritDoc} */ + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for ( int i = _states.length; i-- > 0; ) { + if ( _states[i] == FULL ) { + if ( first ) first = false; + else buf.append( "," ); + buf.append( _set[i] ); + } + } + return buf.toString(); + } + class T#E#HashIterator extends TPrimitiveIterator implements T#E#Iterator { |
From: Jeff R. <uph...@us...> - 2009-09-18 21:50:19
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/map/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4508/test/gnu/trove/map/hash Modified Files: Tag: TROVE_3_WORKING TPrimitiveObjectHashMapTest.java TObjectPrimitiveHashMapTest.java Log Message: Add missing hashCode() to TObjectPrimitiveHashMap and test, accept null keys/values, additional test coverage to TPrimitiveObjectHashMap Index: TPrimitiveObjectHashMapTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/map/hash/Attic/TPrimitiveObjectHashMapTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** TPrimitiveObjectHashMapTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.2 --- TPrimitiveObjectHashMapTest.java 18 Sep 2009 21:50:08 -0000 1.1.2.3 *************** *** 41,44 **** --- 41,45 ---- import gnu.trove.set.TIntSet; import gnu.trove.set.hash.TIntHashSet; + import gnu.trove.TIntCollection; *************** *** 139,142 **** --- 140,150 ---- assertFalse( "Random object should not be present in map: " + map, map.containsValue( new Object() ) ); + + // test with null value + int key = 11010110; + map.put( key, null ); + assertTrue( map.containsKey( key ) ); + assertTrue( map.containsValue( null ) ); + assertNull( map.get( key ) ); } *************** *** 248,252 **** - @SuppressWarnings({"ToArrayCallWithZeroLengthArrayArgument"}) public void testKeySet() { int element_count = 20; --- 256,259 ---- *************** *** 278,281 **** --- 285,289 ---- } + //noinspection ToArrayCallWithZeroLengthArrayArgument keys_array = keyset.toArray( new int[0] ); count = 0; *************** *** 318,323 **** keyset.clear(); assertTrue( keyset.isEmpty() ); - - } --- 326,329 ---- *************** *** 381,384 **** --- 387,823 ---- + public void testKeySetContainsAllCollection() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + Collection<Integer> test_collection = new HashSet<Integer>(); + for ( int i = 0; i < element_count; i++ ) { + test_collection.add( keys[i] ); + } + assertTrue( keyset.containsAll( test_collection ) ) ; + + test_collection.remove( Integer.valueOf( keys[5] ) ); + assertTrue( "should contain all. keyset: " + keyset + ", " + test_collection, + keyset.containsAll( test_collection ) ); + + test_collection.add( Integer.valueOf( 1138 ) ); + assertFalse( "should not contain all. keyset: " + keyset + ", " + test_collection, + keyset.containsAll( test_collection ) ); + } + + + public void testKeySetContainsAllTCollection() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + TIntCollection test_collection = new TIntHashSet(); + for ( int i = 0; i < element_count; i++ ) { + test_collection.add( keys[i] ); + } + assertTrue( keyset.containsAll( test_collection ) ) ; + assertTrue( keyset.equals( keyset ) ); + + test_collection.remove( Integer.valueOf( keys[5] ) ); + assertTrue( "should contain all. keyset: " + keyset + ", " + test_collection, + keyset.containsAll( test_collection ) ); + + test_collection.add( 1138 ); + assertFalse( "should not contain all. keyset: " + keyset + ", " + test_collection, + keyset.containsAll( test_collection ) ); + } + + + public void testKeySetContainsAllArray() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + assertTrue( "should contain all. keyset: " + keyset + ", " + Arrays.toString( keys ), + keyset.containsAll( keys ) ); + + int[] other_array = Arrays.copyOf( keys, keys.length + 1 ); + other_array[other_array.length - 1] = 1138; + assertFalse( "should not contain all. keyset: " + keyset + ", " + Arrays.toString( other_array ), + keyset.containsAll( other_array ) ); + } + + + public void testKeySetRetainAllCollection() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + Collection<Integer> test_collection = new HashSet<Integer>(); + for ( int i = 0; i < element_count; i++ ) { + test_collection.add( keys[i] ); + } + keyset.retainAll( test_collection ); + assertFalse( keyset.isEmpty() ); + assertFalse( map.isEmpty() ); + + // Reset map + for ( int i = 0; i < element_count; i++ ) { + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + test_collection.remove( Integer.valueOf( keys[5] ) ); + keyset.retainAll( test_collection ); + assertEquals( element_count - 1, keyset.size() ); + assertEquals( element_count - 1, map.size() ); + assertFalse( keyset.contains( keys[5] ) ); + assertFalse( map.containsKey( keys[5] ) ); + + + // Reset map + for ( int i = 0; i < element_count; i++ ) { + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + test_collection.add( Integer.valueOf( 1138 ) ); + keyset.retainAll( test_collection ); + + } + + + public void testKeySetRetainAllTCollection() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + assertFalse( "keyset: " + keyset + ", should be unmodified.", + keyset.retainAll( keyset ) ); + + TIntCollection other = new TIntArrayList( keyset ); + assertFalse( "keyset: " + keyset + ", should be unmodified. other: " + + other, keyset.retainAll( other ) ); + + other.remove( keys[5] ); + assertTrue( "keyset: " + keyset + ", should be modified. other: " + + other, keyset.retainAll( other ) ); + assertFalse( keyset.contains( keys[5] ) ); + assertFalse( map.containsKey( keys[5] ) ); + assertFalse( map.containsValue( vals[5] ) ); + assertTrue( "keyset: " + keyset + ", should contain all in other: " + + other, keyset.containsAll( other ) ); + } + + + public void testKeySetRetainAllArray() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + assertFalse( "keyset: " + keyset + ", should be unmodified. array: " + + Arrays.toString( keys ), keyset.retainAll( keys ) ); + + int[] other = new int[element_count - 1]; + for ( int i = 0; i < element_count; i++ ) { + if ( i < 5 ) { + other[i] = i + 1; + } + if ( i > 5 ) { + other[i - 1] = i + 1; + } + } + assertTrue( "keyset: " + keyset + ", should be modified. array: " + + Arrays.toString( other ), keyset.retainAll( other ) ); + } + + + public void testKeySetRemoveAllCollection() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntCollection keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + List<Integer> java_list = new ArrayList<Integer>(); + assertFalse( "collection: " + keyset + ", should contain all in list: " + + java_list, keyset.removeAll( java_list ) ); + + java_list.add( keys[5] ); + assertTrue( "collection: " + keyset + ", should contain all in list: " + + java_list, keyset.removeAll( java_list ) ); + assertFalse( keyset.contains( keys[5] ) ); + assertFalse( map.containsKey( keys[5] ) ); + assertFalse( map.containsValue( vals[5] ) ); + + java_list = new ArrayList<Integer>(); + for ( int key : keys ) { + java_list.add( key ); + } + assertTrue( "collection: " + keyset + ", should contain all in list: " + + java_list, keyset.removeAll( java_list ) ); + assertTrue( keyset.isEmpty() ); + } + + + public void testKeySetRemoveAllTCollection() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntCollection keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + TIntCollection other = new TIntArrayList(); + assertFalse( "collection: " + keyset + ", should be unmodified.", + keyset.removeAll( other ) ); + + other = new TIntArrayList( keyset ); + other.remove( keys[5] ); + assertTrue( "collection: " + keyset + ", should be modified. other: " + + other, keyset.removeAll( other ) ); + assertEquals( 1, keyset.size() ); + for ( int i = 0; i < element_count; i++ ) { + if ( i == 5 ) { + assertTrue( keyset.contains( keys[i] ) ); + assertTrue( map.containsKey( keys[i] ) ); + assertTrue( map.containsValue( vals[i] ) ); + } else { + assertFalse( keyset.contains( keys[i] ) ); + assertFalse( map.containsKey( keys[i] ) ); + assertFalse( map.containsValue( vals[i] ) ); + } + } + + assertFalse( "collection: " + keyset + ", should be unmodified. other: " + + other, keyset.removeAll( other ) ); + + assertTrue( "collection: " + keyset + ", should be modified. other: " + + other, keyset.removeAll( keyset ) ); + assertTrue( keyset.isEmpty() ); + } + + + public void testKeySetRemoveAllArray() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntCollection keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + int[] other = {1138}; + assertFalse( "collection: " + keyset + ", should be unmodified. array: " + + Arrays.toString( vals ), keyset.removeAll( other ) ); + + other = new int[element_count - 1]; + for ( int i = 0; i < element_count; i++ ) { + if ( i < 5 ) { + other[i] = i + 1; + } + if ( i > 5 ) { + other[i - 1] = i + 1; + } + } + assertTrue( "collection: " + keyset + ", should be modified. array: " + + Arrays.toString( other ), keyset.removeAll( other ) ); + assertEquals( 1, keyset.size() ); + for ( int i = 0; i < element_count; i++ ) { + if ( i == 5 ) { + assertTrue( keyset.contains( keys[i] ) ); + assertTrue( map.containsKey( keys[i] ) ); + assertTrue( map.containsValue( vals[i] ) ); + } else { + assertFalse( keyset.contains( keys[i] ) ); + assertFalse( map.containsKey( keys[i] ) ); + assertFalse( map.containsValue( vals[i] ) ); + } + } + } + + + public void testKeySetEqual() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + TIntSet other = new TIntHashSet(); + other.addAll( keys ); + + assertTrue( "sets incorrectly not equal: " + keyset + ", " + other, + keyset.equals( other ) ); + + int[] mismatched = {72, 49, 53, 1024, 999}; + TIntSet unequal = new TIntHashSet(); + unequal.addAll( mismatched ); + + assertFalse( "sets incorrectly equal: " + keyset + ", " + unequal, + keyset.equals( unequal ) ); + + // Change length, different code branch + unequal.add( 1 ); + assertFalse( "sets incorrectly equal: " + keyset + ", " + unequal, + keyset.equals( unequal ) ); + + //noinspection ObjectEqualsNull + assertFalse( keyset.equals( null ) ); + } + + + public void testKeySetHashCode() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + + TIntObjectMap<String> map = new TIntObjectHashMap<String>(); + for ( int i = 0; i < element_count; i++ ) { + keys[i] = i + 1; + vals[i] = Integer.toString( i + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + + TIntSet keyset = map.keySet(); + for ( int i = 0; i < keyset.size(); i++ ) { + assertTrue( keyset.contains( keys[i] ) ); + } + assertFalse( keyset.isEmpty() ); + + assertEquals( keyset.hashCode(), keyset.hashCode() ); + + TIntSet other = new TIntHashSet( keys ); + other.add( 1138 ); + assertTrue( keyset.hashCode() != other.hashCode() ); + } + + public void testKeys() { int element_count = 20; *************** *** 766,820 **** - - public void testValueCollectionEquals() { - int element_count = 20; - int[] keys = new int[element_count]; - String[] vals = new String[element_count]; - - TIntObjectMap<String> map = new TIntObjectHashMap<String>(); - for ( int i = 0; i < element_count; i++ ) { - keys[i] = i + 1; - vals[i] = Integer.toString( i + 1 ); - map.put( keys[i], vals[i] ); - } - assertEquals( element_count, map.size() ); - - Collection<String> values = map.valueCollection(); - Collection<String> set = new HashSet<String>(); - set.addAll( Arrays.asList( vals ) ); - assertTrue( values.equals( set ) ); - - set.add( String.valueOf( 1138 ) ); - assertFalse( values.equals( set ) ); - - assertFalse( "should not equal random object", values.equals( new Object() )); - } - - - public void testValueCollectionHashCode() { - int element_count = 20; - int[] keys = new int[element_count]; - String[] vals = new String[element_count]; - - TIntObjectMap<String> map = new TIntObjectHashMap<String>(); - TIntObjectMap<String> map2 = new TIntObjectHashMap<String>(); - for ( int i = 0; i < element_count; i++ ) { - keys[i] = i + 1; - vals[i] = Integer.toString( i + 1 ); - map.put( keys[i], vals[i] ); - map2.put( keys[i], vals[i] ); - } - assertEquals( element_count, map.size() ); - - Collection<String> values = map.valueCollection(); - Collection<String> other = map2.valueCollection(); - - assertTrue( values.hashCode() == other.hashCode() ); - - map2.put( 1138, String.valueOf( 1138 ) ); - assertFalse( values.hashCode() == other.hashCode() ); - } - - public void testValues() { int element_count = 20; --- 1205,1208 ---- *************** *** 1310,1313 **** --- 1698,1783 ---- assertFalse( "shouldn't equal random object", map.equals( new Object() ) ); + + int key = 11010110; // I thought I saw a two! + assertNull( map.put( key, null ) ); + assertNull( fully_specified.put( key, null ) ); + assertTrue( "incorrectly not-equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + assertTrue( "incorrectly not-equal map: " + map + "\nfully_specified: " + fully_specified, + fully_specified.equals( map ) ); + + assertNull( fully_specified.put( key, "non-null-value" ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + fully_specified.equals( map ) ); + + assertNull( fully_specified.put( key + 1, "blargh" ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + } + + + public void testHashCode() { + int element_count = 20; + int[] keys = new int[element_count]; + String[] vals = new String[element_count]; + int counter = 0; + + TIntObjectMap<String> map = + new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); + for ( int i = 0; i < element_count; i++, counter++ ) { + keys[i] = counter + 1; + vals[i] = Integer.toString( counter + 1 ); + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + assertEquals( map.hashCode(), map.hashCode() ); + + Map<String, TIntObjectMap<String>> string_tmap_map = + new HashMap<String, TIntObjectMap<String>>(); + string_tmap_map.put( "first", map ); + string_tmap_map.put( "second", map ); + assertSame( map, string_tmap_map.get( "first" ) ); + assertSame( map, string_tmap_map.get( "second" ) ); + + TIntObjectMap<String> map2 = + new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); + for ( int i = 0; i < element_count; i++, counter++ ) { + keys[i] = counter + 1; + vals[i] = Integer.toString( counter + 1 ); + map2.put( keys[i], vals[i] ); + } + assertEquals( element_count, map2.size() ); + assertEquals( map2.hashCode(), map2.hashCode() ); + + TIntObjectMap<String> map3 = + new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); + for ( int i = 0; i < element_count; i++, counter++ ) { + keys[i] = counter + 1; + vals[i] = Integer.toString( counter + 1 ); + map3.put( keys[i], vals[i] ); + } + assertEquals( element_count, map3.size() ); + assertEquals( map3.hashCode(), map3.hashCode() ); + + assertFalse( "hashcodes are unlikely equal. map: " + map + " (" + map.hashCode() + + ")\nmap2: " + map2 + " (" + map2.hashCode() + ")", + map.hashCode() == map2.hashCode() ); + assertFalse( "hashcodes are unlikely equal. map: " + map + " (" + map.hashCode() + + ")\nmap3: " + map3 + " (" + map3.hashCode() + ")", + map.hashCode() == map3.hashCode() ); + assertFalse( "hashcodes are unlikely equal. map2: " + map2 + " (" + map2.hashCode() + + ")\nmap3: " + map3 + " (" + map3.hashCode() + ")", + map2.hashCode() == map3.hashCode() ); + + Map<TIntObjectMap<String>, String> tmap_string_map = + new HashMap<TIntObjectMap<String>, String>(); + tmap_string_map.put( map, "map1" ); + tmap_string_map.put( map2, "map2" ); + tmap_string_map.put( map3, "map3" ); + assertEquals( "map1", tmap_string_map.get( map ) ); + assertEquals( "map2", tmap_string_map.get( map2 ) ); + assertEquals( "map3", tmap_string_map.get( map3 ) ); } Index: TObjectPrimitiveHashMapTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/map/hash/Attic/TObjectPrimitiveHashMapTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** TObjectPrimitiveHashMapTest.java 14 Sep 2009 19:02:20 -0000 1.1.2.1 --- TObjectPrimitiveHashMapTest.java 18 Sep 2009 21:50:08 -0000 1.1.2.2 *************** *** 87,91 **** TObjectIntHashMap<String> copy = ! new TObjectIntHashMap<String>( map ); assertEquals( map, copy ); } --- 87,91 ---- TObjectIntHashMap<String> copy = ! new TObjectIntHashMap<String>( fully_specified ); assertEquals( map, copy ); } *************** *** 844,896 **** - public void testValueCollectionEquals() { - int element_count = 20; - String[] keys = new String[element_count]; - int[] vals = new int[element_count]; - - TObjectIntMap<String> map = new TObjectIntHashMap<String>(); - for ( int i = 0; i < element_count; i++ ) { - keys[i] = Integer.toString( i + 1 ); - vals[i] = i + 1; - map.put( keys[i], vals[i] ); - } - assertEquals( element_count, map.size() ); - - TIntCollection values = map.valueCollection(); - TIntCollection list = new TIntArrayList( vals ); - assertTrue( values.equals( list ) ); - - list.add( 1138 ); - assertFalse( values.equals( list ) ); - - assertFalse( "should not equal random object", values.equals( new Object() )); - } - - - public void testValueCollectionHashCode() { - int element_count = 20; - String[] keys = new String[element_count]; - int[] vals = new int[element_count]; - - TObjectIntMap<String> map = new TObjectIntHashMap<String>(); - TObjectIntMap<String> map2 = new TObjectIntHashMap<String>(); - for ( int i = 0; i < element_count; i++ ) { - keys[i] = Integer.toString( i + 1 ); - vals[i] = i + 1; - map.put( keys[i], vals[i] ); - map2.put( keys[i], vals[i] ); - } - assertEquals( element_count, map.size() ); - - TIntCollection values = map.valueCollection(); - TIntCollection other = map2.valueCollection(); - - assertTrue( values.hashCode() == other.hashCode() ); - - map2.put( String.valueOf( 1138 ), 1138 ); - assertFalse( values.hashCode() == other.hashCode() ); - } - - public void testValues() { int element_count = 20; --- 844,847 ---- *************** *** 1461,1464 **** --- 1412,1508 ---- assertFalse( "shouldn't equal random object", map.equals( new Object() ) ); + + int value = 11010110; // I thought I saw a two! + assertEquals( map.getNoEntryValue(), map.put( null, value ) ); + assertEquals( map.getNoEntryValue(), fully_specified.put( null, value ) ); + assertEquals( value, map.get( null ) ); + assertEquals( value, fully_specified.get( null ) ); + assertTrue( "incorrectly not-equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + assertTrue( "incorrectly not-equal map: " + map + "\nfully_specified: " + fully_specified, + fully_specified.equals( map ) ); + + assertEquals( map.getNoEntryValue(), fully_specified.put( "non-null-key", value ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + fully_specified.equals( map ) ); + + int no_value = map.getNoEntryValue(); + assertEquals( map.getNoEntryValue(), map.put( "non-null-key", no_value ) ); + assertEquals( value, fully_specified.put( "non-null-key", no_value ) ); + assertTrue( "incorrectly not-equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + assertTrue( "incorrectly not-equal map: " + map + "\nfully_specified: " + fully_specified, + fully_specified.equals( map ) ); + + assertEquals( no_value, map.put( "non-null-key", value ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + fully_specified.equals( map ) ); + + + assertEquals( map.getNoEntryValue(), fully_specified.put( "blargh", value ) ); + assertFalse( "incorrectly equal map: " + map + "\nfully_specified: " + fully_specified, + map.equals( fully_specified ) ); + } + + + public void testHashCode() { + int element_count = 20; + String[] keys = new String[element_count]; + int[] vals = new int[element_count]; + int counter = 0; + + TObjectIntMap<String> map = + new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); + for ( int i = 0; i < element_count; i++, counter++ ) { + keys[i] = Integer.toString( counter + 1 ); + vals[i] = counter + 1; + map.put( keys[i], vals[i] ); + } + assertEquals( element_count, map.size() ); + assertEquals( map.hashCode(), map.hashCode() ); + + Map<String, TObjectIntMap<String>> string_tmap_map = + new HashMap<String, TObjectIntMap<String>>(); + string_tmap_map.put( "first", map ); + string_tmap_map.put( "second", map ); + assertSame( map, string_tmap_map.get( "first" ) ); + assertSame( map, string_tmap_map.get( "second" ) ); + + TObjectIntMap<String> map2 = + new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); + for ( int i = 0; i < element_count; i++, counter++ ) { + keys[i] = Integer.toString( counter + 1 ); + vals[i] = counter + 1; + map2.put( keys[i], vals[i] ); + } + assertEquals( element_count, map2.size() ); + assertEquals( map2.hashCode(), map2.hashCode() ); + + TObjectIntMap<String> map3 = + new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); + for ( int i = 0; i < element_count; i++, counter++ ) { + keys[i] = Integer.toString( counter + 1 ); + vals[i] = counter + 1; + map3.put( keys[i], vals[i] ); + } + assertEquals( element_count, map3.size() ); + assertEquals( map3.hashCode(), map3.hashCode() ); + + assertFalse( map.hashCode() == map2.hashCode() ); + assertFalse( map.hashCode() == map3.hashCode() ); + assertFalse( map2.hashCode() == map3.hashCode() ); + + Map<TObjectIntMap<String>, String> tmap_string_map = + new HashMap<TObjectIntMap<String>, String>(); + tmap_string_map.put( map, "map1" ); + tmap_string_map.put( map2, "map2" ); + tmap_string_map.put( map3, "map3" ); + assertEquals( "map1", tmap_string_map.get( map ) ); + assertEquals( "map2", tmap_string_map.get( map2 ) ); + assertEquals( "map3", tmap_string_map.get( map3 ) ); } |
From: Jeff R. <uph...@us...> - 2009-09-18 21:50:17
|
Update of /cvsroot/trove4j/trove/src/gnu/trove/impl/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4508/src/gnu/trove/impl/hash Modified Files: Tag: TROVE_3_WORKING TObjectHash.java Log Message: Add missing hashCode() to TObjectPrimitiveHashMap and test, accept null keys/values, additional test coverage to TPrimitiveObjectHashMap Index: TObjectHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/impl/hash/Attic/TObjectHash.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** TObjectHash.java 15 Sep 2009 18:40:57 -0000 1.1.2.4 --- TObjectHash.java 18 Sep 2009 21:50:08 -0000 1.1.2.5 *************** *** 160,163 **** --- 160,167 ---- Object cur = set[index]; + if ( cur == obj ) { + return index; + } + if ( cur == FREE ) { return -1; *************** *** 203,207 **** if ( cur == FREE ) { return index; // empty, all done ! } else if ( cur != REMOVED && cur.equals( obj ) ) { return -index - 1; // already stored } else { // already FULL or REMOVED, must probe --- 207,211 ---- if ( cur == FREE ) { return index; // empty, all done ! } else if ( cur == obj || ( cur != REMOVED && cur.equals( obj ) ) ) { return -index - 1; // already stored } else { // already FULL or REMOVED, must probe *************** *** 231,234 **** --- 235,239 ---- } while ( cur != FREE && cur != REMOVED + && cur != obj && !cur.equals( obj ) ); } *************** *** 240,244 **** int firstRemoved = index; while ( cur != FREE ! && ( cur == REMOVED || !cur.equals( obj ) ) ) { index -= probe; if ( index < 0 ) { --- 245,249 ---- int firstRemoved = index; while ( cur != FREE ! && ( cur == REMOVED || cur != obj || !cur.equals( obj ) ) ) { index -= probe; if ( index < 0 ) { |
From: Jeff R. <uph...@us...> - 2009-09-18 06:07:50
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/decorator In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20982/test/gnu/trove/decorator Added Files: Tag: TROVE_3_WORKING TPrimitiveObjectMapDecoratorTest.java TPrimitivePrimitiveMapDecoratorTest.java TPrimitiveSetDecoratorTest.java TObjectPrimitiveMapDecoratorTest.java Log Message: TDecorator implementatons, testcases and fixes associated with TPrimitiveSet and the maps wrapped. --- NEW FILE: TPrimitiveObjectMapDecoratorTest.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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. /////////////////////////////////////////////////////////////////////////////// [...976 lines suppressed...] ObjectInputStream ois = new ObjectInputStream( bias ); Map<Integer,String> deserialized = (Map<Integer,String>) ois.readObject(); assertEquals( map, deserialized ); } public void testToString() { TIntObjectHashMap<String> raw_map = new TIntObjectHashMap<String>(); Map<Integer,String> map = TDecorators.wrap( raw_map ); map.put( 11, "One" ); map.put( 22, "Two" ); String to_string = map.toString(); assertTrue( to_string, to_string.equals( "{11=One, 22=Two}" ) || to_string.equals( "{22=Two, 11=One}" ) ); } } --- NEW FILE: TPrimitivePrimitiveMapDecoratorTest.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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. /////////////////////////////////////////////////////////////////////////////// [...1135 lines suppressed...] TIntLongMap raw_map = new TIntLongHashMap(); for ( int i = 0; i < keys.length; i++ ) { vals[i] = keys[i] * 2; raw_map.put( keys[i], vals[i] ); } Map<Integer,Long> map = TDecorators.wrap( raw_map ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream( baos ); oos.writeObject( map ); ByteArrayInputStream bias = new ByteArrayInputStream( baos.toByteArray() ); ObjectInputStream ois = new ObjectInputStream( bias ); //noinspection unchecked Map<Integer,Long> deserialized = (Map<Integer,Long>) ois.readObject(); assertEquals( map, deserialized ); } } --- NEW FILE: TPrimitiveSetDecoratorTest.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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 junit.framework.TestCase; import gnu.trove.set.TIntSet; import gnu.trove.set.hash.TIntHashSet; import gnu.trove.TDecorators; import java.util.*; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.io.ByteArrayInputStream; import java.io.ObjectInputStream; /** * @author Eric D. Friedman * @author Robert D. Eden * @author Jeff Randall */ public class TPrimitiveSetDecoratorTest extends TestCase { public TPrimitiveSetDecoratorTest( String name ) { super( name ); } public void setUp() throws Exception { super.setUp(); } public void tearDown() throws Exception { super.tearDown(); } public void testConstructors() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); assertNotNull( set ); Integer[] ints = {1138, 42, 86, 99, 101}; set.addAll( Arrays.asList( ints ) ); Set<Integer> copy = new HashSet<Integer>( set ); assertTrue( "set not a copy: " + set + ", " + copy, set.equals( copy ) ); TIntSet raw_another = new TIntHashSet( 20 ); Set<Integer> another = TDecorators.wrap( raw_another ); another.addAll( Arrays.asList( ints ) ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); raw_another = new TIntHashSet( 2, 1.0f ); another = TDecorators.wrap( raw_another ); another.addAll( Arrays.asList( ints ) ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); raw_another = new TIntHashSet( Arrays.asList( ints ) ); another = TDecorators.wrap( raw_another ); assertTrue( "set not equal: " + set + ", " + copy, set.equals( another ) ); } public void testIsEmpty() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); assertTrue( "new set wasn't empty", set.isEmpty() ); set.add( 1 ); assertFalse( "set with element reports empty", set.isEmpty() ); set.clear(); assertTrue( "cleared set reports not-empty", set.isEmpty() ); } public void testContains() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); int i = 100; set.add( i ); assertTrue( "contains failed", set.contains( i ) ); assertFalse( "contains failed", set.contains( 1000 ) ); } @SuppressWarnings({"ForLoopReplaceableByForEach"}) public void testContainsAll() throws Exception { Integer[] ints = {1138, 42, 13, 86, 99}; TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); TIntSet raw_other = new TIntHashSet(); Set<Integer> other = TDecorators.wrap( raw_other ); other.addAll( Arrays.asList( ints ) ); List<Integer> ints_list = new ArrayList<Integer>(); ints_list.addAll( Arrays.asList( ints ) ); for ( int index = 0; index < ints.length; index++ ) { assertTrue( Integer.valueOf( ints[index] ).toString(), set.contains( ints[index] ) ); } assertTrue( "containsAll(Collection<?>) failed: " + set, set.containsAll( ints_list ) ); assertTrue( "containsAll(TIntSet) failed (same set): " + set, set.containsAll( set ) ); assertTrue( "containsAll(TIntSet) failed (other set): " + set, set.containsAll( other ) ); Integer[] failed = {42, 86, 99, 123456}; TIntSet raw_failed_set = new TIntHashSet(); Set<Integer> failed_set = TDecorators.wrap( raw_failed_set ); failed_set.addAll( Arrays.asList( failed ) ); List<Integer> failed_list = new ArrayList<Integer>(); failed_list.addAll( Arrays.asList( failed ) ); assertFalse( "containsAll(Collection<?>) failed (false positive): " + set, set.containsAll( failed_list ) ); assertFalse( "containsAll(TIntSet) failed (false positive): " + set, set.containsAll( failed_set ) ); } public void testAddAll() throws Exception { Integer[] ints = {1138, 42, 13, 86, 99, 101}; TIntSet raw_set; List<Integer> list = new ArrayList<Integer>(); for ( int element : ints ) { list.add( Integer.valueOf( element ) ); } raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); assertTrue( "addAll(Collection<?>) failed: " + set, set.addAll( list ) ); for ( int element : ints ) { assertTrue( "contains failed: ", set.contains( element ) ); } TIntSet raw_test_set = new TIntHashSet(); Set<Integer> test_set = TDecorators.wrap( raw_test_set ); assertTrue( "addAll(TIntSet) failed: " + test_set, test_set.addAll( set ) ); for ( int element : ints ) { assertTrue( "contains failed: ", set.contains( element ) ); } } public void testRetainAll() throws Exception { Integer[] ints = {1138, 42, 13, 86, 99, 101}; TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); TIntSet other = new TIntHashSet(); other.addAll( Arrays.asList( ints ) ); Integer[] to_retain = {13, 86, 99, 1138}; TIntSet raw_retain_set = new TIntHashSet(); Set<Integer> retain_set = TDecorators.wrap( raw_retain_set ); retain_set.addAll( Arrays.asList( to_retain ) ); List<Integer> retain_list = new ArrayList<Integer>(); retain_list.addAll( Arrays.asList( to_retain ) ); assertFalse( "retainAll(Set) failed (same set): " + set, set.retainAll( set ) ); // Contains all the original elements assertTrue( set.toString(), set.containsAll( Arrays.asList( ints ) ) ); assertTrue( retain_set.toString(), retain_set.containsAll( Arrays.asList( to_retain ) ) ); assertTrue( "retainAll(Collection<?>) failed: " + set, set.retainAll( retain_list ) ); // Contains just the expected elements assertFalse( set.toString(), set.containsAll( Arrays.asList( ints ) ) ); assertTrue( set.toString(), set.containsAll( Arrays.asList( to_retain ) ) ); assertTrue( retain_set.toString(), retain_set.containsAll( Arrays.asList( to_retain ) ) ); // reset the set. raw_set = new TIntHashSet(); set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); assertTrue( "retainAll(TIntSet) failed: " + set, set.retainAll( retain_set ) ); // Contains just the expected elements assertFalse( set.toString(), set.containsAll( Arrays.asList( ints ) ) ); assertTrue( set.toString(), set.containsAll( Arrays.asList( to_retain ) ) ); assertTrue( retain_set.toString(), retain_set.containsAll( Arrays.asList( to_retain ) ) ); } public void testRemoveAll() throws Exception { Integer[] ints = {1138, 42, 13, 86, 99, 101}; TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); TIntSet raw_other = new TIntHashSet(); Set<Integer> other = TDecorators.wrap( raw_other ); other.addAll( Arrays.asList( ints ) ); Integer[] to_remove = {13, 86, 99, 1138}; TIntSet raw_remove_set = new TIntHashSet(); Set<Integer> remove_set = TDecorators.wrap( raw_remove_set ); remove_set.addAll( Arrays.asList( to_remove ) ); List<Integer> remove_list = new ArrayList<Integer>(); remove_list.addAll( Arrays.asList( to_remove ) ); Integer[] remainder = {42, 101}; assertTrue( "removeAll(Collections<?>) failed (same set): " + set, set.removeAll( set ) ); // reset the set. raw_set = new TIntHashSet(); set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); assertTrue( "removeAll(Collection<?>) failed: " + set, set.removeAll( remove_list ) ); // Contains just the expected elements assertTrue( set.toString(), set.containsAll( Arrays.asList( remainder ) ) ); assertFalse( set.toString(), set.containsAll( Arrays.asList( to_remove ) ) ); assertTrue( remove_set.toString(), remove_set.containsAll( Arrays.asList( to_remove ) ) ); // reset the set. raw_set = new TIntHashSet(); set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); assertTrue( "removeAll(TIntSet) failed: " + set, set.removeAll( remove_set ) ); // Contains just the expected elements assertTrue( set.toString(), set.containsAll( Arrays.asList( remainder ) ) ); assertFalse( set.toString(), set.containsAll( Arrays.asList( to_remove ) ) ); assertTrue( remove_set.toString(), remove_set.containsAll( Arrays.asList( to_remove ) ) ); } public void testAdd() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); assertTrue( "add failed", set.add( 1 ) ); assertFalse( "duplicated add modified set", set.add( 1 ) ); } public void testRemove() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.add( 1 ); set.add( 2 ); assertTrue( "One was not added", set.contains( 1 ) ); assertTrue( "One was not removed", set.remove( 1 ) ); assertFalse( "One was not removed", set.contains( 1 ) ); assertTrue( "Two was also removed", set.contains( 2 ) ); } public void testRemoveNonExistant() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.add( 1 ); set.add( 2 ); assertTrue( "One was not added", set.contains( 1 ) ); assertTrue( "One was not removed", set.remove( 1 ) ); assertFalse( "One was not removed", set.contains( 1 ) ); assertTrue( "Two was also removed", set.contains( 2 ) ); assertFalse( "Three was removed (non-existant)", set.remove( 3 ) ); } public void testSize() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); assertEquals( "initial size was not 0", 0, set.size() ); for ( int i = 0; i < 99; i++ ) { set.add( i ); assertEquals( "size did not increase after add", i + 1, set.size() ); } } public void testClear() throws Exception { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.add( 1 ); set.add( 2 ); set.add( 3 ); assertEquals( "size was not 3", 3, set.size() ); set.clear(); assertEquals( "initial size was not 0", 0, set.size() ); } public void testSerialize() throws Exception { Integer[] ints = {1138, 42, 86, 99, 101}; TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream( baos ); oos.writeObject( set ); ByteArrayInputStream bias = new ByteArrayInputStream( baos.toByteArray() ); ObjectInputStream ois = new ObjectInputStream( bias ); //noinspection unchecked Set<Integer> deserialized = ( Set<Integer> ) ois.readObject(); assertEquals( set, deserialized ); } public void testToArray() { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); Integer[] ints = {42, 1138, 13, 86, 99}; set.addAll( Arrays.asList( ints ) ); Object[] obj_res = set.toArray(); Arrays.sort( ints ); Arrays.sort( obj_res ); assertTrue( Arrays.equals( ints, obj_res ) ); Object[] res = set.toArray(); Arrays.sort( ints ); Arrays.sort( res ); assertTrue( Arrays.equals( ints, res ) ); res = set.toArray( new Integer[set.size()] ); Arrays.sort( ints ); Arrays.sort( res ); assertTrue( Arrays.equals( ints, res ) ); } public void testToArrayMatchesIteratorOrder() { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); Integer[] ints = {42, 1138, 13, 86, 99}; set.addAll( Arrays.asList( ints ) ); Integer[] toarray_ints = set.toArray( new Integer[ints.length] ); Integer[] iter_ints = new Integer[ints.length]; Iterator<Integer> iter = set.iterator(); int index = 0; while ( iter.hasNext() ) { iter_ints[index++] = iter.next(); } assertTrue( Arrays.equals( iter_ints, toarray_ints ) ); } public void testToArrayWithParams() { int no_entry_value = Integer.MIN_VALUE; TIntSet raw_set = new TIntHashSet( 10, 0.5f, no_entry_value ); Set<Integer> set = TDecorators.wrap( raw_set ); Integer[] ints = {42, 1138, 13, 86, 99}; set.addAll( Arrays.asList( ints ) ); Integer[] sink = new Integer[ints.length + 2]; sink[sink.length - 1] = -1; sink[sink.length - 2] = -2; Integer[] res = set.toArray( sink ); assertNull( res[set.size()] ); Set<Integer> copy = new HashSet<Integer>(); copy.addAll( Arrays.asList( sink ) ); Set<Integer> bogey = new HashSet<Integer>(); bogey.addAll( Arrays.asList( ints ) ); bogey.add( -1 ); bogey.add( null ); assertEquals( bogey, copy ); } public void testRehashing() throws Exception { int size = 10000; TIntSet set = new TIntHashSet( 10 ); for ( int i = 0; i < size; i++ ) { set.add( i ); } assertEquals( set.size(), size ); } public void testIterator() { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.add( 1 ); set.add( 2 ); set.add( 3 ); set.add( 4 ); Iterator<Integer> iter = set.iterator(); assertTrue( "iterator should have a next item", iter.hasNext() ); int last = -1; while ( iter.hasNext() ) { int next = iter.next(); assertTrue( Integer.valueOf( next ).toString(), next >= 1 && next <= 4 ); assertTrue( Integer.valueOf( next ).toString(), next != last ); last = next; } assertFalse( "iterator should not have a next item", iter.hasNext() ); assertTrue( "set should contain 1", set.contains( 1 ) ); assertTrue( "set should contain 2", set.contains( 2 ) ); assertTrue( "set should contain 3", set.contains( 3 ) ); assertTrue( "set should contain 4", set.contains( 4 ) ); assertEquals( 4, set.size() ); } public void testIteratorRemove() { TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.add( 1 ); set.add( 2 ); set.add( 3 ); set.add( 4 ); Iterator<Integer> iter = set.iterator(); assertTrue( "iterator should have a next item", iter.hasNext() ); int last = -1; while ( iter.hasNext() ) { int next = iter.next(); assertTrue( next >= 1 && next <= 4 ); assertTrue( next != last ); last = next; if ( next == 3 ) { iter.remove(); } } assertFalse( "iterator should not have a next item", iter.hasNext() ); assertFalse( "set should not contain 3", set.contains( 3 ) ); assertTrue( "set should contain 1", set.contains( 1 ) ); assertTrue( "set should contain 2", set.contains( 2 ) ); assertTrue( "set should contain 4", set.contains( 4 ) ); assertEquals( 3, set.size() ); } public void testEquals() { Integer[] ints = {1138, 42, 86, 99, 101}; TIntSet raw_set = new TIntHashSet(); Set<Integer> set = TDecorators.wrap( raw_set ); set.addAll( Arrays.asList( ints ) ); TIntSet raw_other = new TIntHashSet(); Set<Integer> other = TDecorators.wrap( raw_other ); other.addAll( Arrays.asList( ints ) ); assertTrue( "sets incorrectly not equal: " + set + ", " + other, set.equals( other ) ); int[] mismatched = {72, 49, 53, 1024, 999}; TIntSet raw_unequal = new TIntHashSet(); raw_unequal.addAll( mismatched ); Set<Integer> unequal = TDecorators.wrap( raw_unequal ); assertFalse( "sets incorrectly equal: " + set + ", " + unequal, set.equals( unequal ) ); // Change length, different code branch unequal.add( 1 ); assertFalse( "sets incorrectly equal: " + set + ", " + unequal, set.equals( unequal ) ); Set<Number> different_classes = new HashSet<Number>(); different_classes.addAll( Arrays.asList( ints ) ); different_classes.remove( Integer.valueOf( 86 ) ); different_classes.add( Long.valueOf( 86 ) ); assertFalse( "sets incorrectly equal: " + set + ", " + different_classes, set.equals( different_classes ) ); //noinspection ObjectEqualsNull assertFalse( set.equals( null ) ); // test against TIntSet assertTrue( set.equals( raw_other ) ); //noinspection MismatchedQueryAndUpdateOfCollection TIntSetDecorator decorated = new TIntSetDecorator( raw_other ); assertTrue( set.equals( decorated.getSet() ) ); } public void testHashcode() { int[] ints = {1138, 42, 86, 99, 101}; TIntSet raw_set = new TIntHashSet(); raw_set.addAll( ints ); Set<Integer> set = TDecorators.wrap( raw_set ); TIntSet raw_other = new TIntHashSet(); raw_other.addAll( ints ); Set<Integer> other = TDecorators.wrap( raw_other ); assertTrue( "hashcodes incorrectly not equal: " + set + ", " + other, set.hashCode() == other.hashCode() ); int[] mismatched = {72, 49, 53, 1024, 999}; TIntSet unequal = new TIntHashSet(); unequal.addAll( mismatched ); assertFalse( "hashcodes unlikely equal: " + set + ", " + unequal, set.hashCode() == unequal.hashCode() ); } } --- NEW FILE: TObjectPrimitiveMapDecoratorTest.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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. /////////////////////////////////////////////////////////////////////////////// [...966 lines suppressed...] ByteArrayInputStream bias = new ByteArrayInputStream( baos.toByteArray() ); ObjectInputStream ois = new ObjectInputStream( bias ); Map<String,Integer> deserialized = ( Map<String,Integer> ) ois.readObject(); assertEquals( map, deserialized ); } public void testToString() { TObjectIntHashMap<String> m = new TObjectIntHashMap<String>(); 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}" ) ); } } |
Update of /cvsroot/trove4j/trove/templates/gnu/trove/decorator In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20982/templates/gnu/trove/decorator Added Files: Tag: TROVE_3_WORKING _E_ObjectMapDecorator.template _E_SetDecorator.template _K__V_MapDecorator.template Object_E_MapDecorator.template Log Message: TDecorator implementatons, testcases and fixes associated with TPrimitiveSet and the maps wrapped. --- NEW FILE: _E_ObjectMapDecorator.template --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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.map.T#E#ObjectMap; import gnu.trove.iterator.T#E#ObjectIterator; import java.io.*; import java.util.*; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Wrapper class to make a T#E#ObjectMap conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying T#E#ObjectMap and translates the Object-based * APIs into their Trove primitive analogs. * <p/> * 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. * <p/> * Created: Mon Sep 23 22:07:40 PDT 2002 * * @author Eric D. Friedman * @author Robert D. Eden * @author Jeff Randall */ public class T#E#ObjectMapDecorator<V> extends AbstractMap<#ET#, V> implements Map<#ET#, V>, Externalizable, Cloneable { /** the wrapped primitive map */ protected T#E#ObjectMap<V> _map; /** * FOR EXTERNALIZATION ONLY!! */ public T#E#ObjectMapDecorator() {} /** * Creates a wrapper that decorates the specified primitive map. * * @param map the <tt>T#E#ObjectMap</tt> to wrap. */ public T#E#ObjectMapDecorator( T#E#ObjectMap<V> map ) { super(); this._map = map; } /** * Returns a reference to the map wrapped by this decorator. * * @return the wrapped <tt>T#E#ObjectMap</tt> instance. */ public T#E#ObjectMap<V> getMap() { return _map; } /** * Inserts a key/value pair into the map. * * @param key an <code>#ET#</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or <tt>null</tt> if none was found. */ public V put( #ET# key, V value ) { #e# k; if ( key == null ) { k = _map.getNoEntryKey(); } else { k = unwrapKey( key ); } return _map.put( k, value ); } /** * Retrieves the value for <tt>key</tt> * * @param key an <code>Object</code> value * @return the value of <tt>key</tt> or null if no such mapping exists. */ public V get( Object key ) { #e# k; if ( key != null ) { if ( key instanceof #ET# ) { k = unwrapKey( ( #ET# ) key ); } else { return null; } } else { k = _map.getNoEntryKey(); } return _map.get( k ); } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public V remove( Object key ) { #e# k; if ( key != null ) { if ( key instanceof #ET# ) { k = unwrapKey( ( #ET# ) key ); } else { return null; } } else { k = _map.getNoEntryKey(); } return _map.remove( k ); } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set<Map.Entry<#ET#,V>> entrySet() { return new AbstractSet<Map.Entry<#ET#,V>>() { public int size() { return _map.size(); } public boolean isEmpty() { return T#E#ObjectMapDecorator.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#ObjectMapDecorator.this.containsKey( k ) && T#E#ObjectMapDecorator.this.get( k ).equals( v ); } else { return false; } } public Iterator<Map.Entry<#ET#,V>> iterator() { return new Iterator<Map.Entry<#ET#,V>>() { private final T#E#ObjectIterator<V> it = _map.iterator(); public Map.Entry<#ET#,V> next() { it.advance(); final #ET# key = wrapKey( it.key() ); final V v = 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 ) { boolean modified = false; if ( contains( o ) ) { //noinspection unchecked #ET# key = ( ( Map.Entry<#ET#,V> ) o ).getKey(); _map.remove( unwrapKey( key ) ); modified = true; } return modified; } public boolean addAll( Collection<? extends Map.Entry<#ET#,V>> c ) { throw new UnsupportedOperationException(); } public void clear() { T#E#ObjectMapDecorator.this.clear(); } }; } /** * Checks for the presence of <tt>val</tt> in the values of the map. * * @param val an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsValue( Object val ) { return _map.containsValue( val ); } /** * Checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey( Object key ) { if ( key == null ) return _map.containsKey( _map.getNoEntryKey() ); return key instanceof #ET# && _map.containsKey( ( ( #ET# ) key ).#e#Value() ); } /** * 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 <tt>map</tt> into this map. * Note that this will be a <b>deep</b> copy, as storage is by * primitive value. * * @param map a <code>Map</code> value */ public void putAll( Map<? extends #ET#, ? extends V> map ) { Iterator<? extends Entry<? extends #ET#,? extends V>> it = map.entrySet().iterator(); for ( int i = map.size(); i-- > 0; ) { Entry<? extends #ET#,? extends V> 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( #ET# key ) { return key.#e#Value(); } // Implements Externalizable public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP //noinspection unchecked _map = ( T#E#ObjectMap<V> ) in.readObject(); } // Implements Externalizable public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 0 ); // MAP out.writeObject( _map ); } } // T#E#ObjectHashMapDecorator --- NEW FILE: _E_SetDecorator.template --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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.set.T#E#Set; import gnu.trove.iterator.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#Set conform to the <tt>java.util.Set</tt> API. * This class simply decorates an underlying T#E#Set and translates the Object-based * APIs into their Trove primitive analogs. * <p/> * <p/> * 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. * </p> * <p/> * Created: Tue Sep 24 22:08:17 PDT 2002 * * @author Eric D. Friedman * @author Robert D. Eden * @author Jeff Randall */ public class T#E#SetDecorator extends AbstractSet<#ET#> implements Set<#ET#>, Externalizable { /** the wrapped primitive set */ protected T#E#Set _set; /** * FOR EXTERNALIZATION ONLY!! */ public T#E#SetDecorator() {} /** * Creates a wrapper that decorates the specified primitive set. * * @param set the <tt>T#E#Set</tt> to wrap. */ public T#E#SetDecorator( T#E#Set set ) { super(); this._set = set; } /** * Returns a reference to the set wrapped by this decorator. * * @return the wrapped <tt>T#E#Set</tt> instance. */ public T#E#Set getSet() { return _set; } /** * Inserts a value into the set. * * @param value true if the set was modified by the insertion */ public boolean add( #ET# value ) { return value != null && _set.add( value.#e#Value() ); } /** * Compares this set with another set for equality of their stored * entries. * * @param other an <code>Object</code> 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 = ( ( #ET# ) val ).#e#Value(); 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 <code>Object</code> value * @return true if the set was modified */ public boolean remove( Object value ) { return value instanceof #ET# && _set.remove( ( ( #ET# ) value ).#e#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 #ET#.valueOf( 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 this._set.size() == 0; } // Implements Externalizable public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SET _set = ( T#E#Set ) in.readObject(); } // Implements Externalizable public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte( 0 ); // SET out.writeObject( _set ); } } // T#E#HashSetDecorator --- NEW FILE: _K__V_MapDecorator.template --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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.map.T#K##V#Map; import gnu.trove.iterator.T#K##V#Iterator; import java.io.*; import java.util.*; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Wrapper class to make a T#K##V#Map conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying T#K##V#Map and translates the Object-based * APIs into their Trove primitive analogs. * <p/> * 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. * <p/> * Created: Mon Sep 23 22:07:40 PDT 2002 * * @author Eric D. Friedman * @author Robert D. Eden * @author Jeff Randall */ public class T#K##V#MapDecorator extends AbstractMap<#KT#, #VT#> implements Map<#KT#, #VT#>, Externalizable, Cloneable { /** the wrapped primitive map */ protected T#K##V#Map _map; /** * FOR EXTERNALIZATION ONLY!! */ public T#K##V#MapDecorator() {} /** * Creates a wrapper that decorates the specified primitive map. * * @param map the <tt>T#K##V#Map</tt> to wrap. */ public T#K##V#MapDecorator( T#K##V#Map map ) { super(); this._map = map; } /** * Returns a reference to the map wrapped by this decorator. * * @return the wrapped <tt>T#K##V#Map</tt> instance. */ public T#K##V#Map getMap() { return _map; } /** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or #VT#(0) if none was found. */ public #VT# put( #KT# key, #VT# value ) { #k# k; #v# v; if ( key == null ) { k = _map.getNoEntryKey(); } else { k = unwrapKey( key ); } if ( value == null ) { v = _map.getNoEntryValue(); } else { v = unwrapValue( value ); } #v# retval = _map.put( k, v ); if ( retval == _map.getNoEntryValue() ) { return null; } return wrapValue( retval ); } /** * Retrieves the value for <tt>key</tt> * * @param key an <code>Object</code> value * @return the value of <tt>key</tt> or null if no such mapping exists. */ public #VT# get( Object key ) { #k# k; if ( key != null ) { if ( key instanceof #KT# ) { k = unwrapKey( key ); } else { return null; } } else { k = _map.getNoEntryKey(); } #v# v = _map.get( k ); // There may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if ( v == _map.getNoEntryValue() ) { return 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 <code>Object</code> value * @return the removed value, or null if it was not found in the map */ public #VT# remove( Object key ) { #k# k; if ( key != null ) { if ( key instanceof #KT# ) { k = unwrapKey( key ); } else { return null; } } else { k = _map.getNoEntryKey(); } #v# v = _map.remove( k ); // There may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if ( v == _map.getNoEntryValue() ) { return null; } else { return wrapValue( v ); } } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set<Map.Entry<#KT#,#VT#>> entrySet() { return new AbstractSet<Map.Entry<#KT#,#VT#>>() { public int size() { return _map.size(); } public boolean isEmpty() { return T#K##V#MapDecorator.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#MapDecorator.this.containsKey(k) && T#K##V#MapDecorator.this.get(k).equals(v); } else { return false; } } public Iterator<Map.Entry<#KT#,#VT#>> iterator() { return new Iterator<Map.Entry<#KT#,#VT#>>() { 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( Map.Entry<#KT#,#VT#> o ) { throw new UnsupportedOperationException(); } public boolean remove( Object o ) { boolean modified = false; if ( contains( o ) ) { //noinspection unchecked #KT# key = ( ( Map.Entry<#KT#,#VT#> ) o ).getKey(); _map.remove( unwrapKey( key ) ); modified = true; } return modified; } public boolean addAll( Collection<? extends Map.Entry<#KT#, #VT#>> c ) { throw new UnsupportedOperationException(); } public void clear() { T#K##V#MapDecorator.this.clear(); } }; } /** * Checks for the presence of <tt>val</tt> in the values of the map. * * @param val an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsValue( Object val ) { return val instanceof #VT# && _map.containsValue( unwrapValue( val ) ); } /** * Checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey( Object key ) { if ( key == null ) return _map.containsKey( _map.getNoEntryKey() ); return key instanceof #KT# && _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 <tt>map</tt> into this map. * Note that this will be a <b>deep</b> copy, as storage is by * primitive value. * * @param map a <code>Map</code> value */ public void putAll( Map<? extends #KT#, ? extends #VT#> map ) { Iterator<? extends Entry<? extends #KT#,? extends #VT#>> it = map.entrySet().iterator(); for ( int i = map.size(); i-- > 0; ) { Entry<? extends #KT#,? extends #VT#> 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#Map ) in.readObject(); } // Implements Externalizable public void writeExternal( ObjectOutput out ) throws IOException { // VERSION out.writeByte(0); // MAP out.writeObject( _map ); } } // T#K##V#HashMapDecorator --- NEW FILE: Object_E_MapDecorator.template --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // Copyright (c) 2009, Robert D. Eden All Rights Reserved. // Copyright (c) 2009, Jeff Randall 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.map.TObject#E#Map; import gnu.trove.iterator.TObject#E#Iterator; import java.io.*; import java.util.*; ////////////////////////////////////////////////// // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // ////////////////////////////////////////////////// /** * Wrapper class to make a TObject#E#Map conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying TObject#E#Map and translates the Object-based * APIs into their Trove primitive analogs. * <p/> * 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. * <p/> * Created: Mon Sep 23 22:07:40 PDT 2002 * * @author Eric D. Friedman * @author Robert D. Eden * @author Jeff Randall */ public class TObject#E#MapDecorator<K> extends AbstractMap<K, #ET#> implements Map<K, #ET#>, Externalizable, Cloneable { /** * the wrapped primitive map */ protected TObject#E#Map<K> _map; /** * FOR EXTERNALIZATION ONLY!! */ public TObject#E#MapDecorator() {} /** * Creates a wrapper that decorates the specified primitive map. * * @param map the <tt>TObject#E#Map</tt> to wrap. */ public TObject#E#MapDecorator( TObject#E#Map<K> map ) { super(); this._map = map; } /** * Returns a reference to the map wrapped by this decorator. * * @return the wrapped <tt>TObject#E#Map</tt> instance. */ public TObject#E#Map<K> getMap() { return _map; } /** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>#ET#</code> value * @return the previous value associated with <tt>key</tt>, * or Integer(0) if none was found. */ public #ET# put( K key, #ET# value ) { if ( value == null ) return wrapValue( _map.put( key, _map.getNoEntryValue() ) ); return wrapValue( _map.put( key, unwrapValue( value ) ) ); } /** * Retrieves the value for <tt>key</tt> * * @param key an <code>Object</code> value * @return the value of <tt>key</tt> or null if no such mapping exists. */ public #ET# get( Object key ) { #e# v = _map.get( key ); // There may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if ( v == _map.getNoEntryValue() ) { return 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 <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public #ET# remove( Object key ) { #e# v = _map.remove( key ); // There may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if ( v == _map.getNoEntryValue() ) { return null; } else { return wrapValue( v ); } } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set<Map.Entry<K,#ET#>> entrySet() { return new AbstractSet<Map.Entry<K,#ET#>>() { public int size() { return _map.size(); } public boolean isEmpty() { return TObject#E#MapDecorator.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#MapDecorator.this.containsKey( k ) && TObject#E#MapDecorator.this.get( k ).equals( v ); } else { return false; } } public Iterator<Map.Entry<K,#ET#>> iterator() { return new Iterator<Map.Entry<K,#ET#>>() { private final TObject#E#Iterator<K> it = _map.iterator(); public Map.Entry<K,#ET#> next() { it.advance(); final K key = it.key(); final #ET# v = wrapValue( it.value() ); return new Map.Entry<K,#ET#>() { 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 K 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( Map.Entry<K,#ET#> o ) { throw new UnsupportedOperationException(); } public boolean remove( Object o ) { boolean modified = false; if ( contains( o ) ) { //noinspection unchecked K key = ( ( Map.Entry<K,#ET#> ) o ).getKey(); _map.remove( key ); modified = true; } return modified; } public boolean addAll(Collection<? extends Map.Entry<K,#ET#>> c) { throw new UnsupportedOperationException(); } public void clear() { TObject#E#MapDecorator.this.clear(); } }; } /** * Checks for the presence of <tt>val</tt> in the values of the map. * * @param val an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsValue( Object val ) { return val instanceof #ET# && _map.containsValue( unwrapValue( val ) ); } /** * Checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey( Object key ) { return _map.containsKey( 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 this._map.size() == 0; } /** * Copies the key/value mappings in <tt>map</tt> into this map. * Note that this will be a <b>deep</b> copy, as storage is by * primitive value. * * @param map a <code>Map</code> value */ public void putAll( Map<? extends K, ? extends #ET#> map ) { Iterator<? extends Entry<? extends K,? extends #ET#>> it = map.entrySet().iterator(); for ( int i = map.size(); i-- > 0; ) { Entry<? extends K,? extends #ET#> e = it.next(); this.put( e.getKey(), e.getValue() ); } } /** * 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 //noinspection unchecked _map = ( TObject#E#Map<K> ) in.readObject(); } // Implements Externalizable public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte( 0 ); // MAP out.writeObject( _map ); } } // TObject#E#MapDecorator |
From: Jeff R. <uph...@us...> - 2009-09-18 06:07:38
|
Update of /cvsroot/trove4j/trove/templates/gnu/trove/set/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20982/templates/gnu/trove/set/hash Modified Files: Tag: TROVE_3_WORKING _E_HashSet.template Log Message: TDecorator implementatons, testcases and fixes associated with TPrimitiveSet and the maps wrapped. Index: _E_HashSet.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/set/hash/Attic/_E_HashSet.template,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** _E_HashSet.template 15 Sep 2009 18:40:57 -0000 1.1.2.6 --- _E_HashSet.template 18 Sep 2009 06:07:23 -0000 1.1.2.7 *************** *** 107,119 **** /** ! * Creates a new <code>T#E#HashSet</code> instance containing the ! * elements of <tt>array</tt>. ! * ! * @param array an array of <code>#e#</code> primitives ! */ ! public T#E#HashSet( #e#[] array ) { ! this( Math.max( array.length, DEFAULT_CAPACITY ) ); ! addAll( array ); ! } --- 107,119 ---- /** ! * Creates a new <code>T#E#HashSet</code> instance that is a copy ! * of the existing Collection. ! * ! * @param collection a <tt>Collection</tt> that will be duplicated. ! */ ! public T#E#HashSet( Collection<? extends #ET#> collection ) { ! this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); ! addAll( collection ); ! } *************** *** 140,143 **** --- 140,155 ---- + /** + * Creates a new <code>T#E#HashSet</code> instance containing the + * elements of <tt>array</tt>. + * + * @param array an array of <code>#e#</code> primitives + */ + public T#E#HashSet( #e#[] array ) { + this( Math.max( array.length, DEFAULT_CAPACITY ) ); + addAll( array ); + } + + /** {@inheritDoc} */ public T#E#Iterator iterator() { |
From: Jeff R. <uph...@us...> - 2009-09-18 06:07:38
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/set/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20982/test/gnu/trove/set/hash Modified Files: Tag: TROVE_3_WORKING TPrimitiveHashSetTest.java Log Message: TDecorator implementatons, testcases and fixes associated with TPrimitiveSet and the maps wrapped. Index: TPrimitiveHashSetTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/set/hash/Attic/TPrimitiveHashSetTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** TPrimitiveHashSetTest.java 4 Sep 2009 12:32:33 -0000 1.1.2.2 --- TPrimitiveHashSetTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.3 *************** *** 87,91 **** other.addAll( ints ); ! List<Integer> ints_list = new ArrayList<Integer>(); for ( int element : ints ) { ints_list.add( element ); --- 87,91 ---- other.addAll( ints ); ! List<Number> ints_list = new ArrayList<Number>(); for ( int element : ints ) { ints_list.add( element ); *************** *** 99,102 **** --- 99,106 ---- assertTrue( "containsAll(Collection<?>) failed: " + set, set.containsAll( ints_list ) ); + ints_list.remove( Integer.valueOf( 42 ) ); + ints_list.add( Long.valueOf( 42 ) ); + assertFalse( "containsAll(Collection<?>) failed: " + set, + set.containsAll( ints_list ) ); assertTrue( "containsAll(TIntSet) failed (same set): " + set, |
From: Jeff R. <uph...@us...> - 2009-09-18 06:07:34
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/map/hash In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20982/test/gnu/trove/map/hash Modified Files: Tag: TROVE_3_WORKING TPrimitiveObjectHashMapTest.java TPrimitivePrimitiveHashMapTest.java Log Message: TDecorator implementatons, testcases and fixes associated with TPrimitiveSet and the maps wrapped. Index: TPrimitiveObjectHashMapTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/map/hash/Attic/TPrimitiveObjectHashMapTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** TPrimitiveObjectHashMapTest.java 15 Sep 2009 02:38:31 -0000 1.1.2.1 --- TPrimitiveObjectHashMapTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.2 *************** *** 1350,1376 **** ! public void testDecorator() { ! // TObjectIntHashMap<String> map = new TObjectIntHashMap<String>(); ! // ! // map.put( "one", 1 ); ! // map.put( "two", 2 ); ! // ! // Map<String,Integer> decorator = new TObjectIntHashMapDecorator<String>( map ); ! // ! // assertEquals( 2, decorator.size() ); ! // assertEquals( Integer.valueOf( 1 ), decorator.get( "one" ) ); ! // assertEquals( Integer.valueOf( 2 ), decorator.get( "two" ) ); ! // ! // Set<String> decorator_keys = decorator.keySet(); ! // assertEquals( 2, decorator_keys.size() ); ! // Iterator<String> it = decorator_keys.iterator(); ! // int count = 0; ! // while( it.hasNext() ) { ! // count++; ! // System.out.println(it.next()); ! // } ! // assertEquals( 2, count ); ! // ! // assertSame(map, ( ( TObjectIntHashMapDecorator ) decorator ).getMap() ); } } --- 1350,1435 ---- ! /** ! * 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<String> po_double_map = new TDoubleObjectHashMap<String>(); ! TDoubleIntHashMap pp_double_map = new TDoubleIntHashMap(); ! TFloatObjectHashMap<String> po_float_map = new TFloatObjectHashMap<String>(); ! 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 ); } } Index: TPrimitivePrimitiveHashMapTest.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/map/hash/Attic/TPrimitivePrimitiveHashMapTest.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** TPrimitivePrimitiveHashMapTest.java 15 Sep 2009 18:40:57 -0000 1.1.2.4 --- TPrimitivePrimitiveHashMapTest.java 18 Sep 2009 06:07:23 -0000 1.1.2.5 *************** *** 1926,1930 **** TIntIntMap int_map = new TIntIntHashMap(); for ( int i = 0; i < keys.length; i++ ) { ! map.put( keys[i], (int) vals[i] ); } assertFalse( map.equals( int_map ) ); --- 1926,1930 ---- TIntIntMap int_map = new TIntIntHashMap(); for ( int i = 0; i < keys.length; i++ ) { ! int_map.put( keys[i], (int) vals[i] ); } assertFalse( map.equals( int_map ) ); |
From: Jeff R. <uph...@us...> - 2009-09-18 06:07:33
|
Update of /cvsroot/trove4j/trove/templates/gnu/trove In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20982/templates/gnu/trove Modified Files: Tag: TROVE_3_WORKING TDecorators.template Log Message: TDecorator implementatons, testcases and fixes associated with TPrimitiveSet and the maps wrapped. Index: TDecorators.template =================================================================== RCS file: /cvsroot/trove4j/trove/templates/gnu/trove/Attic/TDecorators.template,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** TDecorators.template 14 Sep 2009 04:10:31 -0000 1.1.2.1 --- TDecorators.template 18 Sep 2009 06:07:23 -0000 1.1.2.2 *************** *** 1,4 **** --- 1,5 ---- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2008, Robert D. Eden All Rights Reserved. + // Copyright (c) 2009, Jeff Randall All Rights Reserved. // // This library is free software; you can redistribute it and/or *************** *** 24,27 **** --- 25,30 ---- import gnu.trove.map.*; + import gnu.trove.set.*; + import gnu.trove.decorator.*; *************** *** 32,35 **** --- 35,39 ---- * * @author Robert D. Eden + * @author Jeff Randall * @since Trove 2.1 */ *************** *** 54,61 **** * 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#Map map ) { ! // return new T#K##V#MapDecorator( map ); ! // } =====END_REPLICATED_CONTENT #1===== ====START_REPLICATED_CONTENT #2==== --- 58,68 ---- * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. + * + * @param map the <tt>T#K##V#ObjectMap</tt> to be wrapped + * @return the wrapped map. */ ! public static Map<#KT#,#VT#> wrap( T#K##V#Map map ) { ! return new T#K##V#MapDecorator( map ); ! } =====END_REPLICATED_CONTENT #1===== ====START_REPLICATED_CONTENT #2==== *************** *** 63,70 **** * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. */ ! // public static <T> Map<T,#ET#> wrap( TObject#E#Map<T> map ) { ! // return new TObject#E#MapDecorator<T>( map ); ! // } =====END_REPLICATED_CONTENT #2===== ====START_REPLICATED_CONTENT #3==== --- 70,80 ---- * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. + * + * @param map the <tt>TObject#E#Map</tt> to be wrapped + * @return the wrapped map. */ ! public static <T> Map<T,#ET#> wrap( TObject#E#Map<T> map ) { ! return new TObject#E#MapDecorator<T>( map ); ! } =====END_REPLICATED_CONTENT #2===== ====START_REPLICATED_CONTENT #3==== *************** *** 72,79 **** * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. */ ! // public static <T> Map<#ET#,T> wrap( T#E#ObjectMap<T> map ) { ! // return new T#E#ObjectMapDecorator<T>( map ); ! // } =====END_REPLICATED_CONTENT #3===== ====START_REPLICATED_CONTENT #4==== --- 82,92 ---- * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} * interface. + * + * @param map the <tt>T#E#ObjectMap</tt> to be wrapped + * @return the wrapped map. */ ! public static <T> Map<#ET#,T> wrap( T#E#ObjectMap<T> map ) { ! return new T#E#ObjectMapDecorator<T>( map ); ! } =====END_REPLICATED_CONTENT #3===== ====START_REPLICATED_CONTENT #4==== *************** *** 81,87 **** * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} * interface. */ ! // public static Set<#ET#> wrap( T#E#Set set ) { ! // return new T#E#SetDecorator( set ); ! // } =====END_REPLICATED_CONTENT #4===== \ No newline at end of file --- 94,103 ---- * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} * interface. + * + * @param set the <tt>T#E#Set</tt> to be wrapped + * @return the wrapped set. */ ! public static Set<#ET#> wrap( T#E#Set set ) { ! return new T#E#SetDecorator( set ); ! } =====END_REPLICATED_CONTENT #4===== \ No newline at end of file |
From: Rob E. <ro...@us...> - 2009-09-18 03:55:56
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/benchmark In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7366/trove/test/gnu/trove/benchmark Modified Files: Tag: TROVE_3_WORKING BenchmarkSet.java BenchmarkRunner.java Added Files: Tag: TROVE_3_WORKING JavaHashMapPut.java TroveHashMapPut.java JavaHashMapIteration.java TroveHashMapIteration.java TroveHashMapGet.java TroveHashMapForEach.java JavaHashMapGet.java Log Message: Benchmarks for get, put and iteration --- NEW FILE: JavaHashMapPut.java --- /* * /////////////////////////////////////////////////////////////////////////////// * // Copyright (c) 2009, 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 java.util.Map; import java.util.HashMap; /** * */ class JavaHashMapPut implements Benchmark { private Map<Integer,Integer> map = new HashMap<Integer,Integer>(); public void setUp() {} public void tearDown() { map.clear(); } public String getName() { return "Java HashMap Put"; } public void run() { for( Integer i : BenchmarkRunner.INTEGERS ) { map.put( i, i ); } } } --- NEW FILE: TroveHashMapPut.java --- /* * /////////////////////////////////////////////////////////////////////////////// * // Copyright (c) 2009, 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.map.TIntObjectMap; import gnu.trove.map.hash.TIntObjectHashMap; /** * */ class TroveHashMapPut implements Benchmark { private TIntObjectMap<Integer> map; public void setUp() { if ( map != null ) return; map = new TIntObjectHashMap<Integer>(); ( ( TIntObjectHashMap<Integer> ) map ).ensureCapacity( BenchmarkRunner.INTEGERS.length ); } public void tearDown() { map.clear(); } public String getName() { return "Trove HashMap Put"; } public void run() { for( Integer i : BenchmarkRunner.INTEGERS ) { map.put( i.intValue(), i ); } } } --- NEW FILE: JavaHashMapIteration.java --- /* * /////////////////////////////////////////////////////////////////////////////// * // Copyright (c) 2009, 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 java.util.Map; import java.util.HashMap; /** * */ class JavaHashMapIteration implements Benchmark { private Map<Integer,Integer> map = new HashMap<Integer,Integer>(); public void setUp() { if ( !map.isEmpty() ) return; for( int j = 0; j < 2; j++ ) { for( Integer i : BenchmarkRunner.INTEGERS ) { map.put( i, i ); } } } public void tearDown() {} public String getName() { return "Java HashMap Iteration"; } public void run() { int total = 0; for( int i = 0; i < 5; i++ ) { for( Map.Entry<Integer,Integer> entry : map.entrySet() ) { total += entry.getKey().intValue(); } } } } --- NEW FILE: TroveHashMapIteration.java --- /* * /////////////////////////////////////////////////////////////////////////////// * // Copyright (c) 2009, 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.iterator.TIntObjectIterator; import gnu.trove.map.TIntObjectMap; import gnu.trove.map.hash.TIntObjectHashMap; /** * */ class TroveHashMapIteration implements Benchmark { private TIntObjectMap<Integer> map = new TIntObjectHashMap<Integer>(); public void setUp() { if ( !map.isEmpty() ) return; for( int j = 0; j < 2; j++ ) { for( Integer i : BenchmarkRunner.INTEGERS ) { map.put( i.intValue(), i ); } } } public void tearDown() {} public String getName() { return "Trove HashMap Iteration"; } public void run() { int total = 0; for( int i = 0; i < 5; i++ ) { TIntObjectIterator<Integer> iterator = map.iterator(); while( iterator.hasNext() ) { iterator.advance(); total += iterator.key(); } } } } --- NEW FILE: TroveHashMapGet.java --- /* * /////////////////////////////////////////////////////////////////////////////// * // Copyright (c) 2009, 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.map.TIntObjectMap; import gnu.trove.map.hash.TIntObjectHashMap; /** * */ class TroveHashMapGet implements Benchmark { private TIntObjectMap<Integer> map = new TIntObjectHashMap<Integer>(); public void setUp() { if ( !map.isEmpty() ) return; for( Integer i : BenchmarkRunner.INTEGERS ) { map.put( i.intValue(), i ); } } public void tearDown() {} public String getName() { return "Trove HashMap Get"; } public void run() { for( int j = 0; j < 5; j++ ) { for( Integer i : BenchmarkRunner.INTEGERS ) { map.get( i.intValue() ); } } } } --- NEW FILE: TroveHashMapForEach.java --- /* * /////////////////////////////////////////////////////////////////////////////// * // Copyright (c) 2009, 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.map.TIntObjectMap; import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.procedure.TIntObjectProcedure; /** * */ class TroveHashMapForEach implements Benchmark { private TIntObjectMap<Integer> map = new TIntObjectHashMap<Integer>(); private Totaler totaler = new Totaler(); public void setUp() { if ( !map.isEmpty() ) return; for( int j = 0; j < 2; j++ ) { for( Integer i : BenchmarkRunner.INTEGERS ) { map.put( i.intValue(), i ); } } } public void tearDown() {} public String getName() { return "Trove HashMap ForEach"; } public void run() { totaler.reset(); for( int i = 0; i < 5; i++ ) { map.forEachEntry( totaler ); } } class Totaler implements TIntObjectProcedure<Integer> { int total = 0; void reset() { total = 0; } public boolean execute( int a, Integer b ) { total += a; return true; } } } --- NEW FILE: JavaHashMapGet.java --- /* * /////////////////////////////////////////////////////////////////////////////// * // Copyright (c) 2009, 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 java.util.HashMap; import java.util.Map; /** * */ class JavaHashMapGet implements Benchmark { private Map<Integer,Integer> map = new HashMap<Integer,Integer>(); public void setUp() { if ( !map.isEmpty() ) return; for( Integer i : BenchmarkRunner.INTEGERS ) { map.put( i, i ); } } public void tearDown() {} public String getName() { return "Java HashMap Get"; } public void run() { for( int j = 0; j < 5; j++ ) { for( Integer i : BenchmarkRunner.INTEGERS ) { map.get( i ); } } } } Index: BenchmarkSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/benchmark/Attic/BenchmarkSet.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** BenchmarkSet.java 18 Sep 2009 02:43:23 -0000 1.1.2.2 --- BenchmarkSet.java 18 Sep 2009 03:55:32 -0000 1.1.2.3 *************** *** 23,27 **** * */ ! abstract class BenchmarkSet implements Benchmark { private final String name; --- 23,27 ---- * */ ! class BenchmarkSet implements Benchmark { private final String name; Index: BenchmarkRunner.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/benchmark/Attic/BenchmarkRunner.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** BenchmarkRunner.java 18 Sep 2009 02:43:23 -0000 1.1.2.2 --- BenchmarkRunner.java 18 Sep 2009 03:55:32 -0000 1.1.2.3 *************** *** 23,26 **** --- 23,27 ---- import java.lang.management.ManagementFactory; import java.util.List; + import java.util.concurrent.TimeUnit; *************** *** 29,36 **** */ class BenchmarkRunner { ! private static final Benchmark[] CASES = {}; private static final Runtime RUNTIME = Runtime.getRuntime(); private static int warmup_times = 10; private static long warmup_settle_time = 3000; --- 30,44 ---- */ class BenchmarkRunner { ! private static final Benchmark[] CASES = { ! new BenchmarkSet( "Map Puts", new JavaHashMapPut(), new TroveHashMapPut() ), ! new BenchmarkSet( "Map Gets", new JavaHashMapGet(), new TroveHashMapGet() ), ! new BenchmarkSet( "Map Iteration", new JavaHashMapIteration(), ! new TroveHashMapIteration(), new TroveHashMapForEach() ) ! }; private static final Runtime RUNTIME = Runtime.getRuntime(); + static final Integer INTEGERS[] = new Integer[ 10000 ]; + private static int warmup_times = 10; private static long warmup_settle_time = 3000; *************** *** 50,55 **** System.gc(); for( Benchmark benchmark : CASES ) { ! String indent_level = " "; runBenchmark( benchmark, indent_level, collectors ); --- 58,67 ---- System.gc(); + for( int i = 0; i < INTEGERS.length; i++ ) { + INTEGERS[ i ] = Integer.valueOf( i ); + } + for( Benchmark benchmark : CASES ) { ! String indent_level = ""; runBenchmark( benchmark, indent_level, collectors ); *************** *** 67,71 **** getGCTime( collectors, collection_info, null ); ! long start_time = System.nanoTime(); if ( mark instanceof BenchmarkSet ) { --- 79,83 ---- getGCTime( collectors, collection_info, null ); ! long total_time = 0; if ( mark instanceof BenchmarkSet ) { *************** *** 95,106 **** // Run the tests for( int i = 0; i < run_times; i++ ) { mark.run(); } } - long end_time = System.nanoTime(); // gc_info = getGCTime( collectors, gc_info ); ! mark.tearDown(); } --- 107,129 ---- // Run the tests for( int i = 0; i < run_times; i++ ) { + mark.setUp(); + + long start_time = System.nanoTime(); mark.run(); + total_time += System.nanoTime() - start_time; + + mark.tearDown(); } } // gc_info = getGCTime( collectors, gc_info ); ! System.out.print( "done" ); ! if ( total_time == 0 ) System.out.println( "." ); ! else { ! System.out.print( ": " ); ! System.out.println( ! TimeUnit.MILLISECONDS.convert( total_time, TimeUnit.NANOSECONDS ) ); ! } } |
From: Rob E. <ro...@us...> - 2009-09-18 02:43:34
|
Update of /cvsroot/trove4j/trove/test/gnu/trove/benchmark In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32429/test/gnu/trove/benchmark Modified Files: Tag: TROVE_3_WORKING BenchmarkRunner.java BenchmarkSet.java Log Message: Work on benchmarks Index: BenchmarkRunner.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/benchmark/Attic/BenchmarkRunner.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** BenchmarkRunner.java 15 Sep 2009 04:01:30 -0000 1.1.2.1 --- BenchmarkRunner.java 18 Sep 2009 02:43:23 -0000 1.1.2.2 *************** *** 31,42 **** private static final Benchmark[] CASES = {}; public static void main( String[] args ) { List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans(); } private static CollectionInfo getGCTime( List<GarbageCollectorMXBean> collectors, ! CollectionInfo since_info ) { long count = 0; --- 31,121 ---- private static final Benchmark[] CASES = {}; + private static final Runtime RUNTIME = Runtime.getRuntime(); + + private static int warmup_times = 10; + private static long warmup_settle_time = 3000; + private static long run_times = 100; + private static long case_settle_time = 20; + public static void main( String[] args ) { List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans(); + if ( collectors != null && collectors.isEmpty() ) collectors = null; + + if ( collectors == null ) { + System.out.println( "No garbage collector MX beans found. " + + "Garbage collection statistics will be disabled." ); + } + + System.gc(); + + for( Benchmark benchmark : CASES ) { + String indent_level = " "; + + runBenchmark( benchmark, indent_level, collectors ); + } + } + + private static void runBenchmark( Benchmark mark, String indent_level, + List<GarbageCollectorMXBean> collectors ) { + + System.out.print( indent_level ); + System.out.print( mark.getName() ); + System.out.print( "..." ); + + CollectionInfo collection_info = new CollectionInfo(); + getGCTime( collectors, collection_info, null ); + + long start_time = System.nanoTime(); + + if ( mark instanceof BenchmarkSet ) { + System.out.println(); + + String child_indent = indent_level + " "; + Benchmark[] child_cases = ( ( BenchmarkSet ) mark ).getCases(); + for( Benchmark child : child_cases ) { + runBenchmark( child, child_indent, collectors ); + } + + System.out.print( indent_level ); + System.out.print( mark.getName() ); + System.out.print( ": " ); + } + else { + // Run a few times to warm up + for( int i = 0; i < warmup_times; i++ ) { + mark.setUp(); + mark.run(); + mark.tearDown(); + } + + // Wait for hotspot to have time to compile + sleep( warmup_settle_time ); + + // Run the tests + for( int i = 0; i < run_times; i++ ) { + mark.run(); + } + } + + long end_time = System.nanoTime(); + // gc_info = getGCTime( collectors, gc_info ); + + mark.tearDown(); } + private static void sleep( long time ) { + try { + Thread.sleep( time ); + } + catch( InterruptedException ex ) { + // ignore + } + } + + private static CollectionInfo getGCTime( List<GarbageCollectorMXBean> collectors, ! CollectionInfo fill_into, CollectionInfo since_info ) { long count = 0; *************** *** 50,69 **** } ! if ( since_info == null ) return new CollectionInfo( count, time ); ! else return new CollectionInfo( since_info, count, time ); } private static class CollectionInfo { private long count; private long time; ! CollectionInfo( long count, long time ) { this.count = count; this.time = time; } ! CollectionInfo( CollectionInfo start, long end_count, long end_time ) { this.count = end_count - start.count; this.time = end_time - start.time; --- 129,153 ---- } ! long free_mem = RUNTIME.freeMemory(); ! ! if ( since_info == null ) fill_into.fill( free_mem, count, time ); ! else fill_into.fill( free_mem, since_info, count, time ); ! return fill_into; } private static class CollectionInfo { + private long free_mem; private long count; private long time; + CollectionInfo() {} ! void fill( long free_mem, long count, long time ) { this.count = count; this.time = time; } ! void fill( long free_mem, CollectionInfo start, long end_count, long end_time ) { this.count = end_count - start.count; this.time = end_time - start.time; Index: BenchmarkSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/test/gnu/trove/benchmark/Attic/BenchmarkSet.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** BenchmarkSet.java 15 Sep 2009 04:01:30 -0000 1.1.2.1 --- BenchmarkSet.java 18 Sep 2009 02:43:23 -0000 1.1.2.2 *************** *** 54,58 **** public void run() { ! // TODO: implement } } --- 54,63 ---- public void run() { ! throw new UnsupportedOperationException(); ! } ! ! ! public Benchmark[] getCases() { ! return cases; } } |