Exemple #1
0
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;
}
Exemple #2
0
LLBC_Array::Iter LLBC_Array::Erase(LLBC_Array::Iter n0, LLBC_Array::Iter n1)
{
    if (UNLIKELY(n0 >= n1))
    {
        LLBC_SetLastError(LLBC_ERROR_ARG);
        return End();
    }
    if (!(n0 >= Begin() && n0 < End()) ||
        !(n1 >= Begin() && n1 <= End()))
    {
        LLBC_SetLastError(LLBC_ERROR_ARG);
        return End();
    }

    for (difference_type i = n0._idx; i < n1._idx; i++)
    {
        _objs[i]->Release();
    }

    LLBC_MemCpy(_objs + n0._idx, _objs + n1._idx, (_size - n1._idx) * sizeof(Obj *));
    LLBC_MemSet(_objs + _size - (n1._idx - n0._idx), 0, (n1._idx - n0._idx) * sizeof(Obj *));

    _size -= (n1._idx - n0._idx);

    LLBC_SetLastError(LLBC_ERROR_SUCCESS);
    return Iter(_objs, n0._idx);
}
Exemple #3
0
void LLBC_Array::Recapacity(size_type cap)
{
    if (cap <= _capacity)
    {
        return;
    }

    _objs = reinterpret_cast<Obj **>(realloc(_objs, cap * sizeof(Obj *)));
    LLBC_MemSet(_objs + _capacity, 0, (cap - _capacity) * sizeof(Obj *));

    _capacity = cap;
}
Exemple #4
0
void LLBC_Dictionary::Clear()
{
    LLBC_DictionaryElem *elem = _head;
    while (elem)
    {
        LLBC_DictionaryElem *temp = elem;
        elem = elem->GetElemNext();

        delete temp;
    }

    _size = 0;
    _head = _tail = NULL;

    LLBC_MemSet(_bucket, 0, _bucketSize * sizeof(LLBC_DictionaryElem *));
}
Exemple #5
0
__LLBC_NS_BEGIN

LLBC_Dictionary::LLBC_Dictionary(LLBC_Dictionary::size_type bucketSize)
: _size(0)
, _head(0)
, _tail(NULL)

, _bucketSize(bucketSize)
, _bucket(NULL)

, _objFactory(NULL)
{
    _bucket = reinterpret_cast<LLBC_DictionaryElem **>(
        malloc(_bucketSize * sizeof(LLBC_DictionaryElem *)));
    LLBC_MemSet(_bucket, 0, _bucketSize * sizeof(LLBC_DictionaryElem *));
}