Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
coshcage authored Nov 1, 2023
1 parent d97351b commit e80e1c8
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/sicore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h> /* Using macro BUFSIZ. */
#include <stdlib.h> /* Using function malloc, free, realloc. */
#include <string.h> /* Using function memcpy. */
#include <math.h> /* Using function roundf, round. */
#include <wchar.h> /* Using function wcscmp, wcslen. */
#include "svimrdb.h"

/* size_t integer copmaration function. */
Expand Down
137 changes: 136 additions & 1 deletion src/simisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
* Name: simisc.c
* Description: Misc functions.
* Author: cosh.cage#hotmail.com
* File ID: 0703231856E0809230924L00152
* File ID: 0703231856E1101231110L00287
* License: GPLv2.
*/

#include <ctype.h> /* Using function tolower. */
#include <stdint.h> /* Using type uint32_t, uint64_t. */
#include <string.h> /* 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:
Expand Down Expand Up @@ -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);
}
13 changes: 6 additions & 7 deletions src/sitable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
* 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
#include <stdio.h> /* Using function printf, macro BUFSIZ. */
#include <stdlib.h> /* Using function malloc, free, qsort. */
#include <string.h> /* Using function strdup, memmove. */
#include <math.h> /* Using function round, roundf. */
#include <wchar.h> /* Using function wcslen, wcscmp, wprintf. */
#include <stdarg.h>
#include "svimrdb.h"

Expand Down Expand Up @@ -124,15 +123,15 @@ 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.
* Return value: N/A.
* Caution: N/A.
* Tip: N/A.
*/
void siDestoryView(P_MATRIX pmtx)
void siDestroyView(P_MATRIX pmtx)
{
if (NULL != pmtx)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/svimrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "StoneValley/src/svset.h"
#include "StoneValley/src/svqueue.h"
#include "StoneValley/src/svhash.h"
#include <wchar.h> /* Using function wcslen, wcscmp, wprintf, wcscmp. */

/* Cell type. */
typedef enum en_CellType
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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

0 comments on commit e80e1c8

Please sign in to comment.