예제 #1
0
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;
}
예제 #2
0
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;
}
예제 #3
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;
}
예제 #4
0
BinaryTreeIter* create_BinaryTreeIter(BinaryTree* obj) {
	BinaryTreeIter* iter;
	CHECK_VARN(obj,NULL);
	CHECK_VARE(S(obj),NULL);
	CHECK_VARA((iter = malloc(sizeof *iter)),NULL);
	iter->ptr = H(obj);
	while(L(iter->ptr)) {
		iter->ptr = L(iter->ptr);
	}
	iter->parent = obj;
	return iter;
}
예제 #5
0
BinaryTreeBFSIter* create_BinaryTreeBFSIter(BinaryTree* obj) {
	BinaryTreeBFSIter* iter;
	CHECK_VARN(obj,NULL);
	CHECK_VARE(S(obj),NULL);
	CHECK_VARA((iter = malloc(sizeof *iter)),NULL);
	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 iter;
}
예제 #6
0
int8_t insert_PrioQueue(PrioQueue *obj, int32_t priority, void *data, size_t datasize) {
	PrioNode *ptr;
	CHECK_VARN(obj,EINVAL);
	CHECK_VARN(data,EINVAL);
	CHECK_VARA(ptr = AMMalloc(sizeof *ptr),EALLOCF);
#ifdef AMOS_DEBUG
	if(!(ptr->data = obj->data->API.alloc(datasize, __FILE__, __LINE__))) {
#else
	if(!(ptr->data = obj->data->API.alloc(datasize))) {
#endif
		AMFree(ptr);
		return EALLOCF;
	}
	ptr->priority = priority;
	obj->data->API.copy(ptr->data,data,datasize);
	return insert(Heap,(obj->data),ptr,STATIC);
}

F_DUPLICATE(PrioQueue) {
	PrioQueue *dst;
	CHECK_VARN(obj,NULL);
	CHECK_VARA(dst = AMMalloc(sizeof *dst),NULL);
	if(!(dst->data = duplicate(Heap,obj->data))) {
		AMFree(dst);
		return NULL;
	} else {
		return dst;
	}
}

void *top_data_PrioQueue(PrioQueue *obj) {
	CHECK_VARN(obj,NULL);
	if(!empty(Heap,(obj->data))) {
		return NULL;
	}
	return ((PrioNode *)top(Heap,(obj->data)))->data;
}
예제 #7
0
Node *
construct_Node(size_t nlinks)
{
  Node *ptr = NULL;

  CHECK_VARA(ptr = (Node *)AMMalloc(sizeof *ptr), NULL);
  if (!(ptr->ptr = (struct _Node **)AMMalloc(sizeof *(ptr->ptr) * nlinks))) {
    if (!(ptr->ptr = (struct _Node **)AMMalloc(sizeof *(ptr->ptr) * nlinks))) {
      if (!(ptr->ptr = (struct _Node **)AMMalloc(sizeof *(ptr->ptr) * nlinks))) {
        return ptr;
      }
    }
  }
  return ptr;
}
예제 #8
0
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;
}