com.samskivert.util
Class IntIntMap

java.lang.Object
  extended by com.samskivert.util.IntIntMap
All Implemented Interfaces:
Serializable

public class IntIntMap
extends Object
implements Serializable

An int int map is like an int map, but with integers as values as well as keys. Note that in situations where null would normally be returned to indicate no value, -1 is returned instead. This means that you must be careful if you intend to store -1 as a valid value in the table.

See Also:
Serialized Form

Nested Class Summary
static interface IntIntMap.IntIntEntry
           
protected  class IntIntMap.KeyValueInterator
           
 
Field Summary
protected  float _loadFactor
           
protected  int _modCount
           
static int DEFAULT_BUCKETS
           
static float DEFAULT_LOAD_FACTOR
          The default load factor.
 
Constructor Summary
IntIntMap()
           
IntIntMap(int buckets)
           
IntIntMap(int buckets, float loadFactor)
           
 
Method Summary
protected  void checkShrink()
          Check to see if we want to shrink the table.
 void clear()
           
 boolean contains(int key)
           
 void ensureCapacity(int minCapacity)
          Ensure that the hash can comfortably hold the specified number of elements.
 Set<IntIntMap.IntIntEntry> entrySet()
          Get a set of all the entries in this map.
 int get(int key)
           
 int[] getKeys()
          Get an array of the unique keys in this map.
 int[] getValues()
          Get an array of the values that may be in this map.
 int increment(int key, int amount)
          Increments the value associated with the specified key by the specified amount.
 boolean isEmpty()
           
 Interator keys()
           
protected  com.samskivert.util.IntIntMap.Record locateRecord(int key)
          Internal method to locate the record for the specified key.
 void put(int key, int value)
           
 int remove(int key)
           
protected  int removeImpl(int key)
           
protected  void resizeBuckets(int newsize)
          Resize the hashtable.
 int size()
           
protected  int[] toIntArray(boolean keys)
           
 String toString()
           
 Interator values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BUCKETS

public static final int DEFAULT_BUCKETS
See Also:
Constant Field Values

DEFAULT_LOAD_FACTOR

public static final float DEFAULT_LOAD_FACTOR
The default load factor.

See Also:
Constant Field Values

_loadFactor

protected float _loadFactor

_modCount

protected int _modCount
Constructor Detail

IntIntMap

public IntIntMap(int buckets,
                 float loadFactor)

IntIntMap

public IntIntMap(int buckets)

IntIntMap

public IntIntMap()
Method Detail

isEmpty

public boolean isEmpty()

size

public int size()

put

public void put(int key,
                int value)

get

public int get(int key)

increment

public int increment(int key,
                     int amount)
Increments the value associated with the specified key by the specified amount. If the key has no previously assigned value, it will be set to the amount specified (as if incrementing from zero).

Returns:
the incremented value now stored for the key

contains

public boolean contains(int key)

locateRecord

protected com.samskivert.util.IntIntMap.Record locateRecord(int key)
Internal method to locate the record for the specified key.


remove

public int remove(int key)

removeImpl

protected int removeImpl(int key)

clear

public void clear()

ensureCapacity

public void ensureCapacity(int minCapacity)
Ensure that the hash can comfortably hold the specified number of elements. Calling this method is not necessary, but can improve performance if done prior to adding many elements.


checkShrink

protected void checkShrink()
Check to see if we want to shrink the table.


resizeBuckets

protected void resizeBuckets(int newsize)
Resize the hashtable.

Parameters:
newsize - The new number of buckets to allocate.

keys

public Interator keys()

values

public Interator values()

getKeys

public int[] getKeys()
Get an array of the unique keys in this map.


getValues

public int[] getValues()
Get an array of the values that may be in this map. There may be duplicates.


toString

public String toString()
Overrides:
toString in class Object

toIntArray

protected int[] toIntArray(boolean keys)

entrySet

public Set<IntIntMap.IntIntEntry> entrySet()
Get a set of all the entries in this map.



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.