Skip to content

Commit

Permalink
pushing up lates trees.c file. forgot to update edit date on cheney a…
Browse files Browse the repository at this point in the history
…nd test
  • Loading branch information
rrozansk committed Feb 4, 2017
1 parent 65529c2 commit bfa94bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/cheney.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/*
Author: Ryan Rozanski
Created: 1/14/17
Edited: 1/30/17
Edited: 2/4/17
*/

/**********************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/*
Author: Ryan Rozanski
Created: 1/15/17
Edited: 2/1/17
Edited: 2/4/17
*/

/**********************************************************************
Expand Down
29 changes: 8 additions & 21 deletions src/trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/*
Author: Ryan Rozanski
Created: 1/15/17
Edited: 2/1/17
Edited: 2/4/17
*/

/**********************************************************************
Expand Down Expand Up @@ -44,7 +44,7 @@ void build_tr(void **r, int cells, int cycles) {
cell_t *tr_stk[(int)floor((log(cells + 1) - 1) / log(2))];
int stk_ptr, leaf_c;

for(leaf_c = 0, stk_ptr = 0;;) {
for(leaf_c = 0, stk_ptr = 0;;) { // assign new value to ancestor?
if(!cells) {
set_car(root, genLeaf(&leaf_c, cycles, ancestor));
set_cdr(root, genLeaf(&leaf_c, cycles, ancestor));
Expand All @@ -68,22 +68,21 @@ void build_tr(void **r, int cells, int cycles) {
}
}

traversal_t TREE_WALK;
void print_tr_help(void *tr) {
void traverse_tr(void *tr, traversal_t walk) {
if(tr == NULL) { printf("()"); }
else if(!isPtr(&tr) && !isAtomic(&tr)) { printf("ERR: %p\n", tr); }
else {
switch(TREE_WALK) {
switch(walk) {
case REG:
if(isAtomic(&tr)) {
clrBit((void **)&tr, 0);
printf("%d", *(int *)tr);
//free(tr);
} else {
printf("(");
print_tr_help(((cell_t *)tr)->car);
traverse_tr(((cell_t *)tr)->car, walk);
printf(" . ");
print_tr_help(((cell_t *)tr)->cdr);
traverse_tr(((cell_t *)tr)->cdr, walk);
printf(")");
}
break;
Expand All @@ -97,22 +96,10 @@ void print_tr_help(void *tr) {
printf("cell: %p\n", tr); // fallthrough
case INTACT_CHECK:
if(isPtr(&tr)) {
print_tr_help(((cell_t *)tr)->car);
print_tr_help(((cell_t *)tr)->cdr);
traverse_tr(((cell_t *)tr)->car, walk);
traverse_tr(((cell_t *)tr)->cdr, walk);
}
break;
}
}
}

// call exit(EXIT_FAILURE); if intact check fails?? ...can i even!?
// combine these funcs?
void traverse_tr(void *tr, traversal_t walk_t) {
if(walk_t != REG && walk_t != ADDRS && walk_t != INTACT_CHECK) {
fprintf(stderr, "ERROR: unknown traversal type\nexiting...\n");
exit(EXIT_FAILURE);
}
TREE_WALK = walk_t;
print_tr_help((void *)tr);
printf("\n");
}

0 comments on commit bfa94bd

Please sign in to comment.