org.varienaja.util
Class DenseSet

java.lang.Object
  extended by org.varienaja.util.DenseSet

public class DenseSet
extends java.lang.Object

A Dense Set is a set of long-values. The Set is meant to contain many consecutive longs while using as little memory as possible. The more holes there are in the list of long-values, the more memory will be consumed. The memory consumption per hole is constant and independent of the size of the hole. The advantage of a DenseSet over a BitSet, is that the DenseSet has a constant size. It can hold MAX_LONG values, and still use two longs memory. Only the holes consume memory. A Bitset containing MAX_LONG bits would take an insane amount of 2^64/8 bytes, regardless of the amount of holes. So, when the amount of holes stays low enough, the DenseSet is a better choise than a BitSet.

Author:
varienaja

Field Summary
protected  java.util.Set<org.varienaja.util.Range> _ranges
           
 
Constructor Summary
DenseSet()
           
 
Method Summary
 boolean add(long l)
          Adds a long to the Set of longs.
 void clear()
          Removes all Long-values from the Set
 boolean contains(long l)
          Checks whether a certain value exists in the Set.
 boolean equals(java.lang.Object o)
           
 long get(long index)
          Searches for a long-value at a specific position.
 int hashCode()
           
 java.lang.String prettyPrint()
          Returns a string representation of the contents of the set in the format: a-b,c,d-e, ...
 boolean remove(long l)
          /** Removes a long value from the Set of longs.
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_ranges

protected java.util.Set<org.varienaja.util.Range> _ranges
Constructor Detail

DenseSet

public DenseSet()
Method Detail

size

public int size()
Returns:
The amount of long-values that is contained in the Set

add

public boolean add(long l)
Adds a long to the Set of longs.

Parameters:
l - The value to be added.
Returns:
Whether the Set changed because of this operation

remove

public boolean remove(long l)
/** Removes a long value from the Set of longs.

Parameters:
l - The long-value to be removed.
Returns:
Whether the long was removed

clear

public void clear()
Removes all Long-values from the Set


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

prettyPrint

public java.lang.String prettyPrint()
Returns a string representation of the contents of the set in the format: a-b,c,d-e, ...

Returns:
A String representation of the contents of the dense set.

get

public long get(long index)
Searches for a long-value at a specific position.

Parameters:
index - The position to look in
Returns:
returns the long that is at position index in the Set

contains

public boolean contains(long l)
Checks whether a certain value exists in the Set.

Parameters:
l - The value to check for.
Returns:
True, if this value is contained in this Set, False otherwise.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object


Copyright © 2010 A.J.V.. All Rights Reserved.