LimeWire Collection Component API

org.limewire.collection
Class IntSet

java.lang.Object
  extended by org.limewire.collection.IntSet

public class IntSet
extends Object

Represents a set of distinct integers. Like Set, IntSet is not synchronized.

Optimized to have an extremely compact representation when the set is "dense", i.e., has many sequential elements. For example {1, 2} and {1, 2, ..., 1000} require the same amount of space. All retrieval operations run in O(log n) time, where n is the size of the set. Insertion operations may be slower.

All methods have the same specification as the Set class, except that values are restricted to int' for the reason described above. For this reason, methods are not specified below.

This class is not thread-safe.

    IntSet s = new IntSet(10);
    s.add(1); s.add(1); 
    s.add(3); s.add(4); s.add(5);
    s.add(7);       
    System.out.println("Set is " + s);
    s.add(2);       
    System.out.println("Set is " + s);
    s.remove(3);        
    System.out.println("Set is " + s);

    Output:
        Set is [1, 3-5, 7]
        Set is [1-5, 7]
        Set is [1-2, 4-5, 7]

 


Nested Class Summary
 class IntSet.IntSetIterator
          Yields a sequence of int's (not Object's) in order, without removal support.
 
Constructor Summary
IntSet()
           
IntSet(int expectedSize)
           
 
Method Summary
 boolean add(int x)
           
 boolean addAll(IntSet s)
           
 void clear()
           
 boolean contains(int x)
           
 IntSet.IntSetIterator iterator()
          Returns the values of this in order from lowest to highest, as int.
 int max()
           
 int min()
           
 boolean remove(int x)
           
protected  void repOk()
          Checks rep invariant.
 boolean retainAll(IntSet s)
           
 int size()
           
 String toString()
           
 void trim()
          Ensures that this consumes the minimum amount of memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntSet

public IntSet()

IntSet

public IntSet(int expectedSize)
Method Detail

repOk

protected void repOk()
Checks rep invariant.


max

public int max()

min

public int min()

size

public int size()

clear

public void clear()

contains

public boolean contains(int x)

add

public boolean add(int x)

remove

public boolean remove(int x)

addAll

public boolean addAll(IntSet s)

retainAll

public boolean retainAll(IntSet s)

trim

public void trim()
Ensures that this consumes the minimum amount of memory. This method should typically be called after the last call to add(..). Insertions can still be done after the call, but they might be slower. Because this method only affects the performance of this, there is no modifies clause listed.


iterator

public IntSet.IntSetIterator iterator()
Returns the values of this in order from lowest to highest, as int.


toString

public String toString()
Overrides:
toString in class Object

LimeWire Collection Component API

Copyright © 2008 Lime Wire LLC. All Rights Reserved.