UtlContainable* UtlHashMap::removeKeyAndValue(const UtlContainable* key, UtlContainable*& value) { UtlContainable* removed = NULL; value = NULL; if (key) { OsLock take(mContainerLock); UtlPair* pair; UtlChain* bucket; if ( lookup(key, bucket, pair) ) { removed = pair->data; value = (pair->value != INTERNAL_NULL) ? pair->value : NULL; notifyIteratorsOfRemove(pair); pair->detachFromList(bucket); removed = pair->data; value = pair->value; pair->release(); mElements--; } } return removed; }
UtlContainable* UtlHashBag::remove(const UtlContainable* object) { UtlContainable* removed = NULL; if (object) { OsLock take(mContainerLock); UtlLink* link; UtlChain* bucket; if ( lookup(object, bucket, link) ) { removed = link->data; notifyIteratorsOfRemove(link); link->detachFromList(bucket); removed = link->data; link->release(); mElements--; } } return removed; }
void UtlHashMap::destroyAll() { OsLock take(mContainerLock); size_t i; size_t toBeDestroyed; for (i = 0, toBeDestroyed = mElements; i < numberOfBuckets() && toBeDestroyed; i++ ) // for each bucket { while(!mpBucket[i].isUnLinked()) // bucket is not empty yet { UtlPair* pair = static_cast<UtlPair*>(mpBucket[i].head()); notifyIteratorsOfRemove(pair); pair->detachFromList(&mpBucket[i]); delete pair->data; if (pair->value != INTERNAL_NULL) { delete pair->value; } pair->release(); toBeDestroyed--; } } mElements = 0; }
/** * Removed the designated object by reference * (as opposed to searching for an equality match). * * @return the object if successful, otherwise null */ UtlContainable* UtlHashBag::removeReference(const UtlContainable* object) { UtlContainable* removed = NULL; if (object) { size_t keyHash = object->hash(); OsLock take(mContainerLock); UtlLink* link; UtlChain* bucket; UtlLink* check; bucket = &mpBucket[bucketNumber(keyHash)]; for (link = NULL, check = static_cast<UtlLink*>(bucket->listHead()); ( !link // not found && check // not end of list && check->hash <= keyHash // hash list is ordered, so if > then it's not in the list ); check = check->next() ) { if (check->data == object) { link = check; // found it } } if (link) { notifyIteratorsOfRemove(link); link->detachFromList(bucket); removed = link->data; link->release(); mElements--; } } return removed; }
void UtlHashBag::removeAll() { OsLock take(mContainerLock); size_t i; size_t toBeRemoved; for (i = 0, toBeRemoved = mElements; i < numberOfBuckets() && toBeRemoved; i++ ) // for each bucket { while(!mpBucket[i].isUnLinked()) // bucket is not empty yet { UtlLink* link = static_cast<UtlLink*>(mpBucket[i].head()); notifyIteratorsOfRemove(link); link->detachFromList(&mpBucket[i]); link->release(); toBeRemoved--; } } mElements = 0; }