Skip to content

Commit 60c4499

Browse files
committed
Hopefully fix hashtable CI
1 parent c4cff10 commit 60c4499

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

point/hashtable.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef struct hashTable_t {
1717
* linked list */
1818
} hashTable;
1919

20-
hashTable *ht_create(unsigned int size) {
20+
static hashTable *ht_create(unsigned int size) {
2121
hashTable *ht;
2222
if (size < 1)
2323
return NULL;
@@ -39,7 +39,7 @@ hashTable *ht_create(unsigned int size) {
3939
}
4040

4141
/* free the items in a hashTable. free each individual row and column */
42-
void ht_free(hashTable *ht) {
42+
static void ht_free(hashTable *ht) {
4343
list *tmp;
4444

4545
if (!ht)
@@ -62,7 +62,7 @@ void ht_free(hashTable *ht) {
6262
free(ht);
6363
}
6464

65-
unsigned int hash(const char *key, unsigned int size) {
65+
static unsigned int hash(const char *key, unsigned int size) {
6666
unsigned int hash = 0, i = 0;
6767

6868
while (key && key[i]) {
@@ -72,7 +72,36 @@ unsigned int hash(const char *key, unsigned int size) {
7272
return hash;
7373
}
7474

75-
int ht_put(hashTable *ht, const char *key, const char *value) {
75+
static void node_handle(hashTable *ht, list *node) {
76+
unsigned int i = hash(node->key, ht->size);
77+
list *tmp = ht->array[i];
78+
79+
if (ht->array[i] != NULL) {
80+
tmp = ht->array[i];
81+
while (tmp != NULL) {
82+
if (strcmp(tmp->key, node->key) == 0)
83+
break;
84+
tmp = tmp->next;
85+
}
86+
if (tmp == NULL) {
87+
node->next = ht->array[i];
88+
ht->array[i] = node;
89+
}
90+
else {
91+
free(tmp->value);
92+
tmp->value = strdup(node->value);
93+
free(node->value);
94+
free(node->key);
95+
free(node);
96+
}
97+
}
98+
else {
99+
node->next = NULL;
100+
ht->array[i] = node;
101+
}
102+
}
103+
104+
static int ht_put(hashTable *ht, const char *key, const char *value) {
76105
list *node;
77106

78107
if (!ht) {
@@ -92,7 +121,7 @@ int ht_put(hashTable *ht, const char *key, const char *value) {
92121
return 0;
93122
}
94123

95-
char *ht_get(hashTable *ht, const char *key) {
124+
static char *ht_get(hashTable *ht, const char *key) {
96125
char *key_cp;
97126
unsigned int i;
98127
list *tmp;
@@ -118,35 +147,6 @@ char *ht_get(hashTable *ht, const char *key) {
118147
return tmp->value;
119148
}
120149

121-
void node_handle(hashTable *ht, list *node) {
122-
unsigned int i = hash(node->key, ht->size);
123-
list *tmp = ht->array[i];
124-
125-
if (ht->array[i] != NULL) {
126-
tmp = ht->array[i];
127-
while (tmp != NULL) {
128-
if (strcmp(tmp->key, node->key) == 0)
129-
break;
130-
tmp = tmp->next;
131-
}
132-
if (tmp == NULL) {
133-
node->next = ht->array[i];
134-
ht->array[i] = node;
135-
}
136-
else {
137-
free(tmp->value);
138-
tmp->value = strdup(node->value);
139-
free(node->value);
140-
free(node->key);
141-
free(node);
142-
}
143-
}
144-
else {
145-
node->next = NULL;
146-
ht->array[i] = node;
147-
}
148-
}
149-
150150
int main(void) {
151151
hashTable *ht;
152152
if (!(ht = ht_create(1))) {

0 commit comments

Comments
 (0)