listPo concatList(heapPo H, listPo l1, listPo l2) { integer len1 = l1->length; integer len2 = l2->length; if (len1 == 0) return l2; else if (len2 == 0) return l1; else { int root = gcAddRoot(H, (ptrPo) &l1); gcAddRoot(H, (ptrPo) (&l2)); integer llen = len1 + len2; listPo reslt = createList(H, llen + llen / 2); for (integer ix = 0; ix < len1; ix++) { reslt = addToList(H, reslt, nthEl(l1, ix)); } for (integer ix = 0; ix < len2; ix++) { reslt = addToList(H, reslt, nthEl(l2, ix)); } gcReleaseRoot(H, root); return reslt; } }
void BST::addToList(std::vector<std::list<Node*> >& nodeLists, Node* node, int level) { //add current node to the list // check whether we have the list for level is created. std::vector<std::list<Node*> >::iterator it = nodeLists.begin(); std::list<Node*> list; for (int i = 0; i < level; i++) { it++; } if (it == nodeLists.end()) nodeLists.push_back(list); it = nodeLists.begin(); for (int i = 0; i < level; i++) { it++; } if (it == nodeLists.end()) { std::cout << "WTF" <<std::endl; return; } (*it).push_back(node); if(node->left) addToList(nodeLists, node->left, level+1); if(node->right) addToList(nodeLists, node->right, level+1); }
void getTriplesByPerimeter(triple * t, const uint64_t limit, triple *** const list, uint32_t * const count, uint32_t * const size) { static const int64_t transformationMatrix[3][3][3] = {{{ 1,-2, 2} ,{ 2,-1, 2} ,{ 2,-2, 3}} ,{{ 1, 2, 2} ,{ 2, 1, 2} ,{ 2, 2, 3}} ,{{-1, 2, 2} ,{-2, 1, 2} ,{-2, 2, 3}}}; uint32_t i; uint64_t perimeter_ = perimeter(t); if(perimeter_ > limit) { free(t); return; } addToList(t,list,count,size); for(i=2; i*perimeter_ <= limit; ++i) addToList(scalarMultiply(i,t),list,count,size); for(i=0; i<3; ++i) getTriplesByPerimeter(matrixMultiply((int64_t *)transformationMatrix[i],t) ,limit,list,count,size); }
List *add(List *first, List *second){ List *result = createList(); ListElement *currentFirst = first->head->next; ListElement *currentSecond = second->head->next; while (currentFirst != nullptr || currentSecond != nullptr){ if (currentFirst == nullptr){ addToList(currentSecond->power, currentSecond->ratio, result); currentSecond = currentSecond->next; } else if (currentSecond == nullptr){ addToList(currentFirst->power, currentFirst->ratio, result); currentFirst = currentFirst->next; } else{ if (currentFirst->power > currentSecond->power){ addToList(currentFirst->power, currentFirst->ratio, result); currentFirst = currentFirst->next; } else if (currentFirst->power < currentSecond->power){ addToList(currentSecond->power, currentSecond->ratio, result); currentSecond = currentSecond->next; } else{ if (currentSecond->ratio + currentFirst->ratio != 0) addToList(currentSecond->power, currentSecond->ratio + currentFirst->ratio, result); currentSecond = currentSecond->next; currentFirst = currentFirst->next; } } } return result; }
Status LogReader::SetFilter(const char *a_filter, unsigned int a_filterSize, unsigned int a_maxFindSize, bool a_raw) { if (a_filterSize > 0 && a_filter == InvPtr) return s_invalidParameter; m_filter = a_filter; m_filterSize = a_filterSize; clearList(); StrClose *l_strClose; if (!a_raw) { StrEntry *const l_strEntry = new(std::nothrow) StrEntry; if (l_strEntry == InvPtr) return s_memAllocError; l_strClose = new(std::nothrow) StrClose; if (l_strClose == InvPtr) { delete l_strEntry; return s_memAllocError; } addToList(l_strEntry); } m_status = s_ok; machine(); if (m_status == s_ok && m_list == InvPtr) { Substit *const l_substit = new(std::nothrow) Substit(0, true); if (l_substit == InvPtr) m_status = s_memAllocError; else addToList(l_substit); } if (m_status != s_ok) { delete l_strClose; clearList(); } else { if (!a_raw) addToList(l_strClose); m_raw = a_raw; m_maxFindSize = a_maxFindSize; reset(); } return m_status; }
void createLists() { int iRnd = getRndNumber(0, 10); lnNode = new ListNode(iRnd, NULL); ListNode* tmpNode = NULL; iRnd = getRndNumber(0, 10); tmpNode = new ListNode(iRnd, NULL); tmpNode->next = lnNode; lnNode = tmpNode; iRnd = getRndNumber(0, 10); tmpNode = new ListNode(iRnd, NULL); tmpNode->next = lnNode; lnNode = tmpNode; //--------------------------------- iRnd = getRndNumber(0, 10); lnNodePM = new ListNode(iRnd, NULL); iRnd = getRndNumber(0, 10); addToList(iRnd); iRnd = getRndNumber(0, 10); addToList(iRnd); }
void test_addToList_adds_the_given_data_to_the_list_also_increments_the_length () { LinkedList list = createList(); int a = 5; addToList(&list, &a); assert(list.length == 1); addToList(&list, &a); assert(list.length == 2); }
Expr builtin(Type t, const std::string &name, Expr a, Expr b) { MLVal args = makeList(); args = addToList(args, b.node()); args = addToList(args, a.node()); Expr e(makeExternCall(t.mlval, name, args), t); e.child(a); e.child(b); return e; }
void test_getLastElement_gives_the_address_of_last_element_in_the_list () { LinkedList list = createList(); int a = 5; int b = 10; addToList(&list, &a); addToList(&list, &b); Element *element = getLastElement(list); assert(*(int *)(element->value) == 10); }
void iteration(struct GOL *gol) { struct Cell *cell; unsigned int i; unsigned int count; unsigned int threadNum; double ccTime, wupTime, thTime; // TODO: it can be multithread? reviveCells(&gol->toRevive[0], gol->world); killCells(&gol->toKill[0], gol->world); ccTime = startMeasurement(); #pragma omp parallel shared(gol) private(cell, count, threadNum, thTime) { thTime = startMeasurement(); threadNum = omp_get_thread_num(); for (cell = wit_first_split(&count, threadNum, gol->world); wit_done_split(count, gol->world); cell = wit_next_split(cell, &count, gol->numThreads)) { switch (checkRule(cell, gol->rule)) { case GOL_REVIVE: addToList(cell, &gol->toRevive[threadNum]); break; case GOL_KILL: addToList(cell, &gol->toKill[threadNum]); break; case GOL_SURVIVE: case GOL_KEEP_DEAD: default: break; } } endMeasurement(thTime, threads[threadNum], gol->stats); } endMeasurement(ccTime, cellChecking, gol->stats); wupTime = startMeasurement(); // Add lists for (i = 0; i < gol->numThreads; ++i) { reviveCells(&gol->toRevive[i], gol->world); freeList(&gol->toRevive[i]); } // Free lists for (i = 0; i < gol->numThreads; ++i) { killCells(&gol->toKill[i], gol->world); freeList(&gol->toKill[i]); } endMeasurement(wupTime, worldUpdate, gol->stats); }
// 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); }
int main() { int data1,data2,data3,data4,data5; int nonData = 6; int * pFind = NULL; List test = NULL; initList(&test); data1 = 10;data2 = 20;data3 = 30;data4 = 40;data5 = 50; addToList(test, (void*)&data1); addToList(test, (void*)&data2); addToList(test, (void*)&data3); addToList(test, (void*)&data4); addToList(test, (void*)&data5); displayList(test); printf("%s","Searching for 30"); pFind = (int*)findInList(test, (void*)&data3, intGreater); if (pFind) { printf("%s%d","\nFound data value: ", *pFind); } else { printf("%s","\nData not found"); } printf("%s","\nSearching for 99 (shouldn't be in list)"); pFind = (int*)findInList(test, (void*)&nonData, intGreater); if (pFind) { printf("%s%d","\nFound data value: ", *pFind); } else { printf("%s","\nData not found"); } printf("%s","\nremoving one item then displaying\n"); removeFirst(test); displayList(test); printf("%s","removing all items then displaying\n"); deleteList(test); displayList(test); printf("%s","Attempting to remove from an empty list\n"); removeFirst(test); displayList(test); cleanupList(&test); printf("%s","All tests complete\n"); return 0; }
void test_getElementAt_gives_the_address_of_the_element_at_given_index () { LinkedList list = createList(); int a = 5; int b = 10; void *element; addToList(&list, &a); addToList(&list, &b); element = getElementAt(list, 1); assert(*(int *)element == 10); }
void test_getElementAt_gives_the_NULL_for_a_given_invalid_index () { LinkedList list = createList(); int a = 5; int b = 10; void *element; addToList(&list, &a); addToList(&list, &b); element = getElementAt(list, 9); assert(element == NULL); }
void test_indexOf_returns_the_index_of_given_address_of_the_value () { LinkedList list = createList(); int a = 5; int b = 10; void *element; addToList(&list, &a); addToList(&list, &b); int index = indexOf(list, &b); assert(index == 1); }
char* primeFactorization(long int num, int* success) { // Make sure success poniter is valid if (success == NULL) { return NULL; } else { *success = '\0'; } // Make sure we have a number greater than 1 if (num <= 1) { *success = -1; return NULL; } // Allocate space for the list and initialize it char* list = (char*)malloc(sizeof(char)); list[0] = '\0'; // Check if input is already prime. // If so, return the input num. if (isPrime(num) == 1) { *success = 1; list = addToList(list, num, 1); return list; } // Set starting base and power variables long int base = 2; long int power = 0; while (num != 1) { while (num % base == 0) { num /= base; power++; } if (power != 0) { list = addToList(list, base, power); // Check if the new num is prime. // If so, add it to the list and break. if (num != 1 && isPrime(num) == 1) { list = addToList(list, num, 1); break; } power = 0; } base = getNextPrime(base); } *success = 1; return list; }
void test_indexOf_returns_the_minus_one_of_given_address_of_the_value_if_the_value_is_not_found () { LinkedList list = createList(); int a = 5; int b = 10; int c = 15; void *element; addToList(&list, &a); addToList(&list, &b); int index = indexOf(list, &c); assert(index == -1); }
int main(int argc, const char *argv[]) { int i; int soma = 0; int tamanho = argc - 1; List list; initializeList(&list); for (i = 1; i < argc; i++) { list.head = addToList(&list, atoi(argv[i]), true); soma += atoi(argv[i]); } printf("Conjunto: "); print(&list); if (soma%2 == 0) { int metade = soma / 2; if (max(&list) <= metade) { List partition1; initializeList(&partition1); int val = getVal(&list, 0); partition1.head = addToList(&partition1, val, true); List partition2; partition2 = copy(&list); del(&partition2, val); algoritmo(0 + val, metade, tamanho, &partition1, &partition2, &list, 1); destroy(&list); destroy(&partition1); destroy(&partition2); printf("Quantidade de resultados: %d\n", qtdResult); } else { printf("Não foi encontrado\n"); destroy(&list); } } else { printf("Não foi encontrado\n"); destroy(&list); } return 0; }
void LogReader::sample2Function() { if (m_list == InvPtr || !m_raw && m_list->m_next == InvPtr) { Substit *const l_substit = new(std::nothrow) Substit(0, true); if (l_substit == InvPtr) { m_status = s_memAllocError; return; } addToList(l_substit); } const unsigned int l_sourceDataSize = m_i - m_elementEntry - m_escapes; char *const l_sourceData = new(std::nothrow) char[l_sourceDataSize]; if (l_sourceData == InvPtr) { m_status = s_memAllocError; return; } unsigned int j = 0; bool l_escape = false; for (unsigned int i = m_elementEntry; i < m_i; i++) { const char l_nextOne = m_filter[i]; l_escape = !l_escape && l_nextOne == s_escape; if (l_escape) continue; l_sourceData[j] = l_nextOne; j++; } Sample *const l_sample = new(std::nothrow) Sample(l_sourceData, l_sourceDataSize); if (l_sample != InvPtr) addToList(l_sample); else { delete[] l_sourceData; m_status = s_memAllocError; } }
void kicad_module_scanner::closeEvent(QCloseEvent *event) { settings->clear(); //must clear everything first otherwise items deleted in say a cbo box won't get removed //save General Setup tab settings->setValue("leShellWorkerScript", ui.leShellWorkerScript->text()); settings->setValue("leAwkScript", ui.leAwkScript->text()); settings->setValue("leCopierScript", ui.leCopierScript->text()); settings->setValue("leExtractorScript", ui.leExtractorScript->text()); addToList(ui.cboPostscriptViewer); //save any user amendments - they don't get saved anywhere else saveCboSettings(ui.cboPostscriptViewer); addToList(ui.cboViewerTemporaryFile); //save any user amendments - they don't get saved anywhere else saveCboSettings(ui.cboViewerTemporaryFile); //save Folder Scanning tab saveLstSettings(ui.lstFoldersToScan); saveRdoSettings(ui.rdoFolderScanOutputOverwrite); saveRdoSettings(ui.rdoFolderScanOutputAppend); saveChkSettings(ui.chkFolderIncludePostscript); addToList(ui.cboOutputFile_FolderScanning); saveCboSettings(ui.cboOutputFile_FolderScanning); //save File Scanning tab saveLstSettings(ui.lstFilesToScan); saveRdoSettings(ui.rdoFileScanOutputOverwrite); saveRdoSettings(ui.rdoFileScanOutputAppend); saveChkSettings(ui.chkFileIncludePostscript); addToList(ui.cboOutputFile_FileScanning); saveCboSettings(ui.cboOutputFile_FileScanning); //save Finding/Copying tab saveCboSettings(ui.cboDatabaseFile); settings->setValue("spinBoxNumPins", ui.spinBoxNumPins->value()); addToList(ui.cboFootprintName); saveCboSettings(ui.cboFootprintName); addToList(ui.cboKeywords); saveCboSettings(ui.cboKeywords); addToList(ui.cboDescription); saveCboSettings(ui.cboDescription); saveChkSettings(ui.chkPins); saveCboSettings(ui.cboFootprintName); saveChkSettings(ui.chkFootprintName); saveChkSettings(ui.chkKeywords); saveChkSettings(ui.chkDescription); saveChkSettings(ui.chkAutoPreview); // saveChkSettings(ui.chkShowPinNumbers); // settings->setValue(ui.cboScale->objectName(), ui.cboScale->currentIndex());//item list is fixed, do not use saveCbo settings->setValue(ui.leCopyToModule->objectName(), ui.leCopyToModule->text()); addToList(ui.cboCopyToLibrary); //save any user amendments - they don't get saved anywhere else saveCboSettings(ui.cboCopyToLibrary); saveChkSettings(ui.chkAllowOverwrite); saveBtnSettings(ui.btnViewingMode); saveBtnSettings(ui.btnCopyingMode); settings->sync(); //do not remove // if (this->viewerIsRunning == true) { // this->viewerProcess->close(); // } event->accept(); }
// the magical thingy that have to cut everything and make most of the logical preexecution things, hopefully right :D void cutCommand(struct codeBreaking * code ){ char * buf; int i ; i= nextArgument(&buf, code); if (i !=0 && i != 1) exit (111); // magical error code if(i== 1) return; setCommand(code, &buf); while ((i = nextArgument(&buf, code)) == 0){ addToList(code->argv, buf); } if (buf != NULL) addToList(code->argv, buf); if (i !=1) exit (112); //another magical error code }
void processNeighbour(Node *node, Node *parent, int step_weight, Position destination) { // Check if node if valid or is in the closed list if (node && !inList(list_closed, node)) { // Check wether the node has been added to the open list if (!inList(list_open, node)) { // Add to open list addToList(&list_open, node); // Change parent node->parent = parent; // Set H score to Manhattan distance from destination node->H = abs(node->position.x - destination.x) + abs(node->position.y - destination.y); // Set path weight node->G = parent->G + step_weight; // Set step weight node->step_weight = step_weight; } else { // Check if node's score is better if (parent->G + step_weight < node->G) { // Update node details node->G = parent->G + step_weight; node->parent = parent; node->step_weight = step_weight; } } } }
/** * Returns 1 (true) if the font object passed as a parameter * exists and is added successfully to the manager loading the font directly from * a configuration file, generated with an editor that can export the XML AngelCode format * @param pNewFont Pointer to a font. * @param pFile Name of the configuration file of the font generated by an editor that exports the AngelCode XML format. * @param pType Font type (see ::IND_Type). * @param pQuality Font quality (see ::IND_Quality). */ bool IND_FontManager::addAngelcodeFont(IND_Font *pNewFont, const char *pFile, IND_Type pType, IND_Quality pQuality) { g_debug->header("Parsing and loading AngelCode font", DebugApi::LogHeaderBegin); g_debug->header("File name:", DebugApi::LogHeaderInfo); g_debug->dataChar(pFile, 1); if (!_ok) { writeMessage(); return 0; } if(!parseAngelCodeFont(pNewFont,pFile, pType, pQuality)) return 0; // ----- Puts the object into the manager ----- addToList(pNewFont); // ----- g_debug ----- g_debug->header("AngelCode font parsed and loaded", DebugApi::LogHeaderEnd); return 1; }
int main() { int i, j, number; char a[30]={'\0'}; char b[10]={'\0'}; node head; head.next = NULL; scanf("%d", &number); for(i=0; i<number; i++) { scanf("%s", a); transform(a,b); addToList(b, &head); for(j=0; j<30; j++) { a[j] = '\0'; if(j<10) b[j] = '\0'; } } printList(&head); }
/* * buildDriveList - get a list of all drives */ static bool buildDriveList( void ) { char drv; int cnt; char str[_MAX_PATH]; const char **list; cnt = 0; list = NULL; for( drv = 'A'; drv <= 'Z'; drv++ ) { if( getDriveType( drv ) != DRIVE_NONE ) { str[0] = drv; str[1] = ':'; str[2] = '\0'; if( !addToList( &list, cnt, str, 2 ) ) { freeStringList( &list ); break; } cnt++; } } SetDriveTextList( list ); return( list != NULL ); } /* buildDriveList */
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); ui->ftpServerLineEdit->setText("192.168.12.128"); ui->userNameLineEdit->setText("dev"); ui->passWordLineEdit->setText("123"); ui->passWordLineEdit->setEchoMode(QLineEdit::Password); initiateUI(); // ui->label->clear(); ftp = new QFtp(this); connect(ui->fileListTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(processItem(QTreeWidgetItem*,int))); connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCommandStarted(int))); connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64))); // ftp->connectToHost("192.168.12.128"); // ftp->login("dev", "123"); // ftp->cd("Documents"); // ftp->get("test"); // ftp->close(); }
int mark(MRIS *surf, int vno, int m, bool b_overwrite) { // HISTORY // 18 November 2004 // o Added b_overwrite to force marking irrespective // of current value. Needed in the case of a "HUP" // signal. // VERTEX *v; int rv; v = &surf->vertices[vno]; if (!b_overwrite) { if (v->marked == DIJK_IN_PLAY) { unlist(vno); } if (m == DIJK_IN_PLAY) { rv = addToList(surf, vno); if (rv != NO_ERROR) return(rv); } } v->marked = m; return(NO_ERROR); } /* end mark() */
void LLXferManager::requestFile(const std::string& remote_filename, ELLPath remote_path, const LLHost& remote_host, BOOL delete_remote_on_completion, void (*callback)(void*,S32,void**,S32,LLExtStat), void** user_data, BOOL is_priority) { LLXfer *xferp; xferp = (LLXfer *) new LLXfer_Mem(); if (xferp) { addToList(xferp, mReceiveList, is_priority); ((LLXfer_Mem *)xferp)->initializeRequest(getNextID(), remote_filename, remote_path, remote_host, delete_remote_on_completion, callback, user_data); startPendingDownloads(); } else { llerrs << "Xfer allocation error" << llendl; } }
} return NULL; } int alphasort(const void *a, const void *b) { return (strcmp ((*(const struct dirent **) a)->d_name, (*(const struct dirent **) b)->d_name)); } static int addToList(int i, struct dirent ***namelist, struct dirent *entry) { int size; struct dirent *block; *namelist =
//![0] void FtpWindow::connectOrDisconnect() { if (ftp) { ftp->abort(); ftp->deleteLater(); ftp = 0; //![0] fileList->setEnabled(false); cdToParentButton->setEnabled(false); downloadButton->setEnabled(false); connectButton->setEnabled(true); connectButton->setText(tr("Connect")); #ifndef QT_NO_CURSOR setCursor(Qt::ArrowCursor); #endif statusLabel->setText(tr("Please enter the name of an FTP server.")); return; } #ifndef QT_NO_CURSOR setCursor(Qt::WaitCursor); #endif //![1] ftp = new QFtp(this); connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64))); fileList->clear(); currentPath.clear(); isDirectory.clear(); //![1] //![2] QUrl url(ftpServerLineEdit->text()); if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) { ftp->connectToHost(ftpServerLineEdit->text(), 21); ftp->login(); } else { ftp->connectToHost(url.host(), url.port(21)); if (!url.userName().isEmpty()) ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password()); else ftp->login(); if (!url.path().isEmpty()) ftp->cd(url.path()); } //![2] fileList->setEnabled(true); connectButton->setEnabled(false); connectButton->setText(tr("Disconnect")); statusLabel->setText(tr("Connecting to FTP server %1...") .arg(ftpServerLineEdit->text())); }