|
|
@ -8,6 +8,40 @@ |
|
|
#define HASH_ENTRY_CHUNK_SIZE 128 |
|
|
#define HASH_ENTRY_CHUNK_SIZE 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static |
|
|
|
|
|
void |
|
|
|
|
|
_updateHashSize(struct BIGPOINT_HASH * _this) |
|
|
|
|
|
{ |
|
|
|
|
|
if (_this->used == _this->size) { |
|
|
|
|
|
_this->size += HASH_ENTRY_CHUNK_SIZE; |
|
|
|
|
|
|
|
|
|
|
|
_this->keys = realloc(_this->keys, sizeof(char*) * _this->size); |
|
|
|
|
|
memset(_this->keys + (_this->used * sizeof(char*)), |
|
|
|
|
|
HASH_ENTRY_CHUNK_SIZE * sizeof(char*), |
|
|
|
|
|
0); |
|
|
|
|
|
|
|
|
|
|
|
_this->values = realloc( |
|
|
|
|
|
_this->values, |
|
|
|
|
|
sizeof(struct BIGPOINT_DYNTYPE *) * _this->size); |
|
|
|
|
|
memset(_this->values + (_this->used * sizeof(struct BIGPOINT_DYNTYPE *)), |
|
|
|
|
|
HASH_ENTRY_CHUNK_SIZE * sizeof(struct BIGPOINT_DYNTYPE *), |
|
|
|
|
|
0); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static |
|
|
|
|
|
size_t |
|
|
|
|
|
_getHashIdx(struct BIGPOINT_HASH * _this, const char * key) |
|
|
|
|
|
{ |
|
|
|
|
|
size_t index; |
|
|
|
|
|
|
|
|
|
|
|
for (index = 0; |
|
|
|
|
|
index < _this->used && strcmp(_this->keys[index], key); |
|
|
|
|
|
index++); |
|
|
|
|
|
|
|
|
|
|
|
return index; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
__construct(struct BIGPOINT_HASH * _this, va_list * params) |
|
|
__construct(struct BIGPOINT_HASH * _this, va_list * params) |
|
|
@ -54,41 +88,6 @@ struct BIGPOINT_CCLASS _bigpoint_hash = { |
|
|
|
|
|
|
|
|
const struct BIGPOINT_CCLASS * const BIGPOINT_HASH = &_bigpoint_hash; |
|
|
const struct BIGPOINT_CCLASS * const BIGPOINT_HASH = &_bigpoint_hash; |
|
|
|
|
|
|
|
|
static |
|
|
|
|
|
void |
|
|
|
|
|
_updateHashSize(struct BIGPOINT_HASH * _this) |
|
|
|
|
|
{ |
|
|
|
|
|
if (_this->used == _this->size) { |
|
|
|
|
|
_this->size += HASH_ENTRY_CHUNK_SIZE; |
|
|
|
|
|
|
|
|
|
|
|
_this->keys = realloc(_this->keys, sizeof(char*) * _this->size); |
|
|
|
|
|
memset(_this->keys + (_this->used * sizeof(char*)), |
|
|
|
|
|
HASH_ENTRY_CHUNK_SIZE * sizeof(char*), |
|
|
|
|
|
0); |
|
|
|
|
|
|
|
|
|
|
|
_this->values = realloc( |
|
|
|
|
|
_this->values, |
|
|
|
|
|
sizeof(struct BIGPOINT_DYNTYPE *) * _this->size, |
|
|
|
|
|
0); |
|
|
|
|
|
memset(_this->values + (_this->used * sizeof(struct BIGPOINT_DYNTYPE *)), |
|
|
|
|
|
HASH_ENTRY_CHUNK_SIZE * sizeof(struct BIGPOINT_DYNTYPE *), |
|
|
|
|
|
0); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static |
|
|
|
|
|
size_t |
|
|
|
|
|
_getHashIdx(struct BIGPOINT_HASH * _this, const char * key) |
|
|
|
|
|
{ |
|
|
|
|
|
size_t index; |
|
|
|
|
|
|
|
|
|
|
|
for (index = 0; |
|
|
|
|
|
index < _this->used && strcmp(_this->key[index], key); |
|
|
|
|
|
index++); |
|
|
|
|
|
|
|
|
|
|
|
return index; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
void |
|
|
bigpoint_hash_set(struct BIGPOINT_HASH * _this, |
|
|
bigpoint_hash_set(struct BIGPOINT_HASH * _this, |
|
|
const char * key, |
|
|
const char * key, |
|
|
@ -96,15 +95,15 @@ bigpoint_hash_set(struct BIGPOINT_HASH * _this, |
|
|
{ |
|
|
{ |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
size_t index = _getHashIdx(_this, key); |
|
|
|
|
|
|
|
|
if (index == _this->used) { |
|
|
|
|
|
index = _this->used = index + 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_this->keys[index] = calloc(strlen(key) + 1, sizeof(char)); |
|
|
_this->keys[index] = calloc(strlen(key) + 1, sizeof(char)); |
|
|
memcpy(_this->keys[index], key, strlen(key)); |
|
|
memcpy(_this->keys[index], key, strlen(key)); |
|
|
|
|
|
|
|
|
_this->values[index] = value; |
|
|
_this->values[index] = value; |
|
|
|
|
|
|
|
|
|
|
|
if (index == _this->used) { |
|
|
|
|
|
_this->used += 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
_updateHashSize(_this); |
|
|
_updateHashSize(_this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -117,7 +116,7 @@ bigpoint_hash_get(struct BIGPOINT_HASH * _this, const char * key) |
|
|
return NULL; |
|
|
return NULL; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return _this->value[index]; |
|
|
|
|
|
|
|
|
return _this->values[index]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
struct BIGPOINT_DYNTYPE * |
|
|
struct BIGPOINT_DYNTYPE * |
|
|
@ -130,14 +129,14 @@ bigpoint_hash_del(struct BIGPOINT_HASH * _this, const char * key) |
|
|
return NULL; |
|
|
return NULL; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
free(_this->key[index]); |
|
|
|
|
|
|
|
|
free(_this->keys[index]); |
|
|
|
|
|
|
|
|
memmove(_this->key + index + 1, |
|
|
|
|
|
_this->key + index, |
|
|
|
|
|
|
|
|
memmove(_this->keys + index + 1, |
|
|
|
|
|
_this->keys + index, |
|
|
(_this->size - index) * sizeof(char*)); |
|
|
(_this->size - index) * sizeof(char*)); |
|
|
|
|
|
|
|
|
memmove(_this->value + index + 1, |
|
|
|
|
|
_this->value + index, |
|
|
|
|
|
|
|
|
memmove(_this->values + index + 1, |
|
|
|
|
|
_this->values + index, |
|
|
(_this->size - index) * sizeof(struct BIGPOINT_DYNTYPE *)); |
|
|
(_this->size - index) * sizeof(struct BIGPOINT_DYNTYPE *)); |
|
|
|
|
|
|
|
|
_this->used -= 1; |
|
|
_this->used -= 1; |
|
|
|