|
|
@ -27,11 +27,11 @@ |
|
|
#define HASH_ENTRY_CHUNK_SIZE 128 |
|
|
#define HASH_ENTRY_CHUNK_SIZE 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void _updateHashSize(struct DYNTYPE_HASH * _this); |
|
|
|
|
|
|
|
|
static void _updateHashSize(DYNTYPE_HASH _this); |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
__construct(struct DYNTYPE_HASH * _this, va_list * params) |
|
|
|
|
|
|
|
|
__construct(DYNTYPE_HASH _this, va_list * params) |
|
|
{ |
|
|
{ |
|
|
_this->size = 0; |
|
|
_this->size = 0; |
|
|
_this->used = 0; |
|
|
_this->used = 0; |
|
|
@ -40,7 +40,7 @@ __construct(struct DYNTYPE_HASH * _this, va_list * params) |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
__jsonConst(struct DYNTYPE_HASH * _this, struct json_object * json) |
|
|
|
|
|
|
|
|
__jsonConst(DYNTYPE_HASH _this, struct json_object * json) |
|
|
{ |
|
|
{ |
|
|
__construct(_this, NULL); |
|
|
__construct(_this, NULL); |
|
|
|
|
|
|
|
|
@ -55,7 +55,7 @@ __jsonConst(struct DYNTYPE_HASH * _this, struct json_object * json) |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
__destruct(struct DYNTYPE_HASH * _this) |
|
|
|
|
|
|
|
|
__destruct(DYNTYPE_HASH _this) |
|
|
{ |
|
|
{ |
|
|
size_t index; |
|
|
size_t index; |
|
|
|
|
|
|
|
|
@ -69,7 +69,7 @@ __destruct(struct DYNTYPE_HASH * _this) |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
struct json_object * |
|
|
struct json_object * |
|
|
__toJson(struct DYNTYPE_HASH * _this) |
|
|
|
|
|
|
|
|
__toJson(DYNTYPE_HASH _this) |
|
|
{ |
|
|
{ |
|
|
size_t index; |
|
|
size_t index; |
|
|
struct json_object * json = json_object_new_object(); |
|
|
struct json_object * json = json_object_new_object(); |
|
|
@ -88,7 +88,7 @@ INIT_CCLASS(DYNTYPE_HASH, __jsonConst, __toJson); |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
_updateHashSize(struct DYNTYPE_HASH * _this) |
|
|
|
|
|
|
|
|
_updateHashSize(DYNTYPE_HASH _this) |
|
|
{ |
|
|
{ |
|
|
if (_this->used == _this->size) { |
|
|
if (_this->used == _this->size) { |
|
|
_this->size += HASH_ENTRY_CHUNK_SIZE; |
|
|
_this->size += HASH_ENTRY_CHUNK_SIZE; |
|
|
@ -100,16 +100,16 @@ _updateHashSize(struct DYNTYPE_HASH * _this) |
|
|
|
|
|
|
|
|
_this->values = realloc( |
|
|
_this->values = realloc( |
|
|
_this->values, |
|
|
_this->values, |
|
|
sizeof(struct DYNTYPE *) * _this->size); |
|
|
|
|
|
memset(_this->values + (_this->used * sizeof(struct DYNTYPE *)), |
|
|
|
|
|
|
|
|
sizeof(DYNTYPE) * _this->size); |
|
|
|
|
|
memset(_this->values + (_this->used * sizeof(DYNTYPE)), |
|
|
0, |
|
|
0, |
|
|
HASH_ENTRY_CHUNK_SIZE * sizeof(struct DYNTYPE *)); |
|
|
|
|
|
|
|
|
HASH_ENTRY_CHUNK_SIZE * sizeof(DYNTYPE)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
size_t |
|
|
size_t |
|
|
_getHashIdx(struct DYNTYPE_HASH * _this, const char * key) |
|
|
|
|
|
|
|
|
_getHashIdx(DYNTYPE_HASH _this, const char * key) |
|
|
{ |
|
|
{ |
|
|
size_t index; |
|
|
size_t index; |
|
|
|
|
|
|
|
|
@ -121,9 +121,7 @@ _getHashIdx(struct DYNTYPE_HASH * _this, const char * key) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void |
|
|
void |
|
|
dyntype_hash_set(struct DYNTYPE_HASH * _this, |
|
|
|
|
|
const char * key, |
|
|
|
|
|
struct DYNTYPE * value) |
|
|
|
|
|
|
|
|
dyntype_hash_set(DYNTYPE_HASH _this, const char * key, DYNTYPE value) |
|
|
{ |
|
|
{ |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
|
|
|
|
|
|
@ -139,8 +137,7 @@ dyntype_hash_set(struct DYNTYPE_HASH * _this, |
|
|
_updateHashSize(_this); |
|
|
_updateHashSize(_this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
struct DYNTYPE * |
|
|
|
|
|
dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key) |
|
|
|
|
|
|
|
|
DYNTYPE dyntype_hash_get(DYNTYPE_HASH _this, const char * key) |
|
|
{ |
|
|
{ |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
|
|
|
|
|
|
@ -151,10 +148,9 @@ dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key) |
|
|
return _this->values[index]; |
|
|
return _this->values[index]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
struct DYNTYPE * |
|
|
|
|
|
dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key) |
|
|
|
|
|
|
|
|
DYNTYPE dyntype_hash_del(DYNTYPE_HASH _this, const char * key) |
|
|
{ |
|
|
{ |
|
|
struct DYNTYPE * found = NULL; |
|
|
|
|
|
|
|
|
DYNTYPE found = NULL; |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
|
|
|
|
|
|
if (index == _this->used) { |
|
|
if (index == _this->used) { |
|
|
@ -169,7 +165,7 @@ dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key) |
|
|
|
|
|
|
|
|
memmove(_this->values + index + 1, |
|
|
memmove(_this->values + index + 1, |
|
|
_this->values + index, |
|
|
_this->values + index, |
|
|
(_this->size - index) * sizeof(struct DYNTYPE *)); |
|
|
|
|
|
|
|
|
(_this->size - index) * sizeof(DYNTYPE)); |
|
|
|
|
|
|
|
|
_this->used -= 1; |
|
|
_this->used -= 1; |
|
|
} |
|
|
} |
|
|
|