Oracle Coherence for C++ API
Release 3.7.0.0

E18684-01

LiteSet Class Reference

#include <coherence/util/LiteSet.hpp>

Inherits AbstractSet.

List of all members.


Detailed Description

An implementation of coherence::util::Set that is optimal (in terms of both size and speed) for very small sets of data but still works excellently with large sets of data.

This implementation is not thread-safe.

The LiteSet implementation switches at runtime between several different sub-implementations for storing the set of objects, described here:

  1. "empty set" - a set that contains no data;
  2. "single entry" - a reference directly to an item is used to represent a set with exactly one item in it;
  3. "ObjectArray" - a reference is held to an array of Objects that store the contents of the Set; the item limit for this implementation is determined by the threshold constant;
  4. "delegation" - for more than threshold items, a set is created to delegate the set management to; sub-classes can override the default delegation class (HashSet) by overriding the factory method instantiateSet().

The LiteSet implementation supports the NULL value.

Author:
cp/lh 10/18/2010

Public Types

typedef spec::Handle Handle
 LiteSet Handle definition.
typedef spec::View View
 LiteSet View definition.
typedef spec::Holder Holder
 LiteSet Holder definition.

Public Member Functions

 LiteSet ()
 Construct a LiteSet.
 LiteSet (Collection::View vCollection)
 Construct a LiteSet containing the elements of the passed Collection.
virtual bool isEmpty () const
 Determine whether this collection contains any elements.

Returns:
true if this collection has no elements

virtual size32_t size () const
 Return the number of elements in this collection.

Returns:
the number of elements in this collection

virtual bool contains (Object::View v) const
 Determine if this collection contains the specified element.

Parameters:
v the element to test for containment
Returns:
true iff this collection contains the given element

virtual Iterator::Handle iterator () const
 Return an Iterator over this collection.

Returns:
an Iterator over this collection

virtual Muterator::Handle iterator ()
 Return an Iterator over this collection.

Returns:
an Iterator over this collection

ObjectArray::Handle toArray (ObjectArray::Handle haDest=NULL) const
 Return the contents of this collection as an ObjectArray.

If the collection fits in the specified array, it is returned, otherwise, a new array is allocated that is the size of this collection.

If this collection fits in the array with aditional room then the element in the array immediately following the end of the collection is set to NULL. This can be useful in determining the length of this collection if the caller knows that the collection does not contain any NULL elements.

Parameters:
hao an array in which to store the collection's contents
Returns:
a ObjectArray containing all the elements of the collection in the same order as returned by the collection's Iterator
See also:
Iterator

bool add (Object::Holder oh)
 Add the given element to this collection.

Parameters:
oh the element to add
Returns:
true iff this collection was modified as a result of this operation

This implementation will throw a coherence::lang::UnsupportedOperationException

bool remove (Object::View v)
 Remove the supplied element from this collection.

Parameters:
v the element to remove
Returns:
true iff this collection was modified as a result of this operation

This implementation will throw a coherence::lang::UnsupportedOperationException unless add() is overridden (assuming the specified collection is non-empty).

virtual bool containsAll (Collection::View vCollection) const
 Determine if this collection contains all elements from the supplied collection.

Parameters:
vCol the collection of elements to test for containment
Returns:
true iff this collection contains all elements from the supplied collection
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
contains()

This implementation iterates over the specified collection, checking each element returned by the iterator in turn to see if it's contained in this collection. If all elements are so contained true is returned, otherwise false.

virtual bool addAll (Collection::View vCollection)
 Add all elements from the supplied collection to this collection.

Parameters:
vCol the collection of elements to add
Returns:
true iff this collection was modified as a result of this operation
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
add()

This implementation will throw a coherence::lang::UnsupportedOperationException unless add() is overridden (assuming the specified collection is non-empty).

virtual bool retainAll (Collection::View vCollection)
 Remove all elements from this collection that are not present in the supplied collection.

Parameters:
vCol the collection of elements to retain
Returns:
true iff this collection was modified as a result of this operation.
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
remove()

contains()

This implementation will throw a coherence::lang::UnsupportedOperationException unless remove() is overridden (assuming there are items to be removed by the operation).

virtual bool removeAll (Collection::View vCollection)
 Remove all instances of the elements in the supplied collection from this collection.

Upon completion, contains() on this collection will return false for all elements in the supplied collection.

Parameters:
vCol the collection of elements to remove
Returns:
true iff this collection was modified as a result of this operation
Exceptions:
coherence::lang::NullPointerException if the specified collection is NULL
See also:
remove()

contains()

This implementation will throw a coherence::lang::UnsupportedOperationException} unless remove() is overridden (assuming the specified collection is non-empty).

virtual void clear ()
 Remove all elements from this collection.

This implementation will throw a coherence::lang::UnsupportedOperationException.


Protected Member Functions

Set::Handle instantiateSet ()
 (Factory pattern) Instantiate a Set object to store items in once the "lite" threshold has been exceeded.
Set::View instantiateSet () const
 (Factory pattern) Instantiate a Set object to store items in once the "lite" threshold has been exceeded.
void initFromArray (ObjectArray::View va, size32_t c)
 Initialize the contents of this Set from the passed array ao containing c values.
void checkShrinkFromOther ()
 After a mutation operation has reduced the size of an underlying Set, check if the delegation model should be replaced with a more size-efficient storage approach, and switch accordingly.

Constructor & Destructor Documentation

LiteSet ( Collection::View  vCollection  ) 

Construct a LiteSet containing the elements of the passed Collection.

Parameters:
vCollection a Collection


Member Function Documentation

Set::Handle instantiateSet (  )  [protected]

(Factory pattern) Instantiate a Set object to store items in once the "lite" threshold has been exceeded.

This method permits inheriting classes to easily override the choice of the Set object.

Returns:
an instance of Set

Set::View instantiateSet (  )  const [protected]

(Factory pattern) Instantiate a Set object to store items in once the "lite" threshold has been exceeded.

This method permits inheriting classes to easily override the choice of the Set object.

Returns:
an instance of Set

void initFromArray ( ObjectArray::View  va,
size32_t  c 
) [protected]

Initialize the contents of this Set from the passed array ao containing c values.

Parameters:
va the array that contains the values to place in this Set
c the number of values that will be placed into this Set


The documentation for this class was generated from the following file:
Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.