typedef int HASHTABLE_ERR;
-struct c_hashtableiterator;
+struct t_hashtable_iterator;
struct c_hashtable;
/** %jp{ノード格納用構造体}%en{node} */
typedef struct t_hashtable_node
{
- int iIndex;
struct t_hashtable_node *pNext;
- struct c_hashtableiterator *pIterator;
+ struct t_hashtable_iterator *pIterator;
} T_HASHTABLE_NODE;
-/** %jp{ハッシュ用イテレータクラス}%en{Iterator class} */
-typedef struct c_hashtableiterator
+/** %jp{ハッシュ用イテレータ}%en{Iterator} */
+typedef struct t_hashtable_iterator
{
- struct c_hashtable *pHashTable;
- struct c_hashtableiterator *pNext;
- struct c_hashtableiterator *pPrev;
-
struct t_hashtable_node *pNode;
-} C_HASHTABLEITERATOR;
+ int iIndex;
+
+ struct t_hashtable_iterator *pNext;
+ struct t_hashtable_iterator *pPrev;
+} T_HASHTABLE_ITERATOR;
+
/** %jp{ハッシュテーブルクラス}%en{Hash table class} */
#endif
/* 生成/削除 */
-C_HASHTABLE *HashTable_Create(void); /* %jp{生成}%en{Create} */
-C_HASHTABLE *HashTable_CreateEx(C_MEMHEAP *pMemHeap); /* %jp{生成}%en{Create} */
-void HashTable_Delete(C_HASHTABLE *self); /* %jp{削除}%en{Delete} */
-void HashTable_Constructor(C_HASHTABLE *self, C_MEMHEAP *pMemHeap); /* %jp{コンストラクタ}%en{Constructor} */
-void HashTable_Destructor(C_HASHTABLE *self); /* %jp{デストラクタ}%en{Destructor} */
+C_HASHTABLE *HashTable_Create(int iTableSize); /**< %jp{生成}%en{Create} */
+C_HASHTABLE *HashTable_CreateEx(int iTableSize, C_MEMHEAP *pMemHeap); /**< %jp{生成}%en{Create} */
+void HashTable_Delete(C_HASHTABLE *self); /**< %jp{削除}%en{Delete} */
+void HashTable_Constructor(C_HASHTABLE *self, C_MEMHEAP *pMemHeap); /**< %jp{コンストラクタ}%en{Constructor} */
+void HashTable_Destructor(C_HASHTABLE *self); /**< %jp{デストラクタ}%en{Destructor} */
/* 操作 */
-HASHTABLE_ERR HashTable_Add(C_HASHTABLE *self, const char *pszKey, const void *pData, MEMSIZE Size); /* データの追加 */
-HASHTABLE_ERR HashTable_Set(C_HASHTABLE *self, const char *pszKey, const void *pData, MEMSIZE Size); /* データの設定 */
-const void *HashTable_Get(C_HASHTABLE *self, const char *pszKey); /* データの参照 */
-HASHTABLE_ERR HashTable_Remove(C_HASHTABLE *self, const char *pszKey); /* データの削除 */
+HASHTABLE_ERR HashTable_Add(C_HASHTABLE *self, const char *pszKey, const void *pData, MEMSIZE Size); /**< データの追加 */
+HASHTABLE_ERR HashTable_Set(C_HASHTABLE *self, const char *pszKey, const void *pData, MEMSIZE Size); /**< データの設定 */
+const void *HashTable_Get(C_HASHTABLE *self, const char *pszKey); /**< データの参照 */
+HASHTABLE_ERR HashTable_Remove(C_HASHTABLE *self, const char *pszKey); /**< データの削除 */
/* イテレータ */
-C_HASHTABLEITERATOR *HashTableIterator_Create(C_HASHTABLE *pHashTable); /* イテレータの生成 */
-void HashTableIterator_Delete(C_HASHTABLEITERATOR *self, C_HASHTABLEITERATOR *pIterator); /* イテレータの削除 */
-const void *HashtableIterator_FindNext(C_HASHTABLEITERATOR *self, const char **ppszKey); /**/
+T_HASHTABLE_ITERATOR *HashTable_FindOpen(C_HASHTABLE *self); /**< イテレータの生成 */
+#define HashTable_FindClose(self, pIterator) do{ MemHeap_Free((self)->pMemHeap, (pIterator)); } while(0) /**< イテレータの削除 */
+const void *Hashtable_FindNext(C_HASHTABLE *self, T_HASHTABLE_ITERATOR *pIterator, const char **ppszKey); /**< 次を取得 */
#ifdef __cplusplus
}
-#endif /* __HOS__assoc_h__ */
+#endif /* __HOS__hashtable_h__ */
/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System Application Framework
+ *
+ * @file hashtable_findfirst.c
+ * @brief %jp{ハッシュテーブルクラス}%en{hash table class}
+ *
+ * Copyright (C) 2006-2009 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include "hashtable_local.h"
+
+
+/** %jp{次を取得}%en{find next} */
+const void *Hashtable_FindNext(C_HASHTABLE *self, T_HASHTABLE_ITERATOR *pIterator, const char **ppszKey)
+{
+ T_HASHTABLE_NODE *pNode;
+ int iIndex;
+ const char *pszKey;
+ const void *pData;
+
+ if ( pIterator == NULL )
+ {
+ return NULL;
+ }
+
+ /* 次を探索 */
+ pNode = pIterator->pNode;
+ iIndex = pIterator->iIndex;
+
+ if ( pNode != NULL )
+ {
+ /* リストから取り外し */
+ if ( pIterator->pNext == pIterator )
+ {
+ pNode->pIterator = NULL;
+ }
+ else
+ {
+ pIterator->pNext->pPrev = pIterator->pPrev;
+ pIterator->pPrev->pNext = pIterator->pNext;
+ if ( pNode->pIterator == pIterator )
+ {
+ pNode->pIterator = pIterator->pNext;
+ }
+ }
+
+ /* 次があれば進む */
+ if ( (pNode = pNode->pNext) == NULL )
+ {
+ iIndex++; /* 無ければ次の項 */
+ }
+ }
+
+ if ( pNode == NULL )
+ {
+ for ( iIndex = pIterator->iIndex; iIndex < self->iTableNum; iIndex++ )
+ {
+ if ( (pNode = self->ppTable[iIndex]) != NULL )
+ {
+ break;
+ }
+ }
+ }
+
+ pIterator->pNode = pNode;
+ pIterator->iIndex = iIndex;
+
+ if ( pNode == NULL )
+ {
+ *ppszKey = NULL;
+ return NULL;
+ }
+
+ /* リスト接続 */
+ if ( pNode->pIterator == NULL )
+ {
+ pNode->pIterator = pIterator;
+ pIterator->pNext = pIterator;
+ pIterator->pPrev = pIterator;
+ }
+ else
+ {
+ pIterator->pNext = pNode->pIterator;
+ pIterator->pPrev = pIterator->pNext->pPrev;
+ pIterator->pNext->pPrev = pIterator;
+ pIterator->pPrev->pNext = pIterator;
+ }
+
+ /* データ取り出し */
+ pszKey = (const char *)pNode + sizeof(T_HASHTABLE_NODE);
+ pData = (const void *)(pszKey + MemHeap_AlignSize(self->pMemHeap, strlen(pszKey)));
+
+ /* データ部を返す */
+ *ppszKey = pszKey;
+ return pData;
+}
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System Application Framework
+ *
+ * @file hashtable_findopen.c
+ * @brief %jp{ハッシュテーブルクラス}%en{hash table class}
+ *
+ * Copyright (C) 2006-2009 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include "hashtable_local.h"
+
+
+/** %jp{イテレータの生成}%en{create iterator} */
+T_HASHTABLE_ITERATOR *HashTable_FindOpen(C_HASHTABLE *self)
+{
+ T_HASHTABLE_ITERATOR *pIterator;
+
+ /* 生成 */
+ if ( (pIterator = MemHeap_Alloc(self->pMemHeap, sizeof(T_HASHTABLE_ITERATOR))) == NULL )
+ {
+ return NULL;
+ }
+
+ /* 初期化 */
+ pIterator->pNode = NULL;
+ pIterator->iIndex = 0;
+
+ return pIterator;
+}
+
+
+/* end of file */
/* データの設定 */
HASHTABLE_ERR HashTable_Set(C_HASHTABLE *self, const char *pszKey, const void *pData, MEMSIZE Size)
{
- T_HASHTABLE_NODE *pNode;
- T_HASHTABLE_NODE *pNodeOld;
- T_HASHTABLE_NODE *pNodePrev;
- C_HASHTABLEITERATOR *pIterator;
- int iIndex;
+ T_HASHTABLE_NODE *pNode;
+ T_HASHTABLE_NODE *pNodeOld;
+ T_HASHTABLE_NODE *pNodePrev;
+ T_HASHTABLE_ITERATOR *pIterator;
+ int iIndex;
/* ノード生成 */
if ( (pNode = HashTable_CreateNode(self, pszKey, pData, Size)) == NULL )
}
/* 新ノード設定 */
- pNode->iIndex = iIndex;
pNode->pNext = self->ppTable[iIndex];
self->ppTable[iIndex] = pNode;