Skip to content

Commit

Permalink
Change dsc_set_entry_t to camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-jones committed Apr 23, 2024
1 parent 6892108 commit ba3690b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/dsc_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define DSC_SET_LOAD_FACTOR 0.75

/* Forward declaration of the set entry structure */
typedef struct dsc_set_entry_t dsc_set_entry_t;
typedef struct DSCSetEntry DSCSetEntry;

/* Forward declaration of the set structure */
typedef struct DSCSet DSCSet;
Expand Down
34 changes: 17 additions & 17 deletions src/dsc_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@
#include "../include/dsc_error.h"

/* Represents an entry in the hash set. */
struct dsc_set_entry_t {
struct DSCSetEntry {
int key; /* The key of the entry. */
struct dsc_set_entry_t *next; /* Pointer to the next entry in case of collisions. */
struct DSCSetEntry *next; /* Pointer to the next entry in case of collisions. */
};

/* Represents a hash set. */
struct DSCSet {
struct dsc_set_entry_t **buckets; /* Array of pointers to entries. */
unsigned int size; /* The number of elements in the hash set. */
unsigned int capacity; /* The current capacity of the hash set. */
struct DSCSetEntry **buckets; /* Array of pointers to entries. */
unsigned int size; /* The number of elements in the hash set. */
unsigned int capacity; /* The current capacity of the hash set. */
};

static void dsc_set_rehash(DSCSet *set, unsigned int new_capacity) {
dsc_set_entry_t **new_buckets = calloc(new_capacity, sizeof(dsc_set_entry_t *));
DSCSetEntry **new_buckets = calloc(new_capacity, sizeof(DSCSetEntry *));
if (new_buckets == NULL) {
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
return;
}

/* Rehash all the elements into the new buckets. */
for (unsigned int i = 0; i < set->capacity; ++i) {
dsc_set_entry_t *entry = set->buckets[i];
DSCSetEntry *entry = set->buckets[i];
while (entry != NULL) {
dsc_set_entry_t *next = entry->next;
DSCSetEntry *next = entry->next;

/* Rehash the value to determine the new index. */
int index = dsc_hash(entry->key, new_capacity);
Expand All @@ -71,7 +71,7 @@ DSCSet *dsc_set_create(void) {
new_set->size = 0;
new_set->capacity = DSC_SET_INITIAL_CAPACITY;

new_set->buckets = calloc(new_set->capacity, sizeof(dsc_set_entry_t *));
new_set->buckets = calloc(new_set->capacity, sizeof(DSCSetEntry *));
if (new_set->buckets == NULL) {
free(new_set);
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
Expand All @@ -90,9 +90,9 @@ void dsc_set_free(DSCSet *set) {

/* Free all the entries in the set */
for (unsigned int i = 0; i < set->capacity; ++i) {
dsc_set_entry_t *curr = set->buckets[i];
DSCSetEntry *curr = set->buckets[i];
while (curr != NULL) {
dsc_set_entry_t *next = curr->next;
DSCSetEntry *next = curr->next;
free(curr);
curr = next;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ bool dsc_set_insert(DSCSet *set, int value) {
}

/* Create a new entry */
dsc_set_entry_t *new_entry = malloc(sizeof *new_entry);
DSCSetEntry *new_entry = malloc(sizeof *new_entry);
if (new_entry == NULL) {
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
return false;
Expand Down Expand Up @@ -152,8 +152,8 @@ bool dsc_set_erase(DSCSet *set, int value) {

int index = dsc_hash(value, set->capacity);

dsc_set_entry_t *prev = NULL;
dsc_set_entry_t *entry = set->buckets[index];
DSCSetEntry *prev = NULL;
DSCSetEntry *entry = set->buckets[index];

while (entry != NULL) {
if (entry->key == value) {
Expand Down Expand Up @@ -185,7 +185,7 @@ bool dsc_set_contains(const DSCSet *set, int value) {
int index = dsc_hash(value, set->capacity);

/* Search for the value in the bucket */
dsc_set_entry_t *entry = set->buckets[index];
DSCSetEntry *entry = set->buckets[index];
while (entry != NULL) {
if (entry->key == value) {
dsc_set_error(DSC_ERROR_NONE);
Expand Down Expand Up @@ -226,9 +226,9 @@ void dsc_set_clear(DSCSet *set) {

/* Free all the entries in the set. */
for (unsigned int i = 0; i < set->capacity; ++i) {
dsc_set_entry_t *entry = set->buckets[i];
DSCSetEntry *entry = set->buckets[i];
while (entry != NULL) {
dsc_set_entry_t *next = entry->next;
DSCSetEntry *next = entry->next;
free(entry);
entry = next;
}
Expand Down

0 comments on commit ba3690b

Please sign in to comment.