void processroute (uint32 target, uint32 parent) { int pindex = SYSERR; int tindex = SYSERR; //check if the parent exists if (getindex (parent) == SYSERR) { kprintf (" DAO Message-> Parent does not exist in the map %04x \n", parent); return; } pindex = getindex (parent); if (getindex (target) == SYSERR) tindex = assignindex (target); else tindex = getindex (target); //check if the mapping already exists or it is a new mapping //ignore if the mapping already exists. if (rpladjlist[target][parent] || rpladjlist[parent][target]){ kprintf (" DAO Message-> Mapping already exists (target - parent)%04x - %04x \n", target, parent); return; } rpladjlist[target][parent] = 1; rpladjlist[parent][target] = 1; //kickoff the Dijkstras shortest path calculation. shortestpath (); computepaths (); printpaths (); }
int main(int argc, char **argv) { cwp_String key1, key2; /* x and y key header words */ Value val1, val2; /* ... their values */ cwp_String type1, type2;/* ... their types */ int index1, index2; /* ... their indices in hdr.h */ float x, y; /* temps to hold current x & y */ cwp_String outpar; /* name of par file */ register int npairs; /* number of pairs found */ /* Hook up getpars */ initargs(argc, argv); requestdoc(1); /* Prevent byte codes from spilling to screen */ if (isatty(STDOUT)) err("must redirect or pipe binary output"); /* Get parameters */ if (!getparstring("key1", &key1)) key1 = "sx"; if (!getparstring("key2", &key2)) key2 = "gx"; type1 = hdtype(key1); type2 = hdtype(key2); index1 = getindex(key1); index2 = getindex(key2); /* Loop over traces */ npairs = 0; while(gettr(&tr)) { gethval(&tr, index1, &val1); gethval(&tr, index2, &val2); x = vtof(type1, val1); y = vtof(type2, val2); efwrite(&x, FSIZE, 1, stdout); efwrite(&y, FSIZE, 1, stdout); ++npairs; } /* Make parfile if needed */ if (getparstring("outpar", &outpar)) fprintf(efopen(outpar, "w"), "n=%d label1=%s label2=%s\n", npairs, key1, key2); return(CWP_Exit()); }
int rmmod(char *modulename, int close) { int i,j; module *mods; struct module_dep *mdp; char modulebuf[1024]; strlcpy(modulebuf, modulename, sizeof(modulebuf)); delchars(modulebuf,"./\\;"); i=getindex(modulebuf); if (i<0) return 1; if ((mdp=getmoduledep(modulebuf))) { for (j=0;j<mdp->numchildren;j++) { if (isloaded(mdp->children[j]->name->content)) { if (rmmod(mdp->children[j]->name->content, close)) { Error("core",ERR_WARNING,"Unable to remove child module %s (depends on %s)", mdp->children[j]->name->content, modulebuf); return 1; } } } /* We may have removed other modules - reaquire the index number in case it has changed. */ i=getindex(modulebuf); if (i<0) return 1; } else { Error("core",ERR_WARNING,"Removing module %s without dependency information",modulebuf); } mods=(module *)(modules.content); if (!close #ifdef BROKEN_DLCLOSE || 1 #endif ) { void (*fini)(); fini = dlsym(mods[i].handle, "__fini"); if(!dlerror()) fini(); } else dlclose(mods[i].handle); freesstring(mods[i].name); array_delslot(&modules,i); Error("core",ERR_INFO,"Removed module %s.",modulebuf); return 0; }
void smooth(double *pm, double *wmap, unsigned int dim[3], double *krnl, unsigned int kdim[3], double *opm) { int i=0, j=0, k=0; int ki=0, kj=0, kk=0; int ndx=0, kndx=0; double ii=0.0, wgt=0.0, twgt=0.0; for (i=0; i<dim[0]; i++) { for (j=0; j<dim[1]; j++) { for (k=0; k<dim[2]; k++) { ndx = getindex(i,j,k,dim); twgt = 0.0; ii = 0.0; for (ki=0; ki<kdim[0]; ki++) { for (kj=0; kj<kdim[1]; kj++) { for (kk=0; kk<kdim[2]; kk++) { kndx = getindex(i-(kdim[0]/2)+ki,j-(kdim[1]/2)+kj,k-(kdim[2]/2)+kk,dim); if (kndx > -1) { wgt = krnl[getindex(ki,kj,kk,kdim)] * wmap[kndx]; ii += pm[kndx] * wgt; twgt += wgt; } } } } if (twgt) { opm[ndx] = ii/twgt; } else { opm[ndx]=pm[ndx]; } } } } return; }
bool setData(const QModelIndex& index, const QVariant& value, int role) { if (role == Qt::CheckStateRole) { const QString filepath = filePath(index); bool partiallychecked = partiallyChecked(filepath); if (unchecked.indexOf(filepath) != -1) { // remove unchecked path unchecked.removeAll(filepath); } else if (partiallychecked || checked.indexOf(filepath) != -1) { // remove child selected paths for (int i = checked.size() - 1; i >= 0; --i) { if (checked[i].startsWith(filepath)) checked.removeAt(i); } // remove child unselected paths for (int i = unchecked.size() - 1; i >= 0; --i) { if (unchecked[i].startsWith(filepath)) unchecked.removeAt(i); } // If partialChecked then select this item if (partiallychecked) checked.append(filepath); } else { const int checkindex = getindex(checked, filepath); const int uncheckindex = getindex(unchecked, filepath); if (checkindex == -1) checked.append(filepath); else if (uncheckindex >= 0 && checked[checkindex].size() < unchecked[uncheckindex].size()) checked.append(filepath); else unchecked.append(filepath); } if (rowCount(index) > 0) emit(dataChanged(index, index.child(rowCount(index)-1,0))); // update parents QModelIndex parent = index.parent(); while (parent != QModelIndex()) { emit(dataChanged(parent,parent)); parent = parent.parent(); } return true; } return QFileSystemModel::setData(index, value, role); }
void BFS(Graph G, int s){ if( G==NULL ){ printf("Graph Error: cannot run BFS() on NULL Graph pointer"); exit(1); } if( 1>s || s>getOrder(G) ){ printf("Graph Error: vertex s is not in |V(G)|"); exit(1); } G->source = s; int i, x, y; for( i=1; i<=getOrder(G); i++){ G->color[i] = WHITE; G->dist[i] = INF; G->pred[i] = NIL; } G->color[s] = GRAY; G->dist[s] = 0; G->pred[s] = NIL; List Q = newList(); append(Q, s); moveFront(Q); while( getindex(Q)!=-1 ){ x = get(Q); moveFront(G->adj[x]); while( getindex(G->adj[x])!=-1 ){ y = get(G->adj[x]); if( G->color[y]==WHITE ){ G->color[y] = GRAY; G->dist[y] = G->dist[x] + 1; G->pred[y] = x; append(Q, y); } moveNext(G->adj[x]); } G->color[x] = BLACK; moveNext(Q); } freeList(&Q); }
int ecx_portt::FPRD_multi(int n, uint16 *configlst, ec_alstatust *slstatlst, int timeout) { int sldatapos[MAX_FPRD_MULTI]; uint8 idx = getindex(); for (int slcnt = 0; slcnt < n; ++slcnt) { if (slcnt == 0) { txbuf[idx].setupdatagram(EC_CMD_FPRD, idx, *(configlst + slcnt), ECT_REG_ALSTAT, sizeof(ec_alstatust), slstatlst + slcnt, &txbuflength[idx]); sldatapos[slcnt] = sizeof(EC_Header); } else { boolean more = (slcnt == n - 1) ? FALSE : TRUE; sldatapos[slcnt] = txbuf[idx].adddatagram(EC_CMD_FPRD, idx, more, *(configlst + slcnt), ECT_REG_ALSTAT, sizeof(ec_alstatust), slstatlst + slcnt, &txbuflength[idx]); } } int wkc = srconfirm(idx, timeout); if (wkc >= 0) { for (int slcnt = 0; slcnt < n; slcnt++) { memcpy(slstatlst + slcnt, (static_cast<uint8*>(rxbuf[idx].head()) + sldatapos[slcnt]), sizeof(ec_alstatust)); } } setbufstat(idx, EC_BUF_EMPTY); return wkc; }
main(int argc, char **argv) { String key; /* header key word from segy.h */ String type; /* ... its type */ int index; /* ... its index in hdr.h */ Value val; /* ... its value */ void absval(String type, Value *valp); /* Initialize */ initargs(argc, argv); askdoc(1); /* Get key parameter */ if (!getparstring("key", &key)) key = KEY; file2g(stdin); file2g(stdout); type = hdtype(key); index = getindex(key); while (gettr(&tr)) { gethval(&tr, index, &val); absval(type, &val); puthval(&tr, index, &val); puttr(&tr); } return EXIT_SUCCESS; }
void loadPointLight(FILE *inFP, entity_t *ent, char *token){ char *attributes[] = {"color","brightness","center",NULL}; int ndx; assert(ent->magic == ENTITY_T); pointlight_t *pointlight = ent->entDerived; assert(pointlight->magic == POINTLIGHT_T); ndx = getindex(token,attributes); switch(ndx) { case 0: pointlight->color = readColor(inFP, "Could not read light color"); break; case 1: pointlight->brightness = readDouble(inFP, "Could not read light brightness"); break; case 2: pointlight->center = readTuple(inFP, "Could not read light center"); break; default: loadEntity(inFP, ent, token); break; } }
void printout( int num, char* outs){ int i; for(i=0;i<num;i++){ printf("%d ",datamap[getindex(outs[i])]); } printf("\n"); }
static int getarray(lua_State *L) { unsigned int mask; unsigned int *entry = getindex(L, &mask); lua_pushboolean(L, *entry&mask); return 1; }
/** loadPlane **/ void loadPlane(FILE *inFP, entity_t *ent, char *attribute) { char *attributes[] = {"point", "orient1", "orient2", NULL}; int ndx; assert(ent->magic == ENTITY_T); sobj_t *sobj = ent->entDerived; assert(sobj->magic == SCENEOBJ_T); plane_t *plane = sobj->sobjDerived; assert(plane->magic == PLANE_T); ndx = getindex(attribute, attributes); switch (ndx) { case 0: /* point */ plane->point = readTuple(inFP, "Could not read plane point"); break; case 1: /* orient1 */ plane->orient1 = readTuple(inFP, "Could not read plane orient1"); break; case 2: /* orient1 */ plane->orient2 = readTuple(inFP, "Could not read plane orient2"); break; default: loadSceneObj(inFP, ent, attribute); } }
int main() { char s[16]; scanf("%s", s); printf("%d\n", getindex(week, 7, s)); return 0; }
void ParticleSet3D::Update(const StableFluid3D& g0, const StableFluid3D& g1, const StableFluid3D& g2, double timestep) { for (int i = 0; i < gridLength; i++) { int xi, yi, zi; getposition(i, xi, yi, zi); for (Iterator it = grid1[i].begin(); it != grid1[i].end();) { Particle3D* p = *it; grid1[i].erase(it++); double x, y, z; p->GetPosition(x, y, z); //get from velocity grid double ux0, uy0, uz0, ux1, uy1, uz1, ux2, uy2, uz2; g0.getvalue(x, y, z, ux0, uy0, uz0); g1.getvalue(x, y, z, ux1, uy1, uz1); g2.getvalue(x, y, z, ux2, uy2, uz2); p->Update(ux0, uy0, uz0, ux1, uy1, uz1, ux2, uy2, uz2, timestep); p->GetPosition(x, y, z); if (x < 0 || x >= sizeX || y < 0 || y >= sizeY || z < 0 || z >= sizeZ) continue; grid2[getindex(int(x), int(y), int(z))].push_back(p); } } std::swap(grid1, grid2); }
IndexPtr GetValidIndexPointer(char *word, int pos) { IndexPtr idx; char *morphword; idx = getindex(word, pos); if (idx == NULL) { if ((morphword = morphstr(word, pos)) != NULL) while (morphword) { if ((idx = getindex(morphword, pos)) != NULL) break; morphword = morphstr(NULL, pos); } } return (idx); }
void AGIPane::rightClick(wxMouseEvent& event) { std::cerr << "Right click " << std::endl; const double x = event.GetX(); const double y = event.GetY(); //ドラッグ中に右クリックされると間違いなくバグるのであとで対処 if(!isPoly){ nowindex = getindex(x,y); if(nowindex != -1 && nowindex < data->num){ data->setSIndex(nowindex); pcp->Refresh(); md->setText(nowindex); Refresh(); } else if(nowindex !=-1 && nowindex < data->aginum){ int index = nowindex - data->num; nowindex = -1; std::cerr << data->atrname.at(index)<< std::endl; } } else if(polystart){ //ここで終了処理 calPoly(); polystart = false; clickid = clickid+2; } }
void GHash::erase( iterator iter ) { if ( !iter ) return; size_t index = getindex( iter->m_hkey, m_capacity ); HashElem * pElem = m_table[index]; if ( pElem == iter ) { m_table[index] = iter->m_pNext; } else { if ( !pElem ) return; while( 1 ) { if ( !( pElem->m_pNext )) return ; if ( pElem->m_pNext == iter ) break; pElem = pElem->m_pNext; } pElem->m_pNext = iter->m_pNext; } g_pool.deallocate( iter, sizeof( HashElem ) ); --m_size; }
behav_index_t getindexarray(const array_t & m, const phen_t* requestedElement ) const { behav_index_t _index; for (unsigned int dir = 0; dir < behav_dim; dir++ ) { _index[dir] = getindex( m, requestedElement, dir ); } return _index; }
// private helper function for addEdge() // inserts vertex by vertex label sorted order static void insertVertex(List L, int x){ if( L==NULL ){ printf("Graph Error: cannot insert vertex into NULL referenced List"); exit(1); } moveFront(L); while( getindex(L)!=-1 ){ int temp = get(L); if( temp<x ) moveNext(L); else { insertBefore(L, x); break; } } if( getindex(L)==-1 ) append(L, x); }
GHash::iterator GHash::find_num( GHash *pThis, const void * pKey ) { size_t index = getindex( (hash_key_t) pKey, pThis->m_capacity ); HashElem * pElem = pThis->m_table[index]; while( pElem &&( pKey != pElem->m_pKey )) pElem = pElem->m_pNext; return pElem; }
//Convert production statement to integer representation. Each variable and terminal //will be represented by their index in respective arrays int transform(char s[][20],int si[][20],int count,char e[],int limit) { int i,j,k=0,l=0; for(i=0;i<count;i++) { for(j=0;s[i][j]!=0;j++) { if(s[i][j]>='A'&&s[i][j]<='Z') { si[k][l]=getindex(e,limit,s[i][j]); l++; } else if(s[i][j]>='a'&&s[i][j]<='z') { si[k][l]=getindex(e,limit,s[i][j]); l++; } else if(s[i][j]=='|') { si[k][l]=-1; k++; l=0; si[k][l]=si[k-1][l]; l++; } //i++; } si[k][l]=-1; k++; l=0; //printf("%d ",k); } //printf("test %d ",k); printf("\nProductions in seperated form"); for(i=0;i<k;i++) { printf("\n%c->",e[si[i][0]]); for(j=1;si[i][j]!=-1;j++) { printf("%c",e[si[i][j]]); } } printf("\n"); return k; }
/* very slow, make sure you cache the pointer! */ void *ndlsym(char *modulename, char *fn) { module *mods=(module *)(modules.content); int i=getindex(modulename); if (i<0) return NULL; return dlsym(mods[i].handle, fn); }
long getindex(const char *word, const char *chars, unsigned int len) { if (len < 1) return 0; int chars_len = strlen(chars); int chars_idx = strchr(chars, word[len - 1]) - chars; return chars_idx + chars_len * getindex(word, chars, len - 1); }
int oparse(char *st) { char *fields[20]; int arr[20],delindex; char arr1[20]; int i=0,j=0; for(i=0;i<20;++i) fields[i]=malloc(100); split(st,fields,' '); i=0; j=0; while(fields[j]) { while(fields[j]) arr[i++]=getindex(fields[j++],j); arr[i]=-1; i=0; j=0; while(arr[i+1]!=-1) { arr1[j++]=mat[arr[i]][arr[i+1]]; i=i+1; } arr1[j]=0; for(i=0;i<j;++i) { if(arr1[i]=='<'&&arr1[i+1]=='>') { fields[i+1]="N"; delindex=i+1; break; } } i=0; while(fields[i]) { printf("%s ",fields[i]); i++; } printf("\n"); delet(fields,delindex); j=0; i=0; } return 1; }
static int getarray(lua_State *L) { /*NumArray *a = (NumArray *)lua_touserdata(L, 1); int index = luaL_checkint(L, 2) - 1; luaL_argcheck(L, a != NULL, 1, "'array' expected"); luaL_argcheck(L, 0 <= index && index < a->size, 2, "index out of range"); lua_pushboolean(L, a->values[I_WORD(index)] & I_BIT(index)); return 1;*/ unsigned int mask; unsigned int *entry = getindex(L, &mask); lua_pushboolean(L, *entry & mask); return 1; }
/** LWR "logical memory write" primitive. Blocking. * * @param[in] port = port context struct * @param[in] LogAdr = Logical memory address * @param[in] length = length of databuffer * @param[in] data = databuffer to write to slave. * @param[in] timeout = timeout in us, standard is EC_TIMEOUTRET * @return Workcounter or EC_NOFRAME */ int ecx_portt::LWR(uint32 LogAdr, uint16 length, void *data, int timeout) { uint8 idx; int wkc; idx = getindex(); txbuf[idx].setupdatagram(EC_CMD_LWR, idx, LO_WORD(LogAdr), HI_WORD(LogAdr), length, data, &txbuflength[idx]); wkc = srconfirm(idx, timeout); setbufstat(idx, EC_BUF_EMPTY); return wkc; }
/** FPWR "configured address write" primitive. Blocking. * * @param[in] port = port context struct * @param[in] ADP = Address Position, slave that has address writes. * @param[in] ADO = Address Offset, slave memory address * @param[in] length = length of databuffer * @param[in] data = databuffer to write to slave. * @param[in] timeout = timeout in us, standard is EC_TIMEOUTRET * @return Workcounter or EC_NOFRAME */ int ecx_portt::FPWR(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout) { int wkc; uint8 idx; idx = getindex(); setupdatagram(&(txbuf[idx]), EC_CMD_FPWR, idx, ADP, ADO, length, data); wkc = srconfirm(idx, timeout); setbufstat(idx, EC_BUF_EMPTY); return wkc; }
static int setarray(lua_State *L) { unsigned int mask; unsigned int *entry = getindex(L, &mask); luaL_checkany(L, 3); if(lua_toboolean(L, 3)) *entry |= mask; else *entry &= ~mask; return 0; }
void AGIPane::mouseDown(wxMouseEvent& event) { std::cerr << "MouseDown " << std::endl; //マウスがクリックされたときの処理? double x = event.GetX(); double y = event.GetY(); if(!isMoved){ if(!isPoly){ //このxとyが点の2次元配列に含まれるならOK //もちろんある程度の誤差は許容しなければならない nowindex = getindex(x,y); if(nowindex != -1 && nowindex < data->aginum){ std::cerr << data->name.at(nowindex) << std::endl; _pre[0] = ag->getB(nowindex, 0); _pre[1] = ag->getB(nowindex, 1); isMoved = true; data->setSIndex(nowindex); data->selectedcoord = -1; md->setText(nowindex); Refresh(); pcp->Refresh(); addLog(nowindex,_pre[0],_pre[1]); } else if(data->isPCA && nowindex != -1 && nowindex < data->num+data->atr){ int index = nowindex - data->num; data->selectedcoord = index; std::cerr << data->atrname.at(index)<< std::endl; _pre[0] = ag->getV(index,0); _pre[1] =ag->getV(index,1); isMoved = true; addLog(nowindex,_pre[0],_pre[1]); } //どのノードも近くないときは複数選択 else{ xfrom = x; yfrom = y; rangeselect = true; } } // 投げ縄選択はボタンを押して発動させるようにする //2点以上クリックで選んだのち右クリックして終了 // mouse release後も処理が続くので注意 else if(isPoly){ if(!polystart){ polyvector.clear(); polystart = true; } auto from = pair<int,int>(x,y); polyvector.push_back(from); } } }
QStringList getFiles() const { QStringList ret; // List all files in "checked" folders.. FileList fileLister; fileLister.AddPathList(checked); ret = fileLister.GetFileList(); // Remove all items from ret that are unchecked but not checked.. for (int i = ret.size() - 1; i >= 0; i--) { int uncheckindex = getindex(unchecked, ret[i]); if (uncheckindex == -1) continue; // both checked and unchecked, check which to rely on int checkindex = getindex(checked, ret[i]); if (checked[checkindex].size() < unchecked[uncheckindex].size()) ret.removeAt(i); } return ret; }