Skip to content

Commit

Permalink
Hopefully fix hashtable CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Babkock committed Jul 12, 2024
1 parent c4cff10 commit 60c4499
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions point/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef struct hashTable_t {
* linked list */
} hashTable;

hashTable *ht_create(unsigned int size) {
static hashTable *ht_create(unsigned int size) {
hashTable *ht;
if (size < 1)
return NULL;
Expand All @@ -39,7 +39,7 @@ hashTable *ht_create(unsigned int size) {
}

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

if (!ht)
Expand All @@ -62,7 +62,7 @@ void ht_free(hashTable *ht) {
free(ht);
}

unsigned int hash(const char *key, unsigned int size) {
static unsigned int hash(const char *key, unsigned int size) {
unsigned int hash = 0, i = 0;

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

int ht_put(hashTable *ht, const char *key, const char *value) {
static void node_handle(hashTable *ht, list *node) {
unsigned int i = hash(node->key, ht->size);
list *tmp = ht->array[i];

if (ht->array[i] != NULL) {
tmp = ht->array[i];
while (tmp != NULL) {
if (strcmp(tmp->key, node->key) == 0)
break;
tmp = tmp->next;
}
if (tmp == NULL) {
node->next = ht->array[i];
ht->array[i] = node;
}
else {
free(tmp->value);
tmp->value = strdup(node->value);
free(node->value);
free(node->key);
free(node);
}
}
else {
node->next = NULL;
ht->array[i] = node;
}
}

static int ht_put(hashTable *ht, const char *key, const char *value) {
list *node;

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

char *ht_get(hashTable *ht, const char *key) {
static char *ht_get(hashTable *ht, const char *key) {
char *key_cp;
unsigned int i;
list *tmp;
Expand All @@ -118,35 +147,6 @@ char *ht_get(hashTable *ht, const char *key) {
return tmp->value;
}

void node_handle(hashTable *ht, list *node) {
unsigned int i = hash(node->key, ht->size);
list *tmp = ht->array[i];

if (ht->array[i] != NULL) {
tmp = ht->array[i];
while (tmp != NULL) {
if (strcmp(tmp->key, node->key) == 0)
break;
tmp = tmp->next;
}
if (tmp == NULL) {
node->next = ht->array[i];
ht->array[i] = node;
}
else {
free(tmp->value);
tmp->value = strdup(node->value);
free(node->value);
free(node->key);
free(node);
}
}
else {
node->next = NULL;
ht->array[i] = node;
}
}

int main(void) {
hashTable *ht;
if (!(ht = ht_create(1))) {
Expand Down

0 comments on commit 60c4499

Please sign in to comment.