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: Eric F. <er...@us...> - 2003-03-19 05:07:14
|
Update of /cvsroot/trove4j/trove In directory sc8-pr-cvs1:/tmp/cvs-serv1899 Modified Files: build.xml Log Message: hashCode in primitive lists Index: build.xml =================================================================== RCS file: /cvsroot/trove4j/trove/build.xml,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** build.xml 19 Mar 2003 04:41:29 -0000 1.25 --- build.xml 19 Mar 2003 05:07:11 -0000 1.26 *************** *** 10,14 **** <property name="Name" value="GNU Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="1.0.0"/> <property name="year" value="2001-2002"/> --- 10,14 ---- <property name="Name" value="GNU Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="1.0.1"/> <property name="year" value="2001-2002"/> |
From: Eric F. <er...@us...> - 2003-03-19 04:41:32
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory sc8-pr-cvs1:/tmp/cvs-serv26638/src/gnu/trove Modified Files: TDoubleIterator.java TFloatIterator.java TIntIterator.java TLongIterator.java gen_set_iterators.pl Log Message: Index: TDoubleIterator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleIterator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TDoubleIterator.java 22 Sep 2002 21:53:40 -0000 1.1 --- TDoubleIterator.java 19 Mar 2003 04:41:29 -0000 1.2 *************** *** 43,47 **** * * @return the next double in the collection ! * @excetion NoSuchElementException if the iterator is already exhausted */ public double next() { --- 43,47 ---- * * @return the next double in the collection ! * @exception NoSuchElementException if the iterator is already exhausted */ public double next() { Index: TFloatIterator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatIterator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TFloatIterator.java 22 Sep 2002 21:53:41 -0000 1.1 --- TFloatIterator.java 19 Mar 2003 04:41:29 -0000 1.2 *************** *** 43,47 **** * * @return the next float in the collection ! * @excetion NoSuchElementException if the iterator is already exhausted */ public float next() { --- 43,47 ---- * * @return the next float in the collection ! * @exception NoSuchElementException if the iterator is already exhausted */ public float next() { Index: TIntIterator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntIterator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TIntIterator.java 22 Sep 2002 21:53:42 -0000 1.1 --- TIntIterator.java 19 Mar 2003 04:41:29 -0000 1.2 *************** *** 43,47 **** * * @return the next int in the collection ! * @excetion NoSuchElementException if the iterator is already exhausted */ public int next() { --- 43,47 ---- * * @return the next int in the collection ! * @exception NoSuchElementException if the iterator is already exhausted */ public int next() { Index: TLongIterator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongIterator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TLongIterator.java 22 Sep 2002 21:53:42 -0000 1.1 --- TLongIterator.java 19 Mar 2003 04:41:29 -0000 1.2 *************** *** 43,47 **** * * @return the next long in the collection ! * @excetion NoSuchElementException if the iterator is already exhausted */ public long next() { --- 43,47 ---- * * @return the next long in the collection ! * @exception NoSuchElementException if the iterator is already exhausted */ public long next() { Index: gen_set_iterators.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/gen_set_iterators.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gen_set_iterators.pl 22 Sep 2002 21:53:42 -0000 1.1 --- gen_set_iterators.pl 19 Mar 2003 04:41:29 -0000 1.2 *************** *** 62,66 **** * * @return the next <type> in the collection ! * @excetion NoSuchElementException if the iterator is already exhausted */ public <type> next() { --- 62,66 ---- * * @return the next <type> in the collection ! * @exception NoSuchElementException if the iterator is already exhausted */ public <type> next() { |
From: Eric F. <er...@us...> - 2003-03-19 04:41:32
|
Update of /cvsroot/trove4j/trove In directory sc8-pr-cvs1:/tmp/cvs-serv26638 Modified Files: build.xml Log Message: Index: build.xml =================================================================== RCS file: /cvsroot/trove4j/trove/build.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** build.xml 27 Sep 2002 15:50:56 -0000 1.24 --- build.xml 19 Mar 2003 04:41:29 -0000 1.25 *************** *** 10,14 **** <property name="Name" value="GNU Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="0.1.8"/> <property name="year" value="2001-2002"/> --- 10,14 ---- <property name="Name" value="GNU Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="1.0.0"/> <property name="year" value="2001-2002"/> |
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory sc8-pr-cvs1:/tmp/cvs-serv19510/src/gnu/trove Modified Files: TDoubleDoubleHashMap.java TDoubleFloatHashMap.java TDoubleHash.java TDoubleHashSet.java TDoubleIntHashMap.java TDoubleLongHashMap.java TDoubleObjectHashMap.java TFloatDoubleHashMap.java TFloatFloatHashMap.java TFloatHash.java TFloatHashSet.java TFloatIntHashMap.java TFloatLongHashMap.java TFloatObjectHashMap.java THashMap.java THashMapTests.java THashSet.java TIntArrayListTests.java TIntDoubleHashMap.java TIntFloatHashMap.java TIntHash.java TIntHashSet.java TIntIntHashMap.java TIntLongHashMap.java TIntObjectHashMap.java TLongDoubleHashMap.java TLongFloatHashMap.java TLongHash.java TLongHashSet.java TLongIntHashMap.java TLongLongHashMap.java TLongObjectHashMap.java TObjectHash.java gen_primitive_base.pl gen_primitive_map.pl gen_primitive_set.pl Log Message: made maps, sets implement hashCode based on their contents Index: TDoubleDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleDoubleHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TDoubleDoubleHashMap.java 22 Sep 2002 21:53:39 -0000 1.13 --- TDoubleDoubleHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TDoubleDoubleProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(double key, double value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TDoubleDoubleProcedure { private final TDoubleDoubleHashMap _otherMap; Index: TDoubleFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleFloatHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TDoubleFloatHashMap.java 22 Sep 2002 21:53:39 -0000 1.13 --- TDoubleFloatHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TDoubleFloatProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(double key, float value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TDoubleFloatProcedure { private final TDoubleFloatHashMap _otherMap; Index: TDoubleHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleHash.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TDoubleHash.java 22 Sep 2002 21:53:40 -0000 1.12 --- TDoubleHash.java 19 Mar 2003 04:17:03 -0000 1.13 *************** *** 37,41 **** /** strategy used to hash values in this collection */ ! private TDoubleHashingStrategy hashingStrategy; /** --- 37,41 ---- /** strategy used to hash values in this collection */ ! protected TDoubleHashingStrategy _hashingStrategy; /** *************** *** 45,49 **** public TDoubleHash() { super(); ! this.hashingStrategy = this; } --- 45,49 ---- public TDoubleHash() { super(); ! this._hashingStrategy = this; } *************** *** 57,61 **** public TDoubleHash(int initialCapacity) { super(initialCapacity); ! this.hashingStrategy = this; } --- 57,61 ---- public TDoubleHash(int initialCapacity) { super(initialCapacity); ! this._hashingStrategy = this; } *************** *** 70,74 **** public TDoubleHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this.hashingStrategy = this; } --- 70,74 ---- public TDoubleHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this._hashingStrategy = this; } *************** *** 80,84 **** public TDoubleHash(TDoubleHashingStrategy strategy) { super(); ! this.hashingStrategy = strategy; } --- 80,84 ---- public TDoubleHash(TDoubleHashingStrategy strategy) { super(); ! this._hashingStrategy = strategy; } *************** *** 93,97 **** public TDoubleHash(int initialCapacity, TDoubleHashingStrategy strategy) { super(initialCapacity); ! this.hashingStrategy = strategy; } --- 93,97 ---- public TDoubleHash(int initialCapacity, TDoubleHashingStrategy strategy) { super(initialCapacity); ! this._hashingStrategy = strategy; } *************** *** 107,111 **** public TDoubleHash(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this.hashingStrategy = strategy; } --- 107,111 ---- public TDoubleHash(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this._hashingStrategy = strategy; } *************** *** 186,190 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 186,190 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 222,226 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 222,226 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; Index: TDoubleHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleHashSet.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleHashSet.java 22 Sep 2002 21:53:40 -0000 1.10 --- TDoubleHashSet.java 19 Mar 2003 04:17:03 -0000 1.11 *************** *** 230,233 **** --- 230,252 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TDoubleProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(double key) { + h += _hashingStrategy.computeHashCode(key); + return true; + } + } + /** * Removes <tt>val</tt> from the set. Index: TDoubleIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleIntHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TDoubleIntHashMap.java 22 Sep 2002 21:53:40 -0000 1.13 --- TDoubleIntHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TDoubleIntProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(double key, int value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TDoubleIntProcedure { private final TDoubleIntHashMap _otherMap; Index: TDoubleLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleLongHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TDoubleLongHashMap.java 22 Sep 2002 21:53:40 -0000 1.13 --- TDoubleLongHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TDoubleLongProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(double key, long value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TDoubleLongProcedure { private final TDoubleLongHashMap _otherMap; Index: TDoubleObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleObjectHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TDoubleObjectHashMap.java 22 Sep 2002 21:53:40 -0000 1.13 --- TDoubleObjectHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TDoubleObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(double key, Object value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TDoubleObjectProcedure { private final TDoubleObjectHashMap _otherMap; Index: TFloatDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatDoubleHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TFloatDoubleHashMap.java 22 Sep 2002 21:53:40 -0000 1.13 --- TFloatDoubleHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TFloatDoubleProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(float key, double value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TFloatDoubleProcedure { private final TFloatDoubleHashMap _otherMap; Index: TFloatFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatFloatHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TFloatFloatHashMap.java 22 Sep 2002 21:53:40 -0000 1.13 --- TFloatFloatHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TFloatFloatProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(float key, float value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TFloatFloatProcedure { private final TFloatFloatHashMap _otherMap; Index: TFloatHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatHash.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TFloatHash.java 22 Sep 2002 21:53:40 -0000 1.12 --- TFloatHash.java 19 Mar 2003 04:17:03 -0000 1.13 *************** *** 37,41 **** /** strategy used to hash values in this collection */ ! private TFloatHashingStrategy hashingStrategy; /** --- 37,41 ---- /** strategy used to hash values in this collection */ ! protected TFloatHashingStrategy _hashingStrategy; /** *************** *** 45,49 **** public TFloatHash() { super(); ! this.hashingStrategy = this; } --- 45,49 ---- public TFloatHash() { super(); ! this._hashingStrategy = this; } *************** *** 57,61 **** public TFloatHash(int initialCapacity) { super(initialCapacity); ! this.hashingStrategy = this; } --- 57,61 ---- public TFloatHash(int initialCapacity) { super(initialCapacity); ! this._hashingStrategy = this; } *************** *** 70,74 **** public TFloatHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this.hashingStrategy = this; } --- 70,74 ---- public TFloatHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this._hashingStrategy = this; } *************** *** 80,84 **** public TFloatHash(TFloatHashingStrategy strategy) { super(); ! this.hashingStrategy = strategy; } --- 80,84 ---- public TFloatHash(TFloatHashingStrategy strategy) { super(); ! this._hashingStrategy = strategy; } *************** *** 93,97 **** public TFloatHash(int initialCapacity, TFloatHashingStrategy strategy) { super(initialCapacity); ! this.hashingStrategy = strategy; } --- 93,97 ---- public TFloatHash(int initialCapacity, TFloatHashingStrategy strategy) { super(initialCapacity); ! this._hashingStrategy = strategy; } *************** *** 107,111 **** public TFloatHash(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this.hashingStrategy = strategy; } --- 107,111 ---- public TFloatHash(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this._hashingStrategy = strategy; } *************** *** 186,190 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 186,190 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 222,226 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 222,226 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; Index: TFloatHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatHashSet.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatHashSet.java 22 Sep 2002 21:53:40 -0000 1.10 --- TFloatHashSet.java 19 Mar 2003 04:17:03 -0000 1.11 *************** *** 230,233 **** --- 230,252 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TFloatProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(float key) { + h += _hashingStrategy.computeHashCode(key); + return true; + } + } + /** * Removes <tt>val</tt> from the set. Index: TFloatIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatIntHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TFloatIntHashMap.java 22 Sep 2002 21:53:40 -0000 1.13 --- TFloatIntHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TFloatIntProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(float key, int value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TFloatIntProcedure { private final TFloatIntHashMap _otherMap; Index: TFloatLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatLongHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TFloatLongHashMap.java 22 Sep 2002 21:53:41 -0000 1.13 --- TFloatLongHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TFloatLongProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(float key, long value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TFloatLongProcedure { private final TFloatLongHashMap _otherMap; Index: TFloatObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatObjectHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TFloatObjectHashMap.java 22 Sep 2002 21:53:41 -0000 1.13 --- TFloatObjectHashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TFloatObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(float key, Object value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TFloatObjectProcedure { private final TFloatObjectHashMap _otherMap; Index: THashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** THashMap.java 20 Sep 2002 20:55:57 -0000 1.13 --- THashMap.java 19 Mar 2003 04:17:03 -0000 1.14 *************** *** 203,206 **** --- 203,225 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TObjectObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(Object key, Object value) { + h += (_hashingStrategy.computeHashCode(key) ^ (value == null ? 0 : value.hashCode())); + return true; + } + } + private static final class EqProcedure implements TObjectObjectProcedure { private final Map _otherMap; Index: THashMapTests.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMapTests.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** THashMapTests.java 20 Sep 2002 20:55:57 -0000 1.11 --- THashMapTests.java 19 Mar 2003 04:17:03 -0000 1.12 *************** *** 330,332 **** --- 330,344 ---- assertTrue(! map.equals(m2)); } + + public void testHashCode() throws Exception { + THashMap m1 = new THashMap(); + THashMap m2 = new THashMap(); + m1.put(new String("foo"), new String("bar")); + m2.put(new String("foo"), new String("bar")); + assertEquals(m1.hashCode(), m2.hashCode()); + assertEquals(m1, m2); + m2.put(new String("cruft"), new String("bar")); + assertTrue(m1.hashCode() != m2.hashCode()); + assertTrue(! m1.equals(m2)); + } } // THashMapTests Index: THashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashSet.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** THashSet.java 18 Aug 2002 16:43:14 -0000 1.9 --- THashSet.java 19 Mar 2003 04:17:04 -0000 1.10 *************** *** 160,163 **** --- 160,182 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(Object key) { + h += _hashingStrategy.computeHashCode(key); + return true; + } + } + /** * Expands the set to accomodate new values. Index: TIntArrayListTests.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntArrayListTests.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TIntArrayListTests.java 8 Jul 2002 00:51:20 -0000 1.4 --- TIntArrayListTests.java 19 Mar 2003 04:17:04 -0000 1.5 *************** *** 52,55 **** --- 52,64 ---- } + public void testFill() { + assertEquals(0, list.size()); + list.fill(10); + assertEquals(0, list.size()); + list.fill(0, 100, 10); + assertEquals(100, list.size()); + assertEquals(10, list.get(5)); + } + public void testSize() { assertEquals(0, list.size()); Index: TIntDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntDoubleHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TIntDoubleHashMap.java 22 Sep 2002 21:53:41 -0000 1.13 --- TIntDoubleHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TIntDoubleProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(int key, double value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TIntDoubleProcedure { private final TIntDoubleHashMap _otherMap; Index: TIntFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntFloatHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TIntFloatHashMap.java 22 Sep 2002 21:53:41 -0000 1.13 --- TIntFloatHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TIntFloatProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(int key, float value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TIntFloatProcedure { private final TIntFloatHashMap _otherMap; Index: TIntHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntHash.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TIntHash.java 22 Sep 2002 21:53:41 -0000 1.12 --- TIntHash.java 19 Mar 2003 04:17:04 -0000 1.13 *************** *** 37,41 **** /** strategy used to hash values in this collection */ ! private TIntHashingStrategy hashingStrategy; /** --- 37,41 ---- /** strategy used to hash values in this collection */ ! protected TIntHashingStrategy _hashingStrategy; /** *************** *** 45,49 **** public TIntHash() { super(); ! this.hashingStrategy = this; } --- 45,49 ---- public TIntHash() { super(); ! this._hashingStrategy = this; } *************** *** 57,61 **** public TIntHash(int initialCapacity) { super(initialCapacity); ! this.hashingStrategy = this; } --- 57,61 ---- public TIntHash(int initialCapacity) { super(initialCapacity); ! this._hashingStrategy = this; } *************** *** 70,74 **** public TIntHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this.hashingStrategy = this; } --- 70,74 ---- public TIntHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this._hashingStrategy = this; } *************** *** 80,84 **** public TIntHash(TIntHashingStrategy strategy) { super(); ! this.hashingStrategy = strategy; } --- 80,84 ---- public TIntHash(TIntHashingStrategy strategy) { super(); ! this._hashingStrategy = strategy; } *************** *** 93,97 **** public TIntHash(int initialCapacity, TIntHashingStrategy strategy) { super(initialCapacity); ! this.hashingStrategy = strategy; } --- 93,97 ---- public TIntHash(int initialCapacity, TIntHashingStrategy strategy) { super(initialCapacity); ! this._hashingStrategy = strategy; } *************** *** 107,111 **** public TIntHash(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this.hashingStrategy = strategy; } --- 107,111 ---- public TIntHash(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this._hashingStrategy = strategy; } *************** *** 186,190 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 186,190 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 222,226 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 222,226 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; Index: TIntHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntHashSet.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TIntHashSet.java 22 Sep 2002 21:53:41 -0000 1.10 --- TIntHashSet.java 19 Mar 2003 04:17:04 -0000 1.11 *************** *** 230,233 **** --- 230,252 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TIntProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(int key) { + h += _hashingStrategy.computeHashCode(key); + return true; + } + } + /** * Removes <tt>val</tt> from the set. Index: TIntIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntIntHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TIntIntHashMap.java 22 Sep 2002 21:53:41 -0000 1.13 --- TIntIntHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TIntIntProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(int key, int value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TIntIntProcedure { private final TIntIntHashMap _otherMap; Index: TIntLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntLongHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TIntLongHashMap.java 22 Sep 2002 21:53:42 -0000 1.13 --- TIntLongHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TIntLongProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(int key, long value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TIntLongProcedure { private final TIntLongHashMap _otherMap; Index: TIntObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntObjectHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TIntObjectHashMap.java 22 Sep 2002 21:53:42 -0000 1.13 --- TIntObjectHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TIntObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(int key, Object value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TIntObjectProcedure { private final TIntObjectHashMap _otherMap; Index: TLongDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongDoubleHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TLongDoubleHashMap.java 22 Sep 2002 21:53:42 -0000 1.13 --- TLongDoubleHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TLongDoubleProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(long key, double value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TLongDoubleProcedure { private final TLongDoubleHashMap _otherMap; Index: TLongFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongFloatHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TLongFloatHashMap.java 22 Sep 2002 21:53:42 -0000 1.13 --- TLongFloatHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TLongFloatProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(long key, float value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TLongFloatProcedure { private final TLongFloatHashMap _otherMap; Index: TLongHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongHash.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TLongHash.java 22 Sep 2002 21:53:42 -0000 1.12 --- TLongHash.java 19 Mar 2003 04:17:04 -0000 1.13 *************** *** 37,41 **** /** strategy used to hash values in this collection */ ! private TLongHashingStrategy hashingStrategy; /** --- 37,41 ---- /** strategy used to hash values in this collection */ ! protected TLongHashingStrategy _hashingStrategy; /** *************** *** 45,49 **** public TLongHash() { super(); ! this.hashingStrategy = this; } --- 45,49 ---- public TLongHash() { super(); ! this._hashingStrategy = this; } *************** *** 57,61 **** public TLongHash(int initialCapacity) { super(initialCapacity); ! this.hashingStrategy = this; } --- 57,61 ---- public TLongHash(int initialCapacity) { super(initialCapacity); ! this._hashingStrategy = this; } *************** *** 70,74 **** public TLongHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this.hashingStrategy = this; } --- 70,74 ---- public TLongHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this._hashingStrategy = this; } *************** *** 80,84 **** public TLongHash(TLongHashingStrategy strategy) { super(); ! this.hashingStrategy = strategy; } --- 80,84 ---- public TLongHash(TLongHashingStrategy strategy) { super(); ! this._hashingStrategy = strategy; } *************** *** 93,97 **** public TLongHash(int initialCapacity, TLongHashingStrategy strategy) { super(initialCapacity); ! this.hashingStrategy = strategy; } --- 93,97 ---- public TLongHash(int initialCapacity, TLongHashingStrategy strategy) { super(initialCapacity); ! this._hashingStrategy = strategy; } *************** *** 107,111 **** public TLongHash(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this.hashingStrategy = strategy; } --- 107,111 ---- public TLongHash(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this._hashingStrategy = strategy; } *************** *** 186,190 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 186,190 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 222,226 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; --- 222,226 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; Index: TLongHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongHashSet.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TLongHashSet.java 22 Sep 2002 21:53:42 -0000 1.10 --- TLongHashSet.java 19 Mar 2003 04:17:04 -0000 1.11 *************** *** 230,233 **** --- 230,252 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TLongProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(long key) { + h += _hashingStrategy.computeHashCode(key); + return true; + } + } + /** * Removes <tt>val</tt> from the set. Index: TLongIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongIntHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TLongIntHashMap.java 22 Sep 2002 21:53:42 -0000 1.13 --- TLongIntHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TLongIntProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(long key, int value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TLongIntProcedure { private final TLongIntHashMap _otherMap; Index: TLongLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongLongHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TLongLongHashMap.java 22 Sep 2002 21:53:42 -0000 1.13 --- TLongLongHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TLongLongProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(long key, long value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TLongLongProcedure { private final TLongLongHashMap _otherMap; Index: TLongObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongObjectHashMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TLongObjectHashMap.java 22 Sep 2002 21:53:42 -0000 1.13 --- TLongObjectHashMap.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 250,253 **** --- 250,272 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TLongObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(long key, Object value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements TLongObjectProcedure { private final TLongObjectHashMap _otherMap; Index: TObjectHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TObjectHash.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TObjectHash.java 20 Sep 2002 20:55:58 -0000 1.13 --- TObjectHash.java 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 38,42 **** /** the strategy used to hash objects in this collection. */ ! private TObjectHashingStrategy hashingStrategy; protected static final Object REMOVED = new Object(); --- 38,42 ---- /** the strategy used to hash objects in this collection. */ ! protected TObjectHashingStrategy _hashingStrategy; protected static final Object REMOVED = new Object(); *************** *** 48,52 **** public TObjectHash() { super(); ! this.hashingStrategy = this; } --- 48,52 ---- public TObjectHash() { super(); ! this._hashingStrategy = this; } *************** *** 59,63 **** public TObjectHash(TObjectHashingStrategy strategy) { super(); ! this.hashingStrategy = strategy; } --- 59,63 ---- public TObjectHash(TObjectHashingStrategy strategy) { super(); ! this._hashingStrategy = strategy; } *************** *** 71,75 **** public TObjectHash(int initialCapacity) { super(initialCapacity); ! this.hashingStrategy = this; } --- 71,75 ---- public TObjectHash(int initialCapacity) { super(initialCapacity); ! this._hashingStrategy = this; } *************** *** 85,89 **** public TObjectHash(int initialCapacity, TObjectHashingStrategy strategy) { super(initialCapacity); ! this.hashingStrategy = strategy; } --- 85,89 ---- public TObjectHash(int initialCapacity, TObjectHashingStrategy strategy) { super(initialCapacity); ! this._hashingStrategy = strategy; } *************** *** 98,102 **** public TObjectHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this.hashingStrategy = this; } --- 98,102 ---- public TObjectHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this._hashingStrategy = this; } *************** *** 113,117 **** public TObjectHash(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this.hashingStrategy = strategy; } --- 113,117 ---- public TObjectHash(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { super(initialCapacity, loadFactor); ! this._hashingStrategy = strategy; } *************** *** 190,199 **** set = _set; length = set.length; ! hash = hashingStrategy.computeHashCode(obj) & 0x7fffffff; index = hash % length; cur = set[index]; if (cur != null ! && (cur == REMOVED || ! hashingStrategy.equals(cur, obj))) { // see Knuth, p. 529 probe = 1 + (hash % (length - 2)); --- 190,199 ---- set = _set; length = set.length; ! hash = _hashingStrategy.computeHashCode(obj) & 0x7fffffff; index = hash % length; cur = set[index]; if (cur != null ! && (cur == REMOVED || ! _hashingStrategy.equals(cur, obj))) { // see Knuth, p. 529 probe = 1 + (hash % (length - 2)); *************** *** 206,210 **** cur = set[index]; } while (cur != null ! && (cur == REMOVED || ! hashingStrategy.equals(cur, obj))); } --- 206,210 ---- cur = set[index]; } while (cur != null ! && (cur == REMOVED || ! _hashingStrategy.equals(cur, obj))); } *************** *** 229,233 **** set = _set; length = set.length; ! hash = hashingStrategy.computeHashCode(obj) & 0x7fffffff; index = hash % length; cur = set[index]; --- 229,233 ---- set = _set; length = set.length; ! hash = _hashingStrategy.computeHashCode(obj) & 0x7fffffff; index = hash % length; cur = set[index]; *************** *** 235,239 **** if (cur == null) { return index; // empty, all done ! } else if (hashingStrategy.equals(cur, obj)) { return -index -1; // already stored } else { // already FULL or REMOVED, must probe --- 235,239 ---- if (cur == null) { return index; // empty, all done ! } else if (_hashingStrategy.equals(cur, obj)) { return -index -1; // already stored } else { // already FULL or REMOVED, must probe *************** *** 250,254 **** } while (cur != null && cur != REMOVED ! && ! hashingStrategy.equals(cur, obj)); // if the index we found was removed: continue probing until we --- 250,254 ---- } while (cur != null && cur != REMOVED ! && ! _hashingStrategy.equals(cur, obj)); // if the index we found was removed: continue probing until we *************** *** 258,262 **** int firstRemoved = index; while (cur != null ! && (cur == REMOVED || ! hashingStrategy.equals(cur, obj))) { index -= probe; if (index < 0) { --- 258,262 ---- int firstRemoved = index; while (cur != null ! && (cur == REMOVED || ! _hashingStrategy.equals(cur, obj))) { index -= probe; if (index < 0) { Index: gen_primitive_base.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/gen_primitive_base.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** gen_primitive_base.pl 20 Sep 2002 20:55:58 -0000 1.10 --- gen_primitive_base.pl 19 Mar 2003 04:17:04 -0000 1.11 *************** *** 59,63 **** /** strategy used to hash values in this collection */ ! private T<Type>HashingStrategy hashingStrategy; /** --- 59,63 ---- /** strategy used to hash values in this collection */ ! protected T<Type>HashingStrategy _hashingStrategy; /** *************** *** 67,71 **** public T<Type>Hash() { super(); ! this.hashingStrategy = this; } --- 67,71 ---- public T<Type>Hash() { super(); ! this._hashingStrategy = this; } *************** *** 79,83 **** public T<Type>Hash(int initialCapacity) { super(initialCapacity); ! this.hashingStrategy = this; } --- 79,83 ---- public T<Type>Hash(int initialCapacity) { super(initialCapacity); ! this._hashingStrategy = this; } *************** *** 92,96 **** public T<Type>Hash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this.hashingStrategy = this; } --- 92,96 ---- public T<Type>Hash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); ! this._hashingStrategy = this; } *************** *** 102,106 **** public T<Type>Hash(T<Type>HashingStrategy strategy) { super(); ! this.hashingStrategy = strategy; } --- 102,106 ---- public T<Type>Hash(T<Type>HashingStrategy strategy) { super(); ! this._hashingStrategy = strategy; } *************** *** 115,119 **** public T<Type>Hash(int initialCapacity, T<Type>HashingStrategy strategy) { super(initialCapacity); ! this.hashingStrategy = strategy; } --- 115,119 ---- public T<Type>Hash(int initialCapacity, T<Type>HashingStrategy strategy) { super(initialCapacity); ! this._hashingStrategy = strategy; } *************** *** 129,133 **** public T<Type>Hash(int initialCapacity, float loadFactor, T<Type>HashingStrategy strategy) { super(initialCapacity, loadFactor); ! this.hashingStrategy = strategy; } --- 129,133 ---- public T<Type>Hash(int initialCapacity, float loadFactor, T<Type>HashingStrategy strategy) { super(initialCapacity, loadFactor); ! this._hashingStrategy = strategy; } *************** *** 208,212 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(<instance>) & 0x7fffffff; index = hash % length; --- 208,212 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(<instance>) & 0x7fffffff; index = hash % length; *************** *** 244,248 **** set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(<instance>) & 0x7fffffff; index = hash % length; --- 244,248 ---- set = _set; length = states.length; ! hash = _hashingStrategy.computeHashCode(<instance>) & 0x7fffffff; index = hash % length; Index: gen_primitive_map.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/gen_primitive_map.pl,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** gen_primitive_map.pl 22 Sep 2002 21:53:42 -0000 1.13 --- gen_primitive_map.pl 19 Mar 2003 04:17:04 -0000 1.14 *************** *** 398,401 **** --- 398,420 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + private final class HashProcedure implements T<KeyType><ValueType>Procedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(<keyType> key, <valueType> value) { + h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); + return true; + } + } + private static final class EqProcedure implements T<KeyType><ValueType>Procedure { private final T<KeyType><ValueType>HashMap _otherMap; Index: gen_primitive_set.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/gen_primitive_set.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** gen_primitive_set.pl 22 Sep 2002 21:53:42 -0000 1.10 --- gen_primitive_set.pl 19 Mar 2003 04:17:04 -0000 1.11 *************** *** 251,254 **** --- 251,273 ---- } + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements T<Type>Procedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + public final boolean execute(<type> key) { + h += _hashingStrategy.computeHashCode(key); + return true; + } + } + /** * Removes <tt><instance></tt> from the set. |
From: Eric F. <er...@us...> - 2003-01-10 14:34:59
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory sc8-pr-cvs1:/tmp/cvs-serv11221 Modified Files: TDoubleArrayList.java TIntArrayList.java TLongArrayList.java TFloatArrayList.java gen_primitive_list.pl Log Message: modified fill method so that arrays capacities expand and _pos is shifted if the toIndex of the fill goes beyond the current size of the array Index: TDoubleArrayList.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleArrayList.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleArrayList.java 22 Sep 2002 21:53:39 -0000 1.10 --- TDoubleArrayList.java 10 Jan 2003 14:34:54 -0000 1.11 *************** *** 625,628 **** --- 625,632 ---- */ public void fill(int fromIndex, int toIndex, double val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } Arrays.fill(_data, fromIndex, toIndex, val); } Index: TIntArrayList.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntArrayList.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TIntArrayList.java 8 Jul 2002 00:51:20 -0000 1.8 --- TIntArrayList.java 10 Jan 2003 14:34:54 -0000 1.9 *************** *** 629,632 **** --- 629,636 ---- */ public void fill(int fromIndex, int toIndex, int val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } Arrays.fill(_data, fromIndex, toIndex, val); } Index: TLongArrayList.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongArrayList.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TLongArrayList.java 22 Sep 2002 21:53:42 -0000 1.10 --- TLongArrayList.java 10 Jan 2003 14:34:54 -0000 1.11 *************** *** 625,628 **** --- 625,632 ---- */ public void fill(int fromIndex, int toIndex, long val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } Arrays.fill(_data, fromIndex, toIndex, val); } Index: TFloatArrayList.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatArrayList.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatArrayList.java 22 Sep 2002 21:53:40 -0000 1.10 --- TFloatArrayList.java 10 Jan 2003 14:34:54 -0000 1.11 *************** *** 625,628 **** --- 625,632 ---- */ public void fill(int fromIndex, int toIndex, float val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } Arrays.fill(_data, fromIndex, toIndex, val); } Index: gen_primitive_list.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/gen_primitive_list.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** gen_primitive_list.pl 1 Jan 2002 18:51:23 -0000 1.6 --- gen_primitive_list.pl 10 Jan 2003 14:34:55 -0000 1.7 *************** *** 646,649 **** --- 646,653 ---- */ public void fill(int fromIndex, int toIndex, <type> val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } Arrays.fill(_data, fromIndex, toIndex, val); } |
From: Eric F. <er...@us...> - 2002-09-27 15:50:59
|
Update of /cvsroot/trove4j/trove In directory usw-pr-cvs1:/tmp/cvs-serv23595 Modified Files: build.xml Log Message: added version info to jar manifest Index: build.xml =================================================================== RCS file: /cvsroot/trove4j/trove/build.xml,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** build.xml 25 Sep 2002 05:20:29 -0000 1.23 --- build.xml 27 Sep 2002 15:50:56 -0000 1.24 *************** *** 8,12 **** <target name="init"> <tstamp/> ! <property name="Name" value="Trove for Java"/> <property name="name" value="trove"/> <property name="version" value="0.1.8"/> --- 8,12 ---- <target name="init"> <tstamp/> ! <property name="Name" value="GNU Trove for Java"/> <property name="name" value="trove"/> <property name="version" value="0.1.8"/> *************** *** 76,80 **** <jar jarfile="${output.lib}/${name}.jar" excludes="**/benchmark/" ! basedir="${output.dest}" /> </target> --- 76,88 ---- <jar jarfile="${output.lib}/${name}.jar" excludes="**/benchmark/" ! basedir="${output.dest}"> ! <manifest> ! <attribute name="Built-By" value="${user.name}"/> ! <attribute name="Implementation-Title" value="${Name}"/> ! <attribute name="Implementation-Version" value="${version}"/> ! <attribute name="Implementation-URL" value="http://trove4j.sourceforge.net/"/> ! <attribute name="Sealed" value="false"/> ! </manifest> ! </jar> </target> |
From: Eric F. <er...@us...> - 2002-09-25 05:43:07
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv16922 Modified Files: THash.java Log Message: html fix Index: THash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THash.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** THash.java 20 Sep 2002 20:55:57 -0000 1.5 --- THash.java 25 Sep 2002 05:43:04 -0000 1.6 *************** *** 81,85 **** /** * Creates a new <code>THash</code> instance with a prime capacity ! * at or near the minimum needed to hold <tt>initialCapacity<tt> * elements with load factor <tt>loadFactor</tt> without triggering * a rehash. --- 81,85 ---- /** * Creates a new <code>THash</code> instance with a prime capacity ! * at or near the minimum needed to hold <tt>initialCapacity</tt> * elements with load factor <tt>loadFactor</tt> without triggering * a rehash. |
From: Eric F. <er...@us...> - 2002-09-25 05:20:33
|
Update of /cvsroot/trove4j/trove In directory usw-pr-cvs1:/tmp/cvs-serv12181 Modified Files: ChangeLog build.xml Log Message: 0.1.8 release Index: ChangeLog =================================================================== RCS file: /cvsroot/trove4j/trove/ChangeLog,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ChangeLog 22 Sep 2002 21:53:39 -0000 1.18 --- ChangeLog 25 Sep 2002 05:20:29 -0000 1.19 *************** *** 1,2 **** --- 1,8 ---- + v 0.1.8 + + Added gnu.trove.decorator package, with Decorator classes that wrap trove's + primitive maps and sets for conformance with the java.util.{Map,Set} + APIs. + v 0.1.7 Index: build.xml =================================================================== RCS file: /cvsroot/trove4j/trove/build.xml,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** build.xml 22 Sep 2002 21:53:39 -0000 1.22 --- build.xml 25 Sep 2002 05:20:29 -0000 1.23 *************** *** 10,14 **** <property name="Name" value="Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="0.1.7"/> <property name="year" value="2001-2002"/> --- 10,14 ---- <property name="Name" value="Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="0.1.8"/> <property name="year" value="2001-2002"/> |
Update of /cvsroot/trove4j/trove/src/gnu/trove/decorator In directory usw-pr-cvs1:/tmp/cvs-serv9990 Modified Files: TDoubleHashSetDecorator.java TFloatHashSetDecorator.java TIntHashSetDecorator.java TLongHashSetDecorator.java gen_set_decorators.pl Log Message: documentation tweak Index: TDoubleHashSetDecorator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/decorator/TDoubleHashSetDecorator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TDoubleHashSetDecorator.java 25 Sep 2002 05:10:08 -0000 1.1 --- TDoubleHashSetDecorator.java 25 Sep 2002 05:14:38 -0000 1.2 *************** *** 21,25 **** import gnu.trove.TDoubleHashSet; import gnu.trove.TDoubleIterator; - import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; --- 21,24 ---- *************** *** 45,49 **** */ public class TDoubleHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive map */ protected final TDoubleHashSet _set; --- 44,48 ---- */ public class TDoubleHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive set */ protected final TDoubleHashSet _set; Index: TFloatHashSetDecorator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/decorator/TFloatHashSetDecorator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TFloatHashSetDecorator.java 25 Sep 2002 05:10:08 -0000 1.1 --- TFloatHashSetDecorator.java 25 Sep 2002 05:14:38 -0000 1.2 *************** *** 21,25 **** import gnu.trove.TFloatHashSet; import gnu.trove.TFloatIterator; - import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; --- 21,24 ---- *************** *** 45,49 **** */ public class TFloatHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive map */ protected final TFloatHashSet _set; --- 44,48 ---- */ public class TFloatHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive set */ protected final TFloatHashSet _set; Index: TIntHashSetDecorator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/decorator/TIntHashSetDecorator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TIntHashSetDecorator.java 25 Sep 2002 05:10:08 -0000 1.1 --- TIntHashSetDecorator.java 25 Sep 2002 05:14:38 -0000 1.2 *************** *** 21,25 **** import gnu.trove.TIntHashSet; import gnu.trove.TIntIterator; - import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; --- 21,24 ---- *************** *** 45,49 **** */ public class TIntHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive map */ protected final TIntHashSet _set; --- 44,48 ---- */ public class TIntHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive set */ protected final TIntHashSet _set; Index: TLongHashSetDecorator.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/decorator/TLongHashSetDecorator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TLongHashSetDecorator.java 25 Sep 2002 05:10:09 -0000 1.1 --- TLongHashSetDecorator.java 25 Sep 2002 05:14:38 -0000 1.2 *************** *** 21,25 **** import gnu.trove.TLongHashSet; import gnu.trove.TLongIterator; - import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; --- 21,24 ---- *************** *** 45,49 **** */ public class TLongHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive map */ protected final TLongHashSet _set; --- 44,48 ---- */ public class TLongHashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive set */ protected final TLongHashSet _set; Index: gen_set_decorators.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/decorator/gen_set_decorators.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gen_set_decorators.pl 25 Sep 2002 05:10:09 -0000 1.1 --- gen_set_decorators.pl 25 Sep 2002 05:14:38 -0000 1.2 *************** *** 50,54 **** import gnu.trove.T<Type>HashSet; import gnu.trove.T<Type>Iterator; - import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; --- 50,53 ---- *************** *** 74,78 **** */ public class T<Type>HashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive map */ protected final T<Type>HashSet _set; --- 73,77 ---- */ public class T<Type>HashSetDecorator extends AbstractSet implements Set { ! /** the wrapped primitive set */ protected final T<Type>HashSet _set; |
From: Eric F. <er...@us...> - 2002-09-25 05:11:51
|
Update of /cvsroot/trove4j/trove/src/gnu/trove/decorator In directory usw-pr-cvs1:/tmp/cvs-serv8974 Modified Files: package.html Log Message: doc tweaks Index: package.html =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/decorator/package.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** package.html 25 Sep 2002 05:10:09 -0000 1.1 --- package.html 25 Sep 2002 05:11:48 -0000 1.2 *************** *** 6,10 **** <body> ! <p>GNU Trove: Decorators</p> <p>The classes in this package serve to wrap the Trove primitive --- 6,10 ---- <body> ! <p>GNU Trove: Decorators for java.util.{Map,Set} compatability</p> <p>The classes in this package serve to wrap the Trove primitive |
Update of /cvsroot/trove4j/trove/src/gnu/trove/decorator In directory usw-pr-cvs1:/tmp/cvs-serv8551 Added Files: TDoubleDoubleHashMapDecorator.java TDoubleFloatHashMapDecorator.java TDoubleHashSetDecorator.java TDoubleIntHashMapDecorator.java TDoubleLongHashMapDecorator.java TDoubleObjectHashMapDecorator.java TFloatDoubleHashMapDecorator.java TFloatFloatHashMapDecorator.java TFloatHashSetDecorator.java TFloatIntHashMapDecorator.java TFloatLongHashMapDecorator.java TFloatObjectHashMapDecorator.java TIntDoubleHashMapDecorator.java TIntFloatHashMapDecorator.java TIntHashSetDecorator.java TIntHashSetDecoratorTests.java TIntIntHashMapDecorator.java TIntIntHashMapDecoratorTests.java TIntLongHashMapDecorator.java TIntObjectHashMapDecorator.java TLongDoubleHashMapDecorator.java TLongFloatHashMapDecorator.java TLongHashSetDecorator.java TLongIntHashMapDecorator.java TLongLongHashMapDecorator.java TLongObjectHashMapDecorator.java TObjectDoubleHashMapDecorator.java TObjectFloatHashMapDecorator.java TObjectIntHashMapDecorator.java TObjectLongHashMapDecorator.java gen_map_decorators.pl gen_set_decorators.pl package.html Log Message: new decorator classes, tests, documentation --- NEW FILE: TDoubleDoubleHashMapDecorator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove.decorator; import gnu.trove.TDoubleDoubleHashMap; import gnu.trove.TDoubleDoubleIterator; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; /** * Wrapper class to make a TDoubleDoubleHashMap conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying TDoubleDoubleHashMap 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 * @version $Id: TDoubleDoubleHashMapDecorator.java,v 1.1 2002/09/25 05:10:08 ericdf Exp $ * @since trove 0.1.8 */ public class TDoubleDoubleHashMapDecorator extends AbstractMap implements Map { /** the wrapped primitive map */ protected final TDoubleDoubleHashMap _map; /** * Creates a wrapper that decorates the specified primitive map. */ public TDoubleDoubleHashMapDecorator(TDoubleDoubleHashMap map) { super(); this._map = 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 Integer(0) if none was found. */ public Object put(Object key, Object value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return true if the maps are identical */ public boolean equals(Object other) { if (_map.equals(other)) { return true; // comparing two trove maps } else if (other instanceof Map) { Map that = (Map)other; if (that.size() != _map.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Iterator it = that.entrySet().iterator(); for (int i = that.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); Object key = e.getKey(); Object val = e.getValue(); if (key instanceof Integer && val instanceof Integer) { double k = unwrapKey(key); double v = unwrapValue(val); if (_map.containsKey(k) && v == _map.get(k)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other map } } return true; // all entries match } } else { return false; } } /** * 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 Object get(Object key) { double k = unwrapKey(key); double v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public Object remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set entrySet() { return new AbstractSet() { public int size() { return _map.size(); } public boolean isEmpty() { return TDoubleDoubleHashMapDecorator.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 (TDoubleDoubleHashMapDecorator.this.containsKey(k) && TDoubleDoubleHashMapDecorator.this.get(k).equals(v)); } else { return false; } } public Iterator iterator() { return new Iterator() { private final TDoubleDoubleIterator it = _map.iterator(); public Object next() { it.advance(); final Object key = wrapKey(it.key()); final Object v = wrapValue(it.value()); return new Map.Entry() { private Object 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 Object getKey() { return key; } public Object getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public Object setValue(Object value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(Object o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { TDoubleDoubleHashMapDecorator.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(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(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 map) { Iterator it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param a key in the underlying map * @return an Object representation of the key */ protected Double wrapKey(double k) { return new Double(k); } /** * Unwraps a key * * @param a wrapped key * @return an unwrapped representation of the key */ protected double unwrapKey(Object key) { return ((Double)key).doubleValue(); } /** * Wraps a value * * @param a value in the underlying map * @return an Object representation of the value */ protected Double wrapValue(double k) { return new Double(k); } /** * Unwraps a value * * @param a wrapped value * @return an unwrapped representation of the value */ protected double unwrapValue(Object value) { return ((Double)value).doubleValue(); } } // TDoubleDoubleHashMapDecorator --- NEW FILE: TDoubleFloatHashMapDecorator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove.decorator; import gnu.trove.TDoubleFloatHashMap; import gnu.trove.TDoubleFloatIterator; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; /** * Wrapper class to make a TDoubleFloatHashMap conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying TDoubleFloatHashMap 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 * @version $Id: TDoubleFloatHashMapDecorator.java,v 1.1 2002/09/25 05:10:08 ericdf Exp $ * @since trove 0.1.8 */ public class TDoubleFloatHashMapDecorator extends AbstractMap implements Map { /** the wrapped primitive map */ protected final TDoubleFloatHashMap _map; /** * Creates a wrapper that decorates the specified primitive map. */ public TDoubleFloatHashMapDecorator(TDoubleFloatHashMap map) { super(); this._map = 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 Integer(0) if none was found. */ public Object put(Object key, Object value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return true if the maps are identical */ public boolean equals(Object other) { if (_map.equals(other)) { return true; // comparing two trove maps } else if (other instanceof Map) { Map that = (Map)other; if (that.size() != _map.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Iterator it = that.entrySet().iterator(); for (int i = that.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); Object key = e.getKey(); Object val = e.getValue(); if (key instanceof Integer && val instanceof Integer) { double k = unwrapKey(key); float v = unwrapValue(val); if (_map.containsKey(k) && v == _map.get(k)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other map } } return true; // all entries match } } else { return false; } } /** * 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 Object get(Object key) { double k = unwrapKey(key); float v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public Object remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set entrySet() { return new AbstractSet() { public int size() { return _map.size(); } public boolean isEmpty() { return TDoubleFloatHashMapDecorator.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 (TDoubleFloatHashMapDecorator.this.containsKey(k) && TDoubleFloatHashMapDecorator.this.get(k).equals(v)); } else { return false; } } public Iterator iterator() { return new Iterator() { private final TDoubleFloatIterator it = _map.iterator(); public Object next() { it.advance(); final Object key = wrapKey(it.key()); final Object v = wrapValue(it.value()); return new Map.Entry() { private Object 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 Object getKey() { return key; } public Object getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public Object setValue(Object value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(Object o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { TDoubleFloatHashMapDecorator.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(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(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 map) { Iterator it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param a key in the underlying map * @return an Object representation of the key */ protected Double wrapKey(double k) { return new Double(k); } /** * Unwraps a key * * @param a wrapped key * @return an unwrapped representation of the key */ protected double unwrapKey(Object key) { return ((Double)key).doubleValue(); } /** * Wraps a value * * @param a value in the underlying map * @return an Object representation of the value */ protected Float wrapValue(float k) { return new Float(k); } /** * Unwraps a value * * @param a wrapped value * @return an unwrapped representation of the value */ protected float unwrapValue(Object value) { return ((Float)value).floatValue(); } } // TDoubleFloatHashMapDecorator --- NEW FILE: TDoubleHashSetDecorator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove.decorator; import gnu.trove.TDoubleHashSet; import gnu.trove.TDoubleIterator; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Set; /** * Wrapper class to make a TDoubleHashSet conform to the <tt>java.util.Set</tt> API. * This class simply decorates an underlying TDoubleHashSet 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: Tue Sep 24 22:08:17 PDT 2002 * * @author Eric D. Friedman * @version $Id: TDoubleHashSetDecorator.java,v 1.1 2002/09/25 05:10:08 ericdf Exp $ * @since trove 0.1.8 */ public class TDoubleHashSetDecorator extends AbstractSet implements Set { /** the wrapped primitive map */ protected final TDoubleHashSet _set; /** * Creates a wrapper that decorates the specified primitive set. */ public TDoubleHashSetDecorator(TDoubleHashSet set) { super(); this._set = set; } /** * Inserts a value into the set. * * @param true if the set was modified by the insertion */ public boolean add(Object value) { return _set.add(unwrap(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 Double) { double v = unwrap(val); if (_set.contains(v)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other set } } return true; // all entries match } } else { return false; } } /** * Empties the set. */ public void clear() { this._set.clear(); } /** * Deletes a value from the set. * * @param value an <code>Object</code> value * @return true if the set was modified */ public boolean remove(Object value) { return _set.remove(unwrap(value)); } /** * Creates an iterator over the values of the set. * * @return an iterator with support for removals in the underlying set */ public Iterator iterator() { return new Iterator() { private final TDoubleIterator it = _set.iterator(); public Object next() { return wrap(it.next()); } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } /** * Returns the number of entries in the set. * @return the set's size. */ public int size() { return this._set.size(); } /** * Indicates whether set has any entries. * @return true if the set is empty */ public boolean isEmpty() { return (size() == 0); } /** * Wraps a value * * @param a value in the underlying set * @return an Object representation of the value */ protected Double wrap(double k) { return new Double(k); } /** * Unwraps a value * * @param a wrapped value * @return an unwrapped representation of the value */ protected double unwrap(Object value) { return ((Double)value).doubleValue(); } } // TDoubleHashSetDecorator --- NEW FILE: TDoubleIntHashMapDecorator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove.decorator; import gnu.trove.TDoubleIntHashMap; import gnu.trove.TDoubleIntIterator; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; /** * Wrapper class to make a TDoubleIntHashMap conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying TDoubleIntHashMap 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 * @version $Id: TDoubleIntHashMapDecorator.java,v 1.1 2002/09/25 05:10:08 ericdf Exp $ * @since trove 0.1.8 */ public class TDoubleIntHashMapDecorator extends AbstractMap implements Map { /** the wrapped primitive map */ protected final TDoubleIntHashMap _map; /** * Creates a wrapper that decorates the specified primitive map. */ public TDoubleIntHashMapDecorator(TDoubleIntHashMap map) { super(); this._map = 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 Integer(0) if none was found. */ public Object put(Object key, Object value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return true if the maps are identical */ public boolean equals(Object other) { if (_map.equals(other)) { return true; // comparing two trove maps } else if (other instanceof Map) { Map that = (Map)other; if (that.size() != _map.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Iterator it = that.entrySet().iterator(); for (int i = that.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); Object key = e.getKey(); Object val = e.getValue(); if (key instanceof Integer && val instanceof Integer) { double k = unwrapKey(key); int v = unwrapValue(val); if (_map.containsKey(k) && v == _map.get(k)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other map } } return true; // all entries match } } else { return false; } } /** * 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 Object get(Object key) { double k = unwrapKey(key); int v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public Object remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set entrySet() { return new AbstractSet() { public int size() { return _map.size(); } public boolean isEmpty() { return TDoubleIntHashMapDecorator.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 (TDoubleIntHashMapDecorator.this.containsKey(k) && TDoubleIntHashMapDecorator.this.get(k).equals(v)); } else { return false; } } public Iterator iterator() { return new Iterator() { private final TDoubleIntIterator it = _map.iterator(); public Object next() { it.advance(); final Object key = wrapKey(it.key()); final Object v = wrapValue(it.value()); return new Map.Entry() { private Object 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 Object getKey() { return key; } public Object getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public Object setValue(Object value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(Object o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { TDoubleIntHashMapDecorator.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(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(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 map) { Iterator it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param a key in the underlying map * @return an Object representation of the key */ protected Double wrapKey(double k) { return new Double(k); } /** * Unwraps a key * * @param a wrapped key * @return an unwrapped representation of the key */ protected double unwrapKey(Object key) { return ((Double)key).doubleValue(); } /** * Wraps a value * * @param a value in the underlying map * @return an Object representation of the value */ protected Integer wrapValue(int k) { return new Integer(k); } /** * Unwraps a value * * @param a wrapped value * @return an unwrapped representation of the value */ protected int unwrapValue(Object value) { return ((Integer)value).intValue(); } } // TDoubleIntHashMapDecorator --- NEW FILE: TDoubleLongHashMapDecorator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove.decorator; import gnu.trove.TDoubleLongHashMap; import gnu.trove.TDoubleLongIterator; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; /** * Wrapper class to make a TDoubleLongHashMap conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying TDoubleLongHashMap 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 * @version $Id: TDoubleLongHashMapDecorator.java,v 1.1 2002/09/25 05:10:08 ericdf Exp $ * @since trove 0.1.8 */ public class TDoubleLongHashMapDecorator extends AbstractMap implements Map { /** the wrapped primitive map */ protected final TDoubleLongHashMap _map; /** * Creates a wrapper that decorates the specified primitive map. */ public TDoubleLongHashMapDecorator(TDoubleLongHashMap map) { super(); this._map = 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 Integer(0) if none was found. */ public Object put(Object key, Object value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return true if the maps are identical */ public boolean equals(Object other) { if (_map.equals(other)) { return true; // comparing two trove maps } else if (other instanceof Map) { Map that = (Map)other; if (that.size() != _map.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Iterator it = that.entrySet().iterator(); for (int i = that.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); Object key = e.getKey(); Object val = e.getValue(); if (key instanceof Integer && val instanceof Integer) { double k = unwrapKey(key); long v = unwrapValue(val); if (_map.containsKey(k) && v == _map.get(k)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other map } } return true; // all entries match } } else { return false; } } /** * 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 Object get(Object key) { double k = unwrapKey(key); long v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public Object remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set entrySet() { return new AbstractSet() { public int size() { return _map.size(); } public boolean isEmpty() { return TDoubleLongHashMapDecorator.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 (TDoubleLongHashMapDecorator.this.containsKey(k) && TDoubleLongHashMapDecorator.this.get(k).equals(v)); } else { return false; } } public Iterator iterator() { return new Iterator() { private final TDoubleLongIterator it = _map.iterator(); public Object next() { it.advance(); final Object key = wrapKey(it.key()); final Object v = wrapValue(it.value()); return new Map.Entry() { private Object 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 Object getKey() { return key; } public Object getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public Object setValue(Object value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(Object o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { TDoubleLongHashMapDecorator.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(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(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 map) { Iterator it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param a key in the underlying map * @return an Object representation of the key */ protected Double wrapKey(double k) { return new Double(k); } /** * Unwraps a key * * @param a wrapped key * @return an unwrapped representation of the key */ protected double unwrapKey(Object key) { return ((Double)key).doubleValue(); } /** * Wraps a value * * @param a value in the underlying map * @return an Object representation of the value */ protected Long wrapValue(long k) { return new Long(k); } /** * Unwraps a value * * @param a wrapped value * @return an unwrapped representation of the value */ protected long unwrapValue(Object value) { return ((Long)value).longValue(); } } // TDoubleLongHashMapDecorator --- NEW FILE: TDoubleObjectHashMapDecorator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove.decorator; import gnu.trove.TDoubleObjectHashMap; import gnu.trove.TDoubleObjectIterator; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; /** * Wrapper class to make a TDoubleObjectHashMap conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying TDoubleObjectHashMap 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 * @version $Id: TDoubleObjectHashMapDecorator.java,v 1.1 2002/09/25 05:10:08 ericdf Exp $ * @since trove 0.1.8 */ public class TDoubleObjectHashMapDecorator extends AbstractMap implements Map { /** the wrapped primitive map */ protected final TDoubleObjectHashMap _map; /** * Creates a wrapper that decorates the specified primitive map. */ public TDoubleObjectHashMapDecorator(TDoubleObjectHashMap map) { super(); this._map = 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 Integer(0) if none was found. */ public Object put(Object key, Object value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return true if the maps are identical */ public boolean equals(Object other) { if (_map.equals(other)) { return true; // comparing two trove maps } else if (other instanceof Map) { Map that = (Map)other; if (that.size() != _map.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Iterator it = that.entrySet().iterator(); for (int i = that.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); Object key = e.getKey(); Object val = e.getValue(); if (key instanceof Integer && val instanceof Integer) { double k = unwrapKey(key); Object v = unwrapValue(val); if (_map.containsKey(k) && v == _map.get(k)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other map } } return true; // all entries match } } else { return false; } } /** * 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 Object get(Object key) { return _map.get(unwrapKey(key)); } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public Object remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set entrySet() { return new AbstractSet() { public int size() { return _map.size(); } public boolean isEmpty() { return TDoubleObjectHashMapDecorator.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 (TDoubleObjectHashMapDecorator.this.containsKey(k) && TDoubleObjectHashMapDecorator.this.get(k).equals(v)); } else { return false; } } public Iterator iterator() { return new Iterator() { private final TDoubleObjectIterator it = _map.iterator(); public Object next() { it.advance(); final Object key = wrapKey(it.key()); final Object v = wrapValue(it.value()); return new Map.Entry() { private Object 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 Object getKey() { return key; } public Object getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public Object setValue(Object value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(Object o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { TDoubleObjectHashMapDecorator.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(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(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 map) { Iterator it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param a key in the underlying map * @return an Object representation of the key */ protected Double wrapKey(double k) { return new Double(k); } /** * Unwraps a key * * @param a wrapped key * @return an unwrapped representation of the key */ protected double unwrapKey(Object key) { return ((Double)key).doubleValue(); } /** * Wraps a value * * @param a value in the underlying map * @return an Object representation of the value */ protected final Object wrapValue(Object o) { return o; } /** * Unwraps a value * * @param a wrapped value * @return an unwrapped representation of the value */ protected final Object unwrapValue(Object value) { return value; } } // TDoubleObjectHashMapDecorator --- NEW FILE: TFloatDoubleHashMapDecorator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove.decorator; import gnu.trove.TFloatDoubleHashMap; import gnu.trove.TFloatDoubleIterator; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.Map; import java.util.Set; /** * Wrapper class to make a TFloatDoubleHashMap conform to the <tt>java.util.Map</tt> API. * This class simply decorates an underlying TFloatDoubleHashMap 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 * @version $Id: TFloatDoubleHashMapDecorator.java,v 1.1 2002/09/25 05:10:08 ericdf Exp $ * @since trove 0.1.8 */ public class TFloatDoubleHashMapDecorator extends AbstractMap implements Map { /** the wrapped primitive map */ protected final TFloatDoubleHashMap _map; /** * Creates a wrapper that decorates the specified primitive map. */ public TFloatDoubleHashMapDecorator(TFloatDoubleHashMap map) { super(); this._map = 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 Integer(0) if none was found. */ public Object put(Object key, Object value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); } /** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return true if the maps are identical */ public boolean equals(Object other) { if (_map.equals(other)) { return true; // comparing two trove maps } else if (other instanceof Map) { Map that = (Map)other; if (that.size() != _map.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Iterator it = that.entrySet().iterator(); for (int i = that.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); Object key = e.getKey(); Object val = e.getValue(); if (key instanceof Integer && val instanceof Integer) { float k = unwrapKey(key); double v = unwrapValue(val); if (_map.containsKey(k) && v == _map.get(k)) { // match, ok to continue } else { return false; // no match: we're done } } else { return false; // different type in other map } } return true; // all entries match } } else { return false; } } /** * 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 Object get(Object key) { float k = unwrapKey(key); double v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } } /** * Empties the map. */ public void clear() { this._map.clear(); } /** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return the removed value, or Integer(0) if it was not found in the map */ public Object remove(Object key) { return wrapValue(_map.remove(unwrapKey(key))); } /** * Returns a Set view on the entries of the map. * * @return a <code>Set</code> value */ public Set entrySet() { return new AbstractSet() { public int size() { return _map.size(); } public boolean isEmpty() { return TFloatDoubleHashMapDecorator.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 (TFloatDoubleHashMapDecorator.this.containsKey(k) && TFloatDoubleHashMapDecorator.this.get(k).equals(v)); } else { return false; } } public Iterator iterator() { return new Iterator() { private final TFloatDoubleIterator it = _map.iterator(); public Object next() { it.advance(); final Object key = wrapKey(it.key()); final Object v = wrapValue(it.value()); return new Map.Entry() { private Object 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 Object getKey() { return key; } public Object getValue() { return val; } public int hashCode() { return key.hashCode() + val.hashCode(); } public Object setValue(Object value) { val = value; return put(key, value); } }; } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; } public boolean add(Object o) { throw new UnsupportedOperationException(); } public boolean remove(Object o) { throw new UnsupportedOperationException(); } public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } public void clear() { TFloatDoubleHashMapDecorator.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(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(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 map) { Iterator it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0;) { Map.Entry e = (Map.Entry)it.next(); this.put(e.getKey(), e.getValue()); } } /** * Wraps a key * * @param a key in the underlying map * @return an Object representation of the key */ protected Float wrapKey(float k) { return new Float(k); } /** * Unwraps a key * * @param a wrapped key * @return an unwrapped representation of the key */ protected float unwrapKey(Object key) { return ((Float)key).floatValue(); } /** * Wraps a value * * @param a value in the underlying map * @return an Object representation of the value */ protected Double wrapValue(double k) { return new Double(k); } /** * Unwraps a value * * @param a wrapped value * @return an unwrapped representation of the value */ protected double unwrapValue(Object value) { return ((Double)value).doubleValue(); } } // TFloatDoubleHashMapDecorator --- NEW FILE: TFloatFloatHashMapDecorator.java --- ////////////////////////////////////////////////////////... [truncated message content] |
From: Eric F. <er...@us...> - 2002-09-25 05:08:26
|
Update of /cvsroot/trove4j/trove/src/gnu/trove/decorator In directory usw-pr-cvs1:/tmp/cvs-serv7843/decorator Log Message: Directory /cvsroot/trove4j/trove/src/gnu/trove/decorator added to the repository |
From: Eric F. <er...@us...> - 2002-09-24 02:36:02
|
Update of /cvsroot/trove4j/trove_web In directory usw-pr-cvs1:/tmp/cvs-serv29328 Modified Files: overview.shtml Log Message: doc update Index: overview.shtml =================================================================== RCS file: /cvsroot/trove4j/trove_web/overview.shtml,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** overview.shtml 19 Jan 2002 18:50:55 -0000 1.1.1.1 --- overview.shtml 24 Sep 2002 02:35:59 -0000 1.2 *************** *** 10,61 **** <h2>GNU Trove: High performance collections for Java.</h2> ! <h3>Overview</h3> ! <p>Like the JDK implementations, the GNU Trove library's ! <tt>Map</tt> and <tt>Set</tt> classes use <i>hashtables</i> for ! fast insertions, deletions, and searches. Unlike the JDK, GNU ! Trove uses <i>open addressing</i> instead of <i>chaining</i> to ! resolve hashing conflicts. <b>This approach eliminates the need ! to create <tt>java.util.Map.Entry</tt> objects for every element ! in a collection.</b> (As most seasoned Java programmers know, ! Object creation and garbage collection can be very expensive, ! regardless of the presence of a JIT or HotSpot JVM. See Chapter 4 ! of Jack Shirazi's <i>Java Performance Tuning</i> [O'Reilly & ! Associates, 2000] for more information on this topic.)</p> ! <p>A characteristic of hashtables is that they need to expand to ! accomodate data sets that exceed their current capacity. The ! performance of the hashtable is noticeably improved if its size is ! a prime number. For this reason, the GNU Trove hashtables always ! expand to a prime capacity; this behavior is <i>not</i> provided ! by the JDK implementations.</p> ! <p>In a map/set of 100,000 objects, the use of open addressing and ! prime table sizing yields a <b>fourfold speed improvement</b> for ! most operations. Further: the resulting data structures require ! approximately <b>50% of the memory needed by the JDK ! implementations</b>. The memory savings are especially ! significant in the <tt>Set</tt> implementation. Unlike the JDK ! implementation, the GNU Trove sets are not backed by Maps, and so ! do not have to allocate (and copy) large arrays for values that, ! because of the nature of a <tt>Set</tt>, will never be used.</p> ! <p>The Object <tt>Map</tt> and <tt>Set</tt> implementations in GNU ! Trove are designed so that you can trivially replace a JDK ! implementation with a trove implementation: ! <pre> ! import java.util.*; ! import gnu.trove.*; // trove naming conventions ensure no naming conflicts ! [...] ! //Map myMap = new HashMap(); ! Map myMap = new THashMap(); ! </pre> ! A simple Perl or sed script can be used to switch back and forth ! between the JDK and GNU Trove implementations across a large ! codebase as your application requires.</p> <p>N.B. using <tt>Map.entrySet</tt> on a Trove Map is supported, but --- 10,121 ---- <h2>GNU Trove: High performance collections for Java.</h2> ! <p>The GNU Trove library has two objectives: ! <ol> ! ! <li>Provide "free" (as in "free speech" ! <i>and</i> "free beer"), fast, lightweight ! implementations of the <tt>java.util</tt> Collections API. ! These implementations are designed to be pluggable ! replacements for their JDK equivalents.</li> ! ! <li>Whenever possible, provide the same collections support ! for <strong>primitive</strong> types. This gap in the JDK is ! often addressed by using the "wrapper" classes ! (<tt>java.lang.Integer</tt>, <tt>java.lang.Float</tt>, etc.) ! with Object-based collections. For most applications, ! however, collections which store primitives directly will ! require less space and yield significant performance gains. ! </ol> ! </p> ! <h2>Hashtable techniques</h2> ! <p>The Trove maps/sets use open addressing instead of the chaining ! approach taken by the JDK hashtables. This eliminates the need ! to create Map.Entry wrappper objects for every item in a ! table and so reduces the <tt>O</tt> (big-oh) in the performance of ! the hashtable algorithm. The size of the tables used in Trove's maps/sets is ! always a prime number, improving the probability of an optimal distribution ! of entries across the table, and so reducing the the likelihood ! of performance-degrading collisions. Trove sets are not ! backed by maps, and so using a THashSet does not result in ! the allocation of an unused "values" array. ! </p> ! <h2>Hashing strategies</h2> ! <p>Trove's maps/sets support the use of custom <tt>hashing ! strategies</tt>, allowing you to tune collections based on ! characteristics of the input data. This feature also allows you ! to define hash functions when it is not feasible to override ! Object.hashCode(). For example, the java.lang.String class is ! final, and its implementation of hashCode() takes <tt>O(n)</tt> ! time to complete. In some applications, however, it may be ! possible for a custom hashing function to save time by skipping ! portions of the string that are invariant.</p> ! <p>Using java.util.HashMap, it is not possible to use Java ! language arrays as keys. For example, this code: ! <pre> ! char[] foo, bar; ! foo = new char[] {'a','b','c'}; ! bar = new char[] {'a','b','c'}; ! System.out.println(foo.hashCode() == bar.hashCode() ? "equal" : "not equal"); ! System.out.println(foo.equals(bar) ? "equal" : "not equal"); ! </pre> ! produces this output: ! <pre> ! not equal ! not equal ! </pre> ! And so an entry stored in a java.util.HashMap with foo as a ! key could not be retrieved with bar, since there is no way ! to override hashCode() or equals() on language array objects. ! </p> ! ! <p>In a gnu.trove.THashMap, however, you can implement a TObjectHashingStrategy ! to enable hashing on arrays: ! ! <pre> ! class CharArrayStrategy implements TObjectHashingStrategy { ! public int computeHashCode(Object o) { ! char[] c = (char[])o; ! // use the shift-add-xor class of string hashing functions ! // cf. Ramakrishna and Zobel, "Performance in Practice of String Hashing Functions" ! int h = 31; // seed chosen at random ! for (int i = 0; i < c.length; i++) { // could skip invariants ! h = h ^ ((h << 5) + (h >> 2) + c[i]); // L=5, R=2 works well for ASCII input ! } ! return h; ! } ! ! public boolean equals(Object o1, Object o2) { ! char[] c1 = (char[])o1; ! char[] c2 = (char[])o2; ! if (c1.length != c2.length) { // could drop this check for fixed-length keys ! return false; ! } ! for (int i = 0, len = c1.length; i < len; i++) { // could skip invariants ! if (c1[i] != c2[i]) { ! return false; ! } ! } ! return true; ! } ! } ! </pre> ! </p> ! ! <h2>Iterators in primitive collections</h2> ! ! <p>As of release 0.1.7, Trove's primitive mappings include access through Iterators ! as well as procedures and functions. The API documentation on those classes ! contains several examples showing how these can be used effectively and ! explaining why their semantics differ from those of <tt>java.util.Iterator.</tt></p> ! ! <h2>Miscellaneous</h2> <p>N.B. using <tt>Map.entrySet</tt> on a Trove Map is supported, but |
From: Eric F. <er...@us...> - 2002-09-24 02:26:18
|
Update of /cvsroot/trove4j/trove In directory usw-pr-cvs1:/tmp/cvs-serv26921 Modified Files: AUTHORS README.txt Log Message: project documentation updates Index: AUTHORS =================================================================== RCS file: /cvsroot/trove4j/trove/AUTHORS,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AUTHORS 10 Nov 2001 22:30:27 -0000 1.1 --- AUTHORS 24 Sep 2002 02:26:14 -0000 1.2 *************** *** 1 **** --- 1,9 ---- Eric D. Friedman <er...@us...> + + Please do NOT email bug reports or feature requests. + + Instead use the very fine bug tracking system and feature request + service on SourceForge: http://sourceforge.net/projects/trove4j/ + I'll read your issue just as quickly, and the project's issues will + remain out in the open where everyone can see them. I also monitor + the project fora, so feel free to use those too. Index: README.txt =================================================================== RCS file: /cvsroot/trove4j/trove/README.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** README.txt 10 Nov 2001 22:30:27 -0000 1.1 --- README.txt 24 Sep 2002 02:26:15 -0000 1.2 *************** *** 1,4 **** ! GNU Trove: High performance collections for Java. ! The GNU Trove library has two objectives: 1. Provide "free" (as in "free speech" and "free beer"), fast, --- 1,7 ---- ! ! GNU Trove: High performance collections for Java. ! ! Objectives ! The GNU Trove library has two objectives: 1. Provide "free" (as in "free speech" and "free beer"), fast, *************** *** 12,60 **** collections which store primitives directly will require less space and yield significant performance gains. - - Like the JDK implementations, the GNU Trove library's Map and Set - classes use hashtables for fast insertions, deletions, and searches. - Unlike the JDK, GNU Trove uses open addressing instead of chaining to - resolve hashing conflicts. This approach eliminates the need to create - java.util.Map.Entry objects for every element in a collection. (As - most seasoned Java programmers know, Object creation and garbage - collection can be very expensive, regardless of a presence of a JIT or - HotSpot JVM. See Chapter 4 of Jack Shirazi's Java Performance Tuning - [O'Reilly & Associates, 2000] for more information on this topic.) - - A characteristic of hashtables is that they need to expand to - accomodate data sets that exceed their current capacity. The - performance of the hashtable is noticeably improved if its size is a - prime number. For this reason, the GNU Trove hashtables always expand - to a prime capacity; this behavior is not provided by the JDK - implementations. - - In a map/set of 100,000 objects, the use of open addressing and prime - table sizing yields a fourfold speed improvement for most operations. - Further: the resulting data structures require approximately 50% of - the memory needed by the JDK implementations. The memory savings are - especially significant in the Set implementation. Unlike the JDK - implementation, the GNU Trove sets are not backed by Maps, and so do - not have to allocate (and copy) large arrays for values that, because - of the nature of a Set will never be used. - - The Object Map and Set implementations in GNU Trove are designed so - that you can trivially replace a JDK implementation with a trove - implementation: - import java.util.*; - import gnu.trove.*; // trove naming conventions ensure no naming conflicts ! [...] ! //Map myMap = new HashMap(); ! Map myMap = new THashMap(); - A simple Perl or sed script can be used to switch back and forth - between the JDK and GNU Trove implementations across a large codebase - as your application requires. - N.B. using Map.entrySet on a Trove Map is supported, but not ! encouraged. The reasons is this API requires the creation of the Map.Entry Objects that all other parts of Trove manage to avoid. An alternative is to implement the appropriate Procedure interface and --- 15,108 ---- collections which store primitives directly will require less space and yield significant performance gains. ! Hashtable techniques ! The Trove maps/sets use open addressing instead of the chaining ! approach taken by the JDK hashtables. This eliminates the need to ! create Map.Entry wrappper objects for every item in a table and so ! reduces the O (big-oh) in the performance of the hashtable algorithm. ! The size of the tables used in Trove's maps/sets is always a prime ! number, improving the probability of an optimal distribution of ! entries across the table, and so reducing the the likelihood of ! performance-degrading collisions. Trove sets are not backed by maps, ! and so using a THashSet does not result in the allocation of an unused ! "values" array. + Hashing strategies + + Trove's maps/sets support the use of custom hashing strategies, + allowing you to tune collections based on characteristics of the input + data. This feature also allows you to define hash functions when it is + not feasible to override Object.hashCode(). For example, the + java.lang.String class is final, and its implementation of hashCode() + takes O(n) time to complete. In some applications, however, it may be + possible for a custom hashing function to save time by skipping + portions of the string that are invariant. + + Using java.util.HashMap, it is not possible to use Java language + arrays as keys. For example, this code: + char[] foo, bar; + foo = new char[] {'a','b','c'}; + bar = new char[] {'a','b','c'}; + System.out.println(foo.hashCode() == bar.hashCode() ? "equal" : "not equal" + ); + System.out.println(foo.equals(bar) ? "equal" : "not equal"); + + + produces this output: + not equal + not equal + + + And so an entry stored in a java.util.HashMap with foo as a key could + not be retrieved with bar, since there is no way to override + hashCode() or equals() on language array objects. + + In a gnu.trove.THashMap, however, you can implement a + TObjectHashingStrategy to enable hashing on arrays: + class CharArrayStrategy implements TObjectHashingStrategy { + public int computeHashCode(Object o) { + char[] c = (char[])o; + // use the shift-add-xor class of string hashing functions + // cf. Ramakrishna and Zobel, "Performance in Practice of String Ha + shing Functions" + int h = 31; // seed chosen at random + for (int i = 0; i < c.length; i++) { // could skip invariants + h = h ^ ((h << 5) + (h >> 2) + c[i]); // L=5, R=2 works well fo + r ASCII input + } + return h; + } + + public boolean equals(Object o1, Object o2) { + char[] c1 = (char[])o1; + char[] c2 = (char[])o2; + if (c1.length != c2.length) { // could drop this check for fixed-le + ngth keys + return false; + } + for (int i = 0, len = c1.length; i < len; i++) { // could skip inva + riants + if (c1[i] != c2[i]) { + return false; + } + } + return true; + } + } + + + Iterators in primitive collections + + As of release 0.1.7, Trove's primitive mappings include access through + Iterators as well as procedures and functions. The API documentation + on those classes contains several examples showing how these can be + used effectively and explaining why their semantics differ from those + of java.util.Iterator. + + Miscellaneous N.B. using Map.entrySet on a Trove Map is supported, but not ! encouraged. The reason is that this API requires the creation of the Map.Entry Objects that all other parts of Trove manage to avoid. An alternative is to implement the appropriate Procedure interface and *************** *** 65,70 **** java.util.Map. _________________________________________________________________ ! ! Last modified: Sat Nov 10 13:39:50 PST 2001 ! ! Copyright (c) 2001 Eric D. Friedman. All Rights Reserved. --- 113,116 ---- java.util.Map. _________________________________________________________________ ! ! Last modified: Mon Sep 23 18:22:39 PDT 2002 |
From: Eric F. <er...@us...> - 2002-09-24 02:26:18
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv26921/src/gnu/trove Modified Files: package.html Log Message: project documentation updates Index: package.html =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/package.html,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** package.html 22 Sep 2002 21:53:42 -0000 1.5 --- package.html 24 Sep 2002 02:26:15 -0000 1.6 *************** *** 8,11 **** --- 8,13 ---- <p>GNU Trove: High performance collections for Java.</p> + <h2>Objectives</h2> + <p>The GNU Trove library has two objectives: <ol> *************** *** 27,30 **** --- 29,34 ---- </p> + <h2>Hashtable techniques</h2> + <p>The Trove maps/sets use open addressing instead of the chaining approach taken by the JDK hashtables. This eliminates the need *************** *** 39,42 **** --- 43,48 ---- </p> + <h2>Hashing strategies</h2> + <p>Trove's maps/sets support the use of custom <tt>hashing strategies</tt>, allowing you to tune collections based on *************** *** 104,107 **** --- 110,115 ---- </p> + <h2>Iterators in primitive collections</h2> + <p>As of release 0.1.7, Trove's primitive mappings include access through Iterators as well as procedures and functions. The API documentation on those classes *************** *** 109,112 **** --- 117,122 ---- explaining why their semantics differ from those of <tt>java.util.Iterator.</tt></p> + <h2>Miscellaneous</h2> + <p>N.B. using <tt>Map.entrySet</tt> on a Trove Map is supported, but not encouraged. The reason is that this API requires the creation of *************** *** 123,127 **** <!-- Created: Sat Nov 10 09:52:57 PST 2001 --> <!-- hhmts start --> ! Last modified: Sun Aug 18 11:18:17 PDT 2002 <!-- hhmts end --> </body> --- 133,137 ---- <!-- Created: Sat Nov 10 09:52:57 PST 2001 --> <!-- hhmts start --> ! Last modified: Mon Sep 23 18:22:39 PDT 2002 <!-- hhmts end --> </body> |
From: Eric F. <er...@us...> - 2002-09-22 21:54:12
|
Update of /cvsroot/trove4j/trove In directory usw-pr-cvs1:/tmp/cvs-serv4170 Modified Files: ChangeLog build.xml Log Message: added iterator support to primitive collections Index: ChangeLog =================================================================== RCS file: /cvsroot/trove4j/trove/ChangeLog,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ChangeLog 20 Sep 2002 20:55:57 -0000 1.17 --- ChangeLog 22 Sep 2002 21:53:39 -0000 1.18 *************** *** 1,4 **** --- 1,7 ---- v 0.1.7 + Added iterators to the primitive maps and sets. Note that semantics + differ from those of java.util.Iterator, so RTFM. + Added hashing strategy interfaces to allow users to implement custom hashing schemes for optimal distribution for specific data sets. Index: build.xml =================================================================== RCS file: /cvsroot/trove4j/trove/build.xml,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** build.xml 18 Aug 2002 16:43:14 -0000 1.21 --- build.xml 22 Sep 2002 21:53:39 -0000 1.22 *************** *** 10,14 **** <property name="Name" value="Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="0.1.6"/> <property name="year" value="2001-2002"/> --- 10,14 ---- <property name="Name" value="Trove for Java"/> <property name="name" value="trove"/> ! <property name="version" value="0.1.7"/> <property name="year" value="2001-2002"/> |
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv4170/src/gnu/trove Modified Files: TDoubleArrayList.java TDoubleDoubleHashMap.java TDoubleDoubleProcedure.java TDoubleFloatHashMap.java TDoubleFloatProcedure.java TDoubleFunction.java TDoubleHash.java TDoubleHashSet.java TDoubleHashingStrategy.java TDoubleIntHashMap.java TDoubleIntProcedure.java TDoubleLongHashMap.java TDoubleLongProcedure.java TDoubleObjectHashMap.java TDoubleObjectProcedure.java TDoubleProcedure.java TFloatArrayList.java TFloatDoubleHashMap.java TFloatDoubleProcedure.java TFloatFloatHashMap.java TFloatFloatProcedure.java TFloatFunction.java TFloatHash.java TFloatHashSet.java TFloatHashingStrategy.java TFloatIntHashMap.java TFloatIntProcedure.java TFloatLongHashMap.java TFloatLongProcedure.java TFloatObjectHashMap.java TFloatObjectProcedure.java TFloatProcedure.java THashIterator.java TIntDoubleHashMap.java TIntDoubleProcedure.java TIntFloatHashMap.java TIntFloatProcedure.java TIntFunction.java TIntHash.java TIntHashSet.java TIntHashingStrategy.java TIntIntHashMap.java TIntIntHashMapTests.java TIntIntProcedure.java TIntLongHashMap.java TIntLongProcedure.java TIntObjectHashMap.java TIntObjectProcedure.java TIntProcedure.java TLongArrayList.java TLongDoubleHashMap.java TLongDoubleProcedure.java TLongFloatHashMap.java TLongFloatProcedure.java TLongFunction.java TLongHash.java TLongHashSet.java TLongHashingStrategy.java TLongIntHashMap.java TLongIntProcedure.java TLongLongHashMap.java TLongLongProcedure.java TLongObjectHashMap.java TLongObjectProcedure.java TLongProcedure.java TObjectDoubleHashMap.java TObjectDoubleProcedure.java TObjectFloatHashMap.java TObjectFloatProcedure.java TObjectIntHashMap.java TObjectIntProcedure.java TObjectLongHashMap.java TObjectLongProcedure.java gen_obj_primitive_map.pl gen_primitive_map.pl gen_primitive_set.pl package.html Added Files: TDoubleDoubleIterator.java TDoubleFloatIterator.java TDoubleIntIterator.java TDoubleIterator.java TDoubleLongIterator.java TDoubleObjectIterator.java TFloatDoubleIterator.java TFloatFloatIterator.java TFloatIntIterator.java TFloatIterator.java TFloatLongIterator.java TFloatObjectIterator.java TIntDoubleIterator.java TIntFloatIterator.java TIntIntIterator.java TIntIterator.java TIntLongIterator.java TIntObjectIterator.java TIterator.java TLongDoubleIterator.java TLongFloatIterator.java TLongIntIterator.java TLongIterator.java TLongLongIterator.java TLongObjectIterator.java TObjectDoubleIterator.java TObjectFloatIterator.java TObjectIntIterator.java TObjectLongIterator.java TPrimitiveIterator.java gen_map_iterators.pl gen_object_primitive_iterators.pl gen_set_iterators.pl Log Message: added iterator support to primitive collections --- NEW FILE: TDoubleDoubleIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type double and double. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TDoubleDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TDoubleDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TDoubleDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TDoubleDoubleIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TDoubleDoubleIterator.java,v 1.1 2002/09/22 21:53:39 ericdf Exp $ */ public class TDoubleDoubleIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TDoubleDoubleHashMap _map; /** * Creates an iterator over the specified map */ public TDoubleDoubleIterator(TDoubleDoubleHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public double key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public double value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public double setValue(double val) { double old = value(); _map._values[_index] = val; return old; } }// TDoubleDoubleIterator --- NEW FILE: TDoubleFloatIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type double and float. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TDoubleFloatIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TDoubleFloatIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TDoubleFloatIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TDoubleFloatIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TDoubleFloatIterator.java,v 1.1 2002/09/22 21:53:40 ericdf Exp $ */ public class TDoubleFloatIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TDoubleFloatHashMap _map; /** * Creates an iterator over the specified map */ public TDoubleFloatIterator(TDoubleFloatHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public double key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public float value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public float setValue(float val) { float old = value(); _map._values[_index] = val; return old; } }// TDoubleFloatIterator --- NEW FILE: TDoubleIntIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type double and int. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TDoubleIntIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TDoubleIntIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TDoubleIntIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TDoubleIntIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TDoubleIntIterator.java,v 1.1 2002/09/22 21:53:40 ericdf Exp $ */ public class TDoubleIntIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TDoubleIntHashMap _map; /** * Creates an iterator over the specified map */ public TDoubleIntIterator(TDoubleIntHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public double key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public int value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public int setValue(int val) { int old = value(); _map._values[_index] = val; return old; } }// TDoubleIntIterator --- NEW FILE: TDoubleIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for double collections. * * @author Eric D. Friedman * @version $Id: TDoubleIterator.java,v 1.1 2002/09/22 21:53:40 ericdf Exp $ */ public class TDoubleIterator extends TPrimitiveIterator { /** the collection on which the iterator operates */ private final TDoubleHash _hash; /** * Creates a TDoubleIterator for the elements in the specified collection. */ public TDoubleIterator(TDoubleHash hash) { super(hash); this._hash = hash; } /** * Advances the iterator to the next element in the underlying collection * and returns it. * * @return the next double in the collection * @excetion NoSuchElementException if the iterator is already exhausted */ public double next() { moveToNextIndex(); return _hash._set[_index]; } }// TDoubleIterator --- NEW FILE: TDoubleLongIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type double and long. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TDoubleLongIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TDoubleLongIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TDoubleLongIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TDoubleLongIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TDoubleLongIterator.java,v 1.1 2002/09/22 21:53:40 ericdf Exp $ */ public class TDoubleLongIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TDoubleLongHashMap _map; /** * Creates an iterator over the specified map */ public TDoubleLongIterator(TDoubleLongHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public double key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public long value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public long setValue(long val) { long old = value(); _map._values[_index] = val; return old; } }// TDoubleLongIterator --- NEW FILE: TDoubleObjectIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type double and Object. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TDoubleObjectIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TDoubleObjectIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TDoubleObjectIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TDoubleObjectIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TDoubleObjectIterator.java,v 1.1 2002/09/22 21:53:40 ericdf Exp $ */ public class TDoubleObjectIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TDoubleObjectHashMap _map; /** * Creates an iterator over the specified map */ public TDoubleObjectIterator(TDoubleObjectHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public double key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public Object value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public Object setValue(Object val) { Object old = value(); _map._values[_index] = val; return old; } }// TDoubleObjectIterator --- NEW FILE: TFloatDoubleIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type float and double. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TFloatDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TFloatDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TFloatDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TFloatDoubleIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TFloatDoubleIterator.java,v 1.1 2002/09/22 21:53:40 ericdf Exp $ */ public class TFloatDoubleIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TFloatDoubleHashMap _map; /** * Creates an iterator over the specified map */ public TFloatDoubleIterator(TFloatDoubleHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public float key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public double value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public double setValue(double val) { double old = value(); _map._values[_index] = val; return old; } }// TFloatDoubleIterator --- NEW FILE: TFloatFloatIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type float and float. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TFloatFloatIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TFloatFloatIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TFloatFloatIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TFloatFloatIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TFloatFloatIterator.java,v 1.1 2002/09/22 21:53:40 ericdf Exp $ */ public class TFloatFloatIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TFloatFloatHashMap _map; /** * Creates an iterator over the specified map */ public TFloatFloatIterator(TFloatFloatHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public float key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public float value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public float setValue(float val) { float old = value(); _map._values[_index] = val; return old; } }// TFloatFloatIterator --- NEW FILE: TFloatIntIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type float and int. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TFloatIntIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TFloatIntIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TFloatIntIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TFloatIntIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TFloatIntIterator.java,v 1.1 2002/09/22 21:53:41 ericdf Exp $ */ public class TFloatIntIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TFloatIntHashMap _map; /** * Creates an iterator over the specified map */ public TFloatIntIterator(TFloatIntHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public float key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public int value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public int setValue(int val) { int old = value(); _map._values[_index] = val; return old; } }// TFloatIntIterator --- NEW FILE: TFloatIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for float collections. * * @author Eric D. Friedman * @version $Id: TFloatIterator.java,v 1.1 2002/09/22 21:53:41 ericdf Exp $ */ public class TFloatIterator extends TPrimitiveIterator { /** the collection on which the iterator operates */ private final TFloatHash _hash; /** * Creates a TFloatIterator for the elements in the specified collection. */ public TFloatIterator(TFloatHash hash) { super(hash); this._hash = hash; } /** * Advances the iterator to the next element in the underlying collection * and returns it. * * @return the next float in the collection * @excetion NoSuchElementException if the iterator is already exhausted */ public float next() { moveToNextIndex(); return _hash._set[_index]; } }// TFloatIterator --- NEW FILE: TFloatLongIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type float and long. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TFloatLongIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TFloatLongIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TFloatLongIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TFloatLongIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TFloatLongIterator.java,v 1.1 2002/09/22 21:53:41 ericdf Exp $ */ public class TFloatLongIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TFloatLongHashMap _map; /** * Creates an iterator over the specified map */ public TFloatLongIterator(TFloatLongHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public float key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public long value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public long setValue(long val) { long old = value(); _map._values[_index] = val; return old; } }// TFloatLongIterator --- NEW FILE: TFloatObjectIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type float and Object. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TFloatObjectIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TFloatObjectIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TFloatObjectIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TFloatObjectIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TFloatObjectIterator.java,v 1.1 2002/09/22 21:53:41 ericdf Exp $ */ public class TFloatObjectIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TFloatObjectHashMap _map; /** * Creates an iterator over the specified map */ public TFloatObjectIterator(TFloatObjectHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the key of the entry at the iterator's current position. */ public float key() { return _map._set[_index]; } /** * Provides access to the value of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the value of the entry at the iterator's current position. */ public Object value() { return _map._values[_index]; } /** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public Object setValue(Object val) { Object old = value(); _map._values[_index] = val; return old; } }// TFloatObjectIterator --- NEW FILE: TIntDoubleIterator.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; /** * Iterator for maps of type int and double. * * <p>The iterator semantics for Trove's primitive maps is slightly different * from those defined in <tt>java.util.Iterator</tt>, but still well within * the scope of the pattern, as defined by Gamma, et al.</p> * * <p>This iterator does <b>not</b> implicitly advance to the next entry when * the value at the current position is retrieved. Rather, you must explicitly * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>, * the <tt>value()</tt> or both. This is done so that you have the option, but not * the obligation, to retrieve keys and/or values as your application requires, and * without introducing wrapper objects that would carry both. As the iteration is * stateful, access to the key/value parts of the current map entry happens in * constant time.</p> * * <p>In practice, the iterator is akin to a "search finger" that you move from * position to position. Read or write operations affect the current entry only and * do not assume responsibility for moving the finger.</p> * * <p>Here are some sample scenarios for this class of iterator:</p> * * <pre> * // accessing keys/values through an iterator: * for (TIntDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * doSomethingWithValue(it.value()); * } * } * </pre> * * <pre> * // modifying values in-place through iteration: * for (TIntDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.setValue(newValueForKey(it.key())); * } * } * </pre> * * <pre> * // deleting entries during iteration: * for (TIntDoubleIterator it = map.iterator(); * it.hasNext();) { * it.forward(); * if (satisfiesCondition(it.key()) { * it.remove(); * } * } * </pre> * * <pre> * // faster iteration by avoiding hasNext(): * TIntDoubleIterator iterator = map.iterator(); * for (int i = map.size(); i-- > 0;) { * iterator.advance(); * doSomethingWithKeyAndValue(iterator.key(), iterator.value()); * } * </pre> * * @author Eric D. Friedman * @version $Id: TIntDoubleIterator.java,v 1.1 2002/09/22 21:53:41 ericdf Exp $ */ public class TIntDoubleIterator extends TPrimitiveIterator { /** the collection being iterated over */ private final TIntDoubleHashMap _map; /** * Creates an iterator over the specified map */ public TIntDoubleIterator(TIntDoubleHashMap map) { super(map); this._map = map; } /** * Moves the iterator forward to the next entry in the underlying map. * * @exception NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); } /** * Provides access to the key of the mapping at the iterator's position. * Note that you must <tt>advance()</tt> the iterator at least once * before invoking this method. * * @return the k... [truncated message content] |
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv31441/src/gnu/trove Modified Files: TDoubleArrayList.java TDoubleDoubleHashMap.java TDoubleFloatHashMap.java TDoubleHash.java TDoubleHashSet.java TDoubleHashingStrategy.java TDoubleIntHashMap.java TDoubleLongHashMap.java TDoubleObjectHashMap.java TFloatArrayList.java TFloatDoubleHashMap.java TFloatFloatHashMap.java TFloatHash.java TFloatHashSet.java TFloatHashingStrategy.java TFloatIntHashMap.java TFloatLongHashMap.java TFloatObjectHashMap.java THash.java THashMap.java THashMapTests.java TIntDoubleHashMap.java TIntFloatHashMap.java TIntHash.java TIntHashSet.java TIntHashingStrategy.java TIntIntHashMap.java TIntIntHashMapTests.java TIntLongHashMap.java TIntObjectHashMap.java TLongArrayList.java TLongDoubleHashMap.java TLongFloatHashMap.java TLongHash.java TLongHashSet.java TLongHashingStrategy.java TLongIntHashMap.java TLongLongHashMap.java TLongObjectHashMap.java TObjectHash.java TPrimitiveHash.java gen_primitive_base.pl gen_primitive_map.pl Log Message: implemented Cloneable interface Index: TDoubleArrayList.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleArrayList.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 Index: TDoubleDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleDoubleHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TDoubleDoubleHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TDoubleDoubleHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TDoubleDoubleHashMap m = (TDoubleDoubleHashMap)super.clone(); + m._values = (double[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleFloatHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TDoubleFloatHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TDoubleFloatHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TDoubleFloatHashMap m = (TDoubleFloatHashMap)super.clone(); + m._values = (float[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleHash.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleHash.java 18 Aug 2002 16:43:14 -0000 1.10 --- TDoubleHash.java 20 Sep 2002 20:55:57 -0000 1.11 *************** *** 76,80 **** * Creates a new <code>TDoubleHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare objects. */ public TDoubleHash(TDoubleHashingStrategy strategy) { --- 76,80 ---- * Creates a new <code>TDoubleHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare keys. */ public TDoubleHash(TDoubleHashingStrategy strategy) { *************** *** 89,93 **** * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare objects. */ public TDoubleHash(int initialCapacity, TDoubleHashingStrategy strategy) { --- 89,93 ---- * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare keys. */ public TDoubleHash(int initialCapacity, TDoubleHashingStrategy strategy) { *************** *** 103,111 **** * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare objects. */ public TDoubleHash(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; } --- 103,120 ---- * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare keys. */ public TDoubleHash(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; + } + + /** + * @return a deep clone of this collection + */ + public Object clone() { + TDoubleHash h = (TDoubleHash)super.clone(); + h._set = (double[])this._set.clone(); + return h; } Index: TDoubleHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleHashSet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TDoubleHashSet.java 18 Aug 2002 16:43:14 -0000 1.8 --- TDoubleHashSet.java 20 Sep 2002 20:55:57 -0000 1.9 *************** *** 124,127 **** --- 124,128 ---- addAll(array); } + /** * Inserts a value into the set. Index: TDoubleHashingStrategy.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleHashingStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Index: TDoubleIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleIntHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TDoubleIntHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TDoubleIntHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TDoubleIntHashMap m = (TDoubleIntHashMap)super.clone(); + m._values = (int[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleLongHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TDoubleLongHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TDoubleLongHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TDoubleLongHashMap m = (TDoubleLongHashMap)super.clone(); + m._values = (long[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleObjectHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TDoubleObjectHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TDoubleObjectHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TDoubleObjectHashMap m = (TDoubleObjectHashMap)super.clone(); + m._values = (Object[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatArrayList.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatArrayList.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 Index: TFloatDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatDoubleHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TFloatDoubleHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TFloatDoubleHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TFloatDoubleHashMap m = (TFloatDoubleHashMap)super.clone(); + m._values = (double[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatFloatHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TFloatFloatHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TFloatFloatHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TFloatFloatHashMap m = (TFloatFloatHashMap)super.clone(); + m._values = (float[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatHash.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatHash.java 18 Aug 2002 16:43:14 -0000 1.10 --- TFloatHash.java 20 Sep 2002 20:55:57 -0000 1.11 *************** *** 76,80 **** * Creates a new <code>TFloatHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare objects. */ public TFloatHash(TFloatHashingStrategy strategy) { --- 76,80 ---- * Creates a new <code>TFloatHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare keys. */ public TFloatHash(TFloatHashingStrategy strategy) { *************** *** 89,93 **** * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare objects. */ public TFloatHash(int initialCapacity, TFloatHashingStrategy strategy) { --- 89,93 ---- * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare keys. */ public TFloatHash(int initialCapacity, TFloatHashingStrategy strategy) { *************** *** 103,111 **** * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare objects. */ public TFloatHash(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; } --- 103,120 ---- * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare keys. */ public TFloatHash(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; + } + + /** + * @return a deep clone of this collection + */ + public Object clone() { + TFloatHash h = (TFloatHash)super.clone(); + h._set = (float[])this._set.clone(); + return h; } Index: TFloatHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatHashSet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TFloatHashSet.java 18 Aug 2002 16:43:14 -0000 1.8 --- TFloatHashSet.java 20 Sep 2002 20:55:57 -0000 1.9 *************** *** 124,127 **** --- 124,128 ---- addAll(array); } + /** * Inserts a value into the set. Index: TFloatHashingStrategy.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatHashingStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Index: TFloatIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatIntHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TFloatIntHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TFloatIntHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TFloatIntHashMap m = (TFloatIntHashMap)super.clone(); + m._values = (int[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatLongHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TFloatLongHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TFloatLongHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TFloatLongHashMap m = (TFloatLongHashMap)super.clone(); + m._values = (long[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatObjectHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TFloatObjectHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TFloatObjectHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TFloatObjectHashMap m = (TFloatObjectHashMap)super.clone(); + m._values = (Object[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: THash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THash.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** THash.java 14 Jan 2002 05:59:43 -0000 1.4 --- THash.java 20 Sep 2002 20:55:57 -0000 1.5 *************** *** 29,33 **** */ ! abstract public class THash { /** the current number of occupied slots in the hash. */ protected transient int _size; --- 29,33 ---- */ ! abstract public class THash implements Cloneable { /** the current number of occupied slots in the hash. */ protected transient int _size; *************** *** 92,95 **** --- 92,103 ---- _loadFactor = loadFactor; setUp((int)Math.ceil(initialCapacity / loadFactor)); + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException cnse) { + return null; // it's supported + } } Index: THashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMap.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** THashMap.java 30 Aug 2002 14:26:51 -0000 1.12 --- THashMap.java 20 Sep 2002 20:55:57 -0000 1.13 *************** *** 134,137 **** --- 134,146 ---- /** + * @return a shallow clone of this collection + */ + public Object clone() { + THashMap m = (THashMap)super.clone(); + m._values = (Object[])this._values.clone(); + return m; + } + + /** * initialize the value array of the map. * Index: THashMapTests.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMapTests.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** THashMapTests.java 30 Aug 2002 14:26:51 -0000 1.10 --- THashMapTests.java 20 Sep 2002 20:55:57 -0000 1.11 *************** *** 322,324 **** --- 322,332 ---- t.putAll(m); } + + public void testClone() throws Exception { + map.put("one", "two"); + THashMap m2 = (THashMap)map.clone(); + assertEquals(map, m2); + map.clear(); + assertTrue(! map.equals(m2)); + } } // THashMapTests Index: TIntDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntDoubleHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TIntDoubleHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TIntDoubleHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TIntDoubleHashMap m = (TIntDoubleHashMap)super.clone(); + m._values = (double[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TIntFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntFloatHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TIntFloatHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TIntFloatHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TIntFloatHashMap m = (TIntFloatHashMap)super.clone(); + m._values = (float[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TIntHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntHash.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TIntHash.java 18 Aug 2002 16:43:14 -0000 1.10 --- TIntHash.java 20 Sep 2002 20:55:57 -0000 1.11 *************** *** 76,80 **** * Creates a new <code>TIntHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare objects. */ public TIntHash(TIntHashingStrategy strategy) { --- 76,80 ---- * Creates a new <code>TIntHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare keys. */ public TIntHash(TIntHashingStrategy strategy) { *************** *** 89,93 **** * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare objects. */ public TIntHash(int initialCapacity, TIntHashingStrategy strategy) { --- 89,93 ---- * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare keys. */ public TIntHash(int initialCapacity, TIntHashingStrategy strategy) { *************** *** 103,111 **** * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare objects. */ public TIntHash(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; } --- 103,120 ---- * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare keys. */ public TIntHash(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; + } + + /** + * @return a deep clone of this collection + */ + public Object clone() { + TIntHash h = (TIntHash)super.clone(); + h._set = (int[])this._set.clone(); + return h; } Index: TIntHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntHashSet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TIntHashSet.java 18 Aug 2002 16:43:14 -0000 1.8 --- TIntHashSet.java 20 Sep 2002 20:55:57 -0000 1.9 *************** *** 124,127 **** --- 124,128 ---- addAll(array); } + /** * Inserts a value into the set. Index: TIntHashingStrategy.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntHashingStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Index: TIntIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntIntHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TIntIntHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- TIntIntHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TIntIntHashMap m = (TIntIntHashMap)super.clone(); + m._values = (int[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TIntIntHashMapTests.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntIntHashMapTests.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TIntIntHashMapTests.java 19 Apr 2002 03:31:58 -0000 1.3 --- TIntIntHashMapTests.java 20 Sep 2002 20:55:57 -0000 1.4 *************** *** 95,97 **** --- 95,106 ---- assertTrue(! mm.containsKey(-99999)); } + + public void testClone() throws Exception { + TIntIntHashMap map = new TIntIntHashMap(); + map.put(1, 2); + TIntIntHashMap m2 = (TIntIntHashMap)map.clone(); + assertEquals(map, m2); + map.clear(); + assertTrue(! map.equals(m2)); + } } // TIntIntHashMapTests Index: TIntLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntLongHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TIntLongHashMap.java 18 Aug 2002 16:43:15 -0000 1.11 --- TIntLongHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TIntLongHashMap m = (TIntLongHashMap)super.clone(); + m._values = (long[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TIntObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TIntObjectHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TIntObjectHashMap.java 18 Aug 2002 16:43:15 -0000 1.11 --- TIntObjectHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TIntObjectHashMap m = (TIntObjectHashMap)super.clone(); + m._values = (Object[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TLongArrayList.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongArrayList.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 Index: TLongDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongDoubleHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TLongDoubleHashMap.java 18 Aug 2002 16:43:15 -0000 1.11 --- TLongDoubleHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TLongDoubleHashMap m = (TLongDoubleHashMap)super.clone(); + m._values = (double[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TLongFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongFloatHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TLongFloatHashMap.java 18 Aug 2002 16:43:15 -0000 1.11 --- TLongFloatHashMap.java 20 Sep 2002 20:55:57 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TLongFloatHashMap m = (TLongFloatHashMap)super.clone(); + m._values = (float[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TLongHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongHash.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TLongHash.java 18 Aug 2002 16:43:15 -0000 1.10 --- TLongHash.java 20 Sep 2002 20:55:57 -0000 1.11 *************** *** 76,80 **** * Creates a new <code>TLongHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare objects. */ public TLongHash(TLongHashingStrategy strategy) { --- 76,80 ---- * Creates a new <code>TLongHash</code> instance with the default * capacity and load factor. ! * @param strategy used to compute hash codes and to compare keys. */ public TLongHash(TLongHashingStrategy strategy) { *************** *** 89,93 **** * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare objects. */ public TLongHash(int initialCapacity, TLongHashingStrategy strategy) { --- 89,93 ---- * * @param initialCapacity an <code>int</code> value ! * @param strategy used to compute hash codes and to compare keys. */ public TLongHash(int initialCapacity, TLongHashingStrategy strategy) { *************** *** 103,111 **** * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare objects. */ public TLongHash(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; } --- 103,120 ---- * @param loadFactor used to calculate the threshold over which * rehashing takes place. ! * @param strategy used to compute hash codes and to compare keys. */ public TLongHash(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { super(initialCapacity, loadFactor); this.hashingStrategy = strategy; + } + + /** + * @return a deep clone of this collection + */ + public Object clone() { + TLongHash h = (TLongHash)super.clone(); + h._set = (long[])this._set.clone(); + return h; } Index: TLongHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongHashSet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TLongHashSet.java 18 Aug 2002 16:43:15 -0000 1.8 --- TLongHashSet.java 20 Sep 2002 20:55:58 -0000 1.9 *************** *** 124,127 **** --- 124,128 ---- addAll(array); } + /** * Inserts a value into the set. Index: TLongHashingStrategy.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongHashingStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Index: TLongIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongIntHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TLongIntHashMap.java 18 Aug 2002 16:43:15 -0000 1.11 --- TLongIntHashMap.java 20 Sep 2002 20:55:58 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TLongIntHashMap m = (TLongIntHashMap)super.clone(); + m._values = (int[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TLongLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongLongHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TLongLongHashMap.java 18 Aug 2002 16:43:15 -0000 1.11 --- TLongLongHashMap.java 20 Sep 2002 20:55:58 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TLongLongHashMap m = (TLongLongHashMap)super.clone(); + m._values = (long[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TLongObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TLongObjectHashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TLongObjectHashMap.java 18 Aug 2002 16:43:15 -0000 1.11 --- TLongObjectHashMap.java 20 Sep 2002 20:55:58 -0000 1.12 *************** *** 103,106 **** --- 103,115 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + TLongObjectHashMap m = (TLongObjectHashMap)super.clone(); + m._values = (Object[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TObjectHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TObjectHash.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TObjectHash.java 18 Aug 2002 19:14:28 -0000 1.12 --- TObjectHash.java 20 Sep 2002 20:55:58 -0000 1.13 *************** *** 116,119 **** --- 116,128 ---- } + /** + * @return a shallow clone of this collection + */ + public Object clone() { + TObjectHash h = (TObjectHash)super.clone(); + h._set = (Object[])this._set.clone(); + return h; + } + protected int capacity() { return _set.length; Index: TPrimitiveHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TPrimitiveHash.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TPrimitiveHash.java 19 Jan 2002 19:40:10 -0000 1.2 --- TPrimitiveHash.java 20 Sep 2002 20:55:58 -0000 1.3 *************** *** 84,87 **** --- 84,93 ---- } + public Object clone() { + TPrimitiveHash h = (TPrimitiveHash)super.clone(); + h._states = (byte[])this._states.clone(); + return h; + } + /** * Returns the capacity of the hash table. This is the true Index: gen_primitive_base.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/gen_primitive_base.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** gen_primitive_base.pl 18 Aug 2002 16:43:15 -0000 1.9 --- gen_primitive_base.pl 20 Sep 2002 20:55:58 -0000 1.10 *************** *** 133,136 **** --- 133,145 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + T<Type>Hash h = (T<Type>Hash)super.clone(); + h._set = (<type>[])this._set.clone(); + return h; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: gen_primitive_map.pl =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/gen_primitive_map.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** gen_primitive_map.pl 18 Aug 2002 16:43:15 -0000 1.11 --- gen_primitive_map.pl 20 Sep 2002 20:55:58 -0000 1.12 *************** *** 251,254 **** --- 251,263 ---- /** + * @return a deep clone of this collection + */ + public Object clone() { + T<KeyType><ValueType>HashMap m = (T<KeyType><ValueType>HashMap)super.clone(); + m._values = (<valueType>[])this._values.clone(); + return m; + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. |
From: Eric F. <er...@us...> - 2002-09-20 20:56:01
|
Update of /cvsroot/trove4j/trove In directory usw-pr-cvs1:/tmp/cvs-serv31441 Modified Files: ChangeLog Log Message: implemented Cloneable interface Index: ChangeLog =================================================================== RCS file: /cvsroot/trove4j/trove/ChangeLog,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ChangeLog 30 Aug 2002 14:26:50 -0000 1.16 --- ChangeLog 20 Sep 2002 20:55:57 -0000 1.17 *************** *** 6,9 **** --- 6,12 ---- Fixed bug 602376 -- ClassCastException n THashMap.putAll + Made all collections implement Cloneable. primitive collections clone deeply; + Object collections produce shallow clones. + v 0.1.6 |
From: Eric F. <er...@us...> - 2002-08-30 14:26:54
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv20573/src/gnu/trove Modified Files: THashMap.java THashMapTests.java Log Message: fixed bug #602376, updated changelog Index: THashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMap.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** THashMap.java 18 Aug 2002 16:43:14 -0000 1.11 --- THashMap.java 30 Aug 2002 14:26:51 -0000 1.12 *************** *** 450,454 **** // could optimize this for cases when map instanceof THashMap for (Iterator i = map.entrySet().iterator(); i.hasNext();) { ! Entry e = (Entry)i.next(); put(e.getKey(),e.getValue()); } --- 450,454 ---- // could optimize this for cases when map instanceof THashMap for (Iterator i = map.entrySet().iterator(); i.hasNext();) { ! Map.Entry e = (Map.Entry)i.next(); put(e.getKey(),e.getValue()); } Index: THashMapTests.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMapTests.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** THashMapTests.java 18 Aug 2002 16:43:14 -0000 1.9 --- THashMapTests.java 30 Aug 2002 14:26:51 -0000 1.10 *************** *** 24,27 **** --- 24,28 ---- import java.util.Iterator; import java.util.Map; + import java.util.HashMap; import java.util.Set; import junit.framework.*; *************** *** 311,314 **** --- 312,324 ---- assertTrue(mm.containsKey("c")); assertEquals("b", mm.get("c")); + } + + public void testPutAll() throws Exception { + THashMap t = new THashMap(); + HashMap m = new HashMap(); + m.put("one","two"); + m.put("two","four"); + m.put("three","six"); + t.putAll(m); } } // THashMapTests |
From: Eric F. <er...@us...> - 2002-08-30 14:26:53
|
Update of /cvsroot/trove4j/trove In directory usw-pr-cvs1:/tmp/cvs-serv20573 Modified Files: ChangeLog Log Message: fixed bug #602376, updated changelog Index: ChangeLog =================================================================== RCS file: /cvsroot/trove4j/trove/ChangeLog,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ChangeLog 19 Apr 2002 03:31:58 -0000 1.15 --- ChangeLog 30 Aug 2002 14:26:50 -0000 1.16 *************** *** 1,2 **** --- 1,33 ---- + v 0.1.7 + + Added hashing strategy interfaces to allow users to implement custom + hashing schemes for optimal distribution for specific data sets. + + Fixed bug 602376 -- ClassCastException n THashMap.putAll + + v 0.1.6 + + Minor bug fix release. + + Two bugs in TIntArrayList have been fixed. Thanks to Jessica P. + Hekman for reporting them. + + One of these prevented toNativeArray from working correctly in + certain circumstances; the other problem was with the depth of + cloning operations. + + One enhancement to TintArrayList has been made -- serialized + instances are now compact -- previous versions relied on serialization + behavior of the backing array, which included empty slots and so + wasted space. + + Serialization of sets/maps has been modified as follows: previously + all of the writeObject methods used a local implementation of the + TXXXProcedure for writing out the data in a particular collection. + These have been replaced by a single class (SerializationProcedure) + which implements all of the appropriate interfaces. This reduces + the number of .class files in the trove jar + + v 0.1.5 |
From: Eric F. <er...@us...> - 2002-08-18 19:14:33
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv9225 Modified Files: TObjectHash.java TObjectIdentityHashingStrategy.java Log Message: javadoc tweaks Index: TObjectHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TObjectHash.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TObjectHash.java 18 Aug 2002 16:43:15 -0000 1.11 --- TObjectHash.java 18 Aug 2002 19:14:28 -0000 1.12 *************** *** 271,275 **** * @param object for which the hashcode is to be computed * @return the hashCode ! * @see Object.hashCode() */ public final int computeHashCode(Object o) { --- 271,275 ---- * @param object for which the hashcode is to be computed * @return the hashCode ! * @see Object#hashCode() */ public final int computeHashCode(Object o) { *************** *** 285,289 **** * @param o2 an <code>Object</code> value * @return true if the objects are equal ! * @see Object.equals() */ public final boolean equals(Object o1, Object o2) { --- 285,289 ---- * @param o2 an <code>Object</code> value * @return true if the objects are equal ! * @see Object#equals(Object) */ public final boolean equals(Object o1, Object o2) { Index: TObjectIdentityHashingStrategy.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TObjectIdentityHashingStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TObjectIdentityHashingStrategy.java 18 Aug 2002 16:43:15 -0000 1.1 --- TObjectIdentityHashingStrategy.java 18 Aug 2002 19:14:28 -0000 1.2 *************** *** 17,25 **** public final class TObjectIdentityHashingStrategy implements TObjectHashingStrategy { /** ! * Delegates hash code computation to the System.identityHashCode() method. * * @param object for which the hashcode is to be computed * @return the hashCode - * @see System.identityHashCode() */ public final int computeHashCode(Object object) { --- 17,24 ---- public final class TObjectIdentityHashingStrategy implements TObjectHashingStrategy { /** ! * Delegates hash code computation to the System.identityHashCode(Object) method. * * @param object for which the hashcode is to be computed * @return the hashCode */ public final int computeHashCode(Object object) { |
From: Eric F. <er...@us...> - 2002-08-18 18:58:05
|
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv4952 Modified Files: package.html Log Message: documented hashing strategies Index: package.html =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/package.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** package.html 19 Nov 2001 00:08:15 -0000 1.3 --- package.html 18 Aug 2002 18:58:02 -0000 1.4 *************** *** 27,76 **** </p> ! <p>Like the JDK implementations, the GNU Trove library's ! <tt>Map</tt> and <tt>Set</tt> classes use <i>hashtables</i> for ! fast insertions, deletions, and searches. Unlike the JDK, GNU ! Trove uses <i>open addressing</i> instead of <i>chaining</i> to ! resolve hashing conflicts. <b>This approach eliminates the need ! to create <tt>java.util.Map.Entry</tt> objects for every element ! in a collection.</b> (As most seasoned Java programmers know, ! Object creation and garbage collection can be very expensive, ! regardless of a presence of a JIT or HotSpot JVM. See Chapter 4 ! of Jack Shirazi's <i>Java Performance Tuning</i> [O'Reilly & ! Associates, 2000] for more information on this topic.)</p> ! <p>A characteristic of hashtables is that they need to expand to ! accomodate data sets that exceed their current capacity. The ! performance of the hashtable is noticeably improved if its size is ! a prime number. For this reason, the GNU Trove hashtables always ! expand to a prime capacity; this behavior is <i>not</i> provided ! by the JDK implementations.</p> ! <p>In a map/set of 100,000 objects, the use of open addressing and ! prime table sizing yields a <b>fourfold speed improvement</b> for ! most operations. Further: the resulting data structures require ! approximately <b>50% of the memory needed by the JDK ! implementations</b>. The memory savings are especially ! significant in the <tt>Set</tt> implementation. Unlike the JDK ! implementation, the GNU Trove sets are not backed by Maps, and so ! do not have to allocate (and copy) large arrays for values that, ! because of the nature of a <tt>Set</tt>, will never be used.</p> ! <p>The Object <tt>Map</tt> and <tt>Set</tt> implementations in GNU ! Trove are designed so that you can trivially replace a JDK ! implementation with a trove implementation: ! <pre> ! import java.util.*; ! import gnu.trove.*; // trove naming conventions ensure no naming conflicts ! [...] ! //Map myMap = new HashMap(); ! Map myMap = new THashMap(); ! </pre> ! A simple Perl or sed script can be used to switch back and forth ! between the JDK and GNU Trove implementations across a large ! codebase as your application requires.</p> <p>N.B. using <tt>Map.entrySet</tt> on a Trove Map is supported, but --- 27,106 ---- </p> ! <p>The Trove maps/sets use open addressing instead of the chaining ! approach taken by the JDK hashtables. This eliminates the need ! to create Map.Entry wrappper objects for every item in a ! table and so reduces the <tt>O</tt> (big-oh) in the performance of ! the hashtable algorithm. The size of the tables used in Trove's maps/sets is ! always a prime number, improving the probability of an optimal distribution ! of entries across the table, and so reducing the the likelihood ! of performance-degrading collisions. Trove sets are not ! backed by maps, and so using a THashSet does not result in ! the allocation of an unused "values" array. ! </p> ! <p>Trove's maps/sets support the use of custom <tt>hashing ! strategies</tt>, allowing you to tune collections based on ! characteristics of the input data. This feature also allows you ! to define hash functions when it is not feasible to override ! Object.hashCode(). For example, the java.lang.String class is ! final, and its implementation of hashCode() takes <tt>O(n)</tt> ! time to complete. In some applications, however, it may be ! possible for a custom hashing function to save time by skipping ! portions of the string that are invariant.</p> ! <p>Using java.util.HashMap, it is not possible to use Java ! language arrays as keys. For example, this code: ! <pre> ! char[] foo, bar; ! foo = new char[] {'a','b','c'}; ! bar = new char[] {'a','b','c'}; ! System.out.println(foo.hashCode() == bar.hashCode() ? "equal" : "not equal"); ! System.out.println(foo.equals(bar) ? "equal" : "not equal"); ! </pre> ! produces this output: ! <pre> ! not equal ! not equal ! </pre> ! And so an entry stored in a java.util.HashMap with foo as a ! key could not be retrieved with bar, since there is no way ! to override hashCode() or equals() on language array objects. ! </p> ! <p>In a gnu.trove.THashMap, however, you can implement a TObjectHashingStrategy ! to enable hashing on arrays: ! <pre> ! class CharArrayStrategy implements TObjectHashingStrategy { ! public int computeHashCode(Object o) { ! char[] c = (char[])o; ! // use the shift-add-xor class of string hashing functions ! // cf. Ramakrishna and Zobel, "Performance in Practice of String Hashing Functions" ! int h = 31; // seed chosen at random ! for (int i = 0; i < c.length; i++) { // could skip invariants ! h = h ^ ((h << 5) + (h >> 2) + c[i]); // L=5, R=2 works well for ASCII input ! } ! return h; ! } ! ! public boolean equals(Object o1, Object o2) { ! char[] c1 = (char[])o1; ! char[] c2 = (char[])o2; ! if (c1.length != c2.length) { // could drop this check for fixed-length keys ! return false; ! } ! for (int i = 0, len = c1.length; i < len; i++) { // could skip invariants ! if (c1[i] != c2[i]) { ! return false; ! } ! } ! return true; ! } ! } ! </pre> ! </p> <p>N.B. using <tt>Map.entrySet</tt> on a Trove Map is supported, but *************** *** 88,92 **** <!-- Created: Sat Nov 10 09:52:57 PST 2001 --> <!-- hhmts start --> ! Last modified: Sat Nov 10 13:39:50 PST 2001 <!-- hhmts end --> </body> --- 118,122 ---- <!-- Created: Sat Nov 10 09:52:57 PST 2001 --> <!-- hhmts start --> ! Last modified: Sun Aug 18 11:18:17 PDT 2002 <!-- hhmts end --> </body> |
Update of /cvsroot/trove4j/trove/src/gnu/trove In directory usw-pr-cvs1:/tmp/cvs-serv3389/src/gnu/trove Modified Files: HashFunctions.java TDoubleDoubleHashMap.java TDoubleFloatHashMap.java TDoubleHash.java TDoubleHashSet.java TDoubleIntHashMap.java TDoubleLongHashMap.java TDoubleObjectHashMap.java TFloatDoubleHashMap.java TFloatFloatHashMap.java TFloatHash.java TFloatHashSet.java TFloatIntHashMap.java TFloatLongHashMap.java TFloatObjectHashMap.java THashMap.java THashMapTests.java THashSet.java THashSetTests.java TIntDoubleHashMap.java TIntFloatHashMap.java TIntHash.java TIntHashSet.java TIntIntHashMap.java TIntLongHashMap.java TIntObjectHashMap.java TLongDoubleHashMap.java TLongFloatHashMap.java TLongHash.java TLongHashSet.java TLongIntHashMap.java TLongLongHashMap.java TLongObjectHashMap.java TObjectDoubleHashMap.java TObjectFloatHashMap.java TObjectHash.java TObjectIntHashMap.java TObjectLongHashMap.java gen_obj_primitive_map.pl gen_primitive_base.pl gen_primitive_map.pl gen_primitive_set.pl Added Files: TDoubleHashingStrategy.java TFloatHashingStrategy.java TIdentityHashMapTests.java TIdentityHashSetTests.java TIntHashingStrategy.java TLongHashingStrategy.java TObjectHashingStrategy.java TObjectIdentityHashingStrategy.java gen_primitive_strategy.pl Log Message: added hashing strategy interfaces to support custom hashing schemes added identity hashing strategy for objects --- NEW FILE: TDoubleHashingStrategy.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; import java.io.Serializable; /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use an optimal strategy when computing hashcodes. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: TDoubleHashingStrategy.java,v 1.1 2002/08/18 16:43:14 ericdf Exp $ */ public interface TDoubleHashingStrategy extends Serializable { /** * Computes a hash code for the specified double. Implementors * can use the double's own value or a custom scheme designed to * minimize collisions for a known set of input. * * @param double for which the hashcode is to be computed * @return the hashCode */ public int computeHashCode(double val); } // TDoubleHashingStrategy --- NEW FILE: TFloatHashingStrategy.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; import java.io.Serializable; /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use an optimal strategy when computing hashcodes. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: TFloatHashingStrategy.java,v 1.1 2002/08/18 16:43:14 ericdf Exp $ */ public interface TFloatHashingStrategy extends Serializable { /** * Computes a hash code for the specified float. Implementors * can use the float's own value or a custom scheme designed to * minimize collisions for a known set of input. * * @param float for which the hashcode is to be computed * @return the hashCode */ public int computeHashCode(float val); } // TFloatHashingStrategy --- NEW FILE: TIdentityHashMapTests.java --- // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. package gnu.trove; /** * * Created: Sat Aug 17 11:22:30 2002 * * @author Eric Friedman * @version $Id: TIdentityHashMapTests.java,v 1.1 2002/08/18 16:43:14 ericdf Exp $ */ public class TIdentityHashMapTests extends THashMapTests { public TIdentityHashMapTests(String name) { super(name); } public void setUp() throws Exception { map = new THashMap(new TObjectIdentityHashingStrategy()); count = 0; } public void testIdentityHash() throws Exception { Integer i1, i2; i1 = new Integer(1); i2 = new Integer(1); map.put(i1,i1); assertTrue(map.containsKey(i1)); assertTrue(! map.containsKey(i2)); } } // TIdentityHashMapTests --- NEW FILE: TIdentityHashSetTests.java --- // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. package gnu.trove; /** * * Created: Sat Aug 17 12:13:03 2002 * * @author Eric Friedman * @version $Id: TIdentityHashSetTests.java,v 1.1 2002/08/18 16:43:14 ericdf Exp $ */ public class TIdentityHashSetTests extends THashSetTests { public TIdentityHashSetTests(String name) { super(name); } public void setUp() throws Exception { super.setUp(); s = new THashSet(new TObjectIdentityHashingStrategy()); } } // TIdentityHashSetTests --- NEW FILE: TIntHashingStrategy.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; import java.io.Serializable; /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use an optimal strategy when computing hashcodes. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: TIntHashingStrategy.java,v 1.1 2002/08/18 16:43:14 ericdf Exp $ */ public interface TIntHashingStrategy extends Serializable { /** * Computes a hash code for the specified int. Implementors * can use the int's own value or a custom scheme designed to * minimize collisions for a known set of input. * * @param int for which the hashcode is to be computed * @return the hashCode */ public int computeHashCode(int val); } // TIntHashingStrategy --- NEW FILE: TLongHashingStrategy.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; import java.io.Serializable; /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use an optimal strategy when computing hashcodes. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: TLongHashingStrategy.java,v 1.1 2002/08/18 16:43:15 ericdf Exp $ */ public interface TLongHashingStrategy extends Serializable { /** * Computes a hash code for the specified long. Implementors * can use the long's own value or a custom scheme designed to * minimize collisions for a known set of input. * * @param long for which the hashcode is to be computed * @return the hashCode */ public int computeHashCode(long val); } // TLongHashingStrategy --- NEW FILE: TObjectHashingStrategy.java --- // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. package gnu.trove; import java.io.Serializable; /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use object values, values provided by the java runtime, * or a custom strategy when computing hashcodes. * * Created: Sat Aug 17 10:52:32 2002 * * @author Eric Friedman * @version $Id: TObjectHashingStrategy.java,v 1.1 2002/08/18 16:43:15 ericdf Exp $ */ public interface TObjectHashingStrategy extends Serializable { /** * Computes a hash code for the specified object. Implementors * can use the object's own <tt>hashCode</tt> method, the Java * runtime's <tt>identityHashCode</tt>, or a custom scheme. * * @param object for which the hashcode is to be computed * @return the hashCode */ public int computeHashCode(Object o); /** * Compares o1 and o2 for equality. Strategy implementors may use * the objects' own equals() methods, compare object references, * or implement some custom scheme. * * @param o1 an <code>Object</code> value * @param o2 an <code>Object</code> value * @return true if the objects are equal according to this strategy. */ public boolean equals(Object o1, Object o2); } // TObjectHashingStrategy --- NEW FILE: TObjectIdentityHashingStrategy.java --- // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. package gnu.trove; /** * This object hashing strategy uses the System.identityHashCode * method to provide identity hash codes. These are identical to the * value produced by Object.hashCode(), even when the type of the * object being hashed overrides that method. * * Created: Sat Aug 17 11:13:15 2002 * * @author Eric Friedman * @version $Id: TObjectIdentityHashingStrategy.java,v 1.1 2002/08/18 16:43:15 ericdf Exp $ */ public final class TObjectIdentityHashingStrategy implements TObjectHashingStrategy { /** * Delegates hash code computation to the System.identityHashCode() method. * * @param object for which the hashcode is to be computed * @return the hashCode * @see System.identityHashCode() */ public final int computeHashCode(Object object) { return System.identityHashCode(object); } /** * Compares object references for equality. * * @param o1 an <code>Object</code> value * @param o2 an <code>Object</code> value * @return true if o1 == o2 */ public final boolean equals(Object o1, Object o2) { return o1 == o2; } } // TObjectIdentityHashingStrategy --- NEW FILE: gen_primitive_strategy.pl --- #!/usr/bin/perl -w use strict; use vars qw($code); my @types = qw(int long double float); for my $type (@types) { my $c = $code; my $i = substr $type, 0, 1; my $Type = ucfirst $type; $c =~ s/<type>/$type/g; $c =~ s/<instance>/val/g; $c =~ s/<Type>/$Type/g; open FH, ">T${Type}HashingStrategy.java" || die $!; print FH $c; close FH; } BEGIN { $code = <<'EOF'; /////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /////////////////////////////////////////////////////////////////////////////// package gnu.trove; import java.io.Serializable; /** * Interface to support pluggable hashing strategies in maps and sets. * Implementors can use this interface to make the trove hashing * algorithms use an optimal strategy when computing hashcodes. * * Created: Sun Nov 4 08:56:06 2001 * * @author Eric D. Friedman * @version $Id: gen_primitive_strategy.pl,v 1.1 2002/08/18 16:43:15 ericdf Exp $ */ public interface T<Type>HashingStrategy extends Serializable { /** * Computes a hash code for the specified <type>. Implementors * can use the <type>'s own value or a custom scheme designed to * minimize collisions for a known set of input. * * @param <type> for which the hashcode is to be computed * @return the hashCode */ public int computeHashCode(<type> <instance>); } // T<Type>HashingStrategy EOF } Index: HashFunctions.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/HashFunctions.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HashFunctions.java 23 Nov 2001 20:33:14 -0000 1.2 --- HashFunctions.java 18 Aug 2002 16:43:14 -0000 1.3 *************** *** 1,107 **** ! // Copyright (c) 1999 CERN - European Organization for Nuclear Research. ! ! // Permission to use, copy, modify, distribute and sell this software and ! // its documentation for any purpose is hereby granted without fee, ! // provided that the above copyright notice appear in all copies and that ! // both that copyright notice and this permission notice appear in ! // supporting documentation. CERN makes no representations about the ! // suitability of this software for any purpose. It is provided "as is" ! // without expressed or implied warranty. ! ! package gnu.trove; ! ! /** ! * Provides various hash functions. ! * ! * @author wol...@ce... ! * @version 1.0, 09/24/99 ! */ ! public final class HashFunctions { ! /** ! * Returns a hashcode for the specified value. ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(double value) { ! long bits = Double.doubleToLongBits(value); ! return (int)(bits ^ (bits >>> 32)); ! //return (int) Double.doubleToLongBits(value*663608941.737); ! //this avoids excessive hashCollisions in the case values are ! //of the form (1.0, 2.0, 3.0, ...) ! } ! ! /** ! * Returns a hashcode for the specified value. ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(float value) { ! return Float.floatToIntBits(value*663608941.737f); ! // this avoids excessive hashCollisions in the case values are ! // of the form (1.0, 2.0, 3.0, ...) ! } ! ! /** ! * Returns a hashcode for the specified value. The hashcode is computed as ! * <blockquote><pre> ! * 31^5*(d[0]*31^(n-1) + d[1]*31^(n-2) + ... + d[n-1]) ! * </pre></blockquote> ! * using <code>int</code> arithmetic, where <code>d[i]</code> is ! * the <i>i</i>th digit of the value, counting from the right, ! * <code>n</code> is the number of decimal digits of the specified ! * value, and <code>^</code> indicates exponentiation. (The hash ! * value of the value zero is zero.) ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(int value) { ! //return value * 0x278DDE6D; // see cern.jet.random.engine.DRand ! ! return value; ! ! /* ! value &= 0x7FFFFFFF; // make it >=0 ! int hashCode = 0; ! do hashCode = 31*hashCode + value%10; ! while ((value /= 10) > 0); ! ! return 28629151*hashCode; // spread even further; h*31^5 ! */ ! } ! ! /** ! * Returns a hashcode for the specified value. ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(long value) { ! return (int)(value ^ (value >> 32)); ! ! /* ! * The hashcode is computed as ! * <blockquote><pre> ! * 31^5*(d[0]*31^(n-1) + d[1]*31^(n-2) + ... + d[n-1]) ! * </pre></blockquote> ! * using <code>int</code> arithmetic, where <code>d[i]</code> is the ! * <i>i</i>th digit of the value, counting from the right, <code>n</code> is the number of decimal digits of the specified value, ! * and <code>^</code> indicates exponentiation. ! * (The hash value of the value zero is zero.) ! ! value &= 0x7FFFFFFFFFFFFFFFL; // make it >=0 (0x7FFFFFFFFFFFFFFFL==Long.MAX_VALUE) ! int hashCode = 0; ! do hashCode = 31*hashCode + (int) (value%10); ! while ((value /= 10) > 0); ! ! return 28629151*hashCode; // spread even further; h*31^5 ! */ ! } ! ! /** ! * Returns a hashcode for the specified object. ! * ! * @return a hash code value for the specified object. ! */ ! public static final int hash(Object object) { ! return object==null ? 0 : object.hashCode(); ! } ! } --- 1,107 ---- ! // Copyright (c) 1999 CERN - European Organization for Nuclear Research. ! ! // Permission to use, copy, modify, distribute and sell this software and ! // its documentation for any purpose is hereby granted without fee, ! // provided that the above copyright notice appear in all copies and that ! // both that copyright notice and this permission notice appear in ! // supporting documentation. CERN makes no representations about the ! // suitability of this software for any purpose. It is provided "as is" ! // without expressed or implied warranty. ! ! package gnu.trove; ! ! /** ! * Provides various hash functions. ! * ! * @author wol...@ce... ! * @version 1.0, 09/24/99 ! */ ! public final class HashFunctions { ! /** ! * Returns a hashcode for the specified value. ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(double value) { ! long bits = Double.doubleToLongBits(value); ! return (int)(bits ^ (bits >>> 32)); ! //return (int) Double.doubleToLongBits(value*663608941.737); ! //this avoids excessive hashCollisions in the case values are ! //of the form (1.0, 2.0, 3.0, ...) ! } ! ! /** ! * Returns a hashcode for the specified value. ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(float value) { ! return Float.floatToIntBits(value*663608941.737f); ! // this avoids excessive hashCollisions in the case values are ! // of the form (1.0, 2.0, 3.0, ...) ! } ! ! /** ! * Returns a hashcode for the specified value. The hashcode is computed as ! * <blockquote><pre> ! * 31^5*(d[0]*31^(n-1) + d[1]*31^(n-2) + ... + d[n-1]) ! * </pre></blockquote> ! * using <code>int</code> arithmetic, where <code>d[i]</code> is ! * the <i>i</i>th digit of the value, counting from the right, ! * <code>n</code> is the number of decimal digits of the specified ! * value, and <code>^</code> indicates exponentiation. (The hash ! * value of the value zero is zero.) ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(int value) { ! //return value * 0x278DDE6D; // see cern.jet.random.engine.DRand ! ! return value; ! ! /* ! value &= 0x7FFFFFFF; // make it >=0 ! int hashCode = 0; ! do hashCode = 31*hashCode + value%10; ! while ((value /= 10) > 0); ! ! return 28629151*hashCode; // spread even further; h*31^5 ! */ ! } ! ! /** ! * Returns a hashcode for the specified value. ! * ! * @return a hash code value for the specified value. ! */ ! public static final int hash(long value) { ! return (int)(value ^ (value >> 32)); ! ! /* ! * The hashcode is computed as ! * <blockquote><pre> ! * 31^5*(d[0]*31^(n-1) + d[1]*31^(n-2) + ... + d[n-1]) ! * </pre></blockquote> ! * using <code>int</code> arithmetic, where <code>d[i]</code> is the ! * <i>i</i>th digit of the value, counting from the right, <code>n</code> is the number of decimal digits of the specified value, ! * and <code>^</code> indicates exponentiation. ! * (The hash value of the value zero is zero.) ! ! value &= 0x7FFFFFFFFFFFFFFFL; // make it >=0 (0x7FFFFFFFFFFFFFFFL==Long.MAX_VALUE) ! int hashCode = 0; ! do hashCode = 31*hashCode + (int) (value%10); ! while ((value /= 10) > 0); ! ! return 28629151*hashCode; // spread even further; h*31^5 ! */ ! } ! ! /** ! * Returns a hashcode for the specified object. ! * ! * @return a hash code value for the specified object. ! */ ! public static final int hash(Object object) { ! return object==null ? 0 : object.hashCode(); ! } ! } Index: TDoubleDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleDoubleHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleDoubleHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TDoubleDoubleHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TDoubleDoubleHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleDoubleHashMap(TDoubleHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TDoubleDoubleHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleDoubleHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TDoubleDoubleHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleDoubleHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleFloatHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleFloatHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TDoubleFloatHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TDoubleFloatHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleFloatHashMap(TDoubleHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TDoubleFloatHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleFloatHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TDoubleFloatHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleFloatHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleHash.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TDoubleHash.java 8 Jul 2002 00:51:20 -0000 1.9 --- TDoubleHash.java 18 Aug 2002 16:43:14 -0000 1.10 *************** *** 31,39 **** abstract public class TDoubleHash extends TPrimitiveHash ! implements Serializable { /** the set of doubles */ protected transient double[] _set; /** * Creates a new <code>TDoubleHash</code> instance with the default --- 31,42 ---- abstract public class TDoubleHash extends TPrimitiveHash ! implements Serializable, TDoubleHashingStrategy { /** the set of doubles */ protected transient double[] _set; + /** strategy used to hash values in this collection */ + private TDoubleHashingStrategy hashingStrategy; + /** * Creates a new <code>TDoubleHash</code> instance with the default *************** *** 42,45 **** --- 45,49 ---- public TDoubleHash() { super(); + this.hashingStrategy = this; } *************** *** 53,56 **** --- 57,61 ---- public TDoubleHash(int initialCapacity) { super(initialCapacity); + this.hashingStrategy = this; } *************** *** 65,68 **** --- 70,111 ---- public TDoubleHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); + this.hashingStrategy = this; + } + + /** + * Creates a new <code>TDoubleHash</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare objects. + */ + public TDoubleHash(TDoubleHashingStrategy strategy) { + super(); + this.hashingStrategy = strategy; + } + + /** + * Creates a new <code>TDoubleHash</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare objects. + */ + public TDoubleHash(int initialCapacity, TDoubleHashingStrategy strategy) { + super(initialCapacity); + this.hashingStrategy = strategy; + } + + /** + * Creates a new <code>TDoubleHash</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare objects. + */ + public TDoubleHash(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { + super(initialCapacity, loadFactor); + this.hashingStrategy = strategy; } *************** *** 134,138 **** set = _set; length = states.length; ! hash = HashFunctions.hash(val) & 0x7fffffff; index = hash % length; --- 177,181 ---- set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 170,174 **** set = _set; length = states.length; ! hash = HashFunctions.hash(val) & 0x7fffffff; index = hash % length; --- 213,217 ---- set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 208,210 **** --- 251,263 ---- } + /** + * Default implementation of TDoubleHashingStrategy: + * delegates hashing to HashFunctions.hash(double). + * + * @param the value to hash + * @return the hashcode. + */ + public final int computeHashCode(double val) { + return HashFunctions.hash(val); + } } // TDoubleHash Index: TDoubleHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleHashSet.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TDoubleHashSet.java 8 Jul 2002 00:51:20 -0000 1.7 --- TDoubleHashSet.java 18 Aug 2002 16:43:14 -0000 1.8 *************** *** 80,83 **** --- 80,128 ---- /** + * Creates a new <code>TDoubleHash</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleHashSet(TDoubleHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TDoubleHash</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleHashSet(int initialCapacity, TDoubleHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TDoubleHash</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleHashSet(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** + * Creates a new <code>TDoubleHashSet</code> instance containing the + * elements of <tt>array</tt>. + * + * @param array an array of <code>double</code> primitives + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleHashSet(double[] array, TDoubleHashingStrategy strategy) { + this(array.length, strategy); + addAll(array); + } + /** * Inserts a value into the set. * Index: TDoubleIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleIntHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleIntHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TDoubleIntHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TDoubleIntHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleIntHashMap(TDoubleHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TDoubleIntHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleIntHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TDoubleIntHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleIntHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleLongHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleLongHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TDoubleLongHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TDoubleLongHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleLongHashMap(TDoubleHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TDoubleLongHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleLongHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TDoubleLongHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleLongHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TDoubleObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TDoubleObjectHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TDoubleObjectHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TDoubleObjectHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TDoubleObjectHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleObjectHashMap(TDoubleHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TDoubleObjectHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleObjectHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TDoubleObjectHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TDoubleObjectHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatDoubleHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatDoubleHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatDoubleHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TFloatDoubleHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TFloatDoubleHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatDoubleHashMap(TFloatHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TFloatDoubleHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatDoubleHashMap(int initialCapacity, TFloatHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TFloatDoubleHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatDoubleHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatFloatHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatFloatHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatFloatHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TFloatFloatHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TFloatFloatHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatFloatHashMap(TFloatHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TFloatFloatHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatFloatHashMap(int initialCapacity, TFloatHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TFloatFloatHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatFloatHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatHash.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatHash.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TFloatHash.java 8 Jul 2002 00:51:20 -0000 1.9 --- TFloatHash.java 18 Aug 2002 16:43:14 -0000 1.10 *************** *** 31,39 **** abstract public class TFloatHash extends TPrimitiveHash ! implements Serializable { /** the set of floats */ protected transient float[] _set; /** * Creates a new <code>TFloatHash</code> instance with the default --- 31,42 ---- abstract public class TFloatHash extends TPrimitiveHash ! implements Serializable, TFloatHashingStrategy { /** the set of floats */ protected transient float[] _set; + /** strategy used to hash values in this collection */ + private TFloatHashingStrategy hashingStrategy; + /** * Creates a new <code>TFloatHash</code> instance with the default *************** *** 42,45 **** --- 45,49 ---- public TFloatHash() { super(); + this.hashingStrategy = this; } *************** *** 53,56 **** --- 57,61 ---- public TFloatHash(int initialCapacity) { super(initialCapacity); + this.hashingStrategy = this; } *************** *** 65,68 **** --- 70,111 ---- public TFloatHash(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); + this.hashingStrategy = this; + } + + /** + * Creates a new <code>TFloatHash</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare objects. + */ + public TFloatHash(TFloatHashingStrategy strategy) { + super(); + this.hashingStrategy = strategy; + } + + /** + * Creates a new <code>TFloatHash</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare objects. + */ + public TFloatHash(int initialCapacity, TFloatHashingStrategy strategy) { + super(initialCapacity); + this.hashingStrategy = strategy; + } + + /** + * Creates a new <code>TFloatHash</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare objects. + */ + public TFloatHash(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { + super(initialCapacity, loadFactor); + this.hashingStrategy = strategy; } *************** *** 134,138 **** set = _set; length = states.length; ! hash = HashFunctions.hash(val) & 0x7fffffff; index = hash % length; --- 177,181 ---- set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 170,174 **** set = _set; length = states.length; ! hash = HashFunctions.hash(val) & 0x7fffffff; index = hash % length; --- 213,217 ---- set = _set; length = states.length; ! hash = hashingStrategy.computeHashCode(val) & 0x7fffffff; index = hash % length; *************** *** 208,210 **** --- 251,263 ---- } + /** + * Default implementation of TFloatHashingStrategy: + * delegates hashing to HashFunctions.hash(float). + * + * @param the value to hash + * @return the hashcode. + */ + public final int computeHashCode(float val) { + return HashFunctions.hash(val); + } } // TFloatHash Index: TFloatHashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatHashSet.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TFloatHashSet.java 8 Jul 2002 00:51:20 -0000 1.7 --- TFloatHashSet.java 18 Aug 2002 16:43:14 -0000 1.8 *************** *** 80,83 **** --- 80,128 ---- /** + * Creates a new <code>TFloatHash</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatHashSet(TFloatHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TFloatHash</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatHashSet(int initialCapacity, TFloatHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TFloatHash</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatHashSet(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** + * Creates a new <code>TFloatHashSet</code> instance containing the + * elements of <tt>array</tt>. + * + * @param array an array of <code>float</code> primitives + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatHashSet(float[] array, TFloatHashingStrategy strategy) { + this(array.length, strategy); + addAll(array); + } + /** * Inserts a value into the set. * Index: TFloatIntHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatIntHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatIntHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TFloatIntHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TFloatIntHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatIntHashMap(TFloatHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TFloatIntHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatIntHashMap(int initialCapacity, TFloatHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TFloatIntHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatIntHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatLongHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatLongHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatLongHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TFloatLongHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TFloatLongHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatLongHashMap(TFloatHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TFloatLongHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatLongHashMap(int initialCapacity, TFloatHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TFloatLongHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatLongHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: TFloatObjectHashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/TFloatObjectHashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TFloatObjectHashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- TFloatObjectHashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 69,72 **** --- 69,106 ---- /** + * Creates a new <code>TFloatObjectHashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatObjectHashMap(TFloatHashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new <code>TFloatObjectHashMap</code> instance whose capacity + * is the next highest prime above <tt>initialCapacity + 1</tt> + * unless that value is already prime. + * + * @param initialCapacity an <code>int</code> value + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatObjectHashMap(int initialCapacity, TFloatHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>TFloatObjectHashMap</code> instance with a prime + * value at or near the specified capacity and load factor. + * + * @param initialCapacity used to find a prime capacity for the table. + * @param loadFactor used to calculate the threshold over which + * rehashing takes place. + * @param strategy used to compute hash codes and to compare keys. + */ + public TFloatObjectHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * initializes the hashtable to a prime capacity which is at least * <tt>initialCapacity + 1</tt>. Index: THashMap.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMap.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** THashMap.java 8 Jul 2002 00:51:20 -0000 1.10 --- THashMap.java 18 Aug 2002 16:43:14 -0000 1.11 *************** *** 54,57 **** --- 54,66 ---- /** + * Creates a new <code>THashMap</code> instance with the default + * capacity and load factor. + * @param strategy used to compute hash codes and to compare objects. + */ + public THashMap(TObjectHashingStrategy strategy) { + super(strategy); + } + + /** * Creates a new <code>THashMap</code> instance with a prime * capacity equal to or greater than <tt>initialCapacity</tt> and *************** *** 67,70 **** --- 76,91 ---- * Creates a new <code>THashMap</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 + * @param strategy used to compute hash codes and to compare objects. + */ + public THashMap(int initialCapacity, TObjectHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + /** + * Creates a new <code>THashMap</code> instance with a prime + * capacity equal to or greater than <tt>initialCapacity</tt> and * with the specified load factor. * *************** *** 77,80 **** --- 98,114 ---- /** + * Creates a new <code>THashMap</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 strategy used to compute hash codes and to compare objects. + */ + public THashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { + super(initialCapacity, loadFactor, strategy); + } + + /** * Creates a new <code>THashMap</code> instance which contains the * key/value pairs in <tt>map</tt>. *************** *** 84,87 **** --- 118,133 ---- public THashMap(Map map) { this(map.size()); + putAll(map); + } + + /** + * Creates a new <code>THashMap</code> instance which contains the + * key/value pairs in <tt>map</tt>. + * + * @param map a <code>Map</code> value + * @param strategy used to compute hash codes and to compare objects. + */ + public THashMap(Map map, TObjectHashingStrategy strategy) { + this(map.size(), strategy); putAll(map); } Index: THashMapTests.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashMapTests.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** THashMapTests.java 19 Apr 2002 03:31:58 -0000 1.8 --- THashMapTests.java 18 Aug 2002 16:43:14 -0000 1.9 *************** *** 45,48 **** --- 45,49 ---- public void setUp() throws Exception { + super.setUp(); map = new THashMap(); count = 0; *************** *** 50,53 **** --- 51,55 ---- public void tearDown() throws Exception { + super.tearDown(); map = null; count = 0; *************** *** 212,222 **** public void testCompact() throws Exception { for (int i = 0; i < 1000; i++) { ! Integer x = new Integer(i); ! map.put(x,x); } assertTrue(map._maxSize > 1000); for (int i = 0; i < 500; i++) { ! map.remove(new Integer(i)); } assertEquals(500, map.size()); --- 214,226 ---- public void testCompact() throws Exception { + Integer[] data = new Integer[1000]; + for (int i = 0; i < 1000; i++) { ! data[i] = new Integer(i); ! map.put(data[i], data[i]); } assertTrue(map._maxSize > 1000); for (int i = 0; i < 500; i++) { ! map.remove(data[i]); } assertEquals(500, map.size()); Index: THashSet.java =================================================================== RCS file: /cvsroot/trove4j/trove/src/gnu/trove/THashSet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** THashSet.java 8 Jul 2002 00:51:20 -0000 1.8 --- THashSet.java 18 Aug 2002 16:43:14 -0000 1.9... [truncated message content] |
From: Eric F. <er...@us...> - 2002-08-18 16:43:17
|
Update of /cvsroot/trove4j/trove In directory usw-pr-cvs1:/tmp/cvs-serv3389 Modified Files: build.xml Log Message: added hashing strategy interfaces to support custom hashing schemes added identity hashing strategy for objects Index: build.xml =================================================================== RCS file: /cvsroot/trove4j/trove/build.xml,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** build.xml 8 Jul 2002 00:51:20 -0000 1.20 --- build.xml 18 Aug 2002 16:43:14 -0000 1.21 *************** *** 161,165 **** depends="junit,jar,compile_tests" if="junit.present"> ! <junit> <classpath> <path refid="build.classpath" /> --- 161,165 ---- depends="junit,jar,compile_tests" if="junit.present"> ! <junit haltonfailure="true"> <classpath> <path refid="build.classpath" /> |