//torna indivíduo válido void makevalid(Individual *ind) { int i,j; list genes[2]; genes[0] = newlist(grafo.n); genes[1] = newlist(grafo.n); int* newgenes[2]; newgenes[0] = (int*) malloc(grafo.n*sizeof(int)); newgenes[1] = (int*) malloc(grafo.n*sizeof(int)); int* predecessorsleft = (int*) malloc(grafo.n*sizeof(int)); Edge e; int currenttaskid; for(i=0; i<grafo.n; i++) { add(genes[0],ind->traits[0][i]); add(genes[1],ind->traits[1][i]); predecessorsleft[i] = grafo.nodes[i].predqty; } for(i=0; i<grafo.n; i++) { for(j=0;; j++) { currenttaskid = at(genes[0],j); if(predecessorsleft[currenttaskid] == 0) { newgenes[0][i] = currenttaskid; newgenes[1][i] = at(genes[1],j); erase(genes[0],j); erase(genes[1],j); for(e = grafo.nodes[currenttaskid].successors; e!=NULL; e = e->next) predecessorsleft[e->node->id]--; break; } } } free(genes[0]->info); free(genes[1]->info); free(genes[0]); free(genes[1]); free(ind->traits[0]); free(ind->traits[1]); ind->traits[0] = newgenes[0]; ind->traits[1] = newgenes[1]; }
std::vector<logicalaccess::KeyboardEntry> InputDevice::getDeviceList() { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# begins."); std::vector<logicalaccess::KeyboardEntry> deviceList; std::string root1 = "\\\\?\\Root"; std::string root2 = "\\??\\Root"; UINT nDevices; //PRAWINPUTDEVICELIST pRawInputDeviceList; UINT errorCode = GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)); if (errorCode == 0 || errorCode == ERROR_INSUFFICIENT_BUFFER) { std::vector<RAWINPUTDEVICELIST> newlist(nDevices); nDevices = GetRawInputDeviceList(&newlist[0], &nDevices, sizeof(RAWINPUTDEVICELIST)); if (nDevices > 0 ) { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# {%u} device(s) detected.", nDevices); for (std::vector<RAWINPUTDEVICELIST>::const_iterator it = newlist.begin(); it != newlist.end(); ++it) { if ((*it).dwType == RIM_TYPEKEYBOARD) { logicalaccess::KeyboardEntry entry; memset(&entry, 0x00, sizeof(entry)); entry.handle = (unsigned long long) (*it).hDevice; UINT nSize = 0; GetRawInputDeviceInfo((HANDLE)entry.handle, RIDI_DEVICENAME, NULL, &nSize); if (nSize > 0) { nSize = sizeof(entry.name); errorCode = GetRawInputDeviceInfo((HANDLE)entry.handle, RIDI_DEVICENAME, entry.name, &nSize); } // Skip Terminal Services and Remote Desktop generic keyboards if (memcmp(entry.name, root1.c_str(), root1.size()) != 0 && memcmp(entry.name, root2.c_str(), root2.size()) != 0) { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# Keyboard device found {%s}!", entry.name); deviceList.push_back(entry); } } } } else { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# No devices detected."); } } else { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# Error GetRawInputDeviceList {%d}!", errorCode); } islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# return."); return deviceList; }
/** * Simple oblivious Routing (TOR). */ route_t* TOrouting (long src, long dst) { long lvl; route_t *aux, *aux2, *res; long sc,dc; // cluster (ficonn) the source and destination belong to. long pren, postn; // ids of the nodes connecting the two ficonns if(src==dst) { // printf("should not be trying to route a packet that is at its destination (curr: %ld, dst: %ld)!\n", current, destination); aux=emptylist(); // empty set return aux; // just in case, let's abort the routing } // DEBUG for (lvl=param_k; lvl>0; lvl--) if(src/fic_size[lvl-1]!=dst/fic_size[lvl-1]) break; if(lvl==0) // Easy, just traverse the switch; return concat_nn(0, dst%param_n); // port 0 goes to the switch sc=(src%fic_size[lvl])/fic_size[lvl-1]; dc=(dst%fic_size[lvl])/fic_size[lvl-1]; #ifdef DEBUG if(sc==dc) { printf("should not be in the same ficonn at this level (curr: %ld, dst: %ld)!\n", sc, dc); } #endif // DEBUG if(sc<dc) dc--; else sc--; pren = ((src/fic_size[lvl-1])*fic_size[lvl-1]) // first node in cluster sc + (dc*two_pow[lvl])+two_pow[lvl-1]-1; // node in cluster sc connected to cluster dc postn = ((dst/fic_size[lvl-1])*fic_size[lvl-1]) // same as above + (sc*two_pow[lvl])+two_pow[lvl-1]-1; aux=newlist(1); res=aux; //printf ("lvl %ld: src %ld (%ld,%ld), dst %ld (%ld,%ld), pren %ld, postn %ld\n",lvl,src,sc,sn,dst,dc,dn,pren,postn); if (pren!=src) { res=concat_ll(TOrouting(src,pren),aux); free(aux); // rfree++; aux=res; } if (postn!=dst) { aux2=TOrouting(postn,dst); res=concat_ll(aux,aux2); free(aux2); // rfree++; } return res; }
/* 生成一个从start到end的数组, 其中list[0]记录除][0]元素外的总长度 */ void generateList(int start, int end, int** list) { int i; newlist(end - start + 2); (*list)[0] = end - start + 1; for (i = 1; i <= (*list)[0]; i++) { (*list)[i] = start + i - 1; } return; }
LISTVAR_ *listConstructor_cP(char const *arg) { static LISTVAR_ ret = {e_list, {0}}; ret.vu.i = newlist(); listAdd_cP(&ret, arg); return &ret; }
int main(){ struct list ll; struct list* l = ≪ newlist(l); list_add(l,200); printf("%lf\n",l->head->next->score); freelist(l); return 0; }
int main(int argc, char**argv) { FreqNode *root; char *alltext; FreqNode *buffer[256] = { NULL }; NodeLList *txtfreqs = newlist(); NodeLList *auxlist; Stack *auxstack; char auxchar; char auxchar2; int i, j; int numvalidsymbols; int highestfreq; int isfirst; if (argc == 1) { printf("Error: Missing filename as argument.\n"); exit(-1); } alltext = readfile(argv[1], buffer); numvalidsymbols = 0; for (i = 0; i < 256; i++) { if (buffer[i] && strcmp(buffer[i]->sym, " ") >= 0 && strcmp(buffer[i]->sym, "~") <= 0 ) { numvalidsymbols++; } } isfirst = 1; for (i = 0; i < numvalidsymbols; i++) { for (j = 32; j < 127; j++) { if (buffer[j] && isfirst) { highestfreq = j; isfirst = 0; } else if (buffer[j] && buffer[j]->freq > buffer[highestfreq]->freq) { highestfreq = j; } } addend(&txtfreqs, buffer[highestfreq]); buffer[highestfreq] = NULL; isfirst = 1; } auxlist = copylist(txtfreqs); root = huffman(&txtfreqs, numvalidsymbols-1); auxstack = newstack(); auxchar = 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0; push(&auxstack, auxchar); generatehuffcodes(&root, &auxstack, 0); writefile(argv[1], alltext, root, auxlist, numvalidsymbols); return 0; }
NS_IMETHODIMP nsAbMDBDirectory::AddMailList(nsIAbDirectory *list, nsIAbDirectory **addedList) { NS_ENSURE_ARG_POINTER(addedList); if (mIsQueryURI) return NS_ERROR_NOT_IMPLEMENTED; nsresult rv = NS_OK; if (!mDatabase) rv = GetAbDatabase(); if (NS_FAILED(rv) || !mDatabase) return NS_ERROR_FAILURE; nsCOMPtr<nsIAbMDBDirectory> dblist(do_QueryInterface(list, &rv)); if (NS_FAILED(rv)) { nsCOMPtr<nsIAbDirectory> newlist(new nsAbMDBDirProperty); if (!newlist) return NS_ERROR_OUT_OF_MEMORY; rv = newlist->CopyMailList(list); NS_ENSURE_SUCCESS(rv, rv); dblist = do_QueryInterface(newlist, &rv); NS_ENSURE_SUCCESS(rv, rv); mDatabase->CreateMailListAndAddToDB(newlist, true, this); } else mDatabase->CreateMailListAndAddToDB(list, true, this); mDatabase->Commit(nsAddrDBCommitType::kLargeCommit); uint32_t dbRowID; dblist->GetDbRowID(&dbRowID); nsAutoCString listUri(mURI); listUri.AppendLiteral("/MailList"); listUri.AppendInt(dbRowID); nsCOMPtr<nsIAbDirectory> newList; rv = AddDirectory(listUri.get(), getter_AddRefs(newList)); if (NS_SUCCEEDED(rv) && newList) { nsCOMPtr<nsIAbMDBDirectory> dbnewList(do_QueryInterface(newList, &rv)); NS_ENSURE_SUCCESS(rv, rv); dbnewList->CopyDBMailList(dblist); AddMailListToDirectory(newList); NotifyItemAdded(newList); } NS_IF_ADDREF(*addedList = newList); return rv; }
static void ulthreadlist( int parcnt, genpar *pars, void *d0, void *d1, mapevalenviron* mapenv, evalcontext* ecntxt ) { listtyp ll = NULL; for ( int i = 0; i < ILThread::ILThreads.size(); i++ ) { if ( ILThread::getthread( i ) ) { ll = newlist( ULint, &i, ll, ecntxt ); } } ecntxt->stacks->pushand( ULlist, &ll ); }
void Msg::sendmsgCmd(const QString& from, const QStringList& list) { if(list[0].startsWith("@")) { QStringList users = getUsers(list[0]); QStringList newlist(list); newlist[1] = "[" + list[0] + "] " + list[1]; for(QStringList::ConstIterator it = users.begin(); it != users.end(); ++it) { newlist[0] = *it; sendmsgUser(from,newlist,true); } QString txt("You send a message to " + list[0] + ": " + list[1]); manager()->connectionPlugin()->serverSend(from,txt); } else sendmsgUser(from,list); }
TreeValue* ReadWriteXMLList::ReadValue(XMLReadingMachine& reader, const pugi::xml_node& element) const { // verify all nodes have identical name std::string xml_element_name; pugi::xml_node child; for (child = element.first_child(); child; child = child.next_sibling()) { if (child.type() == pugi::node_element) { if (xml_element_name.empty()) { // first node found - retain name xml_element_name = child.name(); } else { // additional nodes - verify that names are all the same as the first if (xml_element_name.compare(child.name()) != 0) return NULL; } } } // must have found some nodes if (xml_element_name.empty()) return NULL; // new list std::auto_ptr<TreeList> newlist( new TreeList( xml_element_name.c_str() ) ); // read all for (child = element.first_child(); child; child = child.next_sibling()) { if (child.type() == pugi::node_element) { TreeValue* newvalue = reader.ReadValue( child ); if (newvalue != NULL) { newlist->Add( newvalue ); } else { // silently ignore if element type is unrecognised } } } return newlist.release(); }
//gera um indivíduo válido Individual* newindividual() { int i,r,count=0,currenttaskid; Edge e; list availabletasks = newlist(grafo.n); int* predecessorsleft = malloc(grafo.n*sizeof(int)); Individual* ind = allocateindividual(); //inicializa e procura nós sem predecessores for(i=0; i<grafo.n; i++) { predecessorsleft[i] = grafo.nodes[i].predqty; if(predecessorsleft[i]==0) { add(availabletasks,i); } } while(availabletasks->size > 0) { r = rand() % availabletasks->size; currenttaskid = at(availabletasks,r); erase(availabletasks,r); ind->traits[0][count] = currenttaskid; //if(count==0) // ind->traits[1][count] = 0; //obrigar primeiro task a ser alocado no primeiro processador //else ind->traits[1][count] = rand()%2; count++; //adiciona à lista nós cujos predecessores já foram escolhidos for(e = grafo.nodes[currenttaskid].successors; e!=NULL; e = e->next) { predecessorsleft[e->node->id]--; if(predecessorsleft[e->node->id]==0) { add(availabletasks,e->node->id); } } } free(availabletasks->info); free(availabletasks); free(predecessorsleft); return ind; }
int main(void) { int i; node **L; if (sizeof(int) < 4) { puts("This code must be compiled with 32-bit ints!"); return EXIT_FAILURE; } L=newlist(); puts(" DOWN"); for(i = 100; i >= 0; i -=2) insertnode(L, i, i); puts(" UP"); for(i = 1; i < 100; i += 2) insertnode(L, i, i); deletenode(L, 40); puts(" FIND"); for(i = -2; i <= 100; ++i) findnode(L, i); puts(" FAST"); findall(L); puts("SAMPLES"); printf(" %d", findnode(L, -10)); printf(" %d,", findnode(L, 0)); printf(" %d", findnode(L, 1)); printf(" %d", findnode(L, 2)); printf(" %d", findnode(L, 39)); printf(" %d", findnode(L, 40)); printf(" %d", findnode(L, 41)); printf(" %d", findnode(L, 42)); puts(" DONE"); return EXIT_SUCCESS; }
int main(void){ int a[] = {0,1,2,3,4,5,6,7,8,9}; int i; List* list = newlist(); for(i = 0; i < NELEMS(a); i++){ insert(list, a[i]); } Node* np; for(np = list->first; np; np = np->next){ printf("%d ", np->data); } printf("\n"); delete(list, 3); for(np = list->first; np; np = np->next){ printf("%d ", np->data); } printf("\n"); delete(list, 0); for(np = list->first; np; np = np->next){ printf("%d ", np->data); } printf("\n"); delete(list, 9); for(np = list->first; np; np = np->next){ printf("%d ", np->data); } printf("\n"); freelist(list); }
nrn_unit_init() { current = newlist(); concen = newlist(); potential = newlist(); }
void Operator<Node>::paramsToUpper(Teuchos::ParameterList &plist, int &changed, bool rmUnderscore) { changed = 0; // get a list of all parameter names in the list std::vector<std::string> paramNames ; Teuchos::ParameterList::ConstIterator pIter; pIter = plist.begin(); while (1){ ////////////////////////////////////////////////////////////////////// // Compiler considered this while statement an error // for ( pIter = plist.begin() ; pIter != plist.end() ; pIter++ ){ // } ////////////////////////////////////////////////////////////////////// if (pIter == plist.end()) break; const std::string & nm = plist.name(pIter); paramNames.push_back(nm); pIter++; } // Change parameter names and values to upper case for (unsigned int i=0; i < paramNames.size(); i++){ std::string origName(paramNames[i]); int paramNameChanged = 0; stringToUpper(paramNames[i], paramNameChanged, rmUnderscore); if (plist.isSublist(origName)){ Teuchos::ParameterList &sublist = plist.sublist(origName); int sublistChanged=0; paramsToUpper(sublist, sublistChanged, false); if (paramNameChanged){ // this didn't work, so I need to remove the old sublist // and create a new one // //sublist.setName(paramNames[i]); Teuchos::ParameterList newlist(sublist); plist.remove(origName); plist.set(paramNames[i], newlist); } } else if (plist.isParameter(origName)){ std::string paramVal(plist.get<std::string>(origName)); int paramValChanged=0; stringToUpper(paramVal, paramValChanged); if (paramNameChanged || paramValChanged){ if (paramNameChanged){ plist.remove(origName); } plist.set(paramNames[i], paramVal); changed++; } } } // next parameter or sublist }
/*ARGSUSED*/ static void* constructor(Object* ho) { List* sl; sl = newlist(); return (void*)sl; }
LIST *daten_lesen(void) { int i,index=0; int id, armour,startarmour, ticks,hitbyindex, mun,startmun,zeichen; char alive,selfdestruct, name[FCHARS]; LIST *l; NODE *n; short *kills; NODE **robotarr; struct Robot *robo,newrobo; memset(&newrobo,0,sizeof(newrobo)); l=newlist(); while(!feof(stdin)) { gets(buffer); /* AmigaRobots */ if(feof(stdin)) break; gets(buffer); /* Arena */ strcpy(arena,buffer+7); gets(buffer); /* Roboterzahl */ sscanf(buffer,"Roboteranzahl: %ld",&i); gets(buffer); /* Runden ... */ gets(buffer); /* Werte ... */ gets(buffer); /* ID Panzerung ... */ kills=malloc((i+20)*sizeof(*kills)); memset(kills,0,(i+20)*sizeof(*kills)); robotarr=malloc((i+20)*sizeof(*robotarr)); memset(robotarr,0,(i+20)*sizeof(*robotarr)); while(i-- > 0) { gets(buffer); /* Roboterzeile */ sscanf(buffer,"%ld%c %ld/%ld %ld %ld%c %ld/%ld %n", &id, &alive, &armour, &startarmour, &ticks, &hitbyindex, &selfdestruct, &mun, &startmun, &zeichen ); strcpy(name,buffer+zeichen); if(!(n=findname(l,strtoupper(name)))) /* gefunden?, sonst neu */ { n=newnode(&newrobo,sizeof(newrobo),index++,strtoupper(name)); addtail(l,n); } robotarr[id]=n; /* Welcher Roboter liegt wo (der 1. ist ...) */ if(!n) {perror("Kein Speicher für Knoten!\n"); exit(20);} robo=getdata(n); if(alive != '+') { robo->killed++; kills[hitbyindex]++; } else robo->survived++; strncpy(robo->name,name,FCHARS-1); robo->ticks += ticks; robo->armour += armour; robo->startarmour += startarmour; robo->mun += mun; robo->startmun += startmun; } while(id > 0) { if(robotarr[id]) { robo=getdata(robotarr[id]); robo->kills += kills[id]; } id--; } free(kills); free(robotarr); } return l; }