Пример #1
0
int main(void) {
	Heap object;
	unsigned int x, y;
	unsigned int value;
	memset(&object,0,sizeof(object));
	x = RUNS;
	construct(Heap,&object,sizeof(x),FREEOBJ);
	set_alloc(Heap,  &object, ckalloc);
	set_dealloc(Heap,  &object, ckfree);
	set_compare(Heap,  &object, intcmp);
	set_print(Heap,  &object, print);
	for(y = 0; y < x; y++) {
		srand((x * y) / (x - y) + (x + y / x));
		switch((rand() % NUMCASES) + BASE) {
			case 0:
				value = rand() % BOUND + 1;
				insert(Heap,&object,&value,STATIC);
				break;
			case 1:
				pop(Heap,&object);
				break;
			default:
				break;
		};
	}
	/*print_all(Heap,&object);
	dump(Heap,&object);*/
	destruct(Heap,&object);
	return EXIT_SUCCESS;
}
Пример #2
0
AMInt32	AIMAuthModule_create(IAIM *pIM, AMHandle *phAuthModule)
{
	AIMAuthModule *pAuthModule = (AIMAuthModule *)AMMalloc(sizeof(AIMAuthModule));
	
	if(!pAuthModule)
		return eAIM_RESULT_MALLOC_ERROR;

	AMMemset(pAuthModule, 0, sizeof(AIMAuthModule));
	
	if(AMThreadMutexCreate(&pAuthModule->mtxAuth))
	{
		AMFree(pAuthModule);
		return eAIM_RESULT_MALLOC_ERROR;
	}

	pAuthModule->pIM = pIM;
	construct(List, &pAuthModule->lstAuth, sizeof(AIMAuth), FREEOBJ);
	set_dealloc(List, &pAuthModule->lstAuth, _AIMAuth_destroy);

	*phAuthModule = pAuthModule;

	return eAIM_RESULT_OK;
}
Пример #3
0
IAccountModel*	IAccountModel_Create()
{
	if(0 == pSingleAcntModel)
	{
		DPRINT("IAccountModel_Create.................AcntModle Creating\n");

		pSingleAcntModel = (IAccountModel *)AMMalloc(sizeof(IAccountModel));
		AMAssert(0 != pSingleAcntModel);
		AMMemset(pSingleAcntModel, 0, sizeof(IAccountModel));

 		construct(List, &(pSingleAcntModel->listAcnt), sizeof(AIMAccount), FREEOBJ);
 		set_compare(List, &(pSingleAcntModel->listAcnt), IAccount_cmpID);
 		set_dealloc(List, &(pSingleAcntModel->listAcnt), IAccount_Destroy);

		IAccountModel_Restore(pSingleAcntModel);

		DPRINT("IAccountModel_Create.................AcntModle Created\n");
	}
	pSingleAcntModel->iRefCount++;

	DPRINT("IAccountModel_Create.................Add Reference %d\n", pSingleAcntModel->iRefCount);
	return pSingleAcntModel;
}
Пример #4
0
void except_set_allocator(void *(*alloc)(size_t), void (*dealloc)(void *))
{
    set_alloc(alloc);
    set_dealloc(dealloc);
}
Пример #5
0
int
main(void) {
  Vector  object;
  Vector *v_copy = NULL;
  VectorIter *ptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;
  construct(Vector, &object,sizeof(x),FREEOBJ);
  set_alloc(Vector,  &object, ckalloc);
  set_dealloc(Vector,  &object, ckfree);
  set_compare(Vector,  &object, intcmp);
  set_print(Vector,  &object, print);
  for (y = 0; y < x; y++) {
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 11:
        case 1:
        case 12:
        case 13:
        case 2:
        case 14:
        case 3:
        case 15:
        case 4:
          value = rand() % BOUND;
          push_front(Vector,  &object, &value, DYNAMIC);
          break;
          /*pop_front(Vector,  &object);
          break;*/
        case 5:
        case 6:
        case 16:
          /*pop_back(Vector,  &object);
          break;*/
        case 7:
        case 17:
          back(Vector,  &object);
        case 8:
        case 9:
          front(Vector,  &object);
          value = rand() % BOUND;
          push_back(Vector,  &object, &value, DYNAMIC);
          break;
        default:
          break;
    };
  }
  destruct(Vector,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(Vector,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp,  print,
                 memcpy);
  for (x = 0; x < RUNS; x++) {
	  value = rand() % RUNS;
    push_back(Vector,  &object, &value, STATIC);
  }

  ptr = create(VectorIter,  &object);
  head(VectorIter, ptr);
  /*printf("Head = %d\n",*(unsigned int *)retrieve(VectorIter,ptr));*/
  tail(VectorIter,ptr);
  /*printf("Tail = %d\n",*(unsigned int *)retrieve(VectorIter,ptr));*/
  head(VectorIter,ptr);
  do {
    value = *(unsigned int *) retrieve(VectorIter, ptr);
	/*printf("%d ",value);*/
  }
  while (!next(VectorIter, ptr));
  assign(VectorIter, ptr, &object);
  tail(VectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(VectorIter, ptr);
  } while (!prev(VectorIter, ptr));
  /*printf("\n");*/
  for(x = 0; x < RUNS; x++) {
	  switch(rand() % 2) {
		  case 1:
			  next(VectorIter,ptr);
			  break;
		  case 2:
			  prev(VectorIter,ptr);
			  break;
	  }
  }
  destroy(VectorIter, ptr);
  v_copy = duplicate(Vector,&object);
  ptr = create(VectorIter,v_copy);
  do{
	  value = *(unsigned int *)retrieve(VectorIter,ptr);
	  /*printf("%d ",value);*/
  }while(!next(VectorIter,ptr));
  /*printf("\n");*/
  destroy(VectorIter,ptr);
  destruct(Vector,v_copy);
  destruct(Vector,&object);
  free(v_copy);
  return EXIT_SUCCESS;
}
Пример #6
0
int
main(void) {
  QueueVector  object;
  QueueVectorIter *ptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;
  construct(QueueVector, &object,sizeof(x),FREEOBJ);
  set_alloc(QueueVector,  &object, ckalloc);
  set_dealloc(QueueVector,  &object, ckfree);
  set_compare(QueueVector,  &object, intcmp);
  set_print(QueueVector,  &object, print);
  for (y = 0; y < x; y++) {
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 11:
        case 1:
        case 12:
        case 13:
        case 2:
        case 14:
          value = rand() % BOUND;
          push(QueueVector,  &object, &value, DYNAMIC);
          break;
        case 3:
        case 15:
        case 4:
        case 5:
        case 6:
        case 16:
          pop(QueueVector,  &object);
          break;
        case 7:
        case 17:
        case 8:
        case 9:
          front(QueueVector,  &object);
          break;
        default:
          break;
    };
  }
  destruct(QueueVector,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(QueueVector,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp, print,
                 memcpy);
  for (x = 0; x < RUNS; x++) {
	  value = rand();
    push(QueueVector,  &object, &value, STATIC);
  }

  ptr = create(QueueVectorIter,  &object);
  head(QueueVectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(QueueVectorIter, ptr);
  }
  while (!next(QueueVectorIter, ptr));
  assign(QueueVectorIter, ptr, &object);
  tail(QueueVectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(QueueVectorIter, ptr);
  } while (!prev(QueueVectorIter, ptr));
  for(x = 0; x < RUNS; x++) {
	  switch(rand() % 2) {
		  case 1:
			  next(QueueVectorIter,ptr);
			  break;
		  case 2:
			  prev(QueueVectorIter,ptr);
			  break;
	  }
  }
  destroy(QueueVectorIter, ptr);
  destruct(QueueVector,  &object);
  return EXIT_SUCCESS;
}
Пример #7
0
int
main(void) {
  BinaryTree  object,*dupe;
  BinaryTreeIter *ptr;
  BinaryTreeDFSIter *dfsptr;
  BinaryTreeBFSIter *bfsptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;

  construct(BinaryTree, &object,sizeof(x),FREEOBJ);
  
set_alloc(BinaryTree,  &object, ckalloc);
  set_dealloc(BinaryTree,  &object, ckfree);
  set_compare(BinaryTree,  &object, intcmp);
  set_print(BinaryTree,  &object, print);

	
  for (y = 0; y < x; y++) {
	  if (!(y % (RUNS/10))) fprintf(stderr, ".");
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 12:
        case 13:
        case 2:
        case 17:
        case 8:
          value = rand() % BOUND;
          insert(BinaryTree,  &object, &value, STATIC);
          break;
        case 9:
        case 3:
        case 15:
        case 4:
        case 5:
        case 14:
        case 7:
	  value = rand() % BOUND;
          delete(BinaryTree,  &object,&value);
          break;
        case 11:
        case 1:
        case 6:
        case 16:
	  /*value = rand() % BOUND;
	  find(BinaryTree,&object,&value);
          break;*/
        default:
          value = rand() % BOUND;
          insert(BinaryTree,  &object, &value,STATIC);
          break;
    };
    /*dump(BinaryTree,&object);*/
  }
  printf("\n");
  destruct(BinaryTree,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(BinaryTree,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp,  print,
                 memcpy);
  for (x = 0; x < 15; x++) {
	  if (!(x % (RUNS/10))) fprintf(stderr, ".");
	  value = rand() % 30;
    convert(BinaryTree,  &object, &value, sizeof(value),STATIC);
  }

  ptr = create(BinaryTreeIter,  &object);
  head(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*)retrieve(BinaryTreeIter, ptr);
/*	printf("%d ",value);*/
  }
  while (!next(BinaryTreeIter, ptr));
  /*printf("\n");*/
  assign(BinaryTreeIter, ptr, &object);
  tail(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*) retrieve(BinaryTreeIter, ptr);
  } while (!prev(BinaryTreeIter, ptr));
  for(x = 0; x < RUNS; x++) {
	  if (!(x % (RUNS/10))) fprintf(stderr, ".");
	  switch(rand() % 2) {
		  case 1:
			  prev(BinaryTreeIter,ptr);
			  break;
		  case 0:
			  next(BinaryTreeIter,ptr);
			  break;
		  default:
			  break;
	  }
  }
  printf("\n");
  destroy(BinaryTreeIter, ptr);
  dupe = duplicate(BinaryTree,&object);
  ptr = create(BinaryTreeIter,  dupe);
  head(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*)retrieve(BinaryTreeIter, ptr);
	/*printf("%d ",value);*/
  }
  while (!next(BinaryTreeIter, ptr));
  /*printf("\n");*/
  assign(BinaryTreeIter, ptr, dupe);
  tail(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*) retrieve(BinaryTreeIter, ptr);
  } while (!prev(BinaryTreeIter, ptr));
  for(x = 0; x < RUNS; x++) {
	  if (!(x % (RUNS/10))) fprintf(stderr, ".");
	  switch(rand() % 2) {
		  case 1:
			  prev(BinaryTreeIter,ptr);
			  break;
		  case 0:
			  next(BinaryTreeIter,ptr);
			  break;
		  default:
			  break;
	  }
  }
  printf("\n");
  destroy(BinaryTreeIter, ptr);

  bfsptr = create(BinaryTreeBFSIter,&object);
  do {
	  value = *(unsigned int *)retrieve(BinaryTreeBFSIter, bfsptr);
	  /*fprintf(stderr,"%d ",value);*/
  }while(!next(BinaryTreeBFSIter,bfsptr));
  /*printf("\n");*/
  dfsptr = create(BinaryTreeDFSIter,&object);
  do {
	  value = *(unsigned int *)retrieve(BinaryTreeDFSIter, dfsptr);
	  /*fprintf(stderr,"%d ",value);*/
  }while(!next(BinaryTreeDFSIter,dfsptr));
  /*printf("\n");*/
  destroy(BinaryTreeDFSIter,dfsptr);
  destroy(BinaryTreeBFSIter,bfsptr);
  destruct(BinaryTree,  &object);
  destruct(BinaryTree,dupe);
  free(dupe);
  printf("\n");
  return EXIT_SUCCESS;
}