Classes | Public Types | Public Member Functions | Static Protected Member Functions

nsBaseHashtable< KeyClass, DataType, UserDataType > Class Template Reference

templated hashtable for simple data types This class manages simple data types that do not need construction or destruction. More...

#include <nsBaseHashtable.h>

Inheritance diagram for nsBaseHashtable< KeyClass, DataType, UserDataType >:
Collaboration diagram for nsBaseHashtable< KeyClass, DataType, UserDataType >:

List of all members.

Classes

struct  s_EnumArgs
struct  s_EnumReadArgs
 used internally during EnumerateRead. More...

Public Types

typedef KeyClass::KeyType KeyType
 KeyType is typedef'ed for ease of use.
typedef nsBaseHashtableET
< KeyClass, DataType > 
EntryType
typedef PLDHashOperator(* EnumReadFunction )(KeyType aKey, UserDataType aData, void *userArg)
 function type provided by the application for enumeration.
typedef PLDHashOperator(* EnumFunction )(KeyType aKey, DataType &aData, void *userArg)
 function type provided by the application for enumeration.

Public Member Functions

PRBool Init (PRUint32 initSize=16)
 Initialize the object.
PRBool IsInitialized () const
 Check whether the table has been initialized.
PRUint32 Count () const
 Return the number of entries in the table.
PRBool Get (KeyType aKey, UserDataType *pData) const
 retrieve the value for a key.
PRBool Put (KeyType aKey, UserDataType aData)
 put a new value for the associated key
void Remove (KeyType aKey)
 remove the data for the associated key
PRUint32 EnumerateRead (EnumReadFunction enumFunc, void *userArg) const
 enumerate entries in the hashtable, without allowing changes
PRUint32 Enumerate (EnumFunction enumFunc, void *userArg)
 enumerate entries in the hashtable, allowing changes.
void Clear ()
 reset the hashtable, removing all entries

Static Protected Member Functions

static PLDHashOperator s_EnumReadStub (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
static PLDHashOperator s_EnumStub (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)

Detailed Description

template<class KeyClass, class DataType, class UserDataType>
class nsBaseHashtable< KeyClass, DataType, UserDataType >

templated hashtable for simple data types This class manages simple data types that do not need construction or destruction.

Parameters:
KeyClass a wrapper-class for the hashtable key, see nsHashKeys.h for a complete specification.
DataType the datatype stored in the hashtable, for example, PRUint32 or nsCOMPtr. If UserDataType is not the same, DataType must implicitly cast to UserDataType
UserDataType the user sees, for example PRUint32 or nsISupports*

Member Typedef Documentation

template<class KeyClass, class DataType, class UserDataType>
typedef nsBaseHashtableET<KeyClass,DataType> nsBaseHashtable< KeyClass, DataType, UserDataType >::EntryType
template<class KeyClass, class DataType, class UserDataType>
typedef PLDHashOperator(* nsBaseHashtable< KeyClass, DataType, UserDataType >::EnumFunction)(KeyType aKey, DataType &aData, void *userArg)

function type provided by the application for enumeration.

Parameters:
aKey the key being enumerated
aData Reference to data being enumerated, may be altered. e.g. for nsInterfaceHashtable this is an nsCOMPtr reference... userArg passed unchanged from Enumerate
Returns:
bitflag combination of PLDHashOperator::PL_DHASH_REMOVE, PL_DHASH_NEXT , or PL_DHASH_STOP

Reimplemented in nsBaseHashtableMT< KeyClass, DataType, UserDataType >, nsBaseHashtableMT< KeyClass, nsAutoPtr< T >, T * >, nsBaseHashtableMT< KeyClass, nsRefPtr< RefPtr >, RefPtr * >, and nsBaseHashtableMT< KeyClass, DataType, DataType >.

template<class KeyClass, class DataType, class UserDataType>
typedef PLDHashOperator(* nsBaseHashtable< KeyClass, DataType, UserDataType >::EnumReadFunction)(KeyType aKey, UserDataType aData, void *userArg)

function type provided by the application for enumeration.

Parameters:
aKey the key being enumerated
aData data being enumerated userArg passed unchanged from Enumerate
Returns:
either PL_DHASH_NEXT or PL_DHASH_STOP

Reimplemented in nsBaseHashtableMT< KeyClass, DataType, UserDataType >, nsBaseHashtableMT< KeyClass, nsAutoPtr< T >, T * >, nsBaseHashtableMT< KeyClass, nsRefPtr< RefPtr >, RefPtr * >, and nsBaseHashtableMT< KeyClass, DataType, DataType >.

template<class KeyClass, class DataType, class UserDataType>
typedef KeyClass::KeyType nsBaseHashtable< KeyClass, DataType, UserDataType >::KeyType

Member Function Documentation

template<class KeyClass, class DataType, class UserDataType>
void nsBaseHashtable< KeyClass, DataType, UserDataType >::Clear (  )  [inline]
template<class KeyClass, class DataType, class UserDataType>
PRUint32 nsBaseHashtable< KeyClass, DataType, UserDataType >::Count (  )  const [inline]
template<class KeyClass, class DataType, class UserDataType>
PRUint32 nsBaseHashtable< KeyClass, DataType, UserDataType >::Enumerate ( EnumFunction  enumFunc,
void *  userArg 
) [inline]

enumerate entries in the hashtable, allowing changes.

This functions write-locks the hashtable.

Parameters:
enumFunc enumeration callback
userArg passed unchanged to the EnumFunction
template<class KeyClass, class DataType, class UserDataType>
PRUint32 nsBaseHashtable< KeyClass, DataType, UserDataType >::EnumerateRead ( EnumReadFunction  enumFunc,
void *  userArg 
) const [inline]

enumerate entries in the hashtable, without allowing changes

Parameters:
enumFunc enumeration callback
userArg passed unchanged to the EnumReadFunction
template<class KeyClass, class DataType, class UserDataType>
PRBool nsBaseHashtable< KeyClass, DataType, UserDataType >::Get ( KeyType  aKey,
UserDataType *  pData 
) const [inline]

retrieve the value for a key.

Parameters:
aKey the key to retreive
pData data associated with this key will be placed at this pointer. If you only need to check if the key exists, pData may be null.
Returns:
PR_TRUE if the key exists. If key does not exist, pData is not modified.

Reimplemented in nsBaseHashtableMT< KeyClass, DataType, UserDataType >, and nsBaseHashtableMT< KeyClass, DataType, DataType >.

template<class KeyClass, class DataType, class UserDataType>
PRBool nsBaseHashtable< KeyClass, DataType, UserDataType >::Init ( PRUint32  initSize = 16  )  [inline]

Initialize the object.

Parameters:
initSize the initial number of buckets in the hashtable, default 16 locking on all class methods
Returns:
PR_TRUE if the object was initialized properly.

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, DataType > >.

Reimplemented in nsBaseHashtableMT< KeyClass, DataType, UserDataType >, nsBaseHashtableMT< KeyClass, nsAutoPtr< T >, T * >, nsBaseHashtableMT< KeyClass, nsRefPtr< RefPtr >, RefPtr * >, and nsBaseHashtableMT< KeyClass, DataType, DataType >.

template<class KeyClass, class DataType, class UserDataType>
PRBool nsBaseHashtable< KeyClass, DataType, UserDataType >::IsInitialized (  )  const [inline]

Check whether the table has been initialized.

This function is especially useful for static hashtables.

Returns:
PR_TRUE if the table has been initialized.

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, DataType > >.

Reimplemented in nsBaseHashtableMT< KeyClass, DataType, UserDataType >, nsBaseHashtableMT< KeyClass, nsAutoPtr< T >, T * >, nsBaseHashtableMT< KeyClass, nsRefPtr< RefPtr >, RefPtr * >, and nsBaseHashtableMT< KeyClass, DataType, DataType >.

template<class KeyClass, class DataType, class UserDataType>
PRBool nsBaseHashtable< KeyClass, DataType, UserDataType >::Put ( KeyType  aKey,
UserDataType  aData 
) [inline]

put a new value for the associated key

Parameters:
aKey the key to put
aData the new data
Returns:
always PR_TRUE, unless memory allocation failed

Reimplemented in nsBaseHashtableMT< KeyClass, DataType, UserDataType >, and nsBaseHashtableMT< KeyClass, DataType, DataType >.

template<class KeyClass, class DataType, class UserDataType>
void nsBaseHashtable< KeyClass, DataType, UserDataType >::Remove ( KeyType  aKey  )  [inline]
template<class KeyClass , class DataType , class UserDataType >
PLDHashOperator nsBaseHashtable< KeyClass, DataType, UserDataType >::s_EnumReadStub ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void *  arg 
) [static, protected]
template<class KeyClass , class DataType , class UserDataType >
PLDHashOperator nsBaseHashtable< KeyClass, DataType, UserDataType >::s_EnumStub ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void *  arg 
) [static, protected]

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