示例#1
0
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;
}
示例#2
0
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;
}
示例#3
0
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;
  }
}
示例#4
0
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;
}
示例#5
0
int8_t
push_front_DequeList(DequeList *deque, void *obj, size_t objsize, int flag) {
  Node *tmp;

  CHECK_VARN(deque, EINVAL);
  CHECK_VARN(obj, EINVAL);
  CHECK_OBJSIZE(deque,objsize,EINVAL);

  INITIALIZE_NODE(tmp,deque,obj,flag);

  if (!S(deque)) {
    H(deque) = T(deque) = tmp;
    S(deque)++;
  } else {
    ADD_FRONT(tmp, deque);
  }

  return SUCCESS;
allocobjfail:
  ADD_FREE_NODE(deque,tmp);
allocfail:
  return -EALLOCF;
}
示例#6
0
int8_t
push_StackList(StackList * stack, void *obj, size_t objsize, int8_t flag)
{
  Node *tmp;

  CHECK_VARN(stack, EINVAL);
  CHECK_VARN(obj, EINVAL);
  CHECK_OBJSIZE(stack,objsize,EINVAL);

  INITIALIZE_NODE(tmp,stack,obj,flag);

  if (!S(stack)) {
    H(stack) = T(stack) = tmp;
    S(stack)++;
  } else {
    ADD_BACK(tmp, stack);
  }
  return SUCCESS;
allocobjfail:
  ADD_FREE_NODE(stack,tmp);
allocfail:
  return EALLOCF;
}
示例#7
0
void *
insert_BinaryTree(BinaryTree * tree, void *obj, size_t objsize, int flag)
{
  Node *ptr = NULL, *tmp = NULL;
  int res = 0;
  CHECK_VARN(tree,NULL);
  CHECK_VARN(obj,NULL);
  CHECK_OBJSIZE(tree, objsize,NULL);
  INITIALIZE_NODE(tmp,tree,obj,flag);

  if(!S(tree)) {
	  H(tree) = tmp;
	  tmp->ptr[PARENT] = NULL;
	  S(tree)++;
  } else {
	  ptr = H(tree);
	  TRAVERSE_TREE(ptr,tree,tmp->objptr,res,objsize);
	  if(res < 0) {
		  if(ptr->ptr[RIGHT] == T(tree)) {
			  T(tree) = tmp;
		  }
		  INSERT_RIGHT(ptr,tmp);
	  } else if(res > 0) {
		  INSERT_LEFT(ptr,tmp);
	  } else {
		  DELETE_OBJPTR(tree,tmp);
		  ADD_FREE_NODE(tree,tmp);
	  }
  }
  return tmp;
allocobjfail:
  ADD_FREE_NODE(tree,tmp);
allocfail:
  ALLOCFAIL(object);
  return NULL;
}
示例#8
0
int8_t
delete_BinaryTree(BinaryTree * tree, void *obj, size_t objsize)
{
  Node *ptr = NULL;
  int res = 0;
  CHECK_VARN(tree, EINVAL);
  CHECK_VARN(obj, EINVAL);
  CHECK_OBJSIZE(tree, objsize, EINVAL);
  CHECK_VARE(S(tree),EEMPTY);

  ptr = H(tree);

repeat_delete:
  TRAVERSE_TREE(ptr,tree,obj,res,objsize);
  
  if(res == 0) {
	  Node* tmp = ptr,*pnt = ptr->ptr[PARENT];
	  int x =0;
	  if(L(ptr) && R(ptr)) {
		  Node *ptr2;
		  /* there are two children present,
		   * need to handle this accordingly
		   */
		  ptr2 = R(ptr);
		  while(L(ptr2)) {
			  ptr2 = L(ptr2);
		  }
		  DELETE_OBJPTR(tree,ptr);
		  ptr->objptr = tree->API.alloc(O(tree));
		  tree->API.copy(ptr->objptr,ptr2->objptr,O(tree));
		  obj = ptr->objptr;
		  ptr = R(ptr);
		  if(T(tree) == ptr2) {
			  T(tree) = ptr2->ptr[PARENT];
		  }
		  goto repeat_delete;
	  } else if(L(ptr)) {
		  /* only the left child is present
		   * update is simple
		   */
		  if(!pnt) {
			  H(tree) = L(ptr);
		  } else {
			  for(x = 0; x < PARENT; x++) {
				  if(pnt->ptr[x] == tmp) {
					  pnt->ptr[x] = L(ptr);
				  }
			  }
		  }
		  L(ptr)->ptr[PARENT] = pnt;
		  DELETE_OBJPTR(tree,tmp);
		  ADD_FREE_NODE(tree,tmp);
	  } else if(R(ptr)) {
		  /* only the right child is present
		   * update is simple
		   */
		  if(!pnt) {
			  H(tree) = R(ptr);
		  } else {
			  for(x = 0; x < PARENT;x++) {
				  if(pnt->ptr[x] == tmp) {
					pnt->ptr[x] = R(ptr);	  
				  }
			  }
		  }
		  R(ptr)->ptr[PARENT] = pnt;
		  DELETE_OBJPTR(tree,tmp);
		  ADD_FREE_NODE(tree,tmp);
	  } else {
		  /* no children are present,
		   * just remove the node
		   */
		  if(!pnt) {
			  H(tree) = NULL;
		  } else {
			  for(x = 0; x < PARENT; x++) {
				  if(pnt->ptr[x] == tmp) {
					  pnt->ptr[x] = NULL;
				  }
			  }
		  }
		  DELETE_OBJPTR(tree,tmp);
		  ADD_FREE_NODE(tree,tmp);
	 }
  } else {
	  return ENOVAL;
  }
  S(tree)--;
  return SUCCESS;
}