예제 #1
0
파일: main.c 프로젝트: grohj/fit-cvut
void destroyList(Node * head)
{
    Node * n = head->next;
    
    free(head);
    
    if(n != NULL)
        destroyList(n);
}
예제 #2
0
int main(int argc, char** argv)
{
    switch(argc) {
    case 5:
        LIST_LEN = (1<<atoi(argv[4]));
    case 4:
        TOTAL_LISTS = (1<<atoi(argv[3]));
	case 3:
		REPEAT_TIMES = atoi(argv[2]);
	case 2:
		TOGETHER_NUM = atoi(argv[1]);
        break;
    default:
        break;
    }
	int syscpu = sysconf(_SC_NPROCESSORS_CONF);
	int processorid = 0;
	cpu_set_t mask;
	CPU_ZERO(&mask);
	CPU_SET(processorid, &mask);
	if (sched_setaffinity(0, sizeof(mask), &mask) == -1) {
		std::cerr << "could not set CPU affinity in main thread " << std::endl;
	}
#ifdef USING_MALLOC
    head = (List**)malloc(TOTAL_LISTS*sizeof(List*));
    allList = (List**)malloc(TOTAL_LISTS*sizeof(List*));
	listsLen = (int*)malloc(TOTAL_LISTS*sizeof(int));
	listNumber = (int*)malloc(TOTAL_LISTS*sizeof(int));
#else
    head = new List*[TOTAL_LISTS];
    allList = new List*[TOTAL_LISTS];
	listsLen = new int[TOTAL_LISTS];
	listNumber = new int[TOTAL_LISTS];
#endif
	gettimeofday(&start, NULL);
	buildList();
	gettimeofday(&end, NULL);
	double duration = (end.tv_sec-start.tv_sec) + (end.tv_usec-start.tv_usec)/1000000.0;
	std::cerr << "build duration = " << duration << std::endl;
	gettimeofday(&start, NULL);
	int loopNum = TOTAL_LISTS/TOGETHER_NUM;
	if (TOTAL_LISTS%TOGETHER_NUM != 0) {
		loopNum++;
	}
	for (int i = 0; i < loopNum; i++) {
		tracingTask(i);
	}
	gettimeofday(&end, NULL);
	duration = (end.tv_sec-start.tv_sec) + (end.tv_usec-start.tv_usec)/1000000.0;
	std::cout << "traverse duration " << duration << " s" << std::endl;
	std::cerr << "traverse duration " << duration << " s accum " << total_accum << " traverse " << tra_times << std::endl;

	destroyList();

	return 0;
}
예제 #3
0
파일: midiout.cpp 프로젝트: alexpaulzor/qlc
void MIDIOut::rescanDevices()
{
    /* Treat all devices nonexistent and doomed for destruction */
    QList <MIDIDevice*> destroyList(m_devices);

    /* Find out which devices are still present */
    for (ItemCount i = 0; i < MIDIGetNumberOfDevices(); i++)
    {
        MIDIDeviceRef dev = MIDIGetDevice(i);
        for (ItemCount j = 0; j < MIDIDeviceGetNumberOfEntities(dev); j++)
        {
            MIDIEntityRef entity = MIDIDeviceGetEntity(dev, j);
            OSStatus s = 0;
            SInt32 uid = 0;

            /* Check if the entity is able to send data */
            if (MIDIEntityGetNumberOfDestinations(entity) == 0)
                continue;

            /* Extract UID from the entity */
            s = MIDIObjectGetIntegerProperty(entity, kMIDIPropertyUniqueID, &uid);
            if (s != 0)
            {
                qWarning() << "Unable to get entity UID";
                continue;
            }

            MIDIDevice* dev(deviceByUID(uid));
            if (dev != NULL)
            {
                /* Device still exists */
                destroyList.removeAll(dev);
            }
            else
            {
                /* New device */
                dev = new MIDIDevice(this, entity);
                Q_ASSERT(dev != NULL);
                if (dev->extractUID() == true &&
                        dev->extractName() == true)
                {
                    addDevice(dev);
                }
                else
                {
                    delete dev;
                    dev = NULL;
                }
            }
        }
    }

    /* Destroy all devices that were no longer present */
    while (destroyList.isEmpty() == false)
        delete destroyList.takeFirst();
}
예제 #4
0
int destroyList( listOfPaths_t* list)
{
	if (list != NULL)
	{
		if (list->next != NULL) destroyList(list->next);
		free(list->path);
		free(list);
	}
	return 1;
}
예제 #5
0
파일: rbc.cpp 프로젝트: sourekj/Packages
// Exact k-NN search with the RBC.  This version works better on computers
// with a high core count (say > 4)
void searchExactManyCoresK(matrix q, matrix x, matrix r, rep *ri, unint **NNs, real **dNNs, unint K){
  unint i, j, k;
  unint **repID = (unint**)calloc(q.pr, sizeof(*repID));
  for(i=0; i<q.pr; i++)
    repID[i] = (unint*)calloc(K, sizeof(**repID));
  real **dToReps = (real**)calloc(q.pr, sizeof(*dToReps));
  for(i=0; i<q.pr; i++)
    dToReps[i] = (real*)calloc(K, sizeof(**dToReps));
  intList *toSearch = (intList*)calloc(r.pr, sizeof(*toSearch));
  for(i=0;i<r.pr;i++)
    createList(&toSearch[i]);
  
  bruteKHeap(r,q,repID,dToReps,K);

#pragma omp parallel for private(j,k)
  for(i=0; i<r.pr/CL; i++){
    unint row = CL*i;
    real temp[CL];
    
    for(j=0; j<q.r; j++ ){
      for(k=0; k<CL; k++){
	temp[k] = distVec( q, r, j, row+k );
      }
      for(k=0; k<CL; k++){
	//dToRep[j] is current UB on dist to j's NN
	//temp - ri[i].radius is LB to dist belonging to rep i
	if( row+k<r.r && 3.0*dToReps[j][K-1] >= temp[k] && dToReps[j][K-1] >= temp[k] - ri[row+k].radius) 
	  addToList(&toSearch[row+k], j); //query j needs to search rep 
      }
    }
    for(j=0;j<CL;j++){
      if(row+j<r.r){
	while(toSearch[row+j].len % CL != 0)
	  addToList(&toSearch[row+j],DUMMY_IDX);	
      }
    }
  }

  bruteListK(x,q,ri,toSearch,r.r,NNs,dToReps,K);
  
  for(i=0; i<q.r; i++){
    for(j=0; j<K; j++)
      dNNs[i][j]=dToReps[i][j];
  }

  for(i=0;i<q.pr;i++)
    free(dToReps[i]);
  free(dToReps);
  for(i=0;i<r.pr;i++)
    destroyList(&toSearch[i]);
  free(toSearch);
  for(i=0;i<q.pr;i++)
    free(repID[i]);
  free(repID);
}
예제 #6
0
int main()
{
    int a = 0;
    int b = 0;
    int tmp = 0;
    List* listLess = createList();
    List* listBetween = createList();
    List* listMore = createList();

    printf("Enter a\n");
    scanf("%d",&a);
    printf("Enter b \n");
    scanf("%d",&b);

    FILE* f = fopen("input.txt","r");
    FILE* g = fopen("output.txt","w");

    while (!(feof(f)))
    {
        fscanf(f,"%d",&tmp);
        if (tmp < a)
            add(listLess,tmp);
        if ((a <= tmp) && (tmp <= b))
            add(listBetween,tmp);
        if (tmp >= b)
            add(listMore,tmp);
    }

    printListToFile(listLess,g);
    fprintf(g," | ");
    printListToFile(listBetween,g);
    fprintf(g," | ");
    printListToFile(listMore,g);

    destroyList(listLess);
    destroyList(listBetween);
    destroyList(listMore);
    fclose(f);
    fclose(g);
    printf("See output file\n");
    getc(stdin);
}
예제 #7
0
void applyChanges(int *board,int w)
{
    Node *information;
    int i;
    for(i=1;i<=statusList.size;i++)
    {
        information=searchByPos(&statusList,i);
        board[information->data->i*w+information->data->j]=information->data->status;
    }
    destroyList(&statusList);
}
예제 #8
0
파일: VyLink.c 프로젝트: mueschm/Vyper
//Completely free a list
void destroyList(VyNode* node, int destroyData)
{
	//Make sure a node is declared
	if(node == NULL)
	  return;
	//Destroy the data
	if(node->data != NULL && destroyData)
	  free(node->data);
	//Recursilvy call this function
	destroyList(node->nextNode,destroyData);
}
예제 #9
0
typename Particles<ParticleTraits>::Size_t
Particles<ParticleTraits>::deferredDestroyAmount(PatchID_t pid) const
{
  Size_t retval = 0;

  // Add in all relevant sizes

  if (pid < 0)
    {
      PatchID_t i, npatch = attributeLayout_m.sizeLocal();
      for (i = 0; i < npatch; ++i)
	retval += destroyList(i).domain().size();
    }
  else
    {
      retval = destroyList(pid).domain().size();
    }

  return retval;
}
예제 #10
0
void TdmCurrentState::createSkillList(void){
    //Очистить список
    destroyList(skillList, etSKILL);
    skillMap.clear();
    skillList = TSkill::getAll();
    //Создать индексированный список
    for(int i=0; i < skillList->Count; i++){
        TSkill *current = (TSkill*)skillList->Items[i];
        skillMap[current->getId()] = current;
        }
}
예제 #11
0
파일: Stats.c 프로젝트: mkfifo/ddc
void ddcSeaStatsShowTimeDiff(){
  Node* node = timeList;
  while(node != NULL){
    TimeDiff* diff = (TimeDiff*)(node->data);
    fprintf(stderr,",%lu", (unsigned long)(diff->end.tv_usec - diff->start.tv_usec));
    node = node->next;
  }
  fprintf(stderr, "\n");

  destroyList(timeList);
}
/*------------------------------------------------------------------------------
 *name:         destroyChnTbl()
 *arguments:    ChnTbl *chntbl
 *return:       void
 *exception:
 *functions:    销毁哈希链表
 *----------------------------------------------------------------------------*/
void destroyChnTbl(ChnTbl *chntbl)
{
	for (int i = 0; i < chntbl->key_num; ++i)
	{
		destroyList(&chntbl->key_lists[i]);
	}

	free(chntbl->key_lists);

	memset(chntbl, 0, sizeof(ChnTbl));
}
예제 #13
0
int main(int argc, char** argv)
{
    switch(argc) {
    case 5:
        LIST_LEN = (1<<atoi(argv[4]));
    case 4:
        TOTAL_LISTS = (1<<atoi(argv[3]));
	case 3:
		REPEAT_TIMES = atoi(argv[2]);
	case 2:
		CORO_NUM = atoi(argv[1]);
        break;
    default:
        break;
    }
	int syscpu = sysconf(_SC_NPROCESSORS_CONF);
	int quarterCore = syscpu/4;
	int bindid = quarterCore;
	//bindProc(bindid);
	bindProc(0);
#ifdef USING_MALLOC
    head = (List**)malloc(TOTAL_LISTS*sizeof(List*));
    allList = (List**)malloc(TOTAL_LISTS*sizeof(List*));
	listsLen = (int*)malloc(TOTAL_LISTS*sizeof(int));
	listNumber = (int*)malloc(TOTAL_LISTS*sizeof(int));
#else
    head = new List*[TOTAL_LISTS];
    allList = new List*[TOTAL_LISTS];
	listsLen = new int[TOTAL_LISTS];
	listNumber = new int[TOTAL_LISTS];
#endif
	gettimeofday(&start, NULL);
	buildList();
	gettimeofday(&end, NULL);
	double duration = (end.tv_sec-start.tv_sec) + (end.tv_usec-start.tv_usec)/1000000.0;
	std::cerr << "build duration = " << duration << std::endl;
	//bindProc(0);
	AccirrInit(&argc, &argv);
	for (intptr_t i = 0; i < CORO_NUM; i++) {
		createTask(tracingTask, (void*)i);
	}
	gettimeofday(&start, NULL);
	AccirrRun();
	AccirrFinalize();
	gettimeofday(&end, NULL);
	duration = (end.tv_sec-start.tv_sec) + (end.tv_usec-start.tv_usec)/1000000.0;
	std::cout << "traverse duration " << duration << " s accum " << total_accum << " traverse " << tra_times << std::endl;
	std::cerr << "traverse duration " << duration << " s accum " << total_accum << " traverse " << tra_times << std::endl;

	destroyList();

	return 0;
}
예제 #14
0
/*7*/void freeData(hashTable arrayHash[])
{
	int i;

	for(i=0;i<MAX;i++){
		if(arrayHash[i].elemStatus == 1){
			if(arrayHash[i].collision != NULL){
				destroyList(arrayHash[i].collision);
			}
			free(arrayHash[i].word);
		}
	}
}//end freeData
예제 #15
0
void freeValueMemory(void *value)
{
	/* check to see if the value was ever set */
	if(value == NULL)
	{
        return;
	}
	/* else, free the linked list */
	else
	{
        destroyList((linkedList_t *) value);
	}
}
예제 #16
0
파일: Source.c 프로젝트: xsun89/CZBKStudy
int main()
{
	int ret = 0;
	Node *head = NULL;
	ret = createList(&head);
	ret = printList(head);
	ret = reverseList(head);
	ret = printList(head);
	ret = destroyList(head);
	system("pause");

	return ret;
}
예제 #17
0
파일: main.c 프로젝트: grohj/fit-cvut
int main(int argc, char** argv) {

    Node * head;
    int j;
    Node* tail;
    Node * n;
    int i;Node * s;
    
    head = createNode(0);
    tail = head;
    
    
    for(i = 1; i < 20; i++)
    {
        n = createNode (i);
        tail = appendEnd(tail, n);
        
    }
    
    
    
    for (j = 0; j < 20; j+= 2)
    {
        s = search(head,j);
        
        deleteNode(&head, s);
    }
    
    
    
     for(i = 20; i < 30; i++)
    {
        n = createNode (i);
        tail = appendEnd(tail, n);
        
    }
    for (j = 0; j < 40; j+= 2)
    {
        s = search(head,j);
        if( s != NULL)
        deleteNode(&head, s);
    }
    
   
    
    printList(head);
    
    destroyList(head);
    
    return (0);
}
예제 #18
0
static int			getDeclinaisons(t_product *product)
{
  char			request[1024];
  t_list		*ret;
  t_list		*tmp;
  t_list		*start;

  start = NULL;
  product->declinaisons = NULL;
  snprintf(request, 1024,
  	   "SELECT "\
	   "Nom, Attribut, Attribut2, CouleurPrimaire, DeclinaisonStock, DeclinaisonPrixTTC, " \
	   "DeclinaisonPrixHT, DeclinaisonReference "\
	   "FROM declinaisons WHERE LOWER(DeclinaisonReference) LIKE '%s%%';", product->id);
  setScript(request);
  if ((ret = execRequest()) && (tmp = ret) && (ret = ret->next) && ret->content)
    {
      while (ret && ret->content)
	{
	  t_declinaison *current;

	  printf("RET : '%s'\n", ret->content);
	  
	  if (!(current = malloc(sizeof(t_declinaison))))
	    {
	      perror("malloc");
	      exit(FAILURE);
	    }
	  setRequestResult(ret->content);
	  getNextResultValue(&current->Nom);
	  getNextResultValue(&current->Attribut);
	  getNextResultValue(&current->Attribut2);
	  getNextResultValue(&current->CouleurPrimaire);
	  getNextResultValue(&current->DeclinaisonStock);
	  getNextResultValue(&current->DeclinaisonPrixTTC);
	  getNextResultValue(&current->DeclinaisonPrixHT);
	  getNextResultValue(&current->DeclinaisonReference);
	  setRequestResult(NULL);
	  
	  product->declinaisons = addToList(product->declinaisons, current);
	  if (!start)
	    start = product->declinaisons;

	  ret = ret->next;
	}
      product->declinaisons = start;
      destroyList(tmp, TRUE);
      return 0;
    }
  return FAILURE;
}
예제 #19
0
// Call this instead of exit(), so we can clean up SDL
static void
quit(int rc) {

    printf("Cleanup\n");

    ListElement *el;
    
    for(el = texturesList->first; el != NULL; el=el->next) {
      printf("Destroy texture\n");
      SDL_DestroyTexture((SDL_Texture *)el->data);
    }
    destroyList(texturesList);

    for(el = musicList->first; el != NULL; el=el->next) {
      printf("Destroy music\n");
      Mix_FreeMusic((Mix_Music *)el->data);
    }
    destroyList(musicList);

    for(el = fontList->first; el != NULL; el=el->next) {
      printf("Destroy font\n");
      TTF_CloseFont((TTF_Font *)el->data);
    }
    destroyList(fontList);

    if(renderer) {
        SDL_DestroyRenderer(renderer);
        //printf("%s\n", SDL_GetError());
    }
    if(window) {
        SDL_DestroyWindow(window);
        //printf("%s\n", SDL_GetError());
    }
    Mix_CloseAudio();
    SDL_Quit();
    printf("Bye!\n");
    exit(0);
}
예제 #20
0
static void test_peekTail(void **state)
{
    const int a = 1001;
    LinkedList *list = createList();
    assert_non_null(list);
    for (int i = 0; i < a; i++)
    {
        int *c = malloc(sizeof(int));
        *c = i;
        insertTop(list, c);
        assert_int_equal(*(int*)peekTail(list), 0);
    }
    destroyList(list);
}
예제 #21
0
int main (){

	node *list;

		list = createList(list);

		node *SymbolTeste;
		insertSymbol(list, "TESTE");

		SymbolTeste = findSymbol(list, "TESTE");

		destroyList(list);

}
예제 #22
0
static void destroyWriteObject(struct FileWriteObject *object)
{
  if(object != NULL)
  {
    free(object->fileName);
    object->fileName = NULL;

    destroyList(object->writeObjects);
    object->writeObjects = NULL;

    free(object);
    object = NULL;
  }
}
예제 #23
0
int main() {
    const int N = 5;
    int a[N] = {1,2,3,4,5};
    Solution sln;
    for (int i=0; i<10; ++i) {
        ListNode* head = createList(a, N);
        printf("%d-----\n", i);
        printList(head);
        ListNode* newHead = sln.rotateRight(head, i);
        printList(newHead);
        destroyList(newHead);
    }
    return 0;
}
예제 #24
0
void TdmCurrentState::createFightVersionList(void){
    //Очистить список
    destroyList(fightVersionList, etFIGHTVERSION);
    fightVersionMap.clear();
    //Получить список боевых версий
    fightVersionList = TFightVersion::getAll();

    //Создать индексированный список
    for(int i=0; i < fightVersionList->Count; i++){
        TFightVersion *current = (TFightVersion*)fightVersionList->Items[i];
        //Добавить боевую версию в индексированный список
        fightVersionMap[current->getId()] = current;
        }
}
int destroyJobPtr(void** target){

	Job** targetJob = (Job**) target;

	if(targetJob != NULL){
		if(*targetJob != NULL){
			destroyList(&((*targetJob)->argumentList));
			free(*targetJob);
		}
	}

	return 0;

}
예제 #26
0
파일: index.c 프로젝트: zackcolello/Search
int main(int argc, char **argv){

	if(argc != 3){
		printf("Error: invalid number of arguments\n");
		return -1;
	}
	
	if(strcmp(argv[1],argv[2])==0){
		printf("input arguments are the same file. Cannot overwrite. Exiting Indexer.\n");

		return 0;
	}

	int rval;
	char* output=argv[1];
	rval = access(output,F_OK);
	if(rval==0){
	//file exists
	}
	else if(errno==EACCES){
		printf("%s is not accessible\n", output);
		return 0;
	}

	rval = access(output, W_OK);
	if(rval==0){
		//permission to write
	}else if (errno==EACCES){
		printf("you do not have permission to write to %s\n",output);
		return 0;

	}

	struct List *list = SLCreate(); //create list to store words

	struct stat fileStat; //check if directory or file to be indexed exists
	if(stat(argv[2], &fileStat) == 0){

		directoryTraverse(list, argv[2]);


	}else{
		fprintf(stderr, "Directory or file you are trying to index does not exist.\n");	
		return -1;
	}	

	writefile(argv[1],list);
	destroyList(list);
	return 0;
}
예제 #27
0
void TdmCurrentState::createRequestList(TCompetition competition){
    //Очистить список
    destroyList(requestList, etREQUEST);
    requestMap.clear();
    //Получить заявки для соревнования
    requestList = TRequest::getExtendedByCompetitionId(competition.getId());

    //Добавить в индексированный список
    for(int i=0; i < requestList->Count; i++){
        TRequest *current = (TRequest*)requestList->Items[i];
        //Добавить очередную заявку в индексированный список
        requestMap[current->getId()] = current;
        }
}
예제 #28
0
static void test_listLength(void **state)
{
    const int l = 1001;
    LinkedList *list = createList();
    assert_non_null(list);
    assert_int_equal(listLength(NULL), 0);
    assert_int_equal(listLength(list), 0);
    for(int i = 0; i < l; i++)
    {
        insertTop(list, malloc(sizeof(char)));
        assert_int_equal(listLength(list), i + 1);
    }
    destroyList(list);
}
int destroyListPtr(void** target){

	List** targetList = (List**) target;

	if(targetList != NULL){
		if(*targetList != NULL){
			destroyList(*targetList);
			free(*targetList);
			*targetList = NULL;
		}
	}

	return 0;

}
예제 #30
0
void HIDPlugin::rescanDevices()
{
    /* Treat all devices as dead first, until we find them again. Those
       that aren't found, get destroyed at the end of this function. */
    QList <HIDDevice*> destroyList(m_devices);
    int devCount = m_devices.count();

    struct hid_device_info *devs, *cur_dev;
    quint32 line = 0;

    devs = hid_enumerate(0x0, 0x0);

    cur_dev = devs;

    while (cur_dev)
    {
        //qDebug() << "[HID Device found] path:" << QString(cur_dev->path) << ", name:" << QString::fromWCharArray(cur_dev->product_string);

        HIDDevice* dev = device(QString(cur_dev->path));
        if (dev != NULL)
        {
            /** Device already exists, delete from remove list */
            destroyList.removeAll(dev);
        }
        else if((cur_dev->vendor_id == HID_DMX_INTERFACE_VENDOR_ID
                && cur_dev->product_id == HID_DMX_INTERFACE_PRODUCT_ID) ||
                (cur_dev->vendor_id == HID_DMX_INTERFACE_VENDOR_ID_2
                && cur_dev->product_id == HID_DMX_INTERFACE_PRODUCT_ID_2) ||
                (cur_dev->vendor_id == HID_DMX_INTERFACE_VENDOR_ID_3
                && cur_dev->product_id == HID_DMX_INTERFACE_PRODUCT_ID_3))
        {
            /* Device is a USB DMX Interface, add it */
            dev = new HIDDMXDevice(this, line++,
                                   QString::fromWCharArray(cur_dev->manufacturer_string) + " " +
                                   QString::fromWCharArray(cur_dev->product_string),
                                   QString(cur_dev->path));
            addDevice(dev);
        }
#if defined(Q_WS_X11) || defined(Q_OS_LINUX)
        else if (QString(cur_dev->path).contains("js"))
        {
            dev = new HIDLinuxJoystick(this, line++, cur_dev);
#elif defined(WIN32) || defined (Q_OS_WIN)
        else if(HIDWindowsJoystick::isJoystick(cur_dev->vendor_id, cur_dev->product_id) == true)
        {
            dev = new HIDWindowsJoystick(this, line++, cur_dev);
#elif defined (__APPLE__) || defined(Q_OS_MACX)
        else if(HIDOSXJoystick::isJoystick(cur_dev->usage) == true)