Skip to content

Commit

Permalink
Replaced Tab with space.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander committed Apr 16, 2018
1 parent 3201a01 commit ce8508a
Show file tree
Hide file tree
Showing 9 changed files with 1,747 additions and 1,578 deletions.
62 changes: 31 additions & 31 deletions common/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,51 @@

void collection_init(struct collection *col)
{
col->list = malloc(sizeof(void *));
memset(col->list, 0, sizeof(void *));
col->capacity = 1;
col->list = malloc(sizeof(void *));
memset(col->list, 0, sizeof(void *));
col->capacity = 1;
}

void collection_free(struct collection *col)
{
free(col->list);
col->list = NULL;
col->capacity = 0;
free(col->list);
col->list = NULL;
col->capacity = 0;
}

void collection_add(struct collection *col, void *element)
{
int i;
for(i=0; i<col->capacity; i++) {
if(!col->list[i]) {
col->list[i] = element;
return;
}
}
col->list = realloc(col->list, sizeof(void*) * col->capacity * 2);
memset(&col->list[col->capacity], 0, sizeof(void *) * col->capacity);
col->list[col->capacity] = element;
col->capacity *= 2;
int i;
for(i=0; i<col->capacity; i++) {
if(!col->list[i]) {
col->list[i] = element;
return;
}
}
col->list = realloc(col->list, sizeof(void*) * col->capacity * 2);
memset(&col->list[col->capacity], 0, sizeof(void *) * col->capacity);
col->list[col->capacity] = element;
col->capacity *= 2;
}

void collection_remove(struct collection *col, void *element)
{
int i;
for(i=0; i<col->capacity; i++) {
if(col->list[i] == element) {
col->list[i] = NULL;
return;
}
}
fprintf(stderr, "%s: WARNING: element %p not present in collection %p (cap %d)", __func__, element, col, col->capacity);
int i;
for(i=0; i<col->capacity; i++) {
if(col->list[i] == element) {
col->list[i] = NULL;
return;
}
}
fprintf(stderr, "%s: WARNING: element %p not present in collection %p (cap %d)", __func__, element, col, col->capacity);
}

int collection_count(struct collection *col)
{
int i, cnt = 0;
for(i=0; i<col->capacity; i++) {
if(col->list[i])
cnt++;
}
return cnt;
int i, cnt = 0;
for(i=0; i<col->capacity; i++) {
if(col->list[i])
cnt++;
}
return cnt;
}
18 changes: 9 additions & 9 deletions common/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#define COLLECTION_H

struct collection {
void **list;
int capacity;
void **list;
int capacity;
};

void collection_init(struct collection *col);
Expand All @@ -34,14 +34,14 @@ int collection_count(struct collection *col);
void collection_free(struct collection *col);

#define FOREACH(var, col) \
do { \
int _iter; \
for(_iter=0; _iter<(col)->capacity; _iter++) { \
if(!(col)->list[_iter]) continue; \
var = (col)->list[_iter];
do { \
int _iter; \
for(_iter=0; _iter<(col)->capacity; _iter++) { \
if(!(col)->list[_iter]) continue; \
var = (col)->list[_iter];

#define ENDFOREACH \
} \
} while(0);
} \
} while(0);

#endif
Loading

0 comments on commit ce8508a

Please sign in to comment.