int LLBC_Dictionary::SetHashBucketSize(size_type bucketSize) { if (UNLIKELY(bucketSize == 0)) { LLBC_SetLastError(LLBC_ERROR_INVALID); return LLBC_RTN_FAILED; } // Cancel hash. Iter it = this->Begin(), endIt = this->End(); for (; it != endIt; it++) { it.Elem()->CancelHash(); } // ReAlloc bucket. _bucketSize = bucketSize; _bucket = reinterpret_cast<LLBC_DictionaryElem **>( realloc(_bucket, _bucketSize * sizeof(LLBC_DictionaryElem *))); LLBC_MemSet(_bucket, 0, _bucketSize * sizeof(LLBC_DictionaryElem *)); // ReHash. it = this->Begin(); for (; it != endIt; it++) { it.Elem()->Hash(_bucket, _bucketSize); } return LLBC_RTN_OK; }
int LLBC_Dictionary::Erase(Iter it) { if (it == this->End()) { LLBC_SetLastError(LLBC_ERROR_NOT_FOUND); return LLBC_RTN_FAILED; } LLBC_DictionaryElem * elem = it.Elem(); // Remove from hash bucket. elem->CancelHash(); // Remove from doubly-linked list. this->RemoveFromDoublyLinkedList(elem); delete elem; _size -= 1; return LLBC_RTN_OK; }