Classes | Public Types | Public Member Functions | Friends

FbxHashMap< KEY, VALUE, HASH, Destruct, Comparator > Class Template Reference

Search for all occurrences

Detailed Description

template<typename KEY, typename VALUE, typename HASH, class Destruct = FbxNoOpDestruct<VALUE>, class Comparator = FbxDefaultComparator<KEY>>
class FbxHashMap< KEY, VALUE, HASH, Destruct, Comparator >

Definition at line 30 of file fbxhashmap.h.

#include <fbxhashmap.h>

List of all members.

Classes

class   Iterator
class   ListItem

Public Types

typedef KEY  KeyType
typedef VALUE  ValueType
typedef HASH  HashFunctorType

Public Member Functions

  FbxHashMap (int pBucketSize)
  FbxHashMap ()
  ~FbxHashMap ()
void  Clear ()
const Iterator  Find (const KeyType &pKey) const
VALUE  Remove (const KEY &pKey)
ValueType operator[] (const KeyType &pKey)
Iterator  Start () const
Iterator  End () const

Friends

class  Iterator

Member Typedef Documentation

typedef KEY KeyType

Definition at line 33 of file fbxhashmap.h.

typedef VALUE ValueType

Definition at line 34 of file fbxhashmap.h.

typedef HASH HashFunctorType

Definition at line 35 of file fbxhashmap.h.


Constructor & Destructor Documentation

FbxHashMap ( int  pBucketSize ) [inline]

Definition at line 164 of file fbxhashmap.h.

    {
        mBuckets.Resize( pBucketSize );
    }
FbxHashMap ( ) [inline]

Definition at line 169 of file fbxhashmap.h.

    {
        mBuckets.Resize(30);
    }
~FbxHashMap ( ) [inline]

Definition at line 174 of file fbxhashmap.h.

    {
        Clear();
        mBuckets.Resize(0);
    }

Member Function Documentation

void Clear ( ) [inline]

Definition at line 180 of file fbxhashmap.h.

    {
        for( int i = 0; i < mBuckets.GetCount(); ++i)
        {
            if( mBuckets[i] )
            {
                ListItem* lNext = mBuckets[i]->mNext;
                while( lNext )
                {
                    ListItem* lNextNext = lNext->mNext;
                    FbxDelete(lNext);
                    lNext = lNextNext;
                }

                FbxDelete(mBuckets[i]);
                mBuckets[i] = NULL;
            }
        }
    }
const Iterator Find ( const KeyType pKey ) const [inline]

Definition at line 200 of file fbxhashmap.h.

    {
        unsigned int lIndex = mHashFunctor(pKey);
        lIndex = lIndex % mBuckets.GetCount();
        ListItem* lItem = mBuckets[lIndex];
        while( lItem )
        {
            if( Comparator::CompareIt( lItem->mKey, pKey ) )
            {
                Iterator lIt( this, lIndex, lItem );
                return lIt;
            }
            lItem = lItem->mNext;
        }
        
        return End();
    }
VALUE Remove ( const KEY &  pKey ) [inline]

Definition at line 218 of file fbxhashmap.h.

    {
        unsigned int lIndex = mHashFunctor(pKey);
        lIndex = lIndex % mBuckets.GetCount();
        ListItem* lItem = mBuckets.GetAt(lIndex);
        ListItem* lLastItem = NULL;
        
        while( lItem )
        {
            if( lItem->mKey == pKey )
            {
                if( lLastItem )
                    lLastItem->mNext = lItem->mNext;

                if( mBuckets.GetAt(lIndex) == lItem ) 
                    mBuckets.SetAt(lIndex, lItem->mNext );

                VALUE lValue = lItem->mValue;
                FbxDelete(lItem);
                
                return lValue;
            }

            lLastItem = lItem;
            lItem = lItem->mNext;
        }
        
        return VALUE();
    }
ValueType& operator[] ( const KeyType pKey ) [inline]

Definition at line 248 of file fbxhashmap.h.

    {
        Iterator lIt = Find( pKey );
        if( lIt != End() )
        {
            return lIt.mCurrentItem->mValue;
        }

        unsigned int lIndex = mHashFunctor(pKey);
        lIndex = lIndex % mBuckets.GetCount();
        ListItem* lItem = FbxNew< ListItem >();
        lItem->mNext = NULL;
        lItem->mKey = pKey;

        if( !mBuckets.GetAt(lIndex) )
        {
            mBuckets.SetAt(lIndex, lItem);
        }
        else
        {
            lItem->mNext = mBuckets.GetAt(lIndex);
            mBuckets.SetAt(lIndex, lItem);
        }

        return lItem->mValue;
    }
Iterator Start ( ) const [inline]

Definition at line 275 of file fbxhashmap.h.

    {
        for( int i = 0; i < mBuckets.GetCount(); ++i )
        {
            if( mBuckets[i] )
            {
                Iterator lIt( this, i, mBuckets[i] );
                return lIt;
            }
        }

        return End();
    }
Iterator End ( ) const [inline]

Definition at line 289 of file fbxhashmap.h.

    {
        Iterator lIt( this, 0, NULL );
        return lIt;
    }

Friends And Related Function Documentation

friend class Iterator [friend]

Definition at line 303 of file fbxhashmap.h.


The documentation for this class was generated from the following file: