diff --git a/src/sicore.c b/src/sicore.c index b08739d..a0216b3 100644 --- a/src/sicore.c +++ b/src/sicore.c @@ -2,14 +2,13 @@ * Name: svimrdb.h * Description: SI core functions. * Author: cosh.cage#hotmail.com - * File ID: 0628231947B0809230919L00742 + * File ID: 0628231947B1101231110L00741 * License: GPLv2. */ #include /* Using macro BUFSIZ. */ #include /* Using function malloc, free, realloc. */ #include /* Using function memcpy. */ #include /* Using function roundf, round. */ -#include /* Using function wcscmp, wcslen. */ #include "svimrdb.h" /* size_t integer copmaration function. */ diff --git a/src/simisc.c b/src/simisc.c index bf133c9..77d14ce 100644 --- a/src/simisc.c +++ b/src/simisc.c @@ -2,14 +2,20 @@ * Name: simisc.c * Description: Misc functions. * Author: cosh.cage#hotmail.com - * File ID: 0703231856E0809230924L00152 + * File ID: 0703231856E1101231110L00287 * License: GPLv2. */ #include /* Using function tolower. */ #include /* Using type uint32_t, uint64_t. */ +#include /* Using function strcmp. */ #include "svimrdb.h" +int _siCBFCompareNodeDataSPlusA(void * pitem, size_t param); +int _siCBFCompareNodeDataSPlusW(void * pitem, size_t param); +P_NODE_S _siSearchLinkedListSCPlusA(LIST_S list, const void * pitem, size_t size); +P_NODE_S _siSearchLinkedListSCPlusW(LIST_S list, const void * pitem, size_t size); + /* Function name: siStrLCase * Description: Convert a zero terminated string to lower case. * Parameter: @@ -149,3 +155,132 @@ size_t siPlatformSize(void) { return sizeof(size_t); } + +/* Attention: This Is An Internal Function. No Interface for Library Users. + * Function name: _siCBFCompareNodeDataSPlusA + * Description: Used to compare data of NODE_S for strings. + * Parameters: + * pitem Pointer to a NODE_S. + * param Pointer to FindingInfo. + * Return value: If data matched, function would return value CBF_TERMINATE, + * otherwise function would return value CBF_CONTINUE. + */ +int _siCBFCompareNodeDataSPlusA(void * pitem, size_t param) +{ + /* The type of param is P_FindingInfo. */ + if + ( + 0 == strcmp + ( + *(char **)(((P_NODE_S)pitem)->pdata), + *(char **)(((P_FindingInfo)param)->pitem) + ) + ) + { + ((P_FindingInfo)param)->result = pitem; + return CBF_TERMINATE; + } + return CBF_CONTINUE; +} + +/* Attention: This Is An Internal Function. No Interface for Library Users. + * Function name: _siSearchLinkedListSCPlusA + * Description: Find pitem in a single linked-list list. + * Parameters: + * list Pointer to the first NODE_S element you want to search in the linked-list. + * pitem Pointer to the item you want to search. + * size Size of data of pitem. + * Return value: Pointer to the NODE_S which contains the same data as pitem. + * Caution: Data in each node of linked-list must be in the same size. + * Tip: No dead cycles for circular linked-lists. + */ +P_NODE_S _siSearchLinkedListSCPlusA(LIST_S list, const void * pitem, size_t size) +{ + FindingInfo fi; + fi.result = NULL; + fi.pitem = pitem; + fi.size = size; + strTraverseLinkedListSC_X(list, NULL, _siCBFCompareNodeDataSPlusA, (size_t)&fi); + return (P_NODE_S)fi.result; +} + +/* Function name: hshSearchCPlusA + * Description: Search an element in a separate chaining hash table. + * Parameters: + * pht Pointer to the hash table you want to operate. + * cbfhsh Pointer to hash function. + * The same hash table should use the same hash function. + * pkey Pointer to an element. Casted into (const void *). + * param size Size of data of pkey. + * Return value: Pointer to a NODE_S that contains key value. + * Caution: Parameter pht Must Be Allocated first. + */ +P_NODE_S hshSearchCPlusA(P_HSHTBL_C pht, CBF_HASH cbfhsh, const void * pkey, size_t size) +{ + return _siSearchLinkedListSCPlusA(*(P_NODE_S *)(pht->pdata + (cbfhsh(pkey) % strLevelArrayZ(pht)) * sizeof(P_NODE_S)), pkey, size); +} + + +/* Attention: This Is An Internal Function. No Interface for Library Users. + * Function name: _siCBFCompareNodeDataSPlusA + * Description: Used to compare data of NODE_S for strings. + * Parameters: + * pitem Pointer to a NODE_S. + * param Pointer to FindingInfo. + * Return value: If data matched, function would return value CBF_TERMINATE, + * otherwise function would return value CBF_CONTINUE. + */ +int _siCBFCompareNodeDataSPlusW(void * pitem, size_t param) +{ + /* The type of param is P_FindingInfo. */ + if + ( + 0 == wcscmp + ( + *(wchar_t **)(((P_NODE_S)pitem)->pdata), + *(wchar_t **)(((P_FindingInfo)param)->pitem) + ) + ) + { + ((P_FindingInfo)param)->result = pitem; + return CBF_TERMINATE; + } + return CBF_CONTINUE; +} + +/* Attention: This Is An Internal Function. No Interface for Library Users. + * Function name: _siSearchLinkedListSCPlusA + * Description: Find pitem in a single linked-list list. + * Parameters: + * list Pointer to the first NODE_S element you want to search in the linked-list. + * pitem Pointer to the item you want to search. + * size Size of data of pitem. + * Return value: Pointer to the NODE_S which contains the same data as pitem. + * Caution: Data in each node of linked-list must be in the same size. + * Tip: No dead cycles for circular linked-lists. + */ +P_NODE_S _siSearchLinkedListSCPlusW(LIST_S list, const void * pitem, size_t size) +{ + FindingInfo fi; + fi.result = NULL; + fi.pitem = pitem; + fi.size = size; + strTraverseLinkedListSC_X(list, NULL, _siCBFCompareNodeDataSPlusW, (size_t)&fi); + return (P_NODE_S)fi.result; +} + +/* Function name: hshSearchCPlusA + * Description: Search an element in a separate chaining hash table. + * Parameters: + * pht Pointer to the hash table you want to operate. + * cbfhsh Pointer to hash function. + * The same hash table should use the same hash function. + * pkey Pointer to an element. Casted into (const void *). + * param size Size of data of pkey. + * Return value: Pointer to a NODE_S that contains key value. + * Caution: Parameter pht Must Be Allocated first. + */ +P_NODE_S hshSearchCPlusW(P_HSHTBL_C pht, CBF_HASH cbfhsh, const void * pkey, size_t size) +{ + return _siSearchLinkedListSCPlusW(*(P_NODE_S *)(pht->pdata + (cbfhsh(pkey) % strLevelArrayZ(pht)) * sizeof(P_NODE_S)), pkey, size); +} diff --git a/src/sitable.c b/src/sitable.c index a0e9a7d..8e2f025 100644 --- a/src/sitable.c +++ b/src/sitable.c @@ -2,7 +2,7 @@ * Name: sitable.c * Description: SI functions for tables. * Author: cosh.cage#hotmail.com - * File ID: 0628231947C070809231310L00977 + * File ID: 0628231947C1101231110L00976 * License: GPLv2. */ #define _CRT_SECURE_NO_WARNINGS @@ -10,7 +10,6 @@ #include /* Using function malloc, free, qsort. */ #include /* Using function strdup, memmove. */ #include /* Using function round, roundf. */ -#include /* Using function wcslen, wcscmp, wprintf. */ #include #include "svimrdb.h" @@ -124,7 +123,7 @@ P_MATRIX siInstantiateView(P_MATRIX pmtx) return NULL; } -/* Function name: siDestoryView +/* Function name: siDestroyView * Description: Uninitialize a view and its cell. * Parameter: * pmtx Pointer to a view. @@ -132,7 +131,7 @@ P_MATRIX siInstantiateView(P_MATRIX pmtx) * Caution: N/A. * Tip: N/A. */ -void siDestoryView(P_MATRIX pmtx) +void siDestroyView(P_MATRIX pmtx) { if (NULL != pmtx) { @@ -406,7 +405,7 @@ void siDeleteTable(P_TRANS ptrans, P_TABLE ptbl) if (NULL != ptbl->tbldata.arrz.pdata) { - siDestoryView(&ptbl->tbldata); + siDestroyView(&ptbl->tbldata); strFreeMatrix(&ptbl->tbldata); } free(ptbl); @@ -558,7 +557,7 @@ BOOL siInsertIntoTable(P_TRANS ptrans, P_TABLE ptbl, ...) { case CR_UNIQUE: case CR_PRIMARY_KEY: - if (NULL == hshSearchC(pt->phsh, siHashString, &pc->pdata, sizeof(char *))) + if (NULL == hshSearchCPlusA(pt->phsh, siHashString, &pc->pdata, sizeof(char *))) hshInsertC(pt->phsh, siHashString, &pc->pdata, sizeof(char *)); else bins = FALSE; @@ -574,7 +573,7 @@ BOOL siInsertIntoTable(P_TRANS ptrans, P_TABLE ptbl, ...) { case CR_UNIQUE: case CR_PRIMARY_KEY: - if (NULL == hshSearchC(pt->phsh, siHashWString, &pc->pdata, sizeof(wchar_t *))) + if (NULL == hshSearchCPlusW(pt->phsh, siHashWString, &pc->pdata, sizeof(wchar_t *))) hshInsertC(pt->phsh, siHashWString, &pc->pdata, sizeof(wchar_t *)); else bins = FALSE; diff --git a/src/svimrdb.h b/src/svimrdb.h index e9e0c9e..02dac83 100644 --- a/src/svimrdb.h +++ b/src/svimrdb.h @@ -14,6 +14,7 @@ #include "StoneValley/src/svset.h" #include "StoneValley/src/svqueue.h" #include "StoneValley/src/svhash.h" +#include /* Using function wcslen, wcscmp, wprintf, wcscmp. */ /* Cell type. */ typedef enum en_CellType @@ -147,6 +148,8 @@ size_t siHashFloat(const void * pkey); size_t siHashDouble(const void * pkey); size_t siHashString(const void * pkey); size_t siHashWString(const void * pkey); +P_NODE_S hshSearchCPlusA(P_HSHTBL_C pht, CBF_HASH cbfhsh, const void * pkey, size_t size); +P_NODE_S hshSearchCPlusW(P_HSHTBL_C pht, CBF_HASH cbfhsh, const void * pkey, size_t size); size_t siPlatformSize(void); /* Relational algebraic functions. */ P_MATRIX siCreateUniqueView(P_MATRIX pmtx); @@ -162,7 +165,7 @@ void siDeleteCell(P_CELL * ppcell); /* Table and view functions. */ void siSortView(P_MATRIX pmtx, size_t col, BOOL ascd); P_MATRIX siInstantiateView(P_MATRIX pmtx); -void siDestoryView(P_MATRIX pmtx); +void siDestroyView(P_MATRIX pmtx); void siPrintView(P_MATRIX pmtx); ptrdiff_t siGetColumnByString(P_TABLE ptbl, char * strname); P_MATRIX siCreateViewOfTable(P_TABLE ptbl); @@ -184,6 +187,6 @@ BOOL siTrylock(P_TRANS ptrans, void * pobj, LockType lt); void siUnlock(P_TRANS ptrans, void * pobj, LockType lt); #define BKSNUM 1021 /* 1021 is a prime. */ -#define strdup _strdup /* POSIX complient for visual C compiler. */ +#define strdup _strdup /* POSIX compliant for visual C compiler. */ #endif