TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Map.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _CASC_MAP
 

Macros

#define KEY_LENGTH_STRING   0xFFFFFFFF
 

Typedefs

typedef struct _CASC_MAP CASC_MAP
 
typedef struct _CASC_MAPPCASC_MAP
 
typedef bool(* MAP_COMPARE )(PCASC_MAP pMap, void *pvObject, void *pvKey)
 

Functions

PCASC_MAP Map_Create (DWORD dwMaxItems, DWORD dwKeyLength, DWORD dwKeyOffset)
 
size_t Map_EnumObjects (PCASC_MAP pMap, void **ppvArray)
 
void * Map_FindObject (PCASC_MAP pMap, void *pvKey, PDWORD PtrIndex)
 
bool Map_InsertObject (PCASC_MAP pMap, void *pvNewObject, void *pvKey)
 
const char * Map_FindString (PCASC_MAP pMap, const char *szString, const char *szStringEnd)
 
bool Map_InsertString (PCASC_MAP pMap, const char *szString, bool bCutExtension)
 
void Map_Free (PCASC_MAP pMap)
 

Macro Definition Documentation

#define KEY_LENGTH_STRING   0xFFFFFFFF

Typedef Documentation

typedef struct _CASC_MAP CASC_MAP
typedef bool(* MAP_COMPARE)(PCASC_MAP pMap, void *pvObject, void *pvKey)
typedef struct _CASC_MAP * PCASC_MAP

Function Documentation

PCASC_MAP Map_Create ( DWORD  dwMaxItems,
DWORD  dwKeyLength,
DWORD  dwKeyOffset 
)
94 {
95  PCASC_MAP pMap;
96  size_t cbToAllocate;
97  size_t dwTableSize;
98 
99  // Calculate the size of the table
100  dwTableSize = (dwMaxItems * 3 / 2) | 0x01;
101 
102  // Allocate new map for the objects
103  cbToAllocate = sizeof(CASC_MAP) + (dwTableSize * sizeof(void *));
104  pMap = (PCASC_MAP)CASC_ALLOC(LPBYTE, cbToAllocate);
105  if(pMap != NULL)
106  {
107  memset(pMap, 0, cbToAllocate);
108  pMap->KeyLength = dwKeyLength;
109  pMap->TableSize = dwTableSize;
110  pMap->KeyOffset = dwKeyOffset;
111  }
112 
113  // Return the allocated map
114  return pMap;
115 }
size_t KeyOffset
Definition: Map.h:23
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
arena_t NULL
Definition: jemalloc_internal.h:624
struct _CASC_MAP CASC_MAP
BYTE * LPBYTE
Definition: CascPort.h:152
size_t TableSize
Definition: Map.h:21
struct _CASC_MAP * PCASC_MAP
Definition: Map.h:19
size_t KeyLength
Definition: Map.h:24

+ Here is the caller graph for this function:

size_t Map_EnumObjects ( PCASC_MAP  pMap,
void **  ppvArray 
)
118 {
119  size_t nIndex = 0;
120 
121  // Verify pointer to the map
122  if(pMap != NULL && ppvArray != NULL)
123  {
124  // Enumerate all items in main table
125  for(size_t i = 0; i < pMap->TableSize; i++)
126  {
127  // Is that cell valid?
128  if(pMap->HashTable[i] != NULL)
129  {
130  ppvArray[nIndex++] = pMap->HashTable[i];
131  }
132  }
133  }
134 
135  return pMap->ItemCount;
136 }
arena_t NULL
Definition: jemalloc_internal.h:624
size_t TableSize
Definition: Map.h:21
void * HashTable[1]
Definition: Map.h:25
size_t ItemCount
Definition: Map.h:22
void* Map_FindObject ( PCASC_MAP  pMap,
void *  pvKey,
PDWORD  PtrIndex 
)
139 {
140  void * pvObject;
141  DWORD dwHashIndex;
142 
143  // Verify pointer to the map
144  if(pMap != NULL)
145  {
146  // Construct the main index
147  dwHashIndex = CalcHashIndex_Key(pMap, pvKey);
148  while(pMap->HashTable[dwHashIndex] != NULL)
149  {
150  // Get the pointer at that position
151  pvObject = pMap->HashTable[dwHashIndex];
152 
153  // Compare the hash
154  if(CompareObject_Key(pMap, pvObject, pvKey))
155  {
156  if(PtrIndex != NULL)
157  PtrIndex[0] = dwHashIndex;
158  return pvObject;
159  }
160 
161  // Move to the next entry
162  dwHashIndex = (dwHashIndex + 1) % pMap->TableSize;
163  }
164  }
165 
166  // Not found, sorry
167  return NULL;
168 }
arena_t NULL
Definition: jemalloc_internal.h:624
size_t TableSize
Definition: Map.h:21
static DWORD CalcHashIndex_Key(PCASC_MAP pMap, void *pvKey)
Definition: Map.cpp:25
unsigned int DWORD
Definition: CascPort.h:139
static bool CompareObject_Key(PCASC_MAP pMap, void *pvObject, void *pvKey)
Definition: Map.cpp:61
void * HashTable[1]
Definition: Map.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const char* Map_FindString ( PCASC_MAP  pMap,
const char *  szString,
const char *  szStringEnd 
)
252 {
253  const char * szExistingString;
254  DWORD dwHashIndex;
255 
256  // Verify pointer to the map
257  if(pMap != NULL)
258  {
259  // Construct the main index
260  dwHashIndex = CalcHashIndex_String(pMap, szString, szStringEnd);
261  while(pMap->HashTable[dwHashIndex] != NULL)
262  {
263  // Get the pointer at that position
264  szExistingString = (const char *)pMap->HashTable[dwHashIndex];
265 
266  // Compare the hash
267  if(CompareObject_String(pMap, szExistingString, szString, szStringEnd))
268  return szExistingString;
269 
270  // Move to the next entry
271  dwHashIndex = (dwHashIndex + 1) % pMap->TableSize;
272  }
273  }
274 
275  // Not found, sorry
276  return NULL;
277 }
arena_t NULL
Definition: jemalloc_internal.h:624
size_t TableSize
Definition: Map.h:21
unsigned int DWORD
Definition: CascPort.h:139
void * HashTable[1]
Definition: Map.h:25
static bool CompareObject_String(PCASC_MAP pMap, const char *szExistingString, const char *szString, const char *szStringEnd)
Definition: Map.cpp:68
static DWORD CalcHashIndex_String(PCASC_MAP pMap, const char *szString, const char *szStringEnd)
Definition: Map.cpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Map_Free ( PCASC_MAP  pMap)
280 {
281  if(pMap != NULL)
282  {
283  CASC_FREE(pMap);
284  }
285 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define CASC_FREE(ptr)
Definition: CascCommon.h:303

+ Here is the caller graph for this function:

bool Map_InsertObject ( PCASC_MAP  pMap,
void *  pvNewObject,
void *  pvKey 
)
171 {
172  void * pvExistingObject;
173  DWORD dwHashIndex;
174 
175  // Verify pointer to the map
176  if(pMap != NULL)
177  {
178  // Limit check
179  if((pMap->ItemCount + 1) >= pMap->TableSize)
180  return false;
181 
182  // Construct the hash index
183  dwHashIndex = CalcHashIndex_Key(pMap, pvKey);
184  while(pMap->HashTable[dwHashIndex] != NULL)
185  {
186  // Get the pointer at that position
187  pvExistingObject = pMap->HashTable[dwHashIndex];
188 
189  // Check if hash being inserted conflicts with an existing hash
190  if(CompareObject_Key(pMap, pvExistingObject, pvKey))
191  return false;
192 
193  // Move to the next entry
194  dwHashIndex = (dwHashIndex + 1) % pMap->TableSize;
195  }
196 
197  // Insert at that position
198  pMap->HashTable[dwHashIndex] = pvNewObject;
199  pMap->ItemCount++;
200  return true;
201  }
202 
203  // Failed
204  return false;
205 }
arena_t NULL
Definition: jemalloc_internal.h:624
size_t TableSize
Definition: Map.h:21
static DWORD CalcHashIndex_Key(PCASC_MAP pMap, void *pvKey)
Definition: Map.cpp:25
unsigned int DWORD
Definition: CascPort.h:139
static bool CompareObject_Key(PCASC_MAP pMap, void *pvObject, void *pvKey)
Definition: Map.cpp:61
void * HashTable[1]
Definition: Map.h:25
size_t ItemCount
Definition: Map.h:22

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Map_InsertString ( PCASC_MAP  pMap,
const char *  szString,
bool  bCutExtension 
)
208 {
209  const char * szExistingString;
210  const char * szStringEnd = NULL;
211  DWORD dwHashIndex;
212 
213  // Verify pointer to the map
214  if(pMap != NULL)
215  {
216  // Limit check
217  if((pMap->ItemCount + 1) >= pMap->TableSize)
218  return false;
219 
220  // Retrieve the length of the string without extension
221  if(bCutExtension)
222  szStringEnd = String_GetExtension(szString);
223  if(szStringEnd == NULL)
224  szStringEnd = szString + strlen(szString);
225 
226  // Construct the hash index
227  dwHashIndex = CalcHashIndex_String(pMap, szString, szStringEnd);
228  while(pMap->HashTable[dwHashIndex] != NULL)
229  {
230  // Get the pointer at that position
231  szExistingString = (const char *)pMap->HashTable[dwHashIndex];
232 
233  // Check if hash being inserted conflicts with an existing hash
234  if(CompareObject_String(pMap, szExistingString, szString, szStringEnd))
235  return false;
236 
237  // Move to the next entry
238  dwHashIndex = (dwHashIndex + 1) % pMap->TableSize;
239  }
240 
241  // Insert at that position
242  pMap->HashTable[dwHashIndex] = (void *)szString;
243  pMap->ItemCount++;
244  return true;
245  }
246 
247  // Failed
248  return false;
249 }
static const char * String_GetExtension(const char *szString)
Definition: Map.cpp:19
arena_t NULL
Definition: jemalloc_internal.h:624
size_t TableSize
Definition: Map.h:21
unsigned int DWORD
Definition: CascPort.h:139
void * HashTable[1]
Definition: Map.h:25
size_t ItemCount
Definition: Map.h:22
static bool CompareObject_String(PCASC_MAP pMap, const char *szExistingString, const char *szString, const char *szStringEnd)
Definition: Map.cpp:68
static DWORD CalcHashIndex_String(PCASC_MAP pMap, const char *szString, const char *szStringEnd)
Definition: Map.cpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function: