Skip to content

Commit

Permalink
Resolved conflict and fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Cordes committed Aug 24, 2017
1 parent 6eb3c3f commit 6428366
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions 05-methods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ void ht_delete(ht_hash_table* h, const char* key);
To insert a new key-value pair, we iterate through indexes until we find an
empty bucket. We then insert the item into that bucket and increment the hash
table's `count` attribute, to indicate a new item has been added. A hash table's
`count` attribute will become useful when we look at [resizing](/resizing) in
`count` attribute will become useful when we look at [resizing](/06-resizing) in
the next section.

```c
// hash_table.c
void ht_insert(ht_hash_table* ht, const char* key, const char* value) {
ht_item* item = ht_new_item(key, value);
int index = ht_hash(item->key, ht->size, 0);
int index = ht_get_hash(item->key, ht->size, 0);
ht_item* cur_item = ht->items[index];
int i = 1;
while (cur_item != NULL) {
index = ht_hash(item->key, ht->size, i);
index = ht_get_hash(item->key, ht->size, i);
cur_item = ht->items[index];
i++;
}
Expand All @@ -44,14 +44,14 @@ we return the item's value. If the while loop hits a `NULL` bucket, we return
```c
// hash_table.c
char* ht_search(ht_hash_table* ht, const char* key) {
int index = ht_hash(key, ht->size, 0);
int index = ht_get_hash(key, ht->size, 0);
ht_item* item = ht->items[index];
int i = 1;
while (item != NULL) {
if (strcmp(item->key, key) == 0) {
return item->value;
}
index = ht_hash(key, ht->size, i);
index = ht_get_hash(key, ht->size, i);
item = ht->items[index];
i++;
}
Expand All @@ -76,17 +76,17 @@ static ht_item HT_DELETED_ITEM = {NULL, NULL};


void ht_delete(ht_hash_table* ht, const char* key) {
int index = ht_hash(key, ht->size, 0);
int index = ht_get_hash(key, ht->size, 0);
ht_item* item = ht->items[index];
int i = 1;
while (item != NULL) {
if(item!=&HT_DELETED_ITEM) {
if (strcmp(item->key, key) == 0) {
ht_del_item(item);
ht->items[index] = &HT_DELETED_ITEM;
}
}
index = ht_hash(key, ht->size, i);
if(item!=&HT_DELETED_ITEM) {
if (strcmp(item->key, key) == 0) {
ht_del_item(item);
ht->items[index] = &HT_DELETED_ITEM;
}
}
index = ht_get_hash(key, ht->size, i);
item = ht->items[index];
i++;
}
Expand Down Expand Up @@ -117,10 +117,10 @@ char* ht_search(ht_hash_table* ht, const char* key) {
// ...
while (item != NULL) {
if(item!=&HT_DELETED_ITEM) {
if (strcmp(item->key, key) == 0) {
return item->value;
if (strcmp(item->key, key) == 0) {
return item->value;
}
}
}
// ...
}
// ...
Expand Down Expand Up @@ -148,7 +148,7 @@ void ht_insert(ht_hash_table* ht, const char* key, const char* value) {
ht->items[index] = item;
return;
}
}
}
// ...
}
// ...
Expand Down

0 comments on commit 6428366

Please sign in to comment.