概要
ハッシュテーブルキータイプの構造体定義
定義
/*
* Flags used in Tcl_HashKeyType.
*
* TCL_HASH_KEY_RANDOMIZE_HASH -
* There are some things, pointers for example
* which don't hash well because they do not use
* the lower bits. If this flag is set then the
* hash table will attempt to rectify this by
* randomising the bits and then using the upper
* N bits as the index into the table.
* TCL_HASH_KEY_SYSTEM_HASH - If this flag is set then all memory internally
* allocated for the hash table that is not for an
* entry will use the system heap.
*/
#define TCL_HASH_KEY_RANDOMIZE_HASH 0x1
#define TCL_HASH_KEY_SYSTEM_HASH 0x2
typedef unsigned int (Tcl_HashKeyProc) _ANSI_ARGS_(([[Tcl_HashTable]] *tablePtr,VOID *keyPtr));
typedef int (Tcl_CompareHashKeysProc) _ANSI_ARGS_((VOID *keyPtr, [[Tcl_HashEntry]] *hPtr));
typedef Tcl_HashEntry *(Tcl_AllocHashEntryProc) _ANSI_ARGS_(( Tcl_HashTable *tablePtr, VOID *keyPtr));
typedef void (Tcl_FreeHashEntryProc) _ANSI_ARGS_((Tcl_HashEntry *hPtr));
メンバー
- int version; バージョン
- int flags; フラグ、TCL_HASH_KEY_RANDOMIZE_HASH と TCL_HASH_KEY_SYSTEM_HASH が指定できる。
- Tcl_HashKeyProc *hashKeyProc;ハッシュ値を計算する関数。NULLの時は、ポインター自体がハッシュ値として使用される。
- Tcl_CompareHashKeysProc *compareKeysProc; 2つのキーを比較する。マッチするなら0、そうでないなら0以外の値を返す。この値がNULLの場合はポインターが比較される。
- Tcl_AllocHashEntryProc *allocEntryProc; 新しいエントリーの為にメモリをアロケートするために呼ばれる関数。NULLの場合はTcl_Allocが使われる。
- Tcl_FreeHashEntryProc *freeEntryProc; エントリーのメモリを解放する時に呼ばれる関数。NULLならTcl_Freeが使用される。
ソース
/*
* Structure definition for the methods associated with a hash table key type.
*/
#define TCL_HASH_KEY_TYPE_VERSION 1
struct Tcl_HashKeyType {
int version; /* Version of the table. If this structure is
* extended in future then the version can be
* used to distinguish between different
* structures. */
int flags; /* Flags, see above for details. */
Tcl_HashKeyProc *hashKeyProc;
/* Calculates a hash value for the key. If
* this is NULL then the pointer itself is
* used as a hash value. */
Tcl_CompareHashKeysProc *compareKeysProc;
/* Compares two keys and returns zero if they
* do not match, and non-zero if they do. If
* this is NULL then the pointers are
* compared. */
Tcl_AllocHashEntryProc *allocEntryProc;
/* Called to allocate memory for a new entry,
* i.e. if the key is a string then this could
* allocate a single block which contains
* enough space for both the entry and the
* string. Only the key field of the allocated
* Tcl_HashEntry structure needs to be filled
* in. If something else needs to be done to
* the key, i.e. incrementing a reference
* count then that should be done by this
* function. If this is NULL then Tcl_Alloc is
* used to allocate enough space for a
* Tcl_HashEntry and the key pointer is
* assigned to key.oneWordValue. */
Tcl_FreeHashEntryProc *freeEntryProc;
/* Called to free memory associated with an
* entry. If something else needs to be done
* to the key, i.e. decrementing a reference
* count then that should be done by this
* function. If this is NULL then Tcl_Free is
* used to free the Tcl_HashEntry. */
};
最終更新:2011年11月02日 13:45