org.apache.hadoop.hdfs.util
Class LightWeightGSet<K,E extends K>

java.lang.Object
  extended by org.apache.hadoop.hdfs.util.LightWeightGSet<K,E>
Type Parameters:
K - Key type for looking up the elements
E - Element type, which must be (1) a subclass of K, and (2) implementing LightWeightGSet.LinkedElement interface.
All Implemented Interfaces:
Iterable<E>, GSet<K,E>

@InterfaceAudience.Private
public class LightWeightGSet<K,E extends K>
extends Object
implements GSet<K,E>

A low memory footprint GSet implementation, which uses an array for storing the elements and linked lists for collision resolution. No rehash will be performed. Therefore, the internal array will never be resized. This class does not support null element. This class is not thread safe.


Nested Class Summary
static interface LightWeightGSet.LinkedElement
          Elements of LightWeightGSet.
 
Field Summary
static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
LightWeightGSet(int recommended_length)
           
 
Method Summary
 boolean contains(K key)
          Does this set contain an element corresponding to the given key?
 E get(K key)
          Return the stored element which is equal to the given key.
 Iterator<E> iterator()
           
 void printDetails(PrintStream out)
          Print detailed information of this object.
 E put(E element)
          Add/replace an element.
 E remove(K key)
          Remove the element corresponding to the given key.
 int size()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG
Constructor Detail

LightWeightGSet

public LightWeightGSet(int recommended_length)
Parameters:
recommended_length - Recommended size of the internal array.
Method Detail

size

public int size()
Specified by:
size in interface GSet<K,E extends K>
Returns:
The size of this set.

get

public E get(K key)
Description copied from interface: GSet
Return the stored element which is equal to the given key. This operation is similar to Map.get(Object).

Specified by:
get in interface GSet<K,E extends K>
Parameters:
key - The given key.
Returns:
The stored element if it exists. Otherwise, return null.

contains

public boolean contains(K key)
Description copied from interface: GSet
Does this set contain an element corresponding to the given key?

Specified by:
contains in interface GSet<K,E extends K>
Parameters:
key - The given key.
Returns:
true if the given key equals to a stored element. Otherwise, return false.

put

public E put(E element)
Description copied from interface: GSet
Add/replace an element. If the element does not exist, add it to the set. Otherwise, replace the existing element. Note that this operation is similar to Map.put(Object, Object) but is different from Set.add(Object) which does not replace the existing element if there is any.

Specified by:
put in interface GSet<K,E extends K>
Parameters:
element - The element being put.
Returns:
the previous stored element if there is any. Otherwise, return null.

remove

public E remove(K key)
Description copied from interface: GSet
Remove the element corresponding to the given key. This operation is similar to Map.remove(Object).

Specified by:
remove in interface GSet<K,E extends K>
Parameters:
key - The key of the element being removed.
Returns:
If such element exists, return it. Otherwise, return null.

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E extends K>

toString

public String toString()
Overrides:
toString in class Object

printDetails

public void printDetails(PrintStream out)
Print detailed information of this object.



Copyright © 2009 The Apache Software Foundation