# PAbstractSet Class Reference

Abstract set of PObjects. More...

`#include <dict.h>`

Inheritance diagram for PAbstractSet:

List of all members.

## Overrides from class PCollection

virtual PINDEX | Append (PObject *obj)
| Add a new object to the collection.
virtual PINDEX | Insert (const PObject &before, PObject *obj)
| Add a new object to the collection.
virtual PINDEX | InsertAt (PINDEX index, PObject *obj)
| Add a new object to the collection.
virtual PBoolean | Remove (const PObject *obj)
| Remove the object from the collection.
virtual PObject * | RemoveAt (PINDEX index)
| Remove an object at the specified index.
virtual PObject * | GetAt (PINDEX index) const
| This function is the same as PHashTable::AbstractGetKeyAt().
virtual PBoolean | SetAt (PINDEX index, PObject *val)
| Add a new object to the collection.
virtual PINDEX | GetObjectsIndex (const PObject *obj) const
| Search the collection for the specific instance of the object.
virtual PINDEX | GetValuesIndex (const PObject &obj) const
| Search the collection for the specified value of the object.
bool | Union (const PAbstractSet &set)
| Calculate union of sets.
static bool | Intersection (const PAbstractSet &set1, const PAbstractSet &set2, PAbstractSet *intersection=NULL)
| Calculate intersection of sets.

## Public Member Functions

Construction
PINLINE | PAbstractSet ()
| Create a new, empty, set.

## Detailed Description

Abstract set of PObjects.

## Constructor & Destructor Documentation

PINLINE PAbstractSet::PAbstractSet | ( |  | ) |

Create a new, empty, set.

Note that by default, objects placed into the list will be deleted when removed or when all references to the list are destroyed.

## Member Function Documentation

virtual PINDEX PAbstractSet::Append | ( | PObject * | obj | ) | `[virtual]`

Add a new object to the collection.

If the objects value is already in the set then the object is not included. If the `AllowDeleteObjects` option is set then the `obj` parameter is also deleted.

Returns:
  hash function value of the newly added object.

Parameters:

  obj | New object to place into the collection.

Implements PCollection.

virtual PObject* PAbstractSet::GetAt | ( | PINDEX | index | ) | const`[virtual]`

This function is the same as PHashTable::AbstractGetKeyAt().

Returns:
  Always NULL.

Parameters:

  index | Index position in the collection of the object.

Implements PCollection.

virtual PINDEX PAbstractSet::GetObjectsIndex | ( | const PObject * | obj | ) | const`[virtual]`

Search the collection for the specific instance of the object.

The object pointers are compared, not the values. The hash table is used to locate the entry.

Note that that will require value comparisons to be made to find the equivalent entry and then a final check is made with the pointers to see if they are the same instance.

Returns:
  ordinal index position of the object, or P_MAX_INDEX .

Parameters:

  obj | Object to find.

Implements PCollection.

virtual PINDEX PAbstractSet::GetValuesIndex | ( | const PObject & | obj | ) | const`[virtual]`

Search the collection for the specified value of the object.

The object values are compared, not the pointers. So the objects in the collection must correctly implement the `PObject::Compare()` function. The hash table is used to locate the entry.

Returns:
  ordinal index position of the object, or P_MAX_INDEX.

Parameters:

  obj | Object to find equal value.

Implements PCollection.

virtual PINDEX PAbstractSet::Insert | ( | const PObject & | before,
|  | PObject * | obj |
| ) |  |  | `[virtual]`

Add a new object to the collection.

If the objects value is already in the set then the object is not included. If the `AllowDeleteObjects` option is set then the `obj` parameter is also deleted.

The object is always placed in the an ordinal position dependent on its hash function. It is not placed at the specified position. The `before` parameter is ignored.

Returns:
  hash function value of the newly added object.

Parameters:

  before | Object value to insert before.
  obj | New object to place into the collection.

Implements PCollection.

virtual PINDEX PAbstractSet::InsertAt | ( | PINDEX | index,
|  | PObject * | obj |
| ) |  |  | `[virtual]`

Add a new object to the collection.

If the objects value is already in the set then the object is not included. If the `AllowDeleteObjects` option is set then the `obj` parameter is also deleted.

The object is always placed in the an ordinal position dependent on its hash function. It is not placed at the specified position. The `index` parameter is ignored.

Returns:
  hash function value of the newly added object.

Parameters:

  index | Index position in collection to place the object.
  obj | New object to place into the collection.

Implements PCollection.

static bool PAbstractSet::Intersection | ( | const PAbstractSet & | set1,
|  | const PAbstractSet & | set2,
|  | PAbstractSet * | intersection = `NULL` |
| ) |  |  | `[static]`

Calculate intersection of sets.

Returns true if there is an intersection.

virtual PBoolean PAbstractSet::Remove | ( | const PObject * | obj | ) | `[virtual]`

Remove the object from the collection.

If the `AllowDeleteObjects` option is set then the object is also deleted.

Note that the comparison for searching for the object in collection is made by pointer, not by value. Thus the parameter must point to the same instance of the object that is in the collection.

Returns:
  true if the object was in the collection.

Parameters:

  obj | Existing object to remove from the collection.

Implements PCollection.

virtual PObject* PAbstractSet::RemoveAt | ( | PINDEX | index | ) | `[virtual]`

Remove an object at the specified index.

If the `AllowDeleteObjects` option is set then the object is also deleted.

Returns:
  pointer to the object being removed, or NULL if it was deleted.

Parameters:

  index | Index position in collection to place the object.

Implements PCollection.

virtual PBoolean PAbstractSet::SetAt | ( | PINDEX | index,
|  | PObject * | val |
| ) |  |  | `[virtual]`

Add a new object to the collection.

If the objects value is already in the set then the object is not included. If the AllowDeleteObjects option is set then the `obj` parameter is also deleted.

The object is always placed in the an ordinal position dependent on its hash function. It is not placed at the specified position. The `index` parameter is ignored.

Returns:
  true if the object was successfully added.

Parameters:

  index | Index position in collection to set.
  val | New value to place into the collection.

Implements PCollection.

bool PAbstractSet::Union | ( | const PAbstractSet & | set | ) |

Calculate union of sets.

Returns true if any new elements were added.

The documentation for this class was generated from the following file:

- dict.h