com.sleepycat.je.utilint
Class TinyHashSet<T>

java.lang.Object
  extended by com.sleepycat.je.utilint.TinyHashSet<T>
All Implemented Interfaces:
Iterable<T>

public class TinyHashSet<T>
extends Object
implements Iterable<T>

TinyHashSet is used to optimize (for speed, not space) the case where a HashSet generally holds a single element. This saves us the cost of creating the HashSet and related elements as well as call Object.hashCode(). If single != null, it's the only element in the TinyHashSet. If set != null then there are multiple elements in the TinyHashSet. It should never be true that (single != null) && (set != null).


Nested Class Summary
static class TinyHashSet.SingleElementIterator<T>
           
 
Constructor Summary
TinyHashSet()
          Creates an empty set.
TinyHashSet(T o)
          Creates a set with one element.
 
Method Summary
 boolean add(T o)
           
 boolean contains(T o)
           
 Set<T> copy()
           
 Iterator<T> iterator()
           
 boolean remove(T o)
           
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TinyHashSet

public TinyHashSet()
Creates an empty set.


TinyHashSet

public TinyHashSet(T o)
Creates a set with one element.

Method Detail

size

public int size()

contains

public boolean contains(T o)

remove

public boolean remove(T o)

add

public boolean add(T o)

copy

public Set<T> copy()

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>


Copyright (c) 2004-2012 Oracle. All rights reserved.