org.jboss.cache.util
Class BitEncodedIntegerSet

java.lang.Object
  extended by org.jboss.cache.util.BitEncodedIntegerSet

@NotThreadSafe
public class BitEncodedIntegerSet
extends Object

A Set that encodes integers as bits in a long. Does not implement java.util.Set since autoboxing is unnecessarily expensive for the ints stored, but follows very similar semantics to Set: no nulls, no duplicates, and order not guaranteed, and adds one more: this can only store ints from 0 to 63, inclusive.

Integers in this set are packed into a single long, setting bit values accordingly and hence the strict range on allowable integers. The upshot is a guaranteed limit on how much memory is consumed, as well as very efficient operations on the set.

Since:
2.1.0
Author:
Manik Surtani (manik@jboss.org)

Constructor Summary
BitEncodedIntegerSet()
           
 
Method Summary
 void add(int i)
          Adds an integer to the set.
 void addAll(BitEncodedIntegerSet otherSet)
          Adds all elements of another BitEncodedIntegerSet to the current set.
 void clear()
          Clears the set
 boolean contains(int i)
          Tests whether the set contains an integer
 boolean equals(Object o)
           
 int hashCode()
           
 boolean isEmpty()
          Tests if the set is empty
 void remove(int i)
          Removes an integer from the set
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitEncodedIntegerSet

public BitEncodedIntegerSet()
Method Detail

add

public void add(int i)
Adds an integer to the set.

Parameters:
i - integer to add

remove

public void remove(int i)
Removes an integer from the set

Parameters:
i - integer to remove

contains

public boolean contains(int i)
Tests whether the set contains an integer

Parameters:
i - integer to check for
Returns:
true if contained; false otherwise

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clear

public void clear()
Clears the set


isEmpty

public boolean isEmpty()
Tests if the set is empty

Returns:
true if empty

toString

public String toString()
Overrides:
toString in class Object

addAll

public void addAll(BitEncodedIntegerSet otherSet)
Adds all elements of another BitEncodedIntegerSet to the current set.

Parameters:
otherSet - other set to add


Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.