Yate: HashList Class Reference

Yate

Public Member Functions | List of all members
HashList Class Reference

A hashed object list class. More...

`#include <yateclass.h>`

Inheritance diagram for HashList:

## Public Member Functions
| HashList (unsigned int size=17)
virtual | ~HashList ()
virtual void * | getObject (const String &name) const
unsigned int | length () const
unsigned int | count () const
ObjList * | getList (unsigned int index) const
ObjList * | getHashList (unsigned int hash) const
ObjList * | getHashList (const String &str) const
GenObject * | operator[] (const String &str) const
ObjList * | find (const GenObject *obj) const
ObjList * | find (const GenObject *obj, unsigned int hash) const
ObjList * | find (const String &str) const
ObjList * | append (const GenObject *obj)
ObjList * | append (const GenObject *obj, unsigned int hash)
GenObject * | remove (GenObject *obj, bool delobj=true, bool useHash=false)
GenObject * | remove (const String &str, bool delobj=true)
GenObject * | remove (GenObject *obj, unsigned int hash, bool delobj=true)
void | clear ()
bool | resync (GenObject *obj)
bool | resync ()
Public Member Functions inherited from GenObject
| GenObject ()
virtual | ~GenObject ()
virtual bool | alive () const
virtual void | destruct ()
virtual const String & | toString () const
virtual const String & | traceId () const
NamedCounter * | getObjCounter () const
NamedCounter * | setObjCounter (NamedCounter *counter)

## Additional Inherited Members
Static Public Member Functions inherited from GenObject
static void * | getObject (const String &name, const GenObject *obj)
static bool | getObjCounting ()
static void | setObjCounting (bool enable)
static NamedCounter * | getObjCounter (const String &name, bool create=true)
static ObjList & | getObjCounters ()

## Detailed Description

A hashed object list class.

A hashed object list handling class. Objects placed in the list are distributed according to their String hash resulting in faster searches. On the other hand an object placed in a hashed list must never change its String value or it becomes unfindable.

## Constructor & Destructor Documentation

## ◆ HashList()

HashList | ( | unsigned int | size = 17 | ) |
| explicit

Creates a new, empty list.

Parameters

  size | Number of classes to divide the objects

## ◆ ~HashList()

virtual ~HashList | ( |  | ) |
| virtual

Destroys the list and everything in it.

## Member Function Documentation

## ◆ append() [1/2]

ObjList * append | ( | const GenObject * | obj | ) |

Appends an object to the hashed list

Parameters

  obj | Pointer to the object to append

Returns
  A pointer to the inserted list item

References GenObject::GenObject().

## ◆ append() [2/2]

ObjList * append | ( | const GenObject * | obj,
|  | unsigned int | hash )

Appends an object to the hashed list

Parameters

  obj | Pointer to the object to append
  hash | Object hash used to identify the list into which this object should be inserted

Returns
  A pointer to the inserted list item

References GenObject::GenObject().

## ◆ clear()

void clear | ( |  | ) |

Clear the list and optionally delete all contained objects

## ◆ count()

unsigned int count | ( |  | ) | const

Get the number of non-null objects in the list

Returns
  Count of items

## ◆ find() [1/3]

ObjList * find | ( | const GenObject * | obj | ) | const

Get the item in the list that holds an object. The item is searched sequentially in the lists, not using it's String hash

Parameters

  obj | Pointer to the object to search for

Returns
  Pointer to the found item or NULL

References GenObject::GenObject().

Referenced by remove(), and remove().

## ◆ find() [2/3]

ObjList * find | ( | const GenObject * | obj,
|  | unsigned int | hash ) const

Get the item in the list that holds an object

Parameters

  obj | Pointer to the object to search for
  hash | Object hash used to identify the list it belongs to

Returns
  Pointer to the found item or NULL

References GenObject::GenObject().

## ◆ find() [3/3]

ObjList * find | ( | const String & | str | ) | const

Get the item in the list that holds an object by String value

Parameters

  str | String value (toString) of the object to search for

Returns
  Pointer to the first found item or NULL

## ◆ getHashList() [1/2]

ObjList * getHashList | ( | const String & | str | ) | const
| inline

Retrieve one of the internal object lists knowing the String value.

Parameters

  str | String whose hash internal list is to retrieve

Returns
  Pointer to the list or NULL if never filled

References getHashList(), and String::hash().

## ◆ getHashList() [2/2]

ObjList * getHashList | ( | unsigned int | hash | ) | const
| inline

Retrieve one of the internal object lists knowing the hash value.

Parameters

  hash | Hash of the internal list to retrieve

Returns
  Pointer to the list or NULL if never filled

References getList().

Referenced by getHashList().

## ◆ getList()

ObjList * getList | ( | unsigned int | index | ) | const
| inline

Retrieve one of the internal object lists. This method should be used only to iterate all objects in the list.

Parameters

  index | Index of the internal list to retrieve

Returns
  Pointer to the list or NULL

Referenced by getHashList().

## ◆ getObject()

virtual void * getObject | ( | const String & | name | ) | const
| virtual

Get a pointer to a derived class given that class name

Parameters

  name | Name of the class we are asking for

Returns
  Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

## ◆ length()

unsigned int length | ( |  | ) | const
| inline

Get the number of hash entries

Returns
  Count of hash entries

## ◆ operator[]()

GenObject * operator[] | ( | const String & | str | ) | const

Array-like indexing operator

Parameters

  str | String value of the object to locate

Returns
  Pointer to the first object or NULL

References GenObject::GenObject().

## ◆ remove() [1/3]

GenObject * remove | ( | const String & | str,
|  | bool | delobj = true )
| inline

Delete the item in the list that holds an object by String value

Parameters

  str | String value (toString) of the object to remove
  delobj | True to delete the object (default)

Returns
  Pointer to the object if not destroyed

References find(), GenObject::GenObject(), and ObjList::remove().

## ◆ remove() [2/3]

GenObject * remove | ( | GenObject * | obj,
|  | bool | delobj = true,
|  | bool | useHash = false )

Delete the list item that holds a given object

Parameters

  obj | Object to search in the list
  delobj | True to delete the object (default)
  useHash | True to use object hash to identify the list it belongs to

Returns
  Pointer to the object if not destroyed

References GenObject::GenObject().

## ◆ remove() [3/3]

GenObject * remove | ( | GenObject * | obj,
|  | unsigned int | hash,
|  | bool | delobj = true )
| inline

Delete the item in the list that has the associated hash

Parameters

  obj | Object to search in the list
  hash | Object hash used to identify the list from which to remove the object
  delobj | True to delete the object (default)

Returns
  Pointer to the object if not destroyed

References find(), GenObject::GenObject(), and ObjList::remove().

## ◆ resync() [1/2]

bool resync | ( |  | ) |

Resync the list by checking if all stored objects belong to the list according to their hash

Returns
  True if at least one object had to be moved

## ◆ resync() [2/2]

bool resync | ( | GenObject * | obj | ) |

Resync the list by checking if a stored object belongs to the list according to its hash

Parameters

  obj | Object to resync in the list

Returns
  True if object was in the wrong list and had to be moved

References GenObject::GenObject().

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

- yateclass.h