{
T_HASHTABLE_NODE **ppTable;
C_MEMHEAP *pMemHeap;
- int iTableNum;
+ int iTableSize;
+ int iDataNum;
} C_HASHTABLE;
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} */
+HASHTABLE_ERR HashTable_Constructor(C_HASHTABLE *self, C_MEMHEAP *pMemHeap, int iTableSize); /**< %jp{コンストラクタ}%en{Constructor} */
void HashTable_Destructor(C_HASHTABLE *self); /**< %jp{デストラクタ}%en{Destructor} */
/* 操作 */
/* イテレータ */
T_HASHTABLE_ITERATOR *HashTable_FindOpen(C_HASHTABLE *self); /**< イテレータの生成 */
-#define HashTable_FindClose(self, pIterator) do{ MemHeap_Free((self)->pMemHeap, (pIterator)); } while(0) /**< イテレータの削除 */
+void HashTable_FindClose(C_HASHTABLE *self, T_HASHTABLE_ITERATOR *pIterator); /**< イテレータの削除 */
const void *Hashtable_FindNext(C_HASHTABLE *self, T_HASHTABLE_ITERATOR *pIterator, const char **ppszKey); /**< 次を取得 */
#ifdef __cplusplus
--- /dev/null
+/**
+ * Hyper Operating System Application Framework
+ *
+ * @file hashtable_get.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{Constructor} */
+HASHTABLE_ERR HashTable_Constructor(C_HASHTABLE *self, C_MEMHEAP *pMemHeap, int iTableSize)
+{
+ T_HASHTABLE_NODE **ppTable;
+ int i;
+
+ /* メモリ確保 */
+ if ( (ppTable = (T_HASHTABLE_NODE **)MemHeap_Alloc(pMemHeap, sizeof(T_HASHTABLE_NODE *) * iTableSize)) == NULL )
+ {
+ return HASHTABLE_ERR_NG;
+ }
+
+ /* 初期化 */
+ for ( i = 0; i < iTableSize; i++ )
+ {
+ ppTable[i] = NULL;
+ }
+
+ /* 値設定 */
+ self->pMemHeap = pMemHeap;
+ self->ppTable = ppTable;
+ self->iTableSize = iTableSize;
+ self->iDataNum = 0;
+
+ return HASHTABLE_ERR_OK;
+}
+
+
+/* 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"
+
+
+/** イテレータの削除 */
+void HashTable_FindClose(C_HASHTABLE *self, T_HASHTABLE_ITERATOR *pIterator)
+{
+ if ( pIterator->pNode != NULL )
+ {
+ if ( pIterator->pNext == pIterator )
+ {
+ pIterator->pNode->pIterator = NULL;
+ }
+ else
+ {
+ pIterator->pNext->pPrev = pIterator->pPrev;
+ pIterator->pPrev->pNext = pIterator->pNext;
+ if ( pIterator->pNode->pIterator == pIterator )
+ {
+ pIterator->pNode->pIterator = pIterator->pNext;
+ }
+ }
+ }
+
+ /* メモリ開放 */
+ MemHeap_Free(self->pMemHeap, pIterator);
+}
+
+
+/* end of file */
if ( pNode == NULL )
{
- for ( iIndex = pIterator->iIndex; iIndex < self->iTableNum; iIndex++ )
+ for ( iIndex = pIterator->iIndex; iIndex < self->iTableSize; iIndex++ )
{
if ( (pNode = self->ppTable[iIndex]) != NULL )
{
--- /dev/null
+/**
+ * Hyper Operating System Application Framework
+ *
+ * @file hashtable_get.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"
+
+
+
+/** データの削除 */
+HASHTABLE_ERR HashTable_Remove(C_HASHTABLE *self, const char *pszKey)
+{
+ T_HASHTABLE_NODE *pNode;
+ T_HASHTABLE_NODE *pNodePrev;
+ T_HASHTABLE_ITERATOR *pIterator;
+ int iIndex;
+
+ /* 探索 */
+ if ( (pNode = HashTable_SearchNode(self, pszKey, &pNodePrev, &iIndex)) == NULL )
+ {
+ return HASHTABLE_ERR_NG;
+ }
+
+ /* 指しているイテレータがあれば付け替え */
+ if ( (pIterator = pNode->pIterator) != NULL )
+ {
+ if ( pNode->pNext != NULL )
+ {
+ pNode->pNext->pIterator = pIterator;
+ }
+
+ pNode->pIterator = pIterator;
+ do
+ {
+ pIterator->pNode = pNode->pNext;
+ pIterator = pIterator->pNext;
+ } while ( pIterator != pNode->pIterator );
+ }
+
+ /* リストからはずす */
+ if ( pNodePrev != NULL )
+ {
+ pNodePrev->pNext = pNode->pNext;
+ }
+ else
+ {
+ self->ppTable[iIndex] = pNode->pNext;
+ }
+
+ /* 削除 */
+ HashTable_DeleteNode(self, pNode);
+ self->iDataNum--;
+
+ return HASHTABLE_ERR_OK;
+}
+
+
+
+/* end of file */
{
iIndex += c;
}
- *piIndex = iIndex = iIndex % self->iTableNum;
+ *piIndex = iIndex = iIndex % self->iTableSize;
/* 探索 */
/* 削除 */
HashTable_DeleteNode(self, pNodeOld);
}
+ else
+ {
+ self->iDataNum++;
+ }
/* 新ノード設定 */
- pNode->pNext = self->ppTable[iIndex];
+ pNode->pNext = self->ppTable[iIndex];
self->ppTable[iIndex] = pNode;
return HASHTABLE_ERR_OK;