Public Member Functions | Protected Member Functions | Protected Attributes

BaseConnectionManager::CoordSet Class Reference

Represents an minimalistic (hash)set of GridCoords. More...

List of all members.

Public Member Functions

 CoordSet (unsigned sz)
 Initializes the set (hashtable) with the a specified size.
 ~CoordSet ()
 Delete every created GridCoord.
void add (const GridCoord &c)
 Adds a GridCoord to the set. If a GridCoord with the same value already exists in the set nothing happens.
GridCoordnext ()
 Returns the next GridCoord in the set. You can iterate through the set only one time with this function!
unsigned getSize ()
 Returns the number of GridCoords currently saved in this set.
unsigned getmaxSize ()
 Returns the maximum number of elements which can be stored inside this set. To prevent collisions the set should never be more than 75% filled.

Protected Member Functions

void insert (const GridCoord &c, unsigned pos)
 Tries to insert a GridCoord at the specified position.

Protected Attributes

std::vector< GridCoord * > data
 Holds the hash table.
unsigned maxSize
 maximum size of the hash table.
unsigned size
 Current number of entries in the hash table.
unsigned current
 Holds the current element when iterating over this table.

Detailed Description

Represents an minimalistic (hash)set of GridCoords.

It is a workaround because c++ doesn't come with an hash set.

Definition at line 117 of file BaseConnectionManager.h.


Member Function Documentation

void BaseConnectionManager::CoordSet::insert ( const GridCoord c,
unsigned  pos 
) [inline, protected]

Tries to insert a GridCoord at the specified position.

If the same Coord already exists there nothing happens. If an other Coord already exists there calculate a new Position to insert end recursively call this Method again. If the spot is empty the Coord is inserted.

Definition at line 138 of file BaseConnectionManager.h.

References data, maxSize, and size.

Referenced by add().

                                                  {
      if(data[pos] == 0) {
        data[pos] = new GridCoord(c);
        size++;
      } else {
        if(*data[pos] != c) {
          insert(c, (pos + 2) % maxSize);
        }
      }
    }


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