Yate
Public Member Functions | List of all members
HashList Class Reference

A hashed object list class. More...

#include <yateclass.h>

Inheritance diagram for HashList:
GenObject

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
 
ObjListgetList (unsigned int index) const
 
ObjListgetHashList (unsigned int hash) const
 
ObjListgetHashList (const String &str) const
 
GenObjectoperator[] (const String &str) const
 
ObjListfind (const GenObject *obj) const
 
ObjListfind (const GenObject *obj, unsigned int hash) const
 
ObjListfind (const String &str) const
 
ObjListappend (const GenObject *obj)
 
ObjListappend (const GenObject *obj, unsigned int hash)
 
GenObjectremove (GenObject *obj, bool delobj=true, bool useHash=false)
 
GenObjectremove (const String &str, bool delobj=true)
 
GenObjectremove (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 StringtoString () const
 
virtual const StringtraceId () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (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 NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

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 ( unsigned int  size = 17)
explicit

Creates a new, empty list.

Parameters
sizeNumber of classes to divide the objects
virtual ~HashList ( )
virtual

Destroys the list and everything in it.

Member Function Documentation

ObjList* append ( const GenObject obj)

Appends an object to the hashed list

Parameters
objPointer to the object to append
Returns
A pointer to the inserted list item
ObjList* append ( const GenObject obj,
unsigned int  hash 
)

Appends an object to the hashed list

Parameters
objPointer to the object to append
hashObject hash used to identify the list into which this object should be inserted
Returns
A pointer to the inserted list item
void clear ( )

Clear the list and optionally delete all contained objects

unsigned int count ( ) const

Get the number of non-null objects in the list

Returns
Count of items
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
objPointer to the object to search for
Returns
Pointer to the found item or NULL

Referenced by HashList::remove().

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

Get the item in the list that holds an object

Parameters
objPointer to the object to search for
hashObject hash used to identify the list it belongs to
Returns
Pointer to the found item or NULL
ObjList* find ( const String str) const

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

Parameters
strString value (toString) of the object to search for
Returns
Pointer to the first found item or NULL
ObjList* getHashList ( unsigned int  hash) const
inline

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

Parameters
hashHash of the internal list to retrieve
Returns
Pointer to the list or NULL if never filled

References HashList::getList().

Referenced by HashList::getHashList().

ObjList* getHashList ( const String str) const
inline

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

Parameters
strString whose hash internal list is to retrieve
Returns
Pointer to the list or NULL if never filled

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

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
indexIndex of the internal list to retrieve
Returns
Pointer to the list or NULL

Referenced by HashList::getHashList().

virtual void* getObject ( const String name) const
virtual

Get a pointer to a derived class given that class name

Parameters
nameName 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.

unsigned int length ( ) const
inline

Get the number of hash entries

Returns
Count of hash entries
GenObject* operator[] ( const String str) const

Array-like indexing operator

Parameters
strString value of the object to locate
Returns
Pointer to the first object or NULL
GenObject* remove ( GenObject obj,
bool  delobj = true,
bool  useHash = false 
)

Delete the list item that holds a given object

Parameters
objObject to search in the list
delobjTrue to delete the object (default)
useHashTrue to use object hash to identify the list it belongs to
Returns
Pointer to the object if not destroyed
GenObject* remove ( const String str,
bool  delobj = true 
)
inline

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

Parameters
strString value (toString) of the object to remove
delobjTrue to delete the object (default)
Returns
Pointer to the object if not destroyed

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

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

Delete the item in the list that has the associated hash

Parameters
objObject to search in the list
hashObject hash used to identify the list from which to remove the object
delobjTrue to delete the object (default)
Returns
Pointer to the object if not destroyed

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

bool resync ( GenObject obj)

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

Parameters
objObject to resync in the list
Returns
True if object was in the wrong list and had to be moved
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

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