parent
b7adb91784
commit
c6095b96d9
|
@ -6,29 +6,39 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
// NOTE: I guess this marker is used as a type discriminator for implementing
|
||||||
|
// nested dictionaries. That's why every dictionary-related function starts
|
||||||
|
// with a check for this value.
|
||||||
|
#define DICTIONARY_MARKER 0xFEBAFEBA
|
||||||
|
|
||||||
|
static void* dictionaryMallocDefaultImpl(size_t size);
|
||||||
|
static void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize);
|
||||||
|
static void dictionaryFreeDefaultImpl(void* ptr);
|
||||||
|
static int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* index);
|
||||||
|
|
||||||
// 0x51E408
|
// 0x51E408
|
||||||
MallocProc* gDictionaryMallocProc = dictionaryMallocDefaultImpl;
|
static MallocProc* gDictionaryMallocProc = dictionaryMallocDefaultImpl;
|
||||||
|
|
||||||
// 0x51E40C
|
// 0x51E40C
|
||||||
ReallocProc* gDictionaryReallocProc = dictionaryReallocDefaultImpl;
|
static ReallocProc* gDictionaryReallocProc = dictionaryReallocDefaultImpl;
|
||||||
|
|
||||||
// 0x51E410
|
// 0x51E410
|
||||||
FreeProc* gDictionaryFreeProc = dictionaryFreeDefaultImpl;
|
static FreeProc* gDictionaryFreeProc = dictionaryFreeDefaultImpl;
|
||||||
|
|
||||||
// 0x4D9B90
|
// 0x4D9B90
|
||||||
void* dictionaryMallocDefaultImpl(size_t size)
|
static void* dictionaryMallocDefaultImpl(size_t size)
|
||||||
{
|
{
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4D9B98
|
// 0x4D9B98
|
||||||
void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize)
|
static void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize)
|
||||||
{
|
{
|
||||||
return realloc(ptr, newSize);
|
return realloc(ptr, newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4D9BA0
|
// 0x4D9BA0
|
||||||
void dictionaryFreeDefaultImpl(void* ptr)
|
static void dictionaryFreeDefaultImpl(void* ptr)
|
||||||
{
|
{
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +137,7 @@ int dictionaryFree(Dictionary* dictionary)
|
||||||
// specifies an insertion point for given key.
|
// specifies an insertion point for given key.
|
||||||
//
|
//
|
||||||
// 0x4D9CC4
|
// 0x4D9CC4
|
||||||
int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* indexPtr)
|
static int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* indexPtr)
|
||||||
{
|
{
|
||||||
if (dictionary->marker != DICTIONARY_MARKER) {
|
if (dictionary->marker != DICTIONARY_MARKER) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -3,11 +3,6 @@
|
||||||
|
|
||||||
#include "memory_defs.h"
|
#include "memory_defs.h"
|
||||||
|
|
||||||
// NOTE: I guess this marker is used as a type discriminator for implementing
|
|
||||||
// nested dictionaries. That's why every dictionary-related function starts
|
|
||||||
// with a check for this value.
|
|
||||||
#define DICTIONARY_MARKER 0xFEBAFEBA
|
|
||||||
|
|
||||||
// A tuple containing individual key-value pair of a dictionary.
|
// A tuple containing individual key-value pair of a dictionary.
|
||||||
typedef struct DictionaryEntry {
|
typedef struct DictionaryEntry {
|
||||||
char* key;
|
char* key;
|
||||||
|
@ -42,17 +37,9 @@ typedef struct Dictionary {
|
||||||
DictionaryEntry* entries;
|
DictionaryEntry* entries;
|
||||||
} Dictionary;
|
} Dictionary;
|
||||||
|
|
||||||
extern MallocProc* gDictionaryMallocProc;
|
|
||||||
extern ReallocProc* gDictionaryReallocProc;
|
|
||||||
extern FreeProc* gDictionaryFreeProc;
|
|
||||||
|
|
||||||
void* dictionaryMallocDefaultImpl(size_t size);
|
|
||||||
void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize);
|
|
||||||
void dictionaryFreeDefaultImpl(void* ptr);
|
|
||||||
int dictionaryInit(Dictionary* dictionary, int initialCapacity, size_t valueSize, void* a4);
|
int dictionaryInit(Dictionary* dictionary, int initialCapacity, size_t valueSize, void* a4);
|
||||||
int dictionarySetCapacity(Dictionary* dictionary, int newCapacity);
|
int dictionarySetCapacity(Dictionary* dictionary, int newCapacity);
|
||||||
int dictionaryFree(Dictionary* dictionary);
|
int dictionaryFree(Dictionary* dictionary);
|
||||||
int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* index);
|
|
||||||
int dictionaryGetIndexByKey(Dictionary* dictionary, const char* key);
|
int dictionaryGetIndexByKey(Dictionary* dictionary, const char* key);
|
||||||
int dictionaryAddValue(Dictionary* dictionary, const char* key, const void* value);
|
int dictionaryAddValue(Dictionary* dictionary, const char* key, const void* value);
|
||||||
int dictionaryRemoveValue(Dictionary* dictionary, const char* key);
|
int dictionaryRemoveValue(Dictionary* dictionary, const char* key);
|
||||||
|
|
Loading…
Reference in New Issue