Add methods to HashList that allow adding and removing of an object with arbitrary associated hashes.

git-svn-id: http://voip.null.ro/svn/yate@6441 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2020-10-21 10:44:33 +00:00
parent 37c2b36722
commit 100d644ce6
2 changed files with 32 additions and 0 deletions

View File

@ -104,6 +104,17 @@ ObjList* HashList::append(const GenObject* obj)
return m_lists[i]->append(obj);
}
ObjList* HashList::append(const GenObject* obj, unsigned int hash)
{
XDebug(DebugAll,"HashList::append(%p,%u) [%p]",obj,hash,this);
if (!obj)
return 0;
unsigned int i = hash % m_size;
if (!m_lists[i])
m_lists[i] = new ObjList;
return m_lists[i]->append(obj);
}
GenObject* HashList::remove(GenObject* obj, bool delobj, bool useHash)
{
ObjList* n = 0;

View File

@ -3716,6 +3716,14 @@ public:
*/
ObjList* append(const GenObject* obj);
/**
* Appends an object to the hashed list
* @param obj Pointer to the object to append
* @param hash Object hash used to identify the list into which this object should be inserted
* @return A pointer to the inserted list item
*/
ObjList* append(const GenObject* obj, unsigned int hash);
/**
* Delete the list item that holds a given object
* @param obj Object to search in the list
@ -3737,6 +3745,19 @@ public:
return n ? n->remove(delobj) : 0;
}
/**
* Delete the item in the list that has the associated hash
* @param obj Object to search in the list
* @param hash Object hash used to identify the list from which to remove the object
* @param delobj True to delete the object (default)
* @return Pointer to the object if not destroyed
*/
inline GenObject* remove(GenObject* obj, unsigned int hash, bool delobj = true)
{
ObjList* n = find(obj,hash);
return n ? n->remove(delobj) : 0;
}
/**
* Clear the list and optionally delete all contained objects
*/