byte
value
+ * @return true if the collection contains the specified element.
+ */
+ boolean contains( byte entry );
+
+
+ /**
+ * Creates an iterator over the values of the collection. The iterator
+ * supports element deletion.
+ *
+ * @return an TByteIterator
value
+ */
+ TByteIterator iterator();
+
+
+ /**
+ * Returns an array containing all of the elements in this collection.
+ * If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the
+ * elements in the same order.
+ *
+ * The returned array will be "safe" in that no references to it + * are maintained by this collection. (In other words, this method must + * allocate a new array even if this collection is backed by an array). + * The caller is thus free to modify the returned array. + * + *
This method acts as bridge between array-based and collection-based + * APIs. + * + * @return an array containing all the elements in this collection + */ + byte[] toArray(); + + + /** + * Returns an array containing elements in this collection. + * + *
If this collection fits in the specified array with room to spare + * (i.e., the array has more elements than this collection), the element in + * the array immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining + * the length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *
If the native array is smaller than the collection size, + * the array will be filled with elements in Iterator order + * until it is full and exclude the remainder. + * + *
If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the elements
+ * in the same order.
+ *
+ * @param dest the array into which the elements of this collection are to be
+ * stored.
+ * @return an byte[] containing all the elements in this collection
+ * @throws NullPointerException if the specified array is null
+ */
+ byte[] toArray( byte[] dest );
+
+
+ /**
+ * Inserts a value into the collection.
+ *
+ * @param entry a byte
value
+ * @return true if the collection was modified by the add operation
+ */
+ boolean add( byte entry );
+
+
+ /**
+ * Removes entry from the collection.
+ *
+ * @param entry an byte
value
+ * @return true if the collection was modified by the remove operation.
+ */
+ boolean remove( byte entry );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * collection are present.
+ *
+ * @param collection a Collection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( Collection> collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * TByteCollection are present.
+ *
+ * @param collection a TByteCollection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( TByteCollection collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * array are present.
+ *
+ * @param array as array
of byte primitives.
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( byte[] array );
+
+
+ /**
+ * Adds all of the elements in collection to the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( Collection extends Byte> collection );
+
+
+ /**
+ * Adds all of the elements in the TByteCollection to the collection.
+ *
+ * @param collection a TByteCollection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( TByteCollection collection );
+
+
+ /**
+ * Adds all of the elements in the array to the collection.
+ *
+ * @param array a array
of byte primitives.
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( byte[] array );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( Collection> collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * TByteCollection.
+ *
+ * @param collection a TByteCollection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( TByteCollection collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * array.
+ *
+ * @param array an array
of byte primitives.
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( byte[] array );
+
+
+ /**
+ * Removes all of the elements in collection from the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( Collection> collection );
+
+
+ /**
+ * Removes all of the elements in TByteCollection from the collection.
+ *
+ * @param collection a TByteCollection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( TByteCollection collection );
+
+
+ /**
+ * Removes all of the elements in array from the collection.
+ *
+ * @param array an array
of byte primitives.
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( byte[] array );
+
+
+ /**
+ * Empties the collection.
+ */
+ void clear();
+
+
+ /**
+ * Executes procedure for each element in the collection.
+ *
+ * @param procedure a TByteProcedure
value
+ * @return false if the loop over the collection terminated because
+ * the procedure returned false for some value.
+ */
+ boolean forEach( TByteProcedure procedure );
+
+
+ // Comparison and hashing
+
+ /**
+ * Compares the specified object with this collection for equality. Returns
+ * true if the specified object is also a collection, the two collection
+ * have the same size, and every member of the specified collection is
+ * contained in this collection (or equivalently, every member of this collection is
+ * contained in the specified collection). This definition ensures that the
+ * equals method works properly across different implementations of the
+ * collection interface.
+ *
+ * @param o object to be compared for equality with this collection
+ * @return true if the specified object is equal to this collection
+ */
+ boolean equals( Object o );
+
+
+ /**
+ * Returns the hash code value for this collection. The hash code of a collection is
+ * defined to be the sum of the hash codes of the elements in the collection.
+ * This ensures that s1.equals(s2) implies that
+ * s1.hashCode()==s2.hashCode() for any two collection s1
+ * and s2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this collection
+ * @see Object#equals(Object)
+ * @see Collection#equals(Object)
+ */
+ int hashCode();
+
+
+} // TByteCollection
diff --git a/src/gnu/trove/TCharCollection.java b/src/gnu/trove/TCharCollection.java
new file mode 100644
index 00000000..79b33657
--- /dev/null
+++ b/src/gnu/trove/TCharCollection.java
@@ -0,0 +1,317 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove;
+
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+import gnu.trove.iterator.TCharIterator;
+import gnu.trove.procedure.TCharProcedure;
+
+import java.util.Collection;
+import java.io.Serializable;
+
+/**
+ * An interface that mimics the Collection interface.
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden
+ * @author Jeff Randall
+ * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 upholderoftruth Exp $
+ */
+
+public interface TCharCollection {
+ static final long serialVersionUID = 1L;
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ char getNoEntryValue();
+
+
+ /**
+ * Returns the number of elements in this collection (its cardinality). If this
+ * collection contains more than Integer.MAX_VALUE elements, returns
+ * Integer.MAX_VALUE.
+ *
+ * @return the number of elements in this collection (its cardinality)
+ */
+ int size();
+
+
+ /**
+ * Returns true if this collection contains no elements.
+ *
+ * @return true if this collection contains no elements
+ */
+ boolean isEmpty();
+
+
+ /**
+ * Returns true if this collection contains the specified element.
+ *
+ * @param entry an char
value
+ * @return true if the collection contains the specified element.
+ */
+ boolean contains( char entry );
+
+
+ /**
+ * Creates an iterator over the values of the collection. The iterator
+ * supports element deletion.
+ *
+ * @return an TCharIterator
value
+ */
+ TCharIterator iterator();
+
+
+ /**
+ * Returns an array containing all of the elements in this collection.
+ * If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the
+ * elements in the same order.
+ *
+ *
The returned array will be "safe" in that no references to it + * are maintained by this collection. (In other words, this method must + * allocate a new array even if this collection is backed by an array). + * The caller is thus free to modify the returned array. + * + *
This method acts as bridge between array-based and collection-based + * APIs. + * + * @return an array containing all the elements in this collection + */ + char[] toArray(); + + + /** + * Returns an array containing elements in this collection. + * + *
If this collection fits in the specified array with room to spare + * (i.e., the array has more elements than this collection), the element in + * the array immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining + * the length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *
If the native array is smaller than the collection size, + * the array will be filled with elements in Iterator order + * until it is full and exclude the remainder. + * + *
If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the elements
+ * in the same order.
+ *
+ * @param dest the array into which the elements of this collection are to be
+ * stored.
+ * @return an char[] containing all the elements in this collection
+ * @throws NullPointerException if the specified array is null
+ */
+ char[] toArray( char[] dest );
+
+
+ /**
+ * Inserts a value into the collection.
+ *
+ * @param entry a char
value
+ * @return true if the collection was modified by the add operation
+ */
+ boolean add( char entry );
+
+
+ /**
+ * Removes entry from the collection.
+ *
+ * @param entry an char
value
+ * @return true if the collection was modified by the remove operation.
+ */
+ boolean remove( char entry );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * collection are present.
+ *
+ * @param collection a Collection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( Collection> collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * TCharCollection are present.
+ *
+ * @param collection a TCharCollection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( TCharCollection collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * array are present.
+ *
+ * @param array as array
of char primitives.
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( char[] array );
+
+
+ /**
+ * Adds all of the elements in collection to the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( Collection extends Character> collection );
+
+
+ /**
+ * Adds all of the elements in the TCharCollection to the collection.
+ *
+ * @param collection a TCharCollection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( TCharCollection collection );
+
+
+ /**
+ * Adds all of the elements in the array to the collection.
+ *
+ * @param array a array
of char primitives.
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( char[] array );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( Collection> collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * TCharCollection.
+ *
+ * @param collection a TCharCollection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( TCharCollection collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * array.
+ *
+ * @param array an array
of char primitives.
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( char[] array );
+
+
+ /**
+ * Removes all of the elements in collection from the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( Collection> collection );
+
+
+ /**
+ * Removes all of the elements in TCharCollection from the collection.
+ *
+ * @param collection a TCharCollection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( TCharCollection collection );
+
+
+ /**
+ * Removes all of the elements in array from the collection.
+ *
+ * @param array an array
of char primitives.
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( char[] array );
+
+
+ /**
+ * Empties the collection.
+ */
+ void clear();
+
+
+ /**
+ * Executes procedure for each element in the collection.
+ *
+ * @param procedure a TCharProcedure
value
+ * @return false if the loop over the collection terminated because
+ * the procedure returned false for some value.
+ */
+ boolean forEach( TCharProcedure procedure );
+
+
+ // Comparison and hashing
+
+ /**
+ * Compares the specified object with this collection for equality. Returns
+ * true if the specified object is also a collection, the two collection
+ * have the same size, and every member of the specified collection is
+ * contained in this collection (or equivalently, every member of this collection is
+ * contained in the specified collection). This definition ensures that the
+ * equals method works properly across different implementations of the
+ * collection interface.
+ *
+ * @param o object to be compared for equality with this collection
+ * @return true if the specified object is equal to this collection
+ */
+ boolean equals( Object o );
+
+
+ /**
+ * Returns the hash code value for this collection. The hash code of a collection is
+ * defined to be the sum of the hash codes of the elements in the collection.
+ * This ensures that s1.equals(s2) implies that
+ * s1.hashCode()==s2.hashCode() for any two collection s1
+ * and s2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this collection
+ * @see Object#equals(Object)
+ * @see Collection#equals(Object)
+ */
+ int hashCode();
+
+
+} // TCharCollection
diff --git a/src/gnu/trove/TDoubleCollection.java b/src/gnu/trove/TDoubleCollection.java
new file mode 100644
index 00000000..531e2611
--- /dev/null
+++ b/src/gnu/trove/TDoubleCollection.java
@@ -0,0 +1,317 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove;
+
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+import gnu.trove.iterator.TDoubleIterator;
+import gnu.trove.procedure.TDoubleProcedure;
+
+import java.util.Collection;
+import java.io.Serializable;
+
+/**
+ * An interface that mimics the Collection interface.
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden
+ * @author Jeff Randall
+ * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 upholderoftruth Exp $
+ */
+
+public interface TDoubleCollection {
+ static final long serialVersionUID = 1L;
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ double getNoEntryValue();
+
+
+ /**
+ * Returns the number of elements in this collection (its cardinality). If this
+ * collection contains more than Integer.MAX_VALUE elements, returns
+ * Integer.MAX_VALUE.
+ *
+ * @return the number of elements in this collection (its cardinality)
+ */
+ int size();
+
+
+ /**
+ * Returns true if this collection contains no elements.
+ *
+ * @return true if this collection contains no elements
+ */
+ boolean isEmpty();
+
+
+ /**
+ * Returns true if this collection contains the specified element.
+ *
+ * @param entry an double
value
+ * @return true if the collection contains the specified element.
+ */
+ boolean contains( double entry );
+
+
+ /**
+ * Creates an iterator over the values of the collection. The iterator
+ * supports element deletion.
+ *
+ * @return an TDoubleIterator
value
+ */
+ TDoubleIterator iterator();
+
+
+ /**
+ * Returns an array containing all of the elements in this collection.
+ * If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the
+ * elements in the same order.
+ *
+ *
The returned array will be "safe" in that no references to it + * are maintained by this collection. (In other words, this method must + * allocate a new array even if this collection is backed by an array). + * The caller is thus free to modify the returned array. + * + *
This method acts as bridge between array-based and collection-based + * APIs. + * + * @return an array containing all the elements in this collection + */ + double[] toArray(); + + + /** + * Returns an array containing elements in this collection. + * + *
If this collection fits in the specified array with room to spare + * (i.e., the array has more elements than this collection), the element in + * the array immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining + * the length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *
If the native array is smaller than the collection size, + * the array will be filled with elements in Iterator order + * until it is full and exclude the remainder. + * + *
If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the elements
+ * in the same order.
+ *
+ * @param dest the array into which the elements of this collection are to be
+ * stored.
+ * @return an double[] containing all the elements in this collection
+ * @throws NullPointerException if the specified array is null
+ */
+ double[] toArray( double[] dest );
+
+
+ /**
+ * Inserts a value into the collection.
+ *
+ * @param entry a double
value
+ * @return true if the collection was modified by the add operation
+ */
+ boolean add( double entry );
+
+
+ /**
+ * Removes entry from the collection.
+ *
+ * @param entry an double
value
+ * @return true if the collection was modified by the remove operation.
+ */
+ boolean remove( double entry );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * collection are present.
+ *
+ * @param collection a Collection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( Collection> collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * TDoubleCollection are present.
+ *
+ * @param collection a TDoubleCollection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( TDoubleCollection collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * array are present.
+ *
+ * @param array as array
of double primitives.
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( double[] array );
+
+
+ /**
+ * Adds all of the elements in collection to the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( Collection extends Double> collection );
+
+
+ /**
+ * Adds all of the elements in the TDoubleCollection to the collection.
+ *
+ * @param collection a TDoubleCollection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( TDoubleCollection collection );
+
+
+ /**
+ * Adds all of the elements in the array to the collection.
+ *
+ * @param array a array
of double primitives.
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( double[] array );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( Collection> collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * TDoubleCollection.
+ *
+ * @param collection a TDoubleCollection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( TDoubleCollection collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * array.
+ *
+ * @param array an array
of double primitives.
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( double[] array );
+
+
+ /**
+ * Removes all of the elements in collection from the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( Collection> collection );
+
+
+ /**
+ * Removes all of the elements in TDoubleCollection from the collection.
+ *
+ * @param collection a TDoubleCollection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( TDoubleCollection collection );
+
+
+ /**
+ * Removes all of the elements in array from the collection.
+ *
+ * @param array an array
of double primitives.
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( double[] array );
+
+
+ /**
+ * Empties the collection.
+ */
+ void clear();
+
+
+ /**
+ * Executes procedure for each element in the collection.
+ *
+ * @param procedure a TDoubleProcedure
value
+ * @return false if the loop over the collection terminated because
+ * the procedure returned false for some value.
+ */
+ boolean forEach( TDoubleProcedure procedure );
+
+
+ // Comparison and hashing
+
+ /**
+ * Compares the specified object with this collection for equality. Returns
+ * true if the specified object is also a collection, the two collection
+ * have the same size, and every member of the specified collection is
+ * contained in this collection (or equivalently, every member of this collection is
+ * contained in the specified collection). This definition ensures that the
+ * equals method works properly across different implementations of the
+ * collection interface.
+ *
+ * @param o object to be compared for equality with this collection
+ * @return true if the specified object is equal to this collection
+ */
+ boolean equals( Object o );
+
+
+ /**
+ * Returns the hash code value for this collection. The hash code of a collection is
+ * defined to be the sum of the hash codes of the elements in the collection.
+ * This ensures that s1.equals(s2) implies that
+ * s1.hashCode()==s2.hashCode() for any two collection s1
+ * and s2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this collection
+ * @see Object#equals(Object)
+ * @see Collection#equals(Object)
+ */
+ int hashCode();
+
+
+} // TDoubleCollection
diff --git a/src/gnu/trove/TIntCollection.java b/src/gnu/trove/TIntCollection.java
new file mode 100644
index 00000000..7a9fbf4a
--- /dev/null
+++ b/src/gnu/trove/TIntCollection.java
@@ -0,0 +1,317 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove;
+
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+import gnu.trove.iterator.TIntIterator;
+import gnu.trove.procedure.TIntProcedure;
+
+import java.util.Collection;
+import java.io.Serializable;
+
+/**
+ * An interface that mimics the Collection interface.
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden
+ * @author Jeff Randall
+ * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 upholderoftruth Exp $
+ */
+
+public interface TIntCollection {
+ static final long serialVersionUID = 1L;
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ int getNoEntryValue();
+
+
+ /**
+ * Returns the number of elements in this collection (its cardinality). If this
+ * collection contains more than Integer.MAX_VALUE elements, returns
+ * Integer.MAX_VALUE.
+ *
+ * @return the number of elements in this collection (its cardinality)
+ */
+ int size();
+
+
+ /**
+ * Returns true if this collection contains no elements.
+ *
+ * @return true if this collection contains no elements
+ */
+ boolean isEmpty();
+
+
+ /**
+ * Returns true if this collection contains the specified element.
+ *
+ * @param entry an int
value
+ * @return true if the collection contains the specified element.
+ */
+ boolean contains( int entry );
+
+
+ /**
+ * Creates an iterator over the values of the collection. The iterator
+ * supports element deletion.
+ *
+ * @return an TIntIterator
value
+ */
+ TIntIterator iterator();
+
+
+ /**
+ * Returns an array containing all of the elements in this collection.
+ * If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the
+ * elements in the same order.
+ *
+ *
The returned array will be "safe" in that no references to it + * are maintained by this collection. (In other words, this method must + * allocate a new array even if this collection is backed by an array). + * The caller is thus free to modify the returned array. + * + *
This method acts as bridge between array-based and collection-based + * APIs. + * + * @return an array containing all the elements in this collection + */ + int[] toArray(); + + + /** + * Returns an array containing elements in this collection. + * + *
If this collection fits in the specified array with room to spare + * (i.e., the array has more elements than this collection), the element in + * the array immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining + * the length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *
If the native array is smaller than the collection size, + * the array will be filled with elements in Iterator order + * until it is full and exclude the remainder. + * + *
If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the elements
+ * in the same order.
+ *
+ * @param dest the array into which the elements of this collection are to be
+ * stored.
+ * @return an int[] containing all the elements in this collection
+ * @throws NullPointerException if the specified array is null
+ */
+ int[] toArray( int[] dest );
+
+
+ /**
+ * Inserts a value into the collection.
+ *
+ * @param entry a int
value
+ * @return true if the collection was modified by the add operation
+ */
+ boolean add( int entry );
+
+
+ /**
+ * Removes entry from the collection.
+ *
+ * @param entry an int
value
+ * @return true if the collection was modified by the remove operation.
+ */
+ boolean remove( int entry );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * collection are present.
+ *
+ * @param collection a Collection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( Collection> collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * TIntCollection are present.
+ *
+ * @param collection a TIntCollection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( TIntCollection collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * array are present.
+ *
+ * @param array as array
of int primitives.
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( int[] array );
+
+
+ /**
+ * Adds all of the elements in collection to the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( Collection extends Integer> collection );
+
+
+ /**
+ * Adds all of the elements in the TIntCollection to the collection.
+ *
+ * @param collection a TIntCollection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( TIntCollection collection );
+
+
+ /**
+ * Adds all of the elements in the array to the collection.
+ *
+ * @param array a array
of int primitives.
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( int[] array );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( Collection> collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * TIntCollection.
+ *
+ * @param collection a TIntCollection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( TIntCollection collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * array.
+ *
+ * @param array an array
of int primitives.
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( int[] array );
+
+
+ /**
+ * Removes all of the elements in collection from the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( Collection> collection );
+
+
+ /**
+ * Removes all of the elements in TIntCollection from the collection.
+ *
+ * @param collection a TIntCollection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( TIntCollection collection );
+
+
+ /**
+ * Removes all of the elements in array from the collection.
+ *
+ * @param array an array
of int primitives.
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( int[] array );
+
+
+ /**
+ * Empties the collection.
+ */
+ void clear();
+
+
+ /**
+ * Executes procedure for each element in the collection.
+ *
+ * @param procedure a TIntProcedure
value
+ * @return false if the loop over the collection terminated because
+ * the procedure returned false for some value.
+ */
+ boolean forEach( TIntProcedure procedure );
+
+
+ // Comparison and hashing
+
+ /**
+ * Compares the specified object with this collection for equality. Returns
+ * true if the specified object is also a collection, the two collection
+ * have the same size, and every member of the specified collection is
+ * contained in this collection (or equivalently, every member of this collection is
+ * contained in the specified collection). This definition ensures that the
+ * equals method works properly across different implementations of the
+ * collection interface.
+ *
+ * @param o object to be compared for equality with this collection
+ * @return true if the specified object is equal to this collection
+ */
+ boolean equals( Object o );
+
+
+ /**
+ * Returns the hash code value for this collection. The hash code of a collection is
+ * defined to be the sum of the hash codes of the elements in the collection.
+ * This ensures that s1.equals(s2) implies that
+ * s1.hashCode()==s2.hashCode() for any two collection s1
+ * and s2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this collection
+ * @see Object#equals(Object)
+ * @see Collection#equals(Object)
+ */
+ int hashCode();
+
+
+} // TIntCollection
diff --git a/src/gnu/trove/TLongCollection.java b/src/gnu/trove/TLongCollection.java
new file mode 100644
index 00000000..7d1d776d
--- /dev/null
+++ b/src/gnu/trove/TLongCollection.java
@@ -0,0 +1,317 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove;
+
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+import gnu.trove.iterator.TLongIterator;
+import gnu.trove.procedure.TLongProcedure;
+
+import java.util.Collection;
+import java.io.Serializable;
+
+/**
+ * An interface that mimics the Collection interface.
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden
+ * @author Jeff Randall
+ * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 upholderoftruth Exp $
+ */
+
+public interface TLongCollection {
+ static final long serialVersionUID = 1L;
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ long getNoEntryValue();
+
+
+ /**
+ * Returns the number of elements in this collection (its cardinality). If this
+ * collection contains more than Integer.MAX_VALUE elements, returns
+ * Integer.MAX_VALUE.
+ *
+ * @return the number of elements in this collection (its cardinality)
+ */
+ int size();
+
+
+ /**
+ * Returns true if this collection contains no elements.
+ *
+ * @return true if this collection contains no elements
+ */
+ boolean isEmpty();
+
+
+ /**
+ * Returns true if this collection contains the specified element.
+ *
+ * @param entry an long
value
+ * @return true if the collection contains the specified element.
+ */
+ boolean contains( long entry );
+
+
+ /**
+ * Creates an iterator over the values of the collection. The iterator
+ * supports element deletion.
+ *
+ * @return an TLongIterator
value
+ */
+ TLongIterator iterator();
+
+
+ /**
+ * Returns an array containing all of the elements in this collection.
+ * If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the
+ * elements in the same order.
+ *
+ *
The returned array will be "safe" in that no references to it + * are maintained by this collection. (In other words, this method must + * allocate a new array even if this collection is backed by an array). + * The caller is thus free to modify the returned array. + * + *
This method acts as bridge between array-based and collection-based + * APIs. + * + * @return an array containing all the elements in this collection + */ + long[] toArray(); + + + /** + * Returns an array containing elements in this collection. + * + *
If this collection fits in the specified array with room to spare + * (i.e., the array has more elements than this collection), the element in + * the array immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining + * the length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *
If the native array is smaller than the collection size, + * the array will be filled with elements in Iterator order + * until it is full and exclude the remainder. + * + *
If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the elements
+ * in the same order.
+ *
+ * @param dest the array into which the elements of this collection are to be
+ * stored.
+ * @return an long[] containing all the elements in this collection
+ * @throws NullPointerException if the specified array is null
+ */
+ long[] toArray( long[] dest );
+
+
+ /**
+ * Inserts a value into the collection.
+ *
+ * @param entry a long
value
+ * @return true if the collection was modified by the add operation
+ */
+ boolean add( long entry );
+
+
+ /**
+ * Removes entry from the collection.
+ *
+ * @param entry an long
value
+ * @return true if the collection was modified by the remove operation.
+ */
+ boolean remove( long entry );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * collection are present.
+ *
+ * @param collection a Collection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( Collection> collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * TLongCollection are present.
+ *
+ * @param collection a TLongCollection
value
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( TLongCollection collection );
+
+
+ /**
+ * Tests the collection to determine if all of the elements in
+ * array are present.
+ *
+ * @param array as array
of long primitives.
+ * @return true if all elements were present in the collection.
+ */
+ boolean containsAll( long[] array );
+
+
+ /**
+ * Adds all of the elements in collection to the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( Collection extends Long> collection );
+
+
+ /**
+ * Adds all of the elements in the TLongCollection to the collection.
+ *
+ * @param collection a TLongCollection
value
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( TLongCollection collection );
+
+
+ /**
+ * Adds all of the elements in the array to the collection.
+ *
+ * @param array a array
of long primitives.
+ * @return true if the collection was modified by the add all operation.
+ */
+ boolean addAll( long[] array );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( Collection> collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * TLongCollection.
+ *
+ * @param collection a TLongCollection
value
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( TLongCollection collection );
+
+
+ /**
+ * Removes any values in the collection which are not contained in
+ * array.
+ *
+ * @param array an array
of long primitives.
+ * @return true if the collection was modified by the retain all operation
+ */
+ boolean retainAll( long[] array );
+
+
+ /**
+ * Removes all of the elements in collection from the collection.
+ *
+ * @param collection a Collection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( Collection> collection );
+
+
+ /**
+ * Removes all of the elements in TLongCollection from the collection.
+ *
+ * @param collection a TLongCollection
value
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( TLongCollection collection );
+
+
+ /**
+ * Removes all of the elements in array from the collection.
+ *
+ * @param array an array
of long primitives.
+ * @return true if the collection was modified by the remove all operation.
+ */
+ boolean removeAll( long[] array );
+
+
+ /**
+ * Empties the collection.
+ */
+ void clear();
+
+
+ /**
+ * Executes procedure for each element in the collection.
+ *
+ * @param procedure a TLongProcedure
value
+ * @return false if the loop over the collection terminated because
+ * the procedure returned false for some value.
+ */
+ boolean forEach( TLongProcedure procedure );
+
+
+ // Comparison and hashing
+
+ /**
+ * Compares the specified object with this collection for equality. Returns
+ * true if the specified object is also a collection, the two collection
+ * have the same size, and every member of the specified collection is
+ * contained in this collection (or equivalently, every member of this collection is
+ * contained in the specified collection). This definition ensures that the
+ * equals method works properly across different implementations of the
+ * collection interface.
+ *
+ * @param o object to be compared for equality with this collection
+ * @return true if the specified object is equal to this collection
+ */
+ boolean equals( Object o );
+
+
+ /**
+ * Returns the hash code value for this collection. The hash code of a collection is
+ * defined to be the sum of the hash codes of the elements in the collection.
+ * This ensures that s1.equals(s2) implies that
+ * s1.hashCode()==s2.hashCode() for any two collection s1
+ * and s2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this collection
+ * @see Object#equals(Object)
+ * @see Collection#equals(Object)
+ */
+ int hashCode();
+
+
+} // TLongCollection
diff --git a/src/gnu/trove/function/TByteFunction.java b/src/gnu/trove/function/TByteFunction.java
new file mode 100644
index 00000000..1fa50ba4
--- /dev/null
+++ b/src/gnu/trove/function/TByteFunction.java
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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.function;
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * Interface for functions that accept and return one byte primitive.
+ */
+public interface TByteFunction {
+ /**
+ * Execute this function with value
+ *
+ * @param value a byte
input
+ * @return a byte
result
+ */
+ public byte execute( byte value );
+}
diff --git a/src/gnu/trove/function/TDoubleFunction.java b/src/gnu/trove/function/TDoubleFunction.java
new file mode 100644
index 00000000..d46f5aec
--- /dev/null
+++ b/src/gnu/trove/function/TDoubleFunction.java
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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.function;
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * Interface for functions that accept and return one double primitive.
+ */
+public interface TDoubleFunction {
+ /**
+ * Execute this function with value
+ *
+ * @param value a double
input
+ * @return a double
result
+ */
+ public double execute( double value );
+}
diff --git a/src/gnu/trove/function/TIntFunction.java b/src/gnu/trove/function/TIntFunction.java
new file mode 100644
index 00000000..642eabdd
--- /dev/null
+++ b/src/gnu/trove/function/TIntFunction.java
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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.function;
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * Interface for functions that accept and return one int primitive.
+ */
+public interface TIntFunction {
+ /**
+ * Execute this function with value
+ *
+ * @param value a int
input
+ * @return a int
result
+ */
+ public int execute( int value );
+}
diff --git a/src/gnu/trove/function/TLongFunction.java b/src/gnu/trove/function/TLongFunction.java
new file mode 100644
index 00000000..64219cb4
--- /dev/null
+++ b/src/gnu/trove/function/TLongFunction.java
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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.function;
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * Interface for functions that accept and return one long primitive.
+ */
+public interface TLongFunction {
+ /**
+ * Execute this function with value
+ *
+ * @param value a long
input
+ * @return a long
result
+ */
+ public long execute( long value );
+}
diff --git a/src/gnu/trove/function/TObjectFunction.java b/src/gnu/trove/function/TObjectFunction.java
new file mode 100644
index 00000000..e8873b7b
--- /dev/null
+++ b/src/gnu/trove/function/TObjectFunction.java
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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.function;
+
+/**
+ * Interface for functions that accept and return one Object reference.
+ *
Object
input
+ * @return an Object
result
+ */
+ public R execute( T value );
+}// TObjectFunction
diff --git a/src/gnu/trove/impl/Constants.java b/src/gnu/trove/impl/Constants.java
new file mode 100644
index 00000000..09237a25
--- /dev/null
+++ b/src/gnu/trove/impl/Constants.java
@@ -0,0 +1,165 @@
+// ////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+// ////////////////////////////////////////////////////////////////////////////
+package gnu.trove.impl;
+
+/**
+ * Central location for constants needed by various implementations.
+ */
+public class Constants {
+
+ private static final boolean VERBOSE =
+ System.getProperty( "gnu.trove.verbose", null ) != null;
+
+ /** the default capacity for new collections */
+ public static final int DEFAULT_CAPACITY = 10;
+
+ /** the load above which rehashing occurs. */
+ public static final float DEFAULT_LOAD_FACTOR = 0.5f;
+
+
+ /** the default value that represents for byte types. */
+ public static final byte DEFAULT_BYTE_NO_ENTRY_VALUE;
+ static {
+ byte value;
+ String property = System.getProperty( "gnu.trove.no_entry.byte", "0" );
+ if ( "MAX_VALUE".equalsIgnoreCase( property ) ) value = Byte.MAX_VALUE;
+ else if ( "MIN_VALUE".equalsIgnoreCase( property ) ) value = Byte.MIN_VALUE;
+ else value = Byte.valueOf( property );
+
+ if ( value > Byte.MAX_VALUE ) value = Byte.MAX_VALUE;
+ else if ( value < Byte.MIN_VALUE ) value = Byte.MIN_VALUE;
+ DEFAULT_BYTE_NO_ENTRY_VALUE = value;
+ if ( VERBOSE ) {
+ System.out.println( "DEFAULT_BYTE_NO_ENTRY_VALUE: " +
+ DEFAULT_BYTE_NO_ENTRY_VALUE );
+ }
+ }
+
+
+ /** the default value that represents for short types. */
+ public static final short DEFAULT_SHORT_NO_ENTRY_VALUE;
+ static {
+ short value;
+ String property = System.getProperty( "gnu.trove.no_entry.short", "0" );
+ if ( "MAX_VALUE".equalsIgnoreCase( property ) ) value = Short.MAX_VALUE;
+ else if ( "MIN_VALUE".equalsIgnoreCase( property ) ) value = Short.MIN_VALUE;
+ else value = Short.valueOf( property );
+
+ if ( value > Short.MAX_VALUE ) value = Short.MAX_VALUE;
+ else if ( value < Short.MIN_VALUE ) value = Short.MIN_VALUE;
+ DEFAULT_SHORT_NO_ENTRY_VALUE = value;
+ if ( VERBOSE ) {
+ System.out.println( "DEFAULT_SHORT_NO_ENTRY_VALUE: " +
+ DEFAULT_SHORT_NO_ENTRY_VALUE );
+ }
+ }
+
+
+ /** the default value that represents for char types. */
+ public static final char DEFAULT_CHAR_NO_ENTRY_VALUE;
+ static {
+ char value;
+ String property = System.getProperty( "gnu.trove.no_entry.char", "\0" );
+ if ( "MAX_VALUE".equalsIgnoreCase( property ) ) value = Character.MAX_VALUE;
+ else if ( "MIN_VALUE".equalsIgnoreCase( property ) ) value = Character.MIN_VALUE;
+ else value = property.toCharArray()[0];
+
+ if ( value > Character.MAX_VALUE ) value = Character.MAX_VALUE;
+ else if ( value < Character.MIN_VALUE ) value = Character.MIN_VALUE;
+ DEFAULT_CHAR_NO_ENTRY_VALUE = value;
+ if ( VERBOSE ) {
+ System.out.println( "DEFAULT_CHAR_NO_ENTRY_VALUE: " +
+ Integer.valueOf( value ) );
+ }
+ }
+
+
+ /** the default value that represents for int types. */
+ public static final int DEFAULT_INT_NO_ENTRY_VALUE;
+ static {
+ int value;
+ String property = System.getProperty( "gnu.trove.no_entry.int", "0" );
+ if ( "MAX_VALUE".equalsIgnoreCase( property ) ) value = Integer.MAX_VALUE;
+ else if ( "MIN_VALUE".equalsIgnoreCase( property ) ) value = Integer.MIN_VALUE;
+ else value = Integer.valueOf( property );
+ DEFAULT_INT_NO_ENTRY_VALUE = value;
+ if ( VERBOSE ) {
+ System.out.println( "DEFAULT_INT_NO_ENTRY_VALUE: " +
+ DEFAULT_INT_NO_ENTRY_VALUE );
+ }
+ }
+
+
+ /** the default value that represents for long types. */
+ public static final long DEFAULT_LONG_NO_ENTRY_VALUE;
+ static {
+ long value;
+ String property = System.getProperty( "gnu.trove.no_entry.long", "0" );
+ if ( "MAX_VALUE".equalsIgnoreCase( property ) ) value = Long.MAX_VALUE;
+ else if ( "MIN_VALUE".equalsIgnoreCase( property ) ) value = Long.MIN_VALUE;
+ else value = Long.valueOf( property );
+ DEFAULT_LONG_NO_ENTRY_VALUE = value;
+ if ( VERBOSE ) {
+ System.out.println( "DEFAULT_LONG_NO_ENTRY_VALUE: " +
+ DEFAULT_LONG_NO_ENTRY_VALUE );
+ }
+ }
+
+
+ /** the default value that represents for float types. */
+ public static final float DEFAULT_FLOAT_NO_ENTRY_VALUE;
+ static {
+ float value;
+ String property = System.getProperty( "gnu.trove.no_entry.float", "0" );
+ if ( "MAX_VALUE".equalsIgnoreCase( property ) ) value = Float.MAX_VALUE;
+ else if ( "MIN_VALUE".equalsIgnoreCase( property ) ) value = Float.MIN_VALUE;
+ // Value from Float.MIN_NORMAL (introduced in 1.6)
+ else if ( "MIN_NORMAL".equalsIgnoreCase( property ) ) value = 0x1.0p-126f;
+ else if ( "NEGATIVE_INFINITY".equalsIgnoreCase( property ) ) value = Float.NEGATIVE_INFINITY;
+ else if ( "POSITIVE_INFINITY".equalsIgnoreCase( property ) ) value = Float.POSITIVE_INFINITY;
+// else if ( "NaN".equalsIgnoreCase( property ) ) value = Float.NaN;
+ else value = Float.valueOf( property );
+ DEFAULT_FLOAT_NO_ENTRY_VALUE = value;
+ if ( VERBOSE ) {
+ System.out.println( "DEFAULT_FLOAT_NO_ENTRY_VALUE: " +
+ DEFAULT_FLOAT_NO_ENTRY_VALUE );
+ }
+ }
+
+
+ /** the default value that represents for double types. */
+ public static final double DEFAULT_DOUBLE_NO_ENTRY_VALUE;
+ static {
+ double value;
+ String property = System.getProperty( "gnu.trove.no_entry.double", "0" );
+ if ( "MAX_VALUE".equalsIgnoreCase( property ) ) value = Double.MAX_VALUE;
+ else if ( "MIN_VALUE".equalsIgnoreCase( property ) ) value = Double.MIN_VALUE;
+ // Value from Double.MIN_NORMAL (introduced in 1.6)
+ else if ( "MIN_NORMAL".equalsIgnoreCase( property ) ) value = 0x1.0p-1022;
+ else if ( "NEGATIVE_INFINITY".equalsIgnoreCase( property ) ) value = Double.NEGATIVE_INFINITY;
+ else if ( "POSITIVE_INFINITY".equalsIgnoreCase( property ) ) value = Double.POSITIVE_INFINITY;
+// else if ( "NaN".equalsIgnoreCase( property ) ) value = Double.NaN;
+ else value = Double.valueOf( property );
+ DEFAULT_DOUBLE_NO_ENTRY_VALUE = value;
+ if ( VERBOSE ) {
+ System.out.println( "DEFAULT_DOUBLE_NO_ENTRY_VALUE: " +
+ DEFAULT_DOUBLE_NO_ENTRY_VALUE );
+ }
+ }
+}
diff --git a/src/gnu/trove/impl/HashFunctions.java b/src/gnu/trove/impl/HashFunctions.java
new file mode 100644
index 00000000..a7be4436
--- /dev/null
+++ b/src/gnu/trove/impl/HashFunctions.java
@@ -0,0 +1,85 @@
+// 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.impl;
+
+/**
+ * Provides various hash functions.
+ *
+ * @author wolfgang.hoschek@cern.ch
+ * @version 1.0, 09/24/99
+ */
+public final class HashFunctions {
+ /**
+ * Returns a hashcode for the specified value.
+ *
+ * @return a hash code value for the specified value.
+ */
+ public static int hash(double value) {
+ assert !Double.isNaN(value) : "Values of NaN are not supported.";
+
+ long bits = Double.doubleToLongBits(value);
+ return (int)(bits ^ (bits >>> 32));
+ //return (int) Double.doubleToLongBits(value*663608941.737);
+ //this avoids excessive hashCollisions in the case values are
+ //of the form (1.0, 2.0, 3.0, ...)
+ }
+
+ /**
+ * Returns a hashcode for the specified value.
+ *
+ * @return a hash code value for the specified value.
+ */
+ public static int hash(float value) {
+ assert !Float.isNaN(value) : "Values of NaN are not supported.";
+
+ return Float.floatToIntBits(value*663608941.737f);
+ // this avoids excessive hashCollisions in the case values are
+ // of the form (1.0, 2.0, 3.0, ...)
+ }
+
+ /**
+ * Returns a hashcode for the specified value.
+ *
+ * @return a hash code value for the specified value.
+ */
+ public static int hash(int value) {
+ return value;
+ }
+
+ /**
+ * Returns a hashcode for the specified value.
+ *
+ * @return a hash code value for the specified value.
+ */
+ public static int hash(long value) {
+ return ((int)(value ^ (value >>> 32)));
+ }
+
+ /**
+ * Returns a hashcode for the specified object.
+ *
+ * @return a hash code value for the specified object.
+ */
+ public static int hash(Object object) {
+ return object==null ? 0 : object.hashCode();
+ }
+
+
+ /**
+ * In profiling, it has been found to be faster to have our own local implementation
+ * of "ceil" rather than to call to {@link Math#ceil(double)}.
+ */
+ public static int fastCeil( float v ) {
+ int possible_result = ( int ) v;
+ if ( v - possible_result > 0 ) possible_result++;
+ return possible_result;
+ }
+}
diff --git a/src/gnu/trove/impl/PrimeFinder.java b/src/gnu/trove/impl/PrimeFinder.java
new file mode 100644
index 00000000..11abe57e
--- /dev/null
+++ b/src/gnu/trove/impl/PrimeFinder.java
@@ -0,0 +1,158 @@
+// 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.impl;
+
+import java.util.Arrays;
+
+/*
+ * Modified for Trove to use the java.util.Arrays sort/search
+ * algorithms instead of those provided with colt.
+ */
+
+/**
+ * Used to keep hash table capacities prime numbers.
+ * Not of interest for users; only for implementors of hashtables.
+ *
+ * Choosing prime numbers as hash table capacities is a good idea + * to keep them working fast, particularly under hash table + * expansions. + * + *
However, JDK 1.2, JGL 3.1 and many other toolkits do nothing to + * keep capacities prime. This class provides efficient means to + * choose prime capacities. + * + *
Choosing a prime is O(log 300) (binary search in a list
+ * of 300 ints). Memory requirements: 1 KB static memory.
+ *
+ * @author wolfgang.hoschek@cern.ch
+ * @version 1.0, 09/24/99
+ */
+public final class PrimeFinder {
+ /**
+ * The largest prime this class can generate; currently equal to
+ * Integer.MAX_VALUE.
+ */
+ public static final int largestPrime = Integer.MAX_VALUE; //yes, it is prime.
+
+ /**
+ * The prime number list consists of 11 chunks.
+ *
+ * Each chunk contains prime numbers.
+ *
+ * A chunk starts with a prime P1. The next element is a prime
+ * P2. P2 is the smallest prime for which holds: P2 >= 2*P1.
+ *
+ * The next element is P3, for which the same holds with respect
+ * to P2, and so on.
+ *
+ * Chunks are chosen such that for any desired capacity >= 1000
+ * the list includes a prime number <= desired capacity * 1.11.
+ *
+ * Therefore, primes can be retrieved which are quite close to any
+ * desired capacity, which in turn avoids wasting memory.
+ *
+ * For example, the list includes
+ * 1039,1117,1201,1277,1361,1439,1523,1597,1759,1907,2081.
+ *
+ * So if you need a prime >= 1040, you will find a prime <=
+ * 1040*1.11=1154.
+ *
+ * Chunks are chosen such that they are optimized for a hashtable
+ * growthfactor of 2.0;
+ *
+ * If your hashtable has such a growthfactor then, after initially
+ * "rounding to a prime" upon hashtable construction, it will
+ * later expand to prime capacities such that there exist no
+ * better primes.
+ *
+ * In total these are about 32*10=320 numbers -> 1 KB of static
+ * memory needed.
+ *
+ * If you are stingy, then delete every second or fourth chunk.
+ */
+
+ private static final int[] primeCapacities = {
+ //chunk #0
+ largestPrime,
+
+ //chunk #1
+ 5,11,23,47,97,197,397,797,1597,3203,6421,12853,25717,51437,102877,205759,
+ 411527,823117,1646237,3292489,6584983,13169977,26339969,52679969,105359939,
+ 210719881,421439783,842879579,1685759167,
+
+ //chunk #2
+ 433,877,1759,3527,7057,14143,28289,56591,113189,226379,452759,905551,1811107,
+ 3622219,7244441,14488931,28977863,57955739,115911563,231823147,463646329,927292699,
+ 1854585413,
+
+ //chunk #3
+ 953,1907,3821,7643,15287,30577,61169,122347,244703,489407,978821,1957651,3915341,
+ 7830701,15661423,31322867,62645741,125291483,250582987,501165979,1002331963,
+ 2004663929,
+
+ //chunk #4
+ 1039,2081,4177,8363,16729,33461,66923,133853,267713,535481,1070981,2141977,4283963,
+ 8567929,17135863,34271747,68543509,137087021,274174111,548348231,1096696463,
+
+ //chunk #5
+ 31,67,137,277,557,1117,2237,4481,8963,17929,35863,71741,143483,286973,573953,
+ 1147921,2295859,4591721,9183457,18366923,36733847,73467739,146935499,293871013,
+ 587742049,1175484103,
+
+ //chunk #6
+ 599,1201,2411,4831,9677,19373,38747,77509,155027,310081,620171,1240361,2480729,
+ 4961459,9922933,19845871,39691759,79383533,158767069,317534141,635068283,1270136683,
+
+ //chunk #7
+ 311,631,1277,2557,5119,10243,20507,41017,82037,164089,328213,656429,1312867,
+ 2625761,5251529,10503061,21006137,42012281,84024581,168049163,336098327,672196673,
+ 1344393353,
+
+ //chunk #8
+ 3,7,17,37,79,163,331,673,1361,2729,5471,10949,21911,43853,87719,175447,350899,
+ 701819,1403641,2807303,5614657,11229331,22458671,44917381,89834777,179669557,
+ 359339171,718678369,1437356741,
+
+ //chunk #9
+ 43,89,179,359,719,1439,2879,5779,11579,23159,46327,92657,185323,370661,741337,
+ 1482707,2965421,5930887,11861791,23723597,47447201,94894427,189788857,379577741,
+ 759155483,1518310967,
+
+ //chunk #10
+ 379,761,1523,3049,6101,12203,24407,48817,97649,195311,390647,781301,1562611,
+ 3125257,6250537,12501169,25002389,50004791,100009607,200019221,400038451,800076929,
+ 1600153859
+ };
+
+ static { //initializer
+ // The above prime numbers are formatted for human readability.
+ // To find numbers fast, we sort them once and for all.
+
+ Arrays.sort(primeCapacities);
+ }
+
+ /**
+ * Returns a prime number which is >= desiredCapacity
+ * and very close to desiredCapacity
(within 11% if
+ * desiredCapacity >= 1000
).
+ *
+ * @param desiredCapacity the capacity desired by the user.
+ * @return the capacity which should be used for a hashtable.
+ */
+ public static final int nextPrime(int desiredCapacity) {
+ int i = Arrays.binarySearch(primeCapacities, desiredCapacity);
+ if (i<0) {
+ // desired capacity not found, choose next prime greater
+ // than desired capacity
+ i = -i -1; // remember the semantics of binarySearch...
+ }
+ return primeCapacities[i];
+ }
+}
diff --git a/src/gnu/trove/impl/hash/TCharHash.java b/src/gnu/trove/impl/hash/TCharHash.java
new file mode 100644
index 00000000..fd163511
--- /dev/null
+++ b/src/gnu/trove/impl/hash/TCharHash.java
@@ -0,0 +1,334 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove.impl.hash;
+
+import gnu.trove.procedure.TCharProcedure;
+import gnu.trove.impl.HashFunctions;
+import gnu.trove.impl.Constants;
+
+import java.util.Arrays;
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * An open addressed hashing implementation for char primitives.
+ *
+ * Created: Sun Nov 4 08:56:06 2001
+ *
+ * @author Eric D. Friedman, Rob Eden, Jeff Randall
+ * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $
+ */
+abstract public class TCharHash extends TPrimitiveHash {
+ static final long serialVersionUID = 1L;
+
+ /** the set of chars */
+ public transient char[] _set;
+
+ /**
+ * value that represents null
+ *
+ * NOTE: should not be modified after the Hash is created, but is
+ * not final because of Externalization
+ *
+ */
+ protected char no_entry_value;
+
+ protected boolean consumeFreeSlot;
+
+
+ /**
+ * Creates a new TCharHash
instance with the default
+ * capacity and load factor.
+ */
+ public TCharHash() {
+ super();
+ no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( char ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Creates a new TCharHash
instance whose capacity
+ * is the next highest prime above initialCapacity + 1
+ * unless that value is already prime.
+ *
+ * @param initialCapacity an int
value
+ */
+ public TCharHash( int initialCapacity ) {
+ super( initialCapacity );
+ no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( char ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Creates a new TCharHash
instance with a prime
+ * value at or near the specified capacity and load factor.
+ *
+ * @param initialCapacity used to find a prime capacity for the table.
+ * @param loadFactor used to calculate the threshold over which
+ * rehashing takes place.
+ */
+ public TCharHash( int initialCapacity, float loadFactor ) {
+ super(initialCapacity, loadFactor);
+ no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( char ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Creates a new TCharHash
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 no_entry_value value that represents null
+ */
+ public TCharHash( int initialCapacity, float loadFactor, char no_entry_value ) {
+ super(initialCapacity, loadFactor);
+ this.no_entry_value = no_entry_value;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( char ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ public char getNoEntryValue() {
+ return no_entry_value;
+ }
+
+
+ /**
+ * initializes the hashtable to a prime capacity which is at least
+ * initialCapacity + 1.
+ *
+ * @param initialCapacity an int
value
+ * @return the actual capacity chosen
+ */
+ protected int setUp( int initialCapacity ) {
+ int capacity;
+
+ capacity = super.setUp( initialCapacity );
+ _set = new char[capacity];
+ return capacity;
+ }
+
+
+ /**
+ * Searches the set for val
+ *
+ * @param val an char
value
+ * @return a boolean
value
+ */
+ public boolean contains( char val ) {
+ return index(val) >= 0;
+ }
+
+
+ /**
+ * Executes procedure for each element in the set.
+ *
+ * @param procedure a TObjectProcedure
value
+ * @return false if the loop over the set terminated because
+ * the procedure returned false for some value.
+ */
+ public boolean forEach( TCharProcedure procedure ) {
+ byte[] states = _states;
+ char[] set = _set;
+ for ( int i = set.length; i-- > 0; ) {
+ if ( states[i] == FULL && ! procedure.execute( set[i] ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Releases the element currently stored at index.
+ *
+ * @param index an int
value
+ */
+ protected void removeAt( int index ) {
+ _set[index] = no_entry_value;
+ super.removeAt( index );
+ }
+
+
+ /**
+ * Locates the index of val.
+ *
+ * @param val an char
value
+ * @return the index of val or -1 if it isn't in the set.
+ */
+ protected int index( char val ) {
+ int hash, probe, index, length;
+
+ final byte[] states = _states;
+ final char[] set = _set;
+ length = states.length;
+ hash = HashFunctions.hash( val ) & 0x7fffffff;
+ index = hash % length;
+ byte state = states[index];
+
+ if (state == FREE)
+ return -1;
+
+ if (state == FULL && set[index] == val)
+ return index;
+
+ return indexRehashed(val, index, hash, state);
+ }
+
+ int indexRehashed(char key, int index, int hash, byte state) {
+ // see Knuth, p. 529
+ int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+
+ do {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+ //
+ if (state == FREE)
+ return -1;
+
+ //
+ if (key == _set[index] && state != REMOVED)
+ return index;
+ } while (index != loopIndex);
+
+ return -1;
+ }
+
+ /**
+ * Locates the index at which val can be inserted. if
+ * there is already a value equal()ing val in the set,
+ * returns that value as a negative integer.
+ *
+ * @param val an char
value
+ * @return an int
value
+ */
+ protected int insertKey( char val ) {
+ int hash, index;
+
+ hash = HashFunctions.hash(val) & 0x7fffffff;
+ index = hash % _states.length;
+ byte state = _states[index];
+
+ consumeFreeSlot = false;
+
+ if (state == FREE) {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+
+ return index; // empty, all done
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1; // already stored
+ }
+
+ // already FULL or REMOVED, must probe
+ return insertKeyRehash(val, index, hash, state);
+ }
+
+ int insertKeyRehash(char val, int index, int hash, byte state) {
+ // compute the double hash
+ final int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+ int firstRemoved = -1;
+
+ /**
+ * Look until FREE slot or we start to loop
+ */
+ do {
+ // Identify first removed slot
+ if (state == REMOVED && firstRemoved == -1)
+ firstRemoved = index;
+
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+
+ // A FREE slot stops the search
+ if (state == FREE) {
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ } else {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+ return index;
+ }
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1;
+ }
+
+ // Detect loop
+ } while (index != loopIndex);
+
+ // We inspected all reachable slots and did not find a FREE one
+ // If we found a REMOVED slot we return the first one found
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ }
+
+ // Can a resizing strategy be found that resizes the set?
+ throw new IllegalStateException("No free or removed slots available. Key set full?!!");
+ }
+
+ void insertKeyAt(int index, char val) {
+ _set[index] = val; // insert value
+ _states[index] = FULL;
+ }
+
+} // TCharHash
diff --git a/src/gnu/trove/impl/hash/THash.java b/src/gnu/trove/impl/hash/THash.java
new file mode 100644
index 00000000..bcc4d9ba
--- /dev/null
+++ b/src/gnu/trove/impl/hash/THash.java
@@ -0,0 +1,429 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove.impl.hash;
+
+import gnu.trove.impl.Constants;
+import gnu.trove.impl.HashFunctions;
+import gnu.trove.impl.PrimeFinder;
+
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
+
+
+/**
+ * Base class for hashtables that use open addressing to resolve
+ * collisions.
+ *
+ * Created: Wed Nov 28 21:11:16 2001
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden (auto-compaction)
+ * @author Jeff Randall
+ *
+ * @version $Id: THash.java,v 1.1.2.4 2010/03/02 00:55:34 robeden Exp $
+ */
+abstract public class THash implements Externalizable {
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ static final long serialVersionUID = -1792948471915530295L;
+
+ /** the load above which rehashing occurs. */
+ protected static final float DEFAULT_LOAD_FACTOR = Constants.DEFAULT_LOAD_FACTOR;
+
+ /**
+ * the default initial capacity for the hash table. This is one
+ * less than a prime value because one is added to it when
+ * searching for a prime capacity to account for the free slot
+ * required by open addressing. Thus, the real default capacity is
+ * 11.
+ */
+ protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY;
+
+
+ /** the current number of occupied slots in the hash. */
+ protected transient int _size;
+
+ /** the current number of free slots in the hash. */
+ protected transient int _free;
+
+ /**
+ * Determines how full the internal table can become before
+ * rehashing is required. This must be a value in the range: 0.0 <
+ * loadFactor < 1.0. The default value is 0.5, which is about as
+ * large as you can get in open addressing without hurting
+ * performance. Cf. Knuth, Volume 3., Chapter 6.
+ */
+ protected float _loadFactor;
+
+ /**
+ * The maximum number of elements allowed without allocating more
+ * space.
+ */
+ protected int _maxSize;
+
+
+ /** The number of removes that should be performed before an auto-compaction occurs. */
+ protected int _autoCompactRemovesRemaining;
+
+ /**
+ * The auto-compaction factor for the table.
+ *
+ * @see #setAutoCompactionFactor
+ */
+ protected float _autoCompactionFactor;
+
+ /** @see #tempDisableAutoCompaction */
+ protected transient boolean _autoCompactTemporaryDisable = false;
+
+
+ /**
+ * Creates a new THash
instance with the default
+ * capacity and load factor.
+ */
+ public THash() {
+ this( DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR );
+ }
+
+
+ /**
+ * Creates a new THash
instance with a prime capacity
+ * at or near the specified capacity and with the default load
+ * factor.
+ *
+ * @param initialCapacity an int
value
+ */
+ public THash( int initialCapacity ) {
+ this( initialCapacity, DEFAULT_LOAD_FACTOR );
+ }
+
+
+ /**
+ * Creates a new THash
instance with a prime capacity
+ * at or near the minimum needed to hold initialCapacity
+ * elements with load factor loadFactor without triggering
+ * a rehash.
+ *
+ * @param initialCapacity an int
value
+ * @param loadFactor a float
value
+ */
+ public THash( int initialCapacity, float loadFactor ) {
+ super();
+ _loadFactor = loadFactor;
+
+ // Through testing, the load factor (especially the default load factor) has been
+ // found to be a pretty good starting auto-compaction factor.
+ _autoCompactionFactor = loadFactor;
+
+ setUp( HashFunctions.fastCeil( initialCapacity / loadFactor ) );
+ }
+
+
+ /**
+ * Tells whether this set is currently holding any elements.
+ *
+ * @return a boolean
value
+ */
+ public boolean isEmpty() {
+ return 0 == _size;
+ }
+
+
+ /**
+ * Returns the number of distinct elements in this collection.
+ *
+ * @return an int
value
+ */
+ public int size() {
+ return _size;
+ }
+
+
+ /** @return the current physical capacity of the hash table. */
+ abstract public int capacity();
+
+
+ /**
+ * Ensure that this hashtable has sufficient capacity to hold
+ * desiredCapacity additional elements without
+ * requiring a rehash. This is a tuning method you can call
+ * before doing a large insert.
+ *
+ * @param desiredCapacity an int
value
+ */
+ public void ensureCapacity( int desiredCapacity ) {
+ if ( desiredCapacity > ( _maxSize - size() ) ) {
+ rehash( PrimeFinder.nextPrime( Math.max( size() + 1,
+ HashFunctions.fastCeil( ( desiredCapacity + size() ) / _loadFactor ) + 1 ) ) );
+ computeMaxSize( capacity() );
+ }
+ }
+
+
+ /**
+ * Compresses the hashtable to the minimum prime size (as defined
+ * by PrimeFinder) that will hold all of the elements currently in
+ * the table. If you have done a lot of remove
+ * operations and plan to do a lot of queries or insertions or
+ * iteration, it is a good idea to invoke this method. Doing so
+ * will accomplish two things:
+ *
int
value
+ */
+ protected void removeAt( int index ) {
+ _size--;
+
+ // If auto-compaction is enabled, see if we need to compact
+ if ( _autoCompactionFactor != 0 ) {
+ _autoCompactRemovesRemaining--;
+
+ if ( !_autoCompactTemporaryDisable && _autoCompactRemovesRemaining <= 0 ) {
+ // Do the compact
+ // NOTE: this will cause the next compaction interval to be calculated
+ compact();
+ }
+ }
+ }
+
+
+ /** Empties the collection. */
+ public void clear() {
+ _size = 0;
+ _free = capacity();
+ }
+
+
+ /**
+ * initializes the hashtable to a prime capacity which is at least
+ * initialCapacity + 1.
+ *
+ * @param initialCapacity an int
value
+ * @return the actual capacity chosen
+ */
+ protected int setUp( int initialCapacity ) {
+ int capacity;
+
+ capacity = PrimeFinder.nextPrime( initialCapacity );
+ computeMaxSize( capacity );
+ computeNextAutoCompactionAmount( initialCapacity );
+
+ return capacity;
+ }
+
+
+ /**
+ * Rehashes the set.
+ *
+ * @param newCapacity an int
value
+ */
+ protected abstract void rehash( int newCapacity );
+
+
+ /**
+ * Temporarily disables auto-compaction. MUST be followed by calling
+ * {@link #reenableAutoCompaction}.
+ */
+ public void tempDisableAutoCompaction() {
+ _autoCompactTemporaryDisable = true;
+ }
+
+
+ /**
+ * Re-enable auto-compaction after it was disabled via
+ * {@link #tempDisableAutoCompaction()}.
+ *
+ * @param check_for_compaction True if compaction should be performed if needed
+ * before returning. If false, no compaction will be
+ * performed.
+ */
+ public void reenableAutoCompaction( boolean check_for_compaction ) {
+ _autoCompactTemporaryDisable = false;
+
+ if ( check_for_compaction && _autoCompactRemovesRemaining <= 0 &&
+ _autoCompactionFactor != 0 ) {
+
+ // Do the compact
+ // NOTE: this will cause the next compaction interval to be calculated
+ compact();
+ }
+ }
+
+
+ /**
+ * Computes the values of maxSize. There will always be at least
+ * one free slot required.
+ *
+ * @param capacity an int
value
+ */
+ protected void computeMaxSize( int capacity ) {
+ // need at least one free slot for open addressing
+ _maxSize = Math.min( capacity - 1, (int) ( capacity * _loadFactor ) );
+ _free = capacity - _size; // reset the free element count
+ }
+
+
+ /**
+ * Computes the number of removes that need to happen before the next auto-compaction
+ * will occur.
+ *
+ * @param size an int that sets the auto-compaction limit.
+ */
+ protected void computeNextAutoCompactionAmount( int size ) {
+ if ( _autoCompactionFactor != 0 ) {
+ // NOTE: doing the round ourselves has been found to be faster than using
+ // Math.round.
+ _autoCompactRemovesRemaining =
+ (int) ( ( size * _autoCompactionFactor ) + 0.5f );
+ }
+ }
+
+
+ /**
+ * After an insert, this hook is called to adjust the size/free
+ * values of the set and to perform rehashing if necessary.
+ *
+ * @param usedFreeSlot the slot
+ */
+ protected final void postInsertHook( boolean usedFreeSlot ) {
+ if ( usedFreeSlot ) {
+ _free--;
+ }
+
+ // rehash whenever we exhaust the available space in the table
+ if ( ++_size > _maxSize || _free == 0 ) {
+ // choose a new capacity suited to the new state of the table
+ // if we've grown beyond our maximum size, double capacity;
+ // if we've exhausted the free spots, rehash to the same capacity,
+ // which will free up any stale removed slots for reuse.
+ int newCapacity = _size > _maxSize ? PrimeFinder.nextPrime( capacity() << 1 ) : capacity();
+ rehash( newCapacity );
+ computeMaxSize( capacity() );
+ }
+ }
+
+
+ protected int calculateGrownCapacity() {
+ return capacity() << 1;
+ }
+
+
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ // VERSION
+ out.writeByte( 0 );
+
+ // LOAD FACTOR
+ out.writeFloat( _loadFactor );
+
+ // AUTO COMPACTION LOAD FACTOR
+ out.writeFloat( _autoCompactionFactor );
+ }
+
+
+ public void readExternal( ObjectInput in )
+ throws IOException, ClassNotFoundException {
+
+ // VERSION
+ in.readByte();
+
+ // LOAD FACTOR
+ float old_factor = _loadFactor;
+ _loadFactor = in.readFloat();
+
+ // AUTO COMPACTION LOAD FACTOR
+ _autoCompactionFactor = in.readFloat();
+
+ // If we change the laod factor from the default, re-setup
+ if ( old_factor != _loadFactor ) {
+ setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
+ }
+ }
+}// THash
\ No newline at end of file
diff --git a/src/gnu/trove/impl/hash/THashIterator.java b/src/gnu/trove/impl/hash/THashIterator.java
new file mode 100644
index 00000000..4898620d
--- /dev/null
+++ b/src/gnu/trove/impl/hash/THashIterator.java
@@ -0,0 +1,177 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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.impl.hash;
+
+import gnu.trove.iterator.TIterator;
+
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+
+
+/**
+ * Implements all iterator functions for the hashed object set.
+ * Subclasses may override objectAtIndex to vary the object
+ * returned by calls to next() (e.g. for values, and Map.Entry
+ * objects).
+ *
+ * Note that iteration is fastest if you forego the calls to + * hasNext in favor of checking the size of the structure + * yourself and then call next() that many times: + *
+ *+ * Iterator i = collection.iterator(); + * for (int size = collection.size(); size-- > 0;) { + * Object o = i.next(); + * } + *+ * + *
You may, of course, use the hasNext(), next() idiom too if + * you aren't in a performance critical spot.
+ */ +public abstract class THashIteratorObject
value
+ * @throws ConcurrentModificationException
+ * if the structure
+ * was changed using a method that isn't on this iterator.
+ * @throws NoSuchElementException if this is called on an
+ * exhausted iterator.
+ */
+ public V next() {
+ moveToNextIndex();
+ return objectAtIndex( _index );
+ }
+
+
+ /**
+ * Returns true if the iterator can be advanced past its current
+ * location.
+ *
+ * @return a boolean
value
+ */
+ public boolean hasNext() {
+ return nextIndex() >= 0;
+ }
+
+
+ /**
+ * Removes the last entry returned by the iterator.
+ * Invoking this method more than once for a single entry
+ * will leave the underlying data structure in a confused
+ * state.
+ */
+ public void remove() {
+ if ( _expectedSize != _hash.size() ) {
+ throw new ConcurrentModificationException();
+ }
+
+ // Disable auto compaction during the remove. This is a workaround for bug 1642768.
+ try {
+ _hash.tempDisableAutoCompaction();
+ _hash.removeAt( _index );
+ }
+ finally {
+ _hash.reenableAutoCompaction( false );
+ }
+
+ _expectedSize--;
+ }
+
+
+ /**
+ * Sets the internal index so that the `next' object
+ * can be returned.
+ */
+ protected final void moveToNextIndex() {
+ // doing the assignment && < 0 in one line shaves
+ // 3 opcodes...
+ if ( ( _index = nextIndex() ) < 0 ) {
+ throw new NoSuchElementException();
+ }
+ }
+
+
+ /**
+ * Returns the index of the next value in the data structure
+ * or a negative value if the iterator is exhausted.
+ *
+ * @return an int
value
+ * @throws ConcurrentModificationException
+ * if the underlying
+ * collection's size has been modified since the iterator was
+ * created.
+ */
+ protected final int nextIndex() {
+ if ( _expectedSize != _hash.size() ) {
+ throw new ConcurrentModificationException();
+ }
+
+ Object[] set = _object_hash._set;
+ int i = _index;
+ while ( i-- > 0 && ( set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED ) ) {
+ ;
+ }
+ return i;
+ }
+
+
+ /**
+ * Returns the object at the specified index. Subclasses should
+ * implement this to return the appropriate object for the given
+ * index.
+ *
+ * @param index the index of the value to return.
+ * @return an Object
value
+ */
+ abstract protected V objectAtIndex( int index );
+} // THashIterator
diff --git a/src/gnu/trove/impl/hash/THashPrimitiveIterator.java b/src/gnu/trove/impl/hash/THashPrimitiveIterator.java
new file mode 100644
index 00000000..9e7ecb2c
--- /dev/null
+++ b/src/gnu/trove/impl/hash/THashPrimitiveIterator.java
@@ -0,0 +1,143 @@
+// ////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+// ////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove.impl.hash;
+
+import gnu.trove.iterator.TPrimitiveIterator;
+
+import java.util.ConcurrentModificationException;
+import java.util.NoSuchElementException;
+
+
+/**
+ * Implements all iterator functions for the hashed object set.
+ * Subclasses may override objectAtIndex to vary the object
+ * returned by calls to next() (e.g. for values, and Map.Entry
+ * objects).
+ *
+ * Note that iteration is fastest if you forego the calls to + * hasNext in favor of checking the size of the structure + * yourself and then call next() that many times: + *
+ *+ * Iterator i = collection.iterator(); + * for (int size = collection.size(); size-- > 0;) { + * Object o = i.next(); + * } + *+ * + *
You may, of course, use the hasNext(), next() idiom too if + * you aren't in a performance critical spot.
+ */ +public abstract class THashPrimitiveIterator implements TPrimitiveIterator { + + /** the data structure this iterator traverses */ + protected final TPrimitiveHash _hash; + /** + * the number of elements this iterator believes are in the + * data structure it accesses. + */ + protected int _expectedSize; + /** the index used for iteration. */ + protected int _index; + + + /** + * Creates a TPrimitiveIterator for the specified collection. + * + * @param hash the TPrimitiveHash we want to iterate over. + */ + public THashPrimitiveIterator( TPrimitiveHash hash ) { + _hash = hash; + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + + /** + * Returns the index of the next value in the data structure + * or a negative value if the iterator is exhausted. + * + * @return anint
value
+ * @throws java.util.ConcurrentModificationException
+ * if the underlying collection's
+ * size has been modified since the iterator was created.
+ */
+ protected final int nextIndex() {
+ if ( _expectedSize != _hash.size() ) {
+ throw new ConcurrentModificationException();
+ }
+
+ byte[] states = _hash._states;
+ int i = _index;
+ while ( i-- > 0 && ( states[i] != TPrimitiveHash.FULL ) ) {
+ ;
+ }
+ return i;
+ }
+
+
+ /**
+ * Returns true if the iterator can be advanced past its current
+ * location.
+ *
+ * @return a boolean
value
+ */
+ public boolean hasNext() {
+ return nextIndex() >= 0;
+ }
+
+
+ /**
+ * Removes the last entry returned by the iterator.
+ * Invoking this method more than once for a single entry
+ * will leave the underlying data structure in a confused
+ * state.
+ */
+ public void remove() {
+ if (_expectedSize != _hash.size()) {
+ throw new ConcurrentModificationException();
+ }
+
+ // Disable auto compaction during the remove. This is a workaround for bug 1642768.
+ try {
+ _hash.tempDisableAutoCompaction();
+ _hash.removeAt(_index);
+ }
+ finally {
+ _hash.reenableAutoCompaction( false );
+ }
+
+ _expectedSize--;
+ }
+
+
+ /**
+ * Sets the internal index so that the `next' object
+ * can be returned.
+ */
+ protected final void moveToNextIndex() {
+ // doing the assignment && < 0 in one line shaves
+ // 3 opcodes...
+ if ( ( _index = nextIndex() ) < 0 ) {
+ throw new NoSuchElementException();
+ }
+ }
+
+
+} // TPrimitiveIterator
\ No newline at end of file
diff --git a/src/gnu/trove/impl/hash/TIntByteHash.java b/src/gnu/trove/impl/hash/TIntByteHash.java
new file mode 100644
index 00000000..686d272f
--- /dev/null
+++ b/src/gnu/trove/impl/hash/TIntByteHash.java
@@ -0,0 +1,464 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove.impl.hash;
+
+import gnu.trove.procedure.*;
+import gnu.trove.impl.HashFunctions;
+
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+import java.io.IOException;
+
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * An open addressed hashing implementation for int/byte primitive entries.
+ *
+ * Created: Sun Nov 4 08:56:06 2001
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden
+ * @author Jeff Randall
+ * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $
+ */
+abstract public class TIntByteHash extends TPrimitiveHash {
+ static final long serialVersionUID = 1L;
+
+ /** the set of ints */
+ public transient int[] _set;
+
+
+ /**
+ * key that represents null
+ *
+ * NOTE: should not be modified after the Hash is created, but is
+ * not final because of Externalization
+ *
+ */
+ protected int no_entry_key;
+
+
+ /**
+ * value that represents null
+ *
+ * NOTE: should not be modified after the Hash is created, but is
+ * not final because of Externalization
+ *
+ */
+ protected byte no_entry_value;
+
+ protected boolean consumeFreeSlot;
+
+ /**
+ * Creates a new T#E#Hash
instance with the default
+ * capacity and load factor.
+ */
+ public TIntByteHash() {
+ super();
+ no_entry_key = ( int ) 0;
+ no_entry_value = ( byte ) 0;
+ }
+
+
+ /**
+ * Creates a new T#E#Hash
instance whose capacity
+ * is the next highest prime above initialCapacity + 1
+ * unless that value is already prime.
+ *
+ * @param initialCapacity an int
value
+ */
+ public TIntByteHash( int initialCapacity ) {
+ super( initialCapacity );
+ no_entry_key = ( int ) 0;
+ no_entry_value = ( byte ) 0;
+ }
+
+
+ /**
+ * Creates a new TIntByteHash
instance with a prime
+ * value at or near the specified capacity and load factor.
+ *
+ * @param initialCapacity used to find a prime capacity for the table.
+ * @param loadFactor used to calculate the threshold over which
+ * rehashing takes place.
+ */
+ public TIntByteHash( int initialCapacity, float loadFactor ) {
+ super(initialCapacity, loadFactor);
+ no_entry_key = ( int ) 0;
+ no_entry_value = ( byte ) 0;
+ }
+
+
+ /**
+ * Creates a new TIntByteHash
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 no_entry_value value that represents null
+ */
+ public TIntByteHash( int initialCapacity, float loadFactor,
+ int no_entry_key, byte no_entry_value ) {
+ super(initialCapacity, loadFactor);
+ this.no_entry_key = no_entry_key;
+ this.no_entry_value = no_entry_value;
+ }
+
+
+ /**
+ * Returns the value that is used to represent null as a key. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ public int getNoEntryKey() {
+ return no_entry_key;
+ }
+
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ public byte getNoEntryValue() {
+ return no_entry_value;
+ }
+
+
+ /**
+ * initializes the hashtable to a prime capacity which is at least
+ * initialCapacity + 1.
+ *
+ * @param initialCapacity an int
value
+ * @return the actual capacity chosen
+ */
+ protected int setUp( int initialCapacity ) {
+ int capacity;
+
+ capacity = super.setUp( initialCapacity );
+ _set = new int[capacity];
+ return capacity;
+ }
+
+
+ /**
+ * Searches the set for val
+ *
+ * @param val an int
value
+ * @return a boolean
value
+ */
+ public boolean contains( int val ) {
+ return index(val) >= 0;
+ }
+
+
+ /**
+ * Executes procedure for each key in the map.
+ *
+ * @param procedure a TIntProcedure
value
+ * @return false if the loop over the set terminated because
+ * the procedure returned false for some value.
+ */
+ public boolean forEach( TIntProcedure procedure ) {
+ byte[] states = _states;
+ int[] set = _set;
+ for ( int i = set.length; i-- > 0; ) {
+ if ( states[i] == FULL && ! procedure.execute( set[i] ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Releases the element currently stored at index.
+ *
+ * @param index an int
value
+ */
+ protected void removeAt( int index ) {
+ _set[index] = no_entry_key;
+ super.removeAt( index );
+ }
+
+
+ /**
+ * Locates the index of val.
+ *
+ * @param key an int
value
+ * @return the index of val or -1 if it isn't in the set.
+ */
+ protected int index( int key ) {
+ int hash, probe, index, length;
+
+ final byte[] states = _states;
+ final int[] set = _set;
+ length = states.length;
+ hash = HashFunctions.hash( key ) & 0x7fffffff;
+ index = hash % length;
+ byte state = states[index];
+
+ if (state == FREE)
+ return -1;
+
+ if (state == FULL && set[index] == key)
+ return index;
+
+ return indexRehashed(key, index, hash, state);
+ }
+
+ int indexRehashed(int key, int index, int hash, byte state) {
+ // see Knuth, p. 529
+ int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+
+ do {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+ //
+ if (state == FREE)
+ return -1;
+
+ //
+ if (key == _set[index] && state != REMOVED)
+ return index;
+ } while (index != loopIndex);
+
+ return -1;
+ }
+
+
+ /**
+ * Locates the index at which val can be inserted. if
+ * there is already a value equal()ing val in the set,
+ * returns that value as a negative integer.
+ *
+ * @param key an int
value
+ * @return an int
value
+ */
+ protected int insertKey( int val ) {
+ int hash, index;
+
+ hash = HashFunctions.hash(val) & 0x7fffffff;
+ index = hash % _states.length;
+ byte state = _states[index];
+
+ consumeFreeSlot = false;
+
+ if (state == FREE) {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+
+ return index; // empty, all done
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1; // already stored
+ }
+
+ // already FULL or REMOVED, must probe
+ return insertKeyRehash(val, index, hash, state);
+ }
+
+ int insertKeyRehash(int val, int index, int hash, byte state) {
+ // compute the double hash
+ final int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+ int firstRemoved = -1;
+
+ /**
+ * Look until FREE slot or we start to loop
+ */
+ do {
+ // Identify first removed slot
+ if (state == REMOVED && firstRemoved == -1)
+ firstRemoved = index;
+
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+
+ // A FREE slot stops the search
+ if (state == FREE) {
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ } else {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+ return index;
+ }
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1;
+ }
+
+ // Detect loop
+ } while (index != loopIndex);
+
+ // We inspected all reachable slots and did not find a FREE one
+ // If we found a REMOVED slot we return the first one found
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ }
+
+ // Can a resizing strategy be found that resizes the set?
+ throw new IllegalStateException("No free or removed slots available. Key set full?!!");
+ }
+
+ void insertKeyAt(int index, int val) {
+ _set[index] = val; // insert value
+ _states[index] = FULL;
+ }
+
+ protected int XinsertKey( int key ) {
+ int hash, probe, index, length;
+
+ final byte[] states = _states;
+ final int[] set = _set;
+ length = states.length;
+ hash = HashFunctions.hash( key ) & 0x7fffffff;
+ index = hash % length;
+ byte state = states[index];
+
+ consumeFreeSlot = false;
+
+ if ( state == FREE ) {
+ consumeFreeSlot = true;
+ set[index] = key;
+ states[index] = FULL;
+
+ return index; // empty, all done
+ } else if ( state == FULL && set[index] == key ) {
+ return -index -1; // already stored
+ } else { // already FULL or REMOVED, must probe
+ // compute the double hash
+ probe = 1 + ( hash % ( length - 2 ) );
+
+ // if the slot we landed on is FULL (but not removed), probe
+ // until we find an empty slot, a REMOVED slot, or an element
+ // equal to the one we are trying to insert.
+ // finding an empty slot means that the value is not present
+ // and that we should use that slot as the insertion point;
+ // finding a REMOVED slot means that we need to keep searching,
+ // however we want to remember the offset of that REMOVED slot
+ // so we can reuse it in case a "new" insertion (i.e. not an update)
+ // is possible.
+ // finding a matching value means that we've found that our desired
+ // key is already in the table
+
+ if ( state != REMOVED ) {
+ // starting at the natural offset, probe until we find an
+ // offset that isn't full.
+ do {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = states[index];
+ } while ( state == FULL && set[index] != key );
+ }
+
+ // if the index we found was removed: continue probing until we
+ // locate a free location or an element which equal()s the
+ // one we have.
+ if ( state == REMOVED) {
+ int firstRemoved = index;
+ while ( state != FREE && ( state == REMOVED || set[index] != key ) ) {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = states[index];
+ }
+
+ if (state == FULL) {
+ return -index -1;
+ } else {
+ set[index] = key;
+ states[index] = FULL;
+
+ return firstRemoved;
+ }
+ }
+ // if it's full, the key is already stored
+ if (state == FULL) {
+ return -index -1;
+ } else {
+ consumeFreeSlot = true;
+ set[index] = key;
+ states[index] = FULL;
+
+ return index;
+ }
+ }
+ }
+
+
+ /** {@inheritDoc} */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ // VERSION
+ out.writeByte( 0 );
+
+ // SUPER
+ super.writeExternal( out );
+
+ // NO_ENTRY_KEY
+ out.writeInt( no_entry_key );
+
+ // NO_ENTRY_VALUE
+ out.writeByte( no_entry_value );
+ }
+
+
+ /** {@inheritDoc} */
+ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ // VERSION
+ in.readByte();
+
+ // SUPER
+ super.readExternal( in );
+
+ // NO_ENTRY_KEY
+ no_entry_key = in.readInt();
+
+ // NO_ENTRY_VALUE
+ no_entry_value = in.readByte();
+ }
+} // TIntByteHash
diff --git a/src/gnu/trove/impl/hash/TIntHash.java b/src/gnu/trove/impl/hash/TIntHash.java
new file mode 100644
index 00000000..c7739e59
--- /dev/null
+++ b/src/gnu/trove/impl/hash/TIntHash.java
@@ -0,0 +1,334 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove.impl.hash;
+
+import gnu.trove.procedure.TIntProcedure;
+import gnu.trove.impl.HashFunctions;
+import gnu.trove.impl.Constants;
+
+import java.util.Arrays;
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * An open addressed hashing implementation for int primitives.
+ *
+ * Created: Sun Nov 4 08:56:06 2001
+ *
+ * @author Eric D. Friedman, Rob Eden, Jeff Randall
+ * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $
+ */
+abstract public class TIntHash extends TPrimitiveHash {
+ static final long serialVersionUID = 1L;
+
+ /** the set of ints */
+ public transient int[] _set;
+
+ /**
+ * value that represents null
+ *
+ * NOTE: should not be modified after the Hash is created, but is
+ * not final because of Externalization
+ *
+ */
+ protected int no_entry_value;
+
+ protected boolean consumeFreeSlot;
+
+
+ /**
+ * Creates a new TIntHash
instance with the default
+ * capacity and load factor.
+ */
+ public TIntHash() {
+ super();
+ no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( int ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Creates a new TIntHash
instance whose capacity
+ * is the next highest prime above initialCapacity + 1
+ * unless that value is already prime.
+ *
+ * @param initialCapacity an int
value
+ */
+ public TIntHash( int initialCapacity ) {
+ super( initialCapacity );
+ no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( int ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Creates a new TIntHash
instance with a prime
+ * value at or near the specified capacity and load factor.
+ *
+ * @param initialCapacity used to find a prime capacity for the table.
+ * @param loadFactor used to calculate the threshold over which
+ * rehashing takes place.
+ */
+ public TIntHash( int initialCapacity, float loadFactor ) {
+ super(initialCapacity, loadFactor);
+ no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( int ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Creates a new TIntHash
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 no_entry_value value that represents null
+ */
+ public TIntHash( int initialCapacity, float loadFactor, int no_entry_value ) {
+ super(initialCapacity, loadFactor);
+ this.no_entry_value = no_entry_value;
+ //noinspection RedundantCast
+ if ( no_entry_value != ( int ) 0 ) {
+ Arrays.fill( _set, no_entry_value );
+ }
+ }
+
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ public int getNoEntryValue() {
+ return no_entry_value;
+ }
+
+
+ /**
+ * initializes the hashtable to a prime capacity which is at least
+ * initialCapacity + 1.
+ *
+ * @param initialCapacity an int
value
+ * @return the actual capacity chosen
+ */
+ protected int setUp( int initialCapacity ) {
+ int capacity;
+
+ capacity = super.setUp( initialCapacity );
+ _set = new int[capacity];
+ return capacity;
+ }
+
+
+ /**
+ * Searches the set for val
+ *
+ * @param val an int
value
+ * @return a boolean
value
+ */
+ public boolean contains( int val ) {
+ return index(val) >= 0;
+ }
+
+
+ /**
+ * Executes procedure for each element in the set.
+ *
+ * @param procedure a TObjectProcedure
value
+ * @return false if the loop over the set terminated because
+ * the procedure returned false for some value.
+ */
+ public boolean forEach( TIntProcedure procedure ) {
+ byte[] states = _states;
+ int[] set = _set;
+ for ( int i = set.length; i-- > 0; ) {
+ if ( states[i] == FULL && ! procedure.execute( set[i] ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Releases the element currently stored at index.
+ *
+ * @param index an int
value
+ */
+ protected void removeAt( int index ) {
+ _set[index] = no_entry_value;
+ super.removeAt( index );
+ }
+
+
+ /**
+ * Locates the index of val.
+ *
+ * @param val an int
value
+ * @return the index of val or -1 if it isn't in the set.
+ */
+ protected int index( int val ) {
+ int hash, probe, index, length;
+
+ final byte[] states = _states;
+ final int[] set = _set;
+ length = states.length;
+ hash = HashFunctions.hash( val ) & 0x7fffffff;
+ index = hash % length;
+ byte state = states[index];
+
+ if (state == FREE)
+ return -1;
+
+ if (state == FULL && set[index] == val)
+ return index;
+
+ return indexRehashed(val, index, hash, state);
+ }
+
+ int indexRehashed(int key, int index, int hash, byte state) {
+ // see Knuth, p. 529
+ int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+
+ do {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+ //
+ if (state == FREE)
+ return -1;
+
+ //
+ if (key == _set[index] && state != REMOVED)
+ return index;
+ } while (index != loopIndex);
+
+ return -1;
+ }
+
+ /**
+ * Locates the index at which val can be inserted. if
+ * there is already a value equal()ing val in the set,
+ * returns that value as a negative integer.
+ *
+ * @param val an int
value
+ * @return an int
value
+ */
+ protected int insertKey( int val ) {
+ int hash, index;
+
+ hash = HashFunctions.hash(val) & 0x7fffffff;
+ index = hash % _states.length;
+ byte state = _states[index];
+
+ consumeFreeSlot = false;
+
+ if (state == FREE) {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+
+ return index; // empty, all done
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1; // already stored
+ }
+
+ // already FULL or REMOVED, must probe
+ return insertKeyRehash(val, index, hash, state);
+ }
+
+ int insertKeyRehash(int val, int index, int hash, byte state) {
+ // compute the double hash
+ final int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+ int firstRemoved = -1;
+
+ /**
+ * Look until FREE slot or we start to loop
+ */
+ do {
+ // Identify first removed slot
+ if (state == REMOVED && firstRemoved == -1)
+ firstRemoved = index;
+
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+
+ // A FREE slot stops the search
+ if (state == FREE) {
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ } else {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+ return index;
+ }
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1;
+ }
+
+ // Detect loop
+ } while (index != loopIndex);
+
+ // We inspected all reachable slots and did not find a FREE one
+ // If we found a REMOVED slot we return the first one found
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ }
+
+ // Can a resizing strategy be found that resizes the set?
+ throw new IllegalStateException("No free or removed slots available. Key set full?!!");
+ }
+
+ void insertKeyAt(int index, int val) {
+ _set[index] = val; // insert value
+ _states[index] = FULL;
+ }
+
+} // TIntHash
diff --git a/src/gnu/trove/impl/hash/TIntIntHash.java b/src/gnu/trove/impl/hash/TIntIntHash.java
new file mode 100644
index 00000000..e5a4cf90
--- /dev/null
+++ b/src/gnu/trove/impl/hash/TIntIntHash.java
@@ -0,0 +1,464 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove.impl.hash;
+
+import gnu.trove.procedure.*;
+import gnu.trove.impl.HashFunctions;
+
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+import java.io.IOException;
+
+
+//////////////////////////////////////////////////
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
+//////////////////////////////////////////////////
+
+
+/**
+ * An open addressed hashing implementation for int/int primitive entries.
+ *
+ * Created: Sun Nov 4 08:56:06 2001
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden
+ * @author Jeff Randall
+ * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $
+ */
+abstract public class TIntIntHash extends TPrimitiveHash {
+ static final long serialVersionUID = 1L;
+
+ /** the set of ints */
+ public transient int[] _set;
+
+
+ /**
+ * key that represents null
+ *
+ * NOTE: should not be modified after the Hash is created, but is
+ * not final because of Externalization
+ *
+ */
+ protected int no_entry_key;
+
+
+ /**
+ * value that represents null
+ *
+ * NOTE: should not be modified after the Hash is created, but is
+ * not final because of Externalization
+ *
+ */
+ protected int no_entry_value;
+
+ protected boolean consumeFreeSlot;
+
+ /**
+ * Creates a new T#E#Hash
instance with the default
+ * capacity and load factor.
+ */
+ public TIntIntHash() {
+ super();
+ no_entry_key = ( int ) 0;
+ no_entry_value = ( int ) 0;
+ }
+
+
+ /**
+ * Creates a new T#E#Hash
instance whose capacity
+ * is the next highest prime above initialCapacity + 1
+ * unless that value is already prime.
+ *
+ * @param initialCapacity an int
value
+ */
+ public TIntIntHash( int initialCapacity ) {
+ super( initialCapacity );
+ no_entry_key = ( int ) 0;
+ no_entry_value = ( int ) 0;
+ }
+
+
+ /**
+ * Creates a new TIntIntHash
instance with a prime
+ * value at or near the specified capacity and load factor.
+ *
+ * @param initialCapacity used to find a prime capacity for the table.
+ * @param loadFactor used to calculate the threshold over which
+ * rehashing takes place.
+ */
+ public TIntIntHash( int initialCapacity, float loadFactor ) {
+ super(initialCapacity, loadFactor);
+ no_entry_key = ( int ) 0;
+ no_entry_value = ( int ) 0;
+ }
+
+
+ /**
+ * Creates a new TIntIntHash
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 no_entry_value value that represents null
+ */
+ public TIntIntHash( int initialCapacity, float loadFactor,
+ int no_entry_key, int no_entry_value ) {
+ super(initialCapacity, loadFactor);
+ this.no_entry_key = no_entry_key;
+ this.no_entry_value = no_entry_value;
+ }
+
+
+ /**
+ * Returns the value that is used to represent null as a key. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ public int getNoEntryKey() {
+ return no_entry_key;
+ }
+
+
+ /**
+ * Returns the value that is used to represent null. The default
+ * value is generally zero, but can be changed during construction
+ * of the collection.
+ *
+ * @return the value that represents null
+ */
+ public int getNoEntryValue() {
+ return no_entry_value;
+ }
+
+
+ /**
+ * initializes the hashtable to a prime capacity which is at least
+ * initialCapacity + 1.
+ *
+ * @param initialCapacity an int
value
+ * @return the actual capacity chosen
+ */
+ protected int setUp( int initialCapacity ) {
+ int capacity;
+
+ capacity = super.setUp( initialCapacity );
+ _set = new int[capacity];
+ return capacity;
+ }
+
+
+ /**
+ * Searches the set for val
+ *
+ * @param val an int
value
+ * @return a boolean
value
+ */
+ public boolean contains( int val ) {
+ return index(val) >= 0;
+ }
+
+
+ /**
+ * Executes procedure for each key in the map.
+ *
+ * @param procedure a TIntProcedure
value
+ * @return false if the loop over the set terminated because
+ * the procedure returned false for some value.
+ */
+ public boolean forEach( TIntProcedure procedure ) {
+ byte[] states = _states;
+ int[] set = _set;
+ for ( int i = set.length; i-- > 0; ) {
+ if ( states[i] == FULL && ! procedure.execute( set[i] ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Releases the element currently stored at index.
+ *
+ * @param index an int
value
+ */
+ protected void removeAt( int index ) {
+ _set[index] = no_entry_key;
+ super.removeAt( index );
+ }
+
+
+ /**
+ * Locates the index of val.
+ *
+ * @param key an int
value
+ * @return the index of val or -1 if it isn't in the set.
+ */
+ protected int index( int key ) {
+ int hash, probe, index, length;
+
+ final byte[] states = _states;
+ final int[] set = _set;
+ length = states.length;
+ hash = HashFunctions.hash( key ) & 0x7fffffff;
+ index = hash % length;
+ byte state = states[index];
+
+ if (state == FREE)
+ return -1;
+
+ if (state == FULL && set[index] == key)
+ return index;
+
+ return indexRehashed(key, index, hash, state);
+ }
+
+ int indexRehashed(int key, int index, int hash, byte state) {
+ // see Knuth, p. 529
+ int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+
+ do {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+ //
+ if (state == FREE)
+ return -1;
+
+ //
+ if (key == _set[index] && state != REMOVED)
+ return index;
+ } while (index != loopIndex);
+
+ return -1;
+ }
+
+
+ /**
+ * Locates the index at which val can be inserted. if
+ * there is already a value equal()ing val in the set,
+ * returns that value as a negative integer.
+ *
+ * @param key an int
value
+ * @return an int
value
+ */
+ protected int insertKey( int val ) {
+ int hash, index;
+
+ hash = HashFunctions.hash(val) & 0x7fffffff;
+ index = hash % _states.length;
+ byte state = _states[index];
+
+ consumeFreeSlot = false;
+
+ if (state == FREE) {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+
+ return index; // empty, all done
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1; // already stored
+ }
+
+ // already FULL or REMOVED, must probe
+ return insertKeyRehash(val, index, hash, state);
+ }
+
+ int insertKeyRehash(int val, int index, int hash, byte state) {
+ // compute the double hash
+ final int length = _set.length;
+ int probe = 1 + (hash % (length - 2));
+ final int loopIndex = index;
+ int firstRemoved = -1;
+
+ /**
+ * Look until FREE slot or we start to loop
+ */
+ do {
+ // Identify first removed slot
+ if (state == REMOVED && firstRemoved == -1)
+ firstRemoved = index;
+
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = _states[index];
+
+ // A FREE slot stops the search
+ if (state == FREE) {
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ } else {
+ consumeFreeSlot = true;
+ insertKeyAt(index, val);
+ return index;
+ }
+ }
+
+ if (state == FULL && _set[index] == val) {
+ return -index - 1;
+ }
+
+ // Detect loop
+ } while (index != loopIndex);
+
+ // We inspected all reachable slots and did not find a FREE one
+ // If we found a REMOVED slot we return the first one found
+ if (firstRemoved != -1) {
+ insertKeyAt(firstRemoved, val);
+ return firstRemoved;
+ }
+
+ // Can a resizing strategy be found that resizes the set?
+ throw new IllegalStateException("No free or removed slots available. Key set full?!!");
+ }
+
+ void insertKeyAt(int index, int val) {
+ _set[index] = val; // insert value
+ _states[index] = FULL;
+ }
+
+ protected int XinsertKey( int key ) {
+ int hash, probe, index, length;
+
+ final byte[] states = _states;
+ final int[] set = _set;
+ length = states.length;
+ hash = HashFunctions.hash( key ) & 0x7fffffff;
+ index = hash % length;
+ byte state = states[index];
+
+ consumeFreeSlot = false;
+
+ if ( state == FREE ) {
+ consumeFreeSlot = true;
+ set[index] = key;
+ states[index] = FULL;
+
+ return index; // empty, all done
+ } else if ( state == FULL && set[index] == key ) {
+ return -index -1; // already stored
+ } else { // already FULL or REMOVED, must probe
+ // compute the double hash
+ probe = 1 + ( hash % ( length - 2 ) );
+
+ // if the slot we landed on is FULL (but not removed), probe
+ // until we find an empty slot, a REMOVED slot, or an element
+ // equal to the one we are trying to insert.
+ // finding an empty slot means that the value is not present
+ // and that we should use that slot as the insertion point;
+ // finding a REMOVED slot means that we need to keep searching,
+ // however we want to remember the offset of that REMOVED slot
+ // so we can reuse it in case a "new" insertion (i.e. not an update)
+ // is possible.
+ // finding a matching value means that we've found that our desired
+ // key is already in the table
+
+ if ( state != REMOVED ) {
+ // starting at the natural offset, probe until we find an
+ // offset that isn't full.
+ do {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = states[index];
+ } while ( state == FULL && set[index] != key );
+ }
+
+ // if the index we found was removed: continue probing until we
+ // locate a free location or an element which equal()s the
+ // one we have.
+ if ( state == REMOVED) {
+ int firstRemoved = index;
+ while ( state != FREE && ( state == REMOVED || set[index] != key ) ) {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ state = states[index];
+ }
+
+ if (state == FULL) {
+ return -index -1;
+ } else {
+ set[index] = key;
+ states[index] = FULL;
+
+ return firstRemoved;
+ }
+ }
+ // if it's full, the key is already stored
+ if (state == FULL) {
+ return -index -1;
+ } else {
+ consumeFreeSlot = true;
+ set[index] = key;
+ states[index] = FULL;
+
+ return index;
+ }
+ }
+ }
+
+
+ /** {@inheritDoc} */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ // VERSION
+ out.writeByte( 0 );
+
+ // SUPER
+ super.writeExternal( out );
+
+ // NO_ENTRY_KEY
+ out.writeInt( no_entry_key );
+
+ // NO_ENTRY_VALUE
+ out.writeInt( no_entry_value );
+ }
+
+
+ /** {@inheritDoc} */
+ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ // VERSION
+ in.readByte();
+
+ // SUPER
+ super.readExternal( in );
+
+ // NO_ENTRY_KEY
+ no_entry_key = in.readInt();
+
+ // NO_ENTRY_VALUE
+ no_entry_value = in.readInt();
+ }
+} // TIntIntHash
diff --git a/src/gnu/trove/impl/hash/TObjectHash.java b/src/gnu/trove/impl/hash/TObjectHash.java
new file mode 100644
index 00000000..8ae9a408
--- /dev/null
+++ b/src/gnu/trove/impl/hash/TObjectHash.java
@@ -0,0 +1,619 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
+// Copyright (c) 2009, Rob Eden All Rights Reserved.
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+///////////////////////////////////////////////////////////////////////////////
+
+package gnu.trove.impl.hash;
+
+import gnu.trove.procedure.TObjectProcedure;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+/**
+ * An open addressed hashing implementation for Object types.
+ *
+ * Created: Sun Nov 4 08:56:06 2001
+ *
+ * @author Eric D. Friedman
+ * @author Rob Eden
+ * @author Jeff Randall
+ * @version $Id: TObjectHash.java,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $
+ */
+abstract public class TObjectHashTObjectHash
instance with the
+ * default capacity and load factor.
+ */
+ public TObjectHash() {
+ super();
+ }
+
+
+ /**
+ * Creates a new TObjectHash
instance whose capacity
+ * is the next highest prime above initialCapacity + 1
+ * unless that value is already prime.
+ *
+ * @param initialCapacity an int
value
+ */
+ public TObjectHash(int initialCapacity) {
+ super(initialCapacity);
+ }
+
+
+ /**
+ * Creates a new TObjectHash
instance with a prime
+ * value at or near the specified capacity and load factor.
+ *
+ * @param initialCapacity used to find a prime capacity for the table.
+ * @param loadFactor used to calculate the threshold over which
+ * rehashing takes place.
+ */
+ public TObjectHash(int initialCapacity, float loadFactor) {
+ super(initialCapacity, loadFactor);
+ }
+
+
+ public int capacity() {
+ return _set.length;
+ }
+
+
+ protected void removeAt(int index) {
+ _set[index] = REMOVED;
+ super.removeAt(index);
+ }
+
+
+ /**
+ * initializes the Object set of this hash table.
+ *
+ * @param initialCapacity an int
value
+ * @return an int
value
+ */
+ public int setUp(int initialCapacity) {
+ int capacity;
+
+ capacity = super.setUp(initialCapacity);
+ _set = new Object[capacity];
+ Arrays.fill(_set, FREE);
+ return capacity;
+ }
+
+
+ /**
+ * Executes procedure for each element in the set.
+ *
+ * @param procedure a TObjectProcedure
value
+ * @return false if the loop over the set terminated because
+ * the procedure returned false for some value.
+ */
+ @SuppressWarnings({"unchecked"})
+ public boolean forEach(TObjectProcedure super T> procedure) {
+ Object[] set = _set;
+ for (int i = set.length; i-- > 0;) {
+ if (set[i] != FREE
+ && set[i] != REMOVED
+ && !procedure.execute((T) set[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Searches the set for obj
+ *
+ * @param obj an Object
value
+ * @return a boolean
value
+ */
+ @SuppressWarnings({"unchecked"})
+ public boolean contains(Object obj) {
+ return index(obj) >= 0;
+ }
+
+
+ /**
+ * Locates the index of obj.
+ *
+ * @param obj an Object
value
+ * @return the index of obj or -1 if it isn't in the set.
+ */
+ protected int index(Object obj) {
+ if (obj == null)
+ return indexForNull();
+
+ // From here on we know obj to be non-null
+ final int hash = hash(obj) & 0x7fffffff;
+ int index = hash % _set.length;
+ Object cur = _set[index];
+
+
+ if (cur == FREE) {
+ return -1;
+ }
+
+ if (cur == obj || equals(obj, cur)) {
+ return index;
+ }
+
+ return indexRehashed(obj, index, hash, cur);
+ }
+
+ /**
+ * Locates the index of non-null obj.
+ *
+ * @param obj target key, know to be non-null
+ * @param index we start from
+ * @param hash
+ * @param cur
+ * @return
+ */
+ private int indexRehashed(Object obj, int index, int hash, Object cur) {
+ final Object[] set = _set;
+ final int length = set.length;
+
+ // NOTE: here it has to be REMOVED or FULL (some user-given value)
+ // see Knuth, p. 529
+ int probe = 1 + (hash % (length - 2));
+
+ final int loopIndex = index;
+
+ do {
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ cur = set[index];
+ //
+ if (cur == FREE)
+ return -1;
+
+ //
+ if ((cur == obj || equals(obj, cur)))
+ return index;
+ } while (index != loopIndex);
+
+ return -1;
+ }
+
+ /**
+ * Locates the index null.
+ *
+ * null specific loop exploiting several properties to simplify the iteration logic
+ * - the null value hashes to 0 we so we can iterate from the beginning.
+ * - the probe value is 1 for this case
+ * - object identity can be used to match this case
+ *
+ * --> this result a simpler loop
+ *
+ * @return
+ */
+ private int indexForNull() {
+ int index = 0;
+ for (Object o : _set) {
+ if (o == null)
+ return index;
+
+ if (o == FREE)
+ return -1;
+
+ index++;
+ }
+
+ return -1;
+ }
+
+ /**
+ * Alias introduced to avoid breaking the API. The new method name insertKey() reflects the
+ * changes made to the logic.
+ *
+ * @param obj
+ * @return
+ * @deprecated use {@link #insertKey} instead
+ */
+ @Deprecated
+ protected int insertionIndex(T obj) {
+ return insertKey(obj);
+ }
+
+ /**
+ * Locates the index at which key can be inserted. if
+ * there is already a value equal()ing key in the set,
+ * returns that value's index as -index - 1.
+ *
+ * If a slot is found the value is inserted. When a FREE slot is used the consumeFreeSlot field is
+ * set to true. This field should be used in the method invoking insertKey() to pass to postInsertHook()
+ *
+ * @param key an Object
value
+ * @return the index of a FREE slot at which key can be inserted
+ * or, if key is already stored in the hash, the negative value of
+ * that index, minus 1: -index -1.
+ */
+ protected int insertKey(T key) {
+ consumeFreeSlot = false;
+
+ if (key == null)
+ return insertKeyForNull();
+
+ final int hash = hash(key) & 0x7fffffff;
+ int index = hash % _set.length;
+ Object cur = _set[index];
+
+ if (cur == FREE) {
+ consumeFreeSlot = true;
+ _set[index] = key; // insert value
+ return index; // empty, all done
+ }
+
+ if (cur == key || equals(key, cur)) {
+ return -index - 1; // already stored
+ }
+
+ return insertKeyRehash(key, index, hash, cur);
+ }
+
+ /**
+ * Looks for a slot using double hashing for a non-null key values and inserts the value
+ * in the slot
+ *
+ * @param key non-null key value
+ * @param index natural index
+ * @param hash
+ * @param cur value of first matched slot
+ * @return
+ */
+ private int insertKeyRehash(T key, int index, int hash, Object cur) {
+ final Object[] set = _set;
+ final int length = set.length;
+ // already FULL or REMOVED, must probe
+ // compute the double hash
+ final int probe = 1 + (hash % (length - 2));
+
+ final int loopIndex = index;
+ int firstRemoved = -1;
+
+ /**
+ * Look until FREE slot or we start to loop
+ */
+ do {
+ // Identify first removed slot
+ if (cur == REMOVED && firstRemoved == -1)
+ firstRemoved = index;
+
+ index -= probe;
+ if (index < 0) {
+ index += length;
+ }
+ cur = set[index];
+
+ // A FREE slot stops the search
+ if (cur == FREE) {
+ if (firstRemoved != -1) {
+ _set[firstRemoved] = key;
+ return firstRemoved;
+ } else {
+ consumeFreeSlot = true;
+ _set[index] = key; // insert value
+ return index;
+ }
+ }
+
+ if (cur == key || equals(key, cur)) {
+ return -index - 1;
+ }
+
+ // Detect loop
+ } while (index != loopIndex);
+
+ // We inspected all reachable slots and did not find a FREE one
+ // If we found a REMOVED slot we return the first one found
+ if (firstRemoved != -1) {
+ _set[firstRemoved] = key;
+ return firstRemoved;
+ }
+
+ // Can a resizing strategy be found that resizes the set?
+ throw new IllegalStateException("No free or removed slots available. Key set full?!!");
+ }
+
+ /**
+ * Looks for a slot using double hashing for a null key value and inserts the value.
+ *
+ * null specific loop exploiting several properties to simplify the iteration logic
+ * - the null value hashes to 0 we so we can iterate from the beginning.
+ * - the probe value is 1 for this case
+ * - object identity can be used to match this case
+ *
+ * @return
+ */
+ private int insertKeyForNull() {
+ int index = 0;
+ int firstRemoved = -1;
+
+ // Look for a slot containing the 'null' value as key
+ for (Object o : _set) {
+ // Locate first removed
+ if (o == REMOVED && firstRemoved == -1)
+ firstRemoved = index;
+
+ if (o == FREE) {
+ if (firstRemoved != -1) {
+ _set[firstRemoved] = null;
+ return firstRemoved;
+ } else {
+ consumeFreeSlot = true;
+ _set[index] = null; // insert value
+ return index;
+ }
+ }
+
+ if (o == null) {
+ return -index - 1;
+ }
+
+ index++;
+ }
+
+ // We inspected all reachable slots and did not find a FREE one
+ // If we found a REMOVED slot we return the first one found
+ if (firstRemoved != -1) {
+ _set[firstRemoved] = null;
+ return firstRemoved;
+ }
+
+ // We scanned the entire key set and found nothing, is set full?
+ // Can a resizing strategy be found that resizes the set?
+ throw new IllegalStateException("Could not find insertion index for null key. Key set full!?!!");
+ }
+
+
+ /**
+ * Convenience methods for subclasses to use in throwing exceptions about
+ * badly behaved user objects employed as keys. We have to throw an
+ * IllegalArgumentException with a rather verbose message telling the
+ * user that they need to fix their object implementation to conform
+ * to the general contract for java.lang.Object.
+ *
+ *
+ * @param o1 the first of the equal elements with unequal hash codes.
+ * @param o2 the second of the equal elements with unequal hash codes.
+ * @throws IllegalArgumentException the whole point of this method.
+ */
+ protected final void throwObjectContractViolation(Object o1, Object o2)
+ throws IllegalArgumentException {
+ throw buildObjectContractViolation(o1, o2, "");
+ }
+
+ /**
+ * Convenience methods for subclasses to use in throwing exceptions about
+ * badly behaved user objects employed as keys. We have to throw an
+ * IllegalArgumentException with a rather verbose message telling the
+ * user that they need to fix their object implementation to conform
+ * to the general contract for java.lang.Object.
+ *
+ *
+ * @param o1 the first of the equal elements with unequal hash codes.
+ * @param o2 the second of the equal elements with unequal hash codes.
+ * @param size
+ *@param oldSize
+ * @param oldKeys @throws IllegalArgumentException the whole point of this method.
+ */
+ protected final void throwObjectContractViolation(Object o1, Object o2, int size, int oldSize, Object[] oldKeys)
+ throws IllegalArgumentException {
+ String extra = dumpExtraInfo(o1, o2, size(), oldSize, oldKeys);
+
+
+ throw buildObjectContractViolation(o1, o2, extra);
+ }
+
+ /**
+ * Convenience methods for subclasses to use in throwing exceptions about
+ * badly behaved user objects employed as keys. We have to throw an
+ * IllegalArgumentException with a rather verbose message telling the
+ * user that they need to fix their object implementation to conform
+ * to the general contract for java.lang.Object.
+ *
+ *
+ * @param o1 the first of the equal elements with unequal hash codes.
+ * @param o2 the second of the equal elements with unequal hash codes.
+ * @throws IllegalArgumentException the whole point of this method.
+ */
+ protected final IllegalArgumentException buildObjectContractViolation(Object o1, Object o2, String extra ) {
+ return new IllegalArgumentException("Equal objects must have equal hashcodes. " +
+ "During rehashing, Trove discovered that the following two objects claim " +
+ "to be equal (as in java.lang.Object.equals()) but their hashCodes (or " +
+ "those calculated by your TObjectHashingStrategy) are not equal." +
+ "This violates the general contract of java.lang.Object.hashCode(). See " +
+ "bullet point two in that method's documentation. object #1 =" + objectInfo(o1) +
+ "; object #2 =" + objectInfo(o2) + "\n" + extra);
+ }
+
+
+ protected boolean equals(Object notnull, Object two) {
+ if (two == null || two == REMOVED)
+ return false;
+
+ return notnull.equals(two);
+ }
+
+ protected int hash(Object notnull) {
+ return notnull.hashCode();
+ }
+
+ protected static String reportPotentialConcurrentMod(int newSize, int oldSize) {
+ // Note that we would not be able to detect concurrent paired of put()-remove()
+ // operations with this simple check
+ if (newSize != oldSize)
+ return "[Warning] apparent concurrent modification of the key set. " +
+ "Size before and after rehash() do not match " + oldSize + " vs " + newSize;
+
+ return "";
+ }
+
+ /**
+ *
+ * @param newVal the key being inserted
+ * @param oldVal the key already stored at that position
+ * @param currentSize size of the key set during rehashing
+ * @param oldSize size of the key set before rehashing
+ * @param oldKeys the old key set
+ */
+ protected String dumpExtraInfo(Object newVal, Object oldVal, int currentSize, int oldSize, Object[] oldKeys) {
+ StringBuilder b = new StringBuilder();
+ //
+ b.append(dumpKeyTypes(newVal, oldVal));
+
+ b.append(reportPotentialConcurrentMod(currentSize, oldSize));
+ b.append(detectKeyLoss(oldKeys, oldSize));
+
+ // Is de same object already present? Double insert?
+ if (newVal == oldVal) {
+ b.append("Inserting same object twice, rehashing bug. Object= ").append(oldVal);
+ }
+
+ return b.toString();
+ }
+
+ /**
+ * Detect inconsistent hashCode() and/or equals() methods
+ *
+ * @param keys
+ * @param oldSize
+ * @return
+ */
+ private static String detectKeyLoss(Object[] keys, int oldSize) {
+ StringBuilder buf = new StringBuilder();
+ Set