Commit ff561a73 authored by Lindsay Knupp's avatar Lindsay Knupp
Browse files

fixing dlist

parent 2f2fb51d
......@@ -115,12 +115,12 @@ uint32_t dlist_num_elems(struct dlist *l);
/**
* Initialize iterator for traversing a dlist forwards.
*/
void *dlist_iter_begin(struct dlist *l);
struct dnode *dlist_iter_begin(struct dlist *l);
/**
* Returns current item and advances iterator to next item in list.
*/
void *dlist_iter_next(struct dlist *l);
struct dnode *dlist_iter_next(struct dlist *l);
/**
* Check if iterator has reached the end of the list.
......
......@@ -15,7 +15,12 @@
int allocator_init(size_t size){
free_list = malloc(size);
allocated_list = malloc(size);
allocated_list = dlist_create();
allocated_list->front = NULL;
allocated_list->back = NULL;
// Check if lists successfully created
if (!(free_list || allocated_list) == 1) {
......@@ -25,7 +30,7 @@ int allocator_init(size_t size){
return 0;
}
void *allocate(size_t size){
}
//void *allocate(size_t size){
//
//
//}
......@@ -164,30 +164,52 @@ dlist_num_elems(struct dlist *l) {
return l->counter;
}
void *
struct dnode *
dlist_iter_begin(struct dlist *l) {
void *ret_val = NULL;
// void *ret_val = NULL;
//
// l->iter = l->front;
// if (l->iter != NULL) {
// ret_val = l->iter->data;
// }
// return ret_val;
struct dnode *ret_p = NULL;
l->iter = l->front;
if (l->iter != NULL) {
ret_val = l->iter->data;
if(l->iter != NULL){
ret_p = l->iter;
}
return ret_val;
return ret_p;
}
void *
struct dnode *
dlist_iter_next(struct dlist *l) {
void *ret_val = NULL;
// void *ret_val = NULL;
if (l->iter != NULL) {
// if (l->iter != NULL) {
// l->iter = l->iter->next;
// if (l->iter != NULL) {
// ret_val = l->iter->data;
// }
// }
// return ret_val;
struct dnode *ret_p = NULL;
if(l->iter != NULL) {
l->iter = l->iter->next;
if (l->iter != NULL) {
ret_val = l->iter->data;
ret_p = l->iter;
}
}
return ret_p;
return ret_val;
}
bool
......@@ -248,10 +270,14 @@ dlist_iter_has_prev(struct dlist *l) {
void dlist_print(struct dlist *l){
printf("dlist: -");
char *data;
// char *data;
struct dnode *data;
for (data = dlist_iter_begin(l); data != NULL;
data = (char *) dlist_iter_next(l)) {
printf("[%s,%p]-- ",data,data);
data = dlist_iter_next(l)) {
printf("[%zu,%p]-- ",data->size,data);
}
printf("\n");
......
......@@ -12,10 +12,7 @@
int main(int argc, char *argv[]){
allocator_init(1024);
allocator_init(1024);
printf("Memory-test running\n");
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment