Bug fixes

This commit is contained in:
krahets
2023-09-26 10:57:53 +08:00
parent cbea6c584d
commit e567d08348
6 changed files with 15 additions and 217 deletions

View File

@@ -26,16 +26,16 @@ struct mapSet {
typedef struct mapSet mapSet;
/* 基于数组简易实现的哈希表 */
struct ArrayHashMap {
struct arrayHashMap {
pair *buckets[HASH_MAP_DEFAULT_SIZE];
};
typedef struct ArrayHashMap ArrayHashMap;
typedef struct arrayHashMap arrayHashMap;
/* 哈希表初始化函数 */
ArrayHashMap *newArrayHashMap() {
ArrayHashMap *arrayHashMap = malloc(sizeof(ArrayHashMap));
return arrayHashMap;
arrayHashMap *newArrayHashMap() {
arrayHashMap *map = malloc(sizeof(arrayHashMap));
return map;
}
/* 哈希函数 */
@@ -45,7 +45,7 @@ int hashFunc(int key) {
}
/* 查询操作 */
const char *get(const ArrayHashMap *d, const int key) {
const char *get(const arrayHashMap *d, const int key) {
int index = hashFunc(key);
const pair *pair = d->buckets[index];
if (pair == NULL)
@@ -54,7 +54,7 @@ const char *get(const ArrayHashMap *d, const int key) {
}
/* 添加操作 */
void put(ArrayHashMap *d, const int key, const char *val) {
void put(arrayHashMap *d, const int key, const char *val) {
pair *pair = malloc(sizeof(pair));
pair->key = key;
pair->val = malloc(strlen(val) + 1);
@@ -65,7 +65,7 @@ void put(ArrayHashMap *d, const int key, const char *val) {
}
/* 删除操作 */
void removeItem(ArrayHashMap *d, const int key) {
void removeItem(arrayHashMap *d, const int key) {
int index = hashFunc(key);
free(d->buckets[index]->val);
free(d->buckets[index]);
@@ -73,7 +73,7 @@ void removeItem(ArrayHashMap *d, const int key) {
}
/* 获取所有键值对 */
void pairSet(ArrayHashMap *d, mapSet *set) {
void pairSet(arrayHashMap *d, mapSet *set) {
pair *entries;
int i = 0, index = 0;
int total = 0;
@@ -100,7 +100,7 @@ void pairSet(ArrayHashMap *d, mapSet *set) {
}
/* 获取所有键 */
void keySet(ArrayHashMap *d, mapSet *set) {
void keySet(arrayHashMap *d, mapSet *set) {
int *keys;
int i = 0, index = 0;
int total = 0;
@@ -125,7 +125,7 @@ void keySet(ArrayHashMap *d, mapSet *set) {
}
/* 获取所有值 */
void valueSet(ArrayHashMap *d, mapSet *set) {
void valueSet(arrayHashMap *d, mapSet *set) {
char **vals;
int i = 0, index = 0;
int total = 0;
@@ -150,7 +150,7 @@ void valueSet(ArrayHashMap *d, mapSet *set) {
}
/* 打印哈希表 */
void print(ArrayHashMap *d) {
void print(arrayHashMap *d) {
int i;
mapSet set;
pairSet(d, &set);
@@ -164,7 +164,7 @@ void print(ArrayHashMap *d) {
/* Driver Code */
int main() {
/* 初始化哈希表 */
ArrayHashMap *map = newArrayHashMap();
arrayHashMap *map = newArrayHashMap();
/* 添加操作 */
// 在哈希表中添加键值对 (key, value)