ReactOS 0.4.15-dev-7958-gcd0bb1a
sdbstringtable.c File Reference
#include "windows.h"
#include <appcompat/sdbtypes.h>
#include "sdbpapi.h"
#include "sdbstringtable.h"
Include dependency graph for sdbstringtable.c:

Go to the source code of this file.

Classes

struct  SdbHashEntry
 
struct  SdbStringHashTable
 

Macros

#define WIN32_NO_STATUS
 
#define offsetof(TYPE, MEMBER)   ((size_t)&(((TYPE *)0)->MEMBER))
 
#define DEFAULT_TABLE_SIZE   0x100
 

Typedefs

typedef struct SdbHashEntry SdbHashEntry
 

Functions

static struct SdbStringHashTableHashCreate (void)
 
void SdbpTableDestroy (struct SdbStringHashTable **pTable)
 
static DWORD StringHash (const WCHAR *str)
 
int Sdbwcscmp (const WCHAR *s1, const WCHAR *s2)
 
INT Sdbwcscpy (WCHAR *wcDest, size_t numElement, const WCHAR *wcSrc)
 
static struct SdbHashEntry ** TableFindPtr (struct SdbStringHashTable *table, const WCHAR *str)
 
static BOOL HashAddString (struct SdbStringHashTable *table, struct SdbHashEntry **position, const WCHAR *str, TAGID tagid)
 
BOOL SdbpAddStringToTable (struct SdbStringHashTable **table, const WCHAR *str, TAGID *tagid)
 

Macro Definition Documentation

◆ DEFAULT_TABLE_SIZE

#define DEFAULT_TABLE_SIZE   0x100

Definition at line 30 of file sdbstringtable.c.

◆ offsetof

#define offsetof (   TYPE,
  MEMBER 
)    ((size_t)&(((TYPE *)0)->MEMBER))

Definition at line 26 of file sdbstringtable.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file sdbstringtable.c.

Typedef Documentation

◆ SdbHashEntry

Function Documentation

◆ HashAddString()

static BOOL HashAddString ( struct SdbStringHashTable table,
struct SdbHashEntry **  position,
const WCHAR str,
TAGID  tagid 
)
static

Definition at line 147 of file sdbstringtable.c.

148{
149 struct SdbHashEntry* entry;
150 SIZE_T size, len;
151
152 if (!position)
153 position = TableFindPtr(table, str);
154
155 len = SdbpStrlen(str) + 1;
156 size = offsetof(struct SdbHashEntry, Name[len]);
157 entry = (*position) = SdbAlloc(size);
158 if (!entry)
159 {
160 SHIM_ERR("Failed to allocate %u bytes.\n", size);
161 return FALSE;
162 }
163 entry->Tagid = tagid;
164 Sdbwcscpy(entry->Name, len, str);
165 return TRUE;
166}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLsizeiptr size
Definition: glext.h:5919
GLenum GLsizei len
Definition: glext.h:6722
uint32_t entry
Definition: isohybrid.c:63
const WCHAR * str
DWORD SdbpStrlen(PCWSTR string)
Definition: sdbapi.c:152
#define SdbAlloc(size)
Definition: sdbpapi.h:35
#define SHIM_ERR(fmt,...)
Definition: sdbpapi.h:76
INT Sdbwcscpy(WCHAR *wcDest, size_t numElement, const WCHAR *wcSrc)
#define offsetof(TYPE, MEMBER)
static struct SdbHashEntry ** TableFindPtr(struct SdbStringHashTable *table, const WCHAR *str)
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by SdbpAddStringToTable().

◆ HashCreate()

static struct SdbStringHashTable * HashCreate ( void  )
static

Definition at line 46 of file sdbstringtable.c.

47{
48 struct SdbStringHashTable* tab = SdbAlloc(sizeof(*tab));
49 if (!tab)
50 {
51 SHIM_ERR("Failed to allocate 8 bytes.\r\n");
52 return tab;
53 }
55 tab->Entries = SdbAlloc(tab->Size * sizeof(*tab->Entries));
56 return tab;
57}
#define DEFAULT_TABLE_SIZE
struct SdbHashEntry ** Entries

Referenced by SdbpAddStringToTable().

◆ SdbpAddStringToTable()

BOOL SdbpAddStringToTable ( struct SdbStringHashTable **  table,
const WCHAR str,
TAGID pTagid 
)

Find an entry in the stringtable, or allocate it when an entry could not be found.

  • When the string specified does not yet exist, a new entry will be added to the table, and the pTagid specified will be associated with this string.
  • When the string specified does already exist, the TAGID associated with this string will be returned in pTagid.
Parameters
[in]tablePointer to table pointer, will be allocated when needed.
[in]strThe string to search for
[in,out]pTagidthe data written (in bytes)
Returns
TRUE if the string was added to the table, FALSE if it already existed

Definition at line 169 of file sdbstringtable.c.

170{
171 struct SdbHashEntry** entry;
172
173 if (!*table)
174 {
175 *table = HashCreate();
176 if (!*table)
177 {
178 SHIM_ERR("Error creating hash table\n");
179 return FALSE;
180 }
181 }
182
184 if (*entry)
185 {
186 *tagid = (*entry)->Tagid;
187 return FALSE;
188 }
189 return HashAddString(*table, entry, str, *tagid);
190}
static struct SdbStringHashTable * HashCreate(void)
static BOOL HashAddString(struct SdbStringHashTable *table, struct SdbHashEntry **position, const WCHAR *str, TAGID tagid)

Referenced by SdbpGetOrAddStringRef().

◆ SdbpTableDestroy()

void SdbpTableDestroy ( struct SdbStringHashTable **  table)

Destroy the hashtable and release all resources.

Parameters
[in]tablePointer to table pointer, will be cleared after use

Definition at line 60 of file sdbstringtable.c.

61{
63 struct SdbHashEntry* entry, *next;
64 DWORD n, depth = 0, once = 1;
65
66 *pTable = NULL;
67 for (n = 0; n < table->Size; ++n)
68 {
69 depth = 0;
70 entry = next = table->Entries[n];
71 while (entry)
72 {
73 next = entry->Next;
75 entry = next;
76 depth++;
77 }
78 if (once && depth > 3)
79 {
80 // warn
81 once = 0;
82 }
83 }
84 SdbFree(table->Entries);
86}
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLdouble n
Definition: glext.h:7729
static unsigned __int64 next
Definition: rand_nt.c:6
#define SdbFree(mem)
Definition: sdbpapi.h:37
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29

Referenced by SdbCloseDatabase().

◆ Sdbwcscmp()

int Sdbwcscmp ( const WCHAR s1,
const WCHAR s2 
)

Definition at line 99 of file sdbstringtable.c.

100{
101 while (*s1 == *s2)
102 {
103 if (*s1 == 0)
104 return 0;
105 s1++;
106 s2++;
107 }
108 return *s1 - *s2;
109}
struct S1 s1
struct S2 s2

Referenced by TableFindPtr().

◆ Sdbwcscpy()

INT Sdbwcscpy ( WCHAR wcDest,
size_t  numElement,
const WCHAR wcSrc 
)

Definition at line 113 of file sdbstringtable.c.

114{
115 size_t size = 0;
116 if(!wcDest || !numElement)
117 return 22; /* EINVAL */
118
119 wcDest[0] = 0;
120
121 if(!wcSrc)
122 return 22; /* EINVAL */
123
124 size = SdbpStrlen(wcSrc) + 1;
125
126 if(size > numElement)
127 return 34; /* ERANGE */
128
129 memcpy(wcDest, wcSrc, size * sizeof(WCHAR));
130
131 return 0;
132}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const unsigned char *static size_t const wchar_t * wcSrc
Definition: string.c:66
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by HashAddString().

◆ StringHash()

static DWORD StringHash ( const WCHAR str)
static

Definition at line 89 of file sdbstringtable.c.

90{
91 DWORD hash = 0;
92 for (; *str; str++)
93 {
94 hash = ((65599 * hash) + (ULONG)(*str));
95 }
96 return hash;
97}
Definition: _hash_fun.h:40
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ConvertCoffs(), ConvertStabs(), and TableFindPtr().

◆ TableFindPtr()

static struct SdbHashEntry ** TableFindPtr ( struct SdbStringHashTable table,
const WCHAR str 
)
static

Definition at line 134 of file sdbstringtable.c.

135{
137 struct SdbHashEntry** entry = &table->Entries[hash % table->Size];
138 while (*entry)
139 {
140 if (!Sdbwcscmp((*entry)->Name, str))
141 return entry;
142 entry = &(*entry)->Next;
143 }
144 return entry;
145}
static DWORD StringHash(const WCHAR *str)
int Sdbwcscmp(const WCHAR *s1, const WCHAR *s2)

Referenced by HashAddString(), and SdbpAddStringToTable().