// Function to remove all entries from the hash // SHOULD be called when entries have to be deleted! // because the hash also has to do some internal clean-up. void TCPIP_OAHASH_EntriesRemoveAll(OA_HASH_DCPT* pOH) { OA_HASH_ENTRY* pBkt; size_t bktIx; pBkt = (OA_HASH_ENTRY*)pOH->memBlk; for(bktIx = 0; bktIx < pOH->hEntries; bktIx++) { if(pBkt->flags.busy) { // found entry _OAHashRemoveEntry(pOH, pBkt); } pBkt = (OA_HASH_ENTRY*)((uint8_t*)pBkt + pOH->hEntrySize); } }
// Performs look up and insert // if key is found, it returns the pointer to the existing entry // if key was not found but there's an empty slot it will insert // the key in this slot and newEntry flag will be set // If there's no room in the hash it will call the delF to empty // a slot and place the key there // If the delF is NULL it will return NULL. // NULL is also returned when the probeStep is not properly chosen and // the hash cannot be properly traversed in one pass // (detect the situation by probing that the cache was not full: // fullSlots < hElements) OA_HASH_ENTRY* TCPIP_OAHASH_EntryLookupOrInsert(OA_HASH_DCPT* pOH, void* key) { OA_HASH_ENTRY *pBkt, *pDel; pBkt = _OAHashFindBkt(pOH, key); if(pBkt == 0) { if(pOH->fullSlots != pOH->hEntries) { // wrong probeStep! return 0; } // else cache is full // discard an old entry and retry #if defined ( OA_HASH_DYNAMIC_KEY_MANIPULATION ) if(pOH->delF == 0 || (pDel = (*pOH->delF)(pOH)) == 0) { // nothing else we can do return 0; } #else if((pDel = TCPIP_OAHASH_EntryDelete(pOH)) == 0) { // nothing else we can do return 0; } #endif // defined ( OA_HASH_DYNAMIC_KEY_MANIPULATION ) _OAHashRemoveEntry(pOH, pDel); pBkt = _OAHashFindBkt(pOH, key); if(pBkt == 0) { // probeStep failure, again return 0; } } // we found an entry if(pBkt->flags.busy == 0) { pBkt->flags.busy = 1; pBkt->flags.newEntry = 1; } else { // old entry pBkt->flags.newEntry = 0; } return pBkt; }
// Function to delete an entry from the hash // SHOULD be called when entries have to be deleted! // because the hash also has to do some internal clean-up. // Note: when an entry is deleted by TCPIP_OAHASH_EntryLookupOrInsert (calling pOH->delF) // the hash state is maintained internally, no need to call TCPIP_OAHASH_EntryRemove(); void TCPIP_OAHASH_EntryRemove(OA_HASH_DCPT* pOH, OA_HASH_ENTRY* pOE) { _OAHashRemoveEntry(pOH, pOE); }
// Function to delete an entry from the hash // SHOULD be called when entries have to be deleted! // because the hash also has to do some internal clean-up. // Note: when an entry is deleted by OAHashLookUpInsert (calling pOH->delF) // the hash state is maintained internally, no need to call OAHashRemoveEntry(); void OAHashRemoveEntry(OA_HASH_DCPT* pOH, OA_HASH_ENTRY* pOE) { _OAHashRemoveEntry(pOH, pOE); }