アットウィキロゴ

Tcl_HashEntry

概要

ハッシュテーブルの中のエントリー構造体の定義。アクセスには専用のマクロを使う。


メンバー

TCL_HASH_KEY_STORE_HASH はtcl.hの中で1に定義されいる。

  • Tcl_HashEntry *nextPtr; この bucket 内の次のエントリーを示すポインタ。chainの最後はNULL
  • Tcl_HashTable *tablePtr; エントリーを含んでいるテーブルへのポインタ
  • VOID *hash; この構造の中のオフセットが変わらないことを保証するために、ポインターとして保存されるハッシュ値。
  • ClientData clientData; Tcl_SetHashValue によってアプリケーションが保存するデータ
  • union key

union key

  • char *oneWordValue; キーへのOne-word value
  • Tcl_Obj *objPtr; キーの値 key value.
  • int words[1]; キーへの複数の整数ワード。実際のサイズは、このテーブルのキーに必要なだけの大きさである。
  • char string[4]; キーへの文字列

アクセス用マクロ

Tcl_GetHashValue

#define Tcl_GetHashValue(h) ((h)->clientData)

Tcl_SetHashValue

#define Tcl_SetHashValue(h, value) ((h)->clientData = (ClientData) (value))

Tcl_Gethashkey

#define Tcl_GetHashKey(tablePtr, h) \
	((char *) (((tablePtr)->keyType == TCL_ONE_WORD_KEYS || \
		    (tablePtr)->keyType == TCL_CUSTOM_PTR_KEYS) \
		   ? (h)->key.oneWordValue \
		   : (h)->key.string))

ソース

 /*
  * Structure definition for an entry in a hash table. No-one outside Tcl
  * should access any of these fields directly; use the macros defined below.
  */
 
 struct Tcl_HashEntry {
     Tcl_HashEntry *nextPtr;	/* Pointer to next entry in this hash bucket,
 				 * or NULL for end of chain. */
     [[Tcl_HashTable]] *tablePtr;	/* Pointer to table containing entry. */
 #if TCL_HASH_KEY_STORE_HASH
     VOID *hash;			/* Hash value, stored as pointer to ensure
 				 * that the offsets of the fields in this
 				 * structure are not changed. */
 #else
     Tcl_HashEntry **bucketPtr;	/* Pointer to bucket that points to first
 				 * entry in this entry's chain: used for
 				 * deleting the entry. */
 #endif
     [[ClientData]] clientData;	/* Application stores something here with
 				 * Tcl_SetHashValue. */
     union {			/* Key has one of these forms: */
 	char *oneWordValue;	/* One-word value for key. */
 	[[Tcl_Obj]] *objPtr;	/* Tcl_Obj * key value. */
 	int words[1];		/* Multiple integer words for key. The actual
 				 * size will be as large as necessary for this
 				 * table's keys. */
 	char string[4];		/* String for key. The actual size will be as
 				 * large as needed to hold the key. */
     } key;			/* MUST BE LAST FIELD IN RECORD!! */
 };
最終更新:2011年11月02日 10:00