void * top_StackList(StackList * stack) { CHECK_VARN(stack,NULL); CHECK_VARN(T(stack),NULL); return T(stack)->objptr; }
int8_t tail_BinaryTreeBFSIter(BinaryTreeBFSIter* iter) { CHECK_VARN(iter,EINVAL); CHECK_VARN(iter->parent,EINVAL); clear(QueueList,&iter->queue); iter->ptr = T(iter->parent); return SUCCESS; }
int8_t next_BinaryTreeIter(BinaryTreeIter* iter) { CHECK_VARN(iter,EINVAL); CHECK_VARN(iter->parent,EINVAL); /*printf("at %p L %p R %p\n",iter->ptr,L(iter->ptr),R(iter->ptr));*/ if(R(iter->ptr)) { iter->ptr = R(iter->ptr); while(L(iter->ptr)) { iter->ptr = L(iter->ptr); } } else { if(iter->ptr == H(iter->parent)) { return SUCCESS; } else if(!iter->ptr) { iter->ptr = H(iter->parent); return EINVAL; } else { /*printf("Checking %p against %p h %p\n",iter->ptr,iter->ptr->ptr[PARENT]->ptr[RIGHT],H(iter->parent));*/ while(iter->ptr == iter->ptr->ptr[PARENT]->ptr[RIGHT]) { iter->ptr = iter->ptr->ptr[PARENT]; if(iter->ptr == H(iter->parent)) { return EINVAL; } } iter->ptr = iter->ptr->ptr[PARENT]; } } return SUCCESS; }
int8_t pop_StackVector(StackVector *stack) { CHECK_VARN(stack,EINVAL); CHECK_VARN(T(stack),EINVAL); if(!S(stack)) { return 0; } ARR_POP_BACK(StackVector,stack); return 0; }
int8_t tail_BinaryTreeIter(BinaryTreeIter* iter) { CHECK_VARN(iter,EINVAL); CHECK_VARN(iter->parent,EINVAL); iter->ptr = H(iter->parent); while(R(iter->ptr)) { iter->ptr = R(iter->ptr); } return SUCCESS; }
int8_t head_BinaryTreeBFSIter(BinaryTreeBFSIter* iter) { CHECK_VARN(iter,EINVAL); CHECK_VARN(iter->parent,EINVAL); CHECK_VARN(H(iter->parent),EINVAL); clear(QueueList,&iter->queue); iter->ptr = H(iter->parent); push(QueueList,&iter->queue,iter->ptr->ptr[LEFT],DYNAMIC); push(QueueList,&iter->queue,iter->ptr->ptr[RIGHT],DYNAMIC); return SUCCESS; }
int8_t head_BinaryTreeDFSIter(BinaryTreeDFSIter* iter) { CHECK_VARN(iter,EINVAL); CHECK_VARN(iter->parent,EINVAL); CHECK_VARN(H(iter->parent),EINVAL); clear(StackList,&iter->stack); iter->ptr = H(iter->parent); push(StackList,&iter->stack,iter->ptr->ptr[RIGHT],DYNAMIC); push(StackList,&iter->stack,iter->ptr->ptr[LEFT],DYNAMIC); return SUCCESS; }
int8_t push_back_Vector(Vector *vec, void *obj, size_t objsize, int flag) { CHECK_VARN(vec,EINVAL); CHECK_VARN(obj,EINVAL); if(objsize != O(vec)) { flag = 0; return EINVAL; } ARR_PUSH_BACK(Vector,vec,obj,objsize); return SUCCESS; }
int8_t pop_back_Vector(Vector *vec) { CHECK_VARN(vec,EINVAL); CHECK_VARN(T(vec),EINVAL); if(!S(vec)) { return EEMPTY; } ARR_POP_BACK(Vector,vec); return SUCCESS; }
int8_t assign_BinaryTreeDFSIter(BinaryTreeDFSIter* iter, BinaryTree* obj) { CHECK_VARN(iter,EINVAL); CHECK_VARN(obj,EINVAL); iter->parent = obj; iter->ptr =H(obj); memset(&iter->stack,0,sizeof iter->stack); construct(StackList,&iter->stack,sizeof *H(obj),NOFREE); push(StackList,&iter->stack,iter->ptr->ptr[RIGHT],DYNAMIC); push(StackList,&iter->stack,iter->ptr->ptr[LEFT],DYNAMIC); return 0; }
void * min_BinaryTree(BinaryTree* tree) { Node* ptr = NULL; CHECK_VARN(tree,NULL); CHECK_VARN(H(tree),NULL); ptr = H(tree); while(R(ptr)) { ptr = R(ptr); } return ptr; }
int8_t pop_front_Vector(Vector *vec) { CHECK_VARN(vec,EINVAL); CHECK_VARN(H(vec),EINVAL); if(!S(vec)) { return EEMPTY; } ARR_POP_FRONT(Vector,vec); return SUCCESS; }
int8_t assign_BinaryTreeIter(BinaryTreeIter* iter, BinaryTree* obj) { CHECK_VARN(iter,EINVAL); CHECK_VARN(obj,EINVAL); CHECK_VARN(H(obj),EINVAL); iter->parent = obj; iter->ptr = H(obj); while(L(iter->ptr)) { iter->ptr = L(iter->ptr); } return SUCCESS; }
int8_t pop_back_DequeVector(DequeVector *deque) { CHECK_VARN(deque,EINVAL); CHECK_VARN(T(deque),EINVAL); if(!S(deque)) { return 0; } ARR_POP_BACK(DequeVector,deque); return 0; }
int8_t pop_front_DequeVector(DequeVector *deque) { CHECK_VARN(deque,EINVAL); CHECK_VARN(H(deque),EINVAL); if(!S(deque)) { return 0; } ARR_POP_FRONT(DequeVector,deque); return 0; }
int8_t next_BinaryTreeDFSIter(BinaryTreeDFSIter *iter) { CHECK_VARN(iter,EINVAL); CHECK_VARN(iter->parent,EINVAL); iter->ptr = top(StackList,&iter->stack); if(!pop(StackList,&iter->stack)) { push(StackList,&iter->stack,iter->ptr->ptr[RIGHT],DYNAMIC); push(StackList,&iter->stack,iter->ptr->ptr[LEFT],DYNAMIC); return SUCCESS; } else { return EINVAL; } }
int8_t push_StackVector(StackVector *stack, void *obj, size_t objsize, int flag) { CHECK_VARN(stack,EINVAL); CHECK_VARN(obj,EINVAL); if(objsize != O(stack)) { flag = 0; return EINVAL; } ARR_PUSH_BACK(StackVector,stack,obj,objsize); return 0; }
int8_t assign_BinaryTreeBFSIter(BinaryTreeBFSIter* iter, BinaryTree* obj) { CHECK_VARN(iter,EINVAL); CHECK_VARN(obj,EINVAL); CHECK_VARN(H(obj),EINVAL); iter->parent = obj; iter->ptr = H(obj); memset(&iter->queue,0,sizeof iter->queue); construct(QueueList,&iter->queue,sizeof *H(obj),NOFREE); push(QueueList,&iter->queue,iter->ptr->ptr[LEFT],DYNAMIC); push(QueueList,&iter->queue,iter->ptr->ptr[RIGHT],DYNAMIC); return SUCCESS; }
int8_t push_back_DequeVector(DequeVector *deque, void *obj, size_t objsize, int flag) { CHECK_VARN(deque,EINVAL); CHECK_VARN(obj,EINVAL); if(objsize != O(deque)) { flag = 0; return EINVAL; } ARR_PUSH_BACK(DequeVector,deque,obj,objsize); return 0; }
int8_t next_BinaryTreeBFSIter(BinaryTreeBFSIter* iter) { CHECK_VARN(iter,EINVAL); CHECK_VARN(iter->parent,EINVAL); iter->ptr = front(QueueList,&iter->queue); if(!pop(QueueList,&iter->queue)) { push(QueueList,&iter->queue,iter->ptr->ptr[LEFT],DYNAMIC); push(QueueList,&iter->queue,iter->ptr->ptr[RIGHT],DYNAMIC); return SUCCESS; } else { return EINVAL; } }
int32_t find_prio_PrioQueue(PrioQueue *obj, void *data, size_t datasize) { PrioNode *ptr; CHECK_VARN(obj,INT_MIN); CHECK_VARN(data,INT_MIN); CHECK_OBJSIZE((obj->data),datasize,INT_MIN); if(!empty(Heap,(obj->data))) { return EEMPTY; } if(!(ptr = find_data_PrioQueue(obj,data,datasize))) { return ENOVAL; } return ptr->priority; }
int8_t dec_prio_PrioQueue(PrioQueue *obj, int32_t amt, void *data, size_t datasize) { PrioNode *ptr; CHECK_VARN(obj,EINVAL); CHECK_VARN(data,EINVAL); CHECK_OBJSIZE((obj->data),datasize,EINVAL); if(!empty(Heap,(obj->data))) { return EEMPTY; } if(!(ptr = find_data_PrioQueue(obj,data,datasize))) { return ENOVAL; } ptr->priority -= amt; return SUCCESS; }
void * front_DequeList(DequeList * deque) { CHECK_VARN(deque, NULL); CHECK_VARE(H(deque), NULL); return H(deque)->objptr; }
int8_t resize_Vector(Vector * vec, size_t size) { void *ptr; size_t offset = size * O(vec); CHECK_VARN(vec, EINVAL); CHECK_VARA(ptr = AMMalloc(offset),EALLOCF); ARR_COPY_WRAP(Vector,ptr,vec,size); /*offset = S(vec) * O(vec); if(M(vec)) { if(S(vec) == 0) { printf("%d\n",__LINE__); } else if(H(vec) < T(vec)) { printf("%d\n",__LINE__); memcpy(ptr,H(vec),((char *)T(vec) - (char *)H(vec))); } else if((void *)((char *)(H(vec)) + offset) < vec->end) { printf("%d\n",__LINE__); memcpy(ptr,H(vec),offset); } else { ptrdiff_t spaces = ((char *)vec->end - (char *)H(vec)); memcpy(ptr,H(vec),(size_t)spaces); memcpy((char *)(ptr + spaces),M(vec),O(vec) * (S(vec) - spaces/O(vec))); } AMFree(M(vec)); }*/ ARR_SETUP_POINTERS(Vector,ptr,vec,size); return SUCCESS; }
int32_t top_prio_PrioQueue(PrioQueue* obj) { CHECK_VARN(obj,INT_MIN); if(!empty(Heap,(obj->data))) { return INT_MIN; } return ((PrioNode *)top(Heap,(obj->data)))->priority; }
void * find_BinaryTree(BinaryTree * tree, void *obj, size_t objsize) { Node *ptr = NULL; int res = 0; CHECK_VARN(tree, NULL); CHECK_VARN(obj, NULL); CHECK_OBJSIZE(tree, objsize,NULL); CHECK_VARE(S(tree),NULL); ptr = H(tree); TRAVERSE_TREE(ptr,tree,obj,res,objsize); if(res == 0) { return ptr->objptr; } else { return NULL; } }
int8_t insert_at_Vector(Vector * vec, void *obj, uint32_t loc) { size_t offset; CHECK_VARN(vec, EINVAL); CHECK_VARN(obj, EINVAL); if (loc > C(vec)) { return EOOB; } offset = O(vec) * loc; if(!S(vec)) { if(M(vec) == NULL) { CHECK_VARA(M(vec) = AMMalloc((offset << 1) == 0 ? (O(vec)):(offset << 1)),EALLOCF); C(vec) = (offset << 1) == 0 ? (1):(offset << 1); } H(vec) = M(vec); T(vec) = ((char *)H(vec) + O(vec)); vec->end = ((char *)(M(vec))) + (C(vec) * O(vec)); offset = 0; S(vec) = 1; } if(H(vec) < T(vec)) { /* No wraparound */ if (loc >= S(vec)) { S(vec) = loc + 1; T(vec) = offset + D(vec); } } else if((void *)(D(vec) + offset) < vec->end) { /* Wraparound, but index is before end */ if (loc >= S(vec)) { S(vec) = loc + 1; T(vec) = D(vec) + offset; } } else { /* Wraparound, with index at beginning */ ptrdiff_t spaces = ((char *)vec->end - D(vec)); if(loc > S(vec)) { S(vec) = loc; T(vec) = (offset - spaces) + D(vec); } offset -= spaces; } vec->API.copy(D(vec) + offset, obj, O(vec)); return SUCCESS; }
PrioNode* find_data_PrioQueue(PrioQueue* obj, void* data, size_t datasize) { Heap *heap; PrioNode *ptr; CHECK_VARN(obj,NULL); CHECK_VARN(data,NULL); CHECK_VARN(obj->data,NULL); CHECK_OBJSIZE((obj->data),datasize,NULL); if(!empty(Heap,obj->data)) { return NULL; } for(ptr = (PrioNode *)heap->mem; ptr < &((PrioNode*)heap->mem)[heap->capacity]; ptr++) { if(memcmp(ptr->data,data,datasize) == 0) { return ptr; } } return NULL; }
int8_t resize_DequeVector(DequeVector *deque,size_t size) { void *ptr = NULL; CHECK_VARN(deque,EINVAL); CHECK_VARA(ptr = malloc(size * O(deque)),EALLOCF); ARR_COPY_WRAP(DequeVector,ptr,deque,size); ARR_SETUP_POINTERS(DequeVector,ptr,deque,size); return 0; }
int8_t resize_StackVector(StackVector *stack,size_t size) { void *ptr = NULL; CHECK_VARN(stack,EINVAL); CHECK_VARA(ptr = malloc(size * O(stack)),EALLOCF); ARR_COPY_WRAP(StackVector,ptr,stack,size); ARR_SETUP_POINTERS(StackVector,ptr,stack,size); return 0; }