示例#1
0
SList* listConcatUnique(SList* list1, SList* list2, int(*cmp)(void*, void*))
{
	if(!list1 || listEmpty(list1))
	{
		list1->head = list2->head;
		list1->curr = list2->curr;
	}
	else if(!list2 || listEmpty(list2))
	{
		return list1;
	}
	else
	{
		listHead(list2);
		do
		{
			int found = 0;
			listHead(list1);
			do
			{
				found = cmp(listCurrent(list1), listCurrent(list2));
			}while(!found && listNext(list1));

			if(!found)
			{
				listAdd(list1, listCurrent(list2));
			}
		}while(listNext(list2));
	}
	return list1;
}
示例#2
0
文件: Expr.cpp 项目: FreeAlex/Halide
    std::vector<int> Expr::footprint(const Func& f) const {
        MLVal fp = footprintOfFuncInExpr(f.name(), contents->node);
        assert(!listEmpty(fp));

        std::vector<int> footprint;
        for (; !listEmpty(fp); fp = listTail(fp)) {          
            footprint.push_back(int(listHead(fp)));
        }

        return footprint;
    }
示例#3
0
static void deleteSession(SessionList *list)
{
   if( listEmpty(list) ) return;

   list->readIndex = (list->readIndex + 1) % SESSION_LIST_LENGTH;
   list->numberInList--;
}
示例#4
0
static int timeInterrupt(IRQRegisters *reg,void *data)
{
   u64 rflags;
   ++ticks;

   for(;;){
      lockSpinLockCloseInterrupt(&timerLock,&rflags);

      if(listEmpty(&timers))
         break; /*Just break if empty.*/
      Timer *timer = listEntry(timers.next,Timer,list);
      if(timer->ticks > ticks)
         break; /*Break if timers are not timeout.*/
      listDelete(&timer->list); /*Timeout!Delete it.*/
      
      unlockSpinLockRestoreInterrupt(&timerLock,&rflags);
      
      (*timer->callback)(timer->data); /*Call callback.*/
   }

   unlockSpinLockRestoreInterrupt(&timerLock,&rflags);
      /*Need unlock.*/

   return 0;
}
示例#5
0
文件: list.c 项目: LCAD-UFES/MAE
void listDestroy (LIST *list)
{
     listEmpty (list);
     free (list);
     
     return;
}
示例#6
0
void* listRemove(SList* list, int index)
{
	void* res = NULL;
	if(list)
	{
		listHead(list);
		if(!listEmpty(list))
		{
			if(index == 0)
			{
				SListNode* to_delete = list->head;
				list->head = list->head->next;
				res = to_delete->data;
				free(to_delete);
			}
			else
			{
				int i = 1;
				while(listNext(list) && i != index-1) ++i;

				if( i == index-1)
				{
					// l'element existe
					SListNode* to_delete = list->curr->next;
					list->curr->next = list->curr->next->next;
					res = to_delete->data;
					free(to_delete);
				}
			}
		}
	}
	return res;
}
metamodelica_string stringAppendList(modelica_metatype lst)
{
  /* fprintf(stderr, "stringAppendList(%s)\n", anyString(lst)); */
  modelica_integer lstLen = 0, len = 0;
  unsigned nbytes = 0, header = 0, nwords = 0;
  modelica_metatype car = NULL, lstHead = NULL, lstTmp = NULL;
  char *tmp = NULL;
  struct mmc_string *res = NULL;
  void *p = NULL;

  lstLen = 0;
  nbytes = 0;
  lstHead = lst;
  lstTmp = lst;
  while (!listEmpty(lstTmp)) {
    MMC_CHECK_STRING(MMC_CAR(lstTmp));
    nbytes += MMC_STRLEN(MMC_CAR(lstTmp));
    /* fprintf(stderr, "stringAppendList: Has success reading input %d: %s\n", lstLen, MMC_STRINGDATA(MMC_CAR(lst))); */
    lstTmp = MMC_CDR(lstTmp);
    lstLen++;
  }
  if (nbytes == 0) return mmc_emptystring;
  if (lstLen == 1) return MMC_CAR(lstHead);

  header = MMC_STRINGHDR(nbytes);
  nwords = MMC_HDRSLOTS(header) + 1;
  res = (struct mmc_string *) mmc_alloc_words_atomic(nwords);
  res->header = header;
  tmp = (char*) res->data;
  nbytes = 0;
  lstTmp = lstHead;
  while (!listEmpty(lstTmp)) {
    car = MMC_CAR(lstTmp);
    len = MMC_STRLEN(car);
    /* fprintf(stderr, "stringAppendList: %s %d %d\n", MMC_STRINGDATA(car), len, strlen(MMC_STRINGDATA(car))); */
    /* Might be useful to check this when debugging. String literals are often done wrong :) */
    MMC_DEBUG_ASSERT(len == strlen(MMC_STRINGDATA(car)));
    memcpy(tmp+nbytes,MMC_STRINGDATA(car),len);
    nbytes += len;
    lstTmp = MMC_CDR(lstTmp);
  }
  tmp[nbytes] = '\0';
  /* fprintf(stderr, "stringAppendList(%s)=>%s\n", anyString(lstHead), anyString(MMC_TAGPTR(res))); */
  p = MMC_TAGPTR(res);
  MMC_CHECK_STRING(p);
  return p;
}
示例#8
0
ECouleur determineCouleurTerritoire(SPlateau* plateau, STerritoire* territoire, ECouleur couleur)
{
	ECouleur couleur_de_comparaison = couleur;
	SPosition* position_territoire = listCurrent(listEnsembleColore(territoire));
	if(listEmpty(listEnsembleColore(territoire))) return BORD;

	return compareCouleur(couleur_de_comparaison, determineCouleurTerritoire(plateau, listNext(listEnsembleColore(territoire)), couleurVoisin(plateau,position_territoire)));
}
示例#9
0
void listDelete(SList* list)
{
	if(list)
	{
		while(!listEmpty(list))
		{
			listRemove(list,0);
		}
		free(list);
	}
}
modelica_metatype boxptr_listDelete(threadData_t *threadData, modelica_metatype lst, modelica_metatype iix)
{
  /* TODO: If we assume the index exists we can do this in a much better way */
  int ix = mmc_unbox_integer(iix);
  modelica_metatype *tmpArr = NULL;
  int i = 0;

  if (ix <= 0) {
    MMC_THROW_INTERNAL();
  }

  tmpArr = (modelica_metatype *) GC_malloc(sizeof(modelica_metatype)*(ix-1)); /* We know the size of the first part of the list */
  if (tmpArr == NULL) {
    fprintf(stderr, "%s:%d: malloc failed", __FILE__, __LINE__);
    EXIT(1);
  }

  for (i=0; i<ix-1; i++) {
    if (listEmpty(lst)) {
      if (tmpArr) {
        GC_free(tmpArr);
      }
      MMC_THROW_INTERNAL();
    }
    tmpArr[i] = MMC_CAR(lst);
    lst = MMC_CDR(lst);
  }

  if (listEmpty(lst)) {
    GC_free(tmpArr);
    MMC_THROW_INTERNAL();
  }
  lst = MMC_CDR(lst);

  for (i=ix-2; i>=0; i--) {
    lst = mmc_mk_cons(tmpArr[i], lst);
  }
  GC_free(tmpArr);

  return lst;
}
示例#11
0
void* listNext(SList* list)
{
	void* res = NULL;
	if(!listEmpty(list))
	{
		if(list->curr->next)
		{
			res = list->curr->next->data;
			list->curr = list->curr->next;
		}
	}
	return res;
}
示例#12
0
int listSearch(SList* list, void* elem, int(*cmp)(void*, void*))
{
	int found = 0;
	if(list && elem && cmp && !listEmpty(list))
	{
		listHead(list);
		do
		{
			found = cmp(listCurrent(list), elem);
		}while(!found && listNext(list));
	}
	return found;
}
示例#13
0
SList* listConcat(SList* list1, SList* list2)
{
	if(listEmpty(list1))
	{
		list1->head = list2->head;
		list1->curr = list2->curr;
	}
	else
	{
		while(list1->curr->next) listNext(list1);
		list1->curr->next = list2->head;
	}
	return list1;
}
示例#14
0
void bank_simulation(int closeTime)
{
    openForDay();

    while(!listEmpty(ev))
    {
        Event tmpEn;
        delFirst(ev, tmpEn);

        if(0 == tmpEn.nType)
        {
            customerArrived(closeTime);
        }
        else
        {
            customerDeparture();
        }
    }
}
示例#15
0
文件: main.c 项目: senilica/IOOPM
void renderList(sLinkedList* list, sSdlWrapper* wrap)
{
  Uint32 bg = makeColor(255, 50, 25, 175);
  Uint32 fg = makeColor(255, 75, 50, 200);
  if(listEmpty(list))
    return;
  sListIterator* it = 0;
  listHead(list, &it);
  point* toDraw = 0;
  int x = 0;
  int y = 0;
  while(!listIteratorEnd(it))
  {
    toDraw = (point*)listGet(it);
    pointGetPos(toDraw, &x, &y);
    drawBevel(wrap, x*25, y*25, 25, 25, bg, fg);
    listIteratorNext(it);
  }
  free(it);
}
示例#16
0
void listAdd(SList* list, void* elem)
{
	if(elem)
	{
		SListNode* node = malloc(sizeof(SListNode));
		node->data = elem;
		node->next = NULL;

		if(listEmpty(list))
		{
			list->head = node;
			list->curr = node;
		}
		else
		{
			while(listNext(list));
			list->curr->next = node;
		}
	}
}
示例#17
0
void* listRemoveElement(SList* list, void* elem)
{
	void* res = NULL;

	if(!listEmpty(list))
	{
		SListNode* prev = NULL;
		SListNode* curr = NULL;
		listHead(list);

		int found = 0;

		do
		{
			prev = curr;
			curr = list->curr;
			if(listCurrent(list) == elem)
			{
				found = 1;

				if(curr == list->head)
				{
					list->head = list->head->next;
					list->curr = list->head;
				}
				else
				{
					prev->next = curr->next;
					list->curr = prev;
				}

				res = curr->data;
				free(curr);
			}
		}while(!found && listNext(list));
	}

	return res;
}
示例#18
0
文件: list.c 项目: LCAD-UFES/MAE
int main (int argc, char **argv)
{
   LIST *list = NULL;
   char info[3]= "Oi\0";
   NO *aux;
 
   list = listCreate();
   listAppend (list, (void *) info);
   listAppend (list, (void *) info);
   listAppend (list, (void *) info);
   listAppend (list, (void *) info);
 
    for (aux = list->head; aux != NULL; aux = aux->next)
        printf("%s\n", aux->info);    
 
    listEmpty (list);
    
    for (aux = list->head; aux != NULL; aux = aux->next)
        printf("%s\n", aux->info);    
  
  return (0);  
}
示例#19
0
文件: test.c 项目: arktur04/test_task
int main(void)
{
    ListNode* testList = NULL;
    ListNode* node = listPushBack(&testList);
    node->data = allocData(1);
    printf("test 1\nsize = %u, last id = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listPushBack(&testList); //->data = allocData(i);
        node->data = allocData(i);
    }
    printf("test 2\nsize = %u, last id = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listPushFront(&testList);
        node->data = allocData(i);
    }
    printf("test 3\nsize = %u, first id = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listInsert(listNext(&testList, 50));
        node->data = allocData(i);
    }
    printf("test 4\nsize = %u, id(100) = %i\n", listSize(&testList), getId(listNext(&testList, 100)->data));
    //--------
    listFree(&testList);
    if(listEmpty(&testList))
        printf("test4: list empty\n");
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listPushFront(&testList);
        node->data = allocData(i);
    }
    listErase(&testList, listFront(&testList));
    printf("test 5\nsize = %u, id(0) = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    listErase(&testList, listFront(&testList));
    //--------------
    listEraseRange(&testList, listNext(testList, 10), listNext(testList, 20));
    node = testList;
    for(int i = 0; i < 30; ++i) {
        printf("id(%d) = %d\n", i, ((ListData*)(node->data))->id);
        node = node->next;
    }
    printf("test 6\nsize = %u, id(10) = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    //--------------
    listPopBack(&testList);
    printf("test 7\nsize = %u, id(back) = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------------
    listPopFront(&testList);
    printf("test 8\nsize = %u, id(front) = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    //--------------
    listResize(&testList, 10);
    printf("test 9\nsize = %u, id(back) = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------------
    listResize(&testList, 20);
    node = testList;
    for(int i = 0; i < 20; ++i) {
        node->data = allocData(i);
        node = node->next;
    }
    printf("test 10\nsize = %u, id(back) = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    return 0;
}
示例#20
0
文件: adlist.c 项目: wzlphp/demo
/* Free the whole list.
 * 释放整个链表,以及链表中所有节点
 * This function can't fail. */
void listRelease(list *list)
{
    listEmpty(list);
    zfree(list);
}
示例#21
0
static SessionElement *getNextSession(SessionList *list)
{
   if( listEmpty(list) ) return(0);

   return(&list->list[list->readIndex]);
}
示例#22
0
MainW::MainW(QWidget *parent)
	: QMainWindow(parent)
{
	this->resize(1024, 768);
	this->currentFocusWordPadLineEdit = nullptr;
	this->wordListWidget = new WordlistWidget(this);
	this->wordPadWidget = new WordPadWidget(this);
	this->kanaPadWidget = new KanaPadWidget(this);
	this->previewWidget = new PreviewWidget(this);

	this->setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
	this->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
	this->setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
	this->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);

	this->wordListDockWidget = new QDockWidget(tr("Word List"), this);
	wordListDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
	wordListDockWidget->setWidget(this->wordListWidget);
	wordListDockWidget->setFeatures(/*QDockWidget::DockWidgetClosable |*/ QDockWidget::DockWidgetMovable);
	this->addDockWidget(Qt::LeftDockWidgetArea, wordListDockWidget);
	connect(this->wordListWidget, SIGNAL(hideSig()), this, SLOT(wordListCloseSlot()));

	this->wordPadDockWidget = new QDockWidget(tr("Word"), this);
	wordPadDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
	wordPadDockWidget->setWidget(this->wordPadWidget);
	wordPadDockWidget->setFeatures(/*QDockWidget::DockWidgetClosable |*/ QDockWidget::DockWidgetMovable);
	this->addDockWidget(Qt::TopDockWidgetArea, wordPadDockWidget);
	connect(this->wordPadWidget, SIGNAL(lostFocus(QLineEdit*)), this, SLOT(wordPadLostFocus(QLineEdit*)));
	connect(this->wordPadWidget, SIGNAL(hideSig()), this, SLOT(wordPadCloseSlot()));

	this->kanaPadDockWidget = new QDockWidget(tr("Kana Pad"), this);
	kanaPadDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
	kanaPadDockWidget->setWidget(this->kanaPadWidget);
	kanaPadDockWidget->setFeatures(/*QDockWidget::DockWidgetClosable |*/ QDockWidget::DockWidgetMovable);
	this->addDockWidget(Qt::BottomDockWidgetArea, kanaPadDockWidget);
	connect(this->kanaPadWidget, SIGNAL(kanaClicked(QString,bool)), this, SLOT(kanaPadClickedSlot(QString,bool)));
	connect(this->kanaPadWidget, SIGNAL(hideSig()), this, SLOT(kanaPadCloseSlot()));

	this->setCentralWidget(this->previewWidget);

	this->createMenus();

#ifdef __DEBUG__
	//QWidget *w = new QWidget(this);
	//this->setCentralWidget(w);

	//connect(this->kanaPadWidget, SIGNAL(kanaClicked(QString,bool)), this, SLOT(kanaClickedSlot(QString,bool)));
	//connect(this->wordPadWidget, SIGNAL(lostFocus(QLineEdit*)), this, SLOT(wordLostFocus(QLineEdit*)));
#endif

	this->fileNotOpenStatement();

	this->wordListWidget->clearList();

	connect(this->wordListWidget, SIGNAL(clicked(int)), this, SLOT(wordListClicked(int)));
	connect(this->wordListWidget, SIGNAL(removed(int)), this, SLOT(wordListRemoved(int)));
	connect(this->wordListWidget, SIGNAL(movedUp(int)), this, SLOT(wordListMovedUp(int)));
	connect(this->wordListWidget, SIGNAL(movedDown(int)), this, SLOT(wordListMovedDown(int)));
	connect(this->wordListWidget, SIGNAL(draged(int,int)), this, SLOT(wordListDraged(int,int)));
	connect(this->wordListWidget, SIGNAL(add(int)), this, SLOT(wordListAdded(int)));
	connect(this->wordListWidget, SIGNAL(listEmpty()), this, SLOT(wordListEmpty()));

	connect(this->wordPadWidget, SIGNAL(saveButtonClicked()), this, SLOT(saveToList()));
	connect(this->wordPadWidget, SIGNAL(textChangedSig(QString)), this->previewWidget, SLOT(setKanjiSlot(QString)));
}
示例#23
0
文件: Xlist.cpp 项目: F5000/spree
void _XList::disposeList(void)
{
     while(!listEmpty())
           delete removeItem(currentItem());
}
示例#24
0
文件: kp8.c 项目: BlagoProg/MAI
int main(void)
{
	const int N = 10;
	int i, isFound, action, pos, arg;
	List list;
	Iterator it;

	listCreate(&list, N);

	do
	{
		printf("Меню:\n");
		printf("1) Вставить элемент\n");
		printf("2) Удалить элемент\n");
		printf("3) Печать списка\n");
		printf("4) Размер списка\n");
		printf("5) Выполнить задание над списком\n");
		printf("6) Выход\n");
		printf("Выберите действие: ");
		scanf("%d", &action);

		switch (action)
		{
			case 1:
			{
				printf("Введите позицию элемента: ");
				scanf("%d", &pos);
				printf("Введите значение элемента (1 - true, 0 - false): ");
				scanf("%d", &arg);

				if (arg != 0 && arg != 1)
					printf("Ошибка. Введено недопустимое значение\n");
				else
					listInsert(&list, pos - 1, arg);

				break;
			}

			case 2:
			{
				printf("Введите номер элемента: ");
				scanf("%d", &pos);

				listRemove(&list, pos - 1);

				break;
			}

			case 3:
			{	
				listPrint(&list);

				break;
			}

			case 4:
			{
				printf("Длина списка: %d\n", listSize(&list));

				break;
			}

			case 5:
			{
				printf("Введите значение: ");
				scanf("%d", &arg);
				
				if (arg != 0 && arg != 1)
					printf("Ошибка. Введено недопустимое значение\n");
				else
				{
					it = itFirst(&list);

					isFound = 0;

					for (i = 0; i < listSize(&list); i++)
					{
						if (itFetch(&it) == arg)
						{
							while (!listEmpty(&list))
								listRemove(&list, 0);

							isFound = 1;

							break;
						}

						itNext(&it);
					}

					if (isFound)
						printf("Список был очищен, так как в нем было найдено введенное значение\n");
					else
						printf("Список не был очищен, так как в нем не найдено введенное значение\n");
				}

				break;
			}

			case 6: break;

			default:
			{
				printf("Ошибка. Такого пункта меню не существует\n");

				break;
			}
		}
	}
	while (action != 6);

	listDestroy(&list);

	return 0;
}
示例#25
0
文件: kp8.c 项目: BlagoProg/MAI
int main(void)
{
	const int N = 10;
	int i, isFound, action, pos, arg;
	List list;
	Iterator it1, it2;

	listCreate(&list, N);

	do
	{
		printf("Меню:\n");
		printf("1) Вставить элемент\n");
		printf("2) Удалить элемент\n");
		printf("3) Печать списка\n");
		printf("4) Подсчет длины списка\n");
		printf("5) Выполнить задание над списком\n");
		printf("6) Выход\n");
		printf("Выберите действие: ");
		scanf("%d", &action);

		switch (action)
		{
			case 1:
			{
				printf("Введите позицию элемента: ");
				scanf("%d", &pos);
				printf("Введите значение элемента (1 - true, 0 - false): ");
				scanf("%d", &arg);

				if (arg != 0 && arg != 1)
					printf("Ошибка. Введено недопустимое значение\n");
				else
					listInsert(&list, pos - 1, arg);

				break;
			}

			case 2:
			{
				printf("Введите номер элемента: ");
				scanf("%d", &pos);

				listRemove(&list, pos - 1);

				break;
			}

			case 3:
			{
				if (listEmpty(&list))
					printf("Список пуст\n");
				else
					listPrint(&list);

				break;
			}

			case 4:
			{
				printf("Длина списка: %d\n", listSize(&list));

				break;
			}

			case 5:
			{
				it1 = itFirst(&list);
				it2 = it1;

				itNext(&it2);

				for (i = 0; i < listSize(&list) / 2; i++)
				{
					listSwapElems(&it1, &it2);

					itNext(&it1);
					itNext(&it1);
					itNext(&it2);
					itNext(&it2);
				}

				break;
			}

			case 6: break;

			default:
			{
				printf("Ошибка. Такого пункта меню не существует\n");

				break;
			}
		}
	}
	while (action != 6);

	listDestroy(&list);

	return 0;
}