/* DFS */ void DFS(GraphRef G, ListRef S){ int i, s, top, low; moveTo(S, 0); s = getCurrent(S); G->parent[s] = 0; for(i=0;i<=getLength(S);i++){ if(G->color[s] == 1){ G->parent[s] = 0; visit(G, s); } if(i<getLength(S)-1){ moveNext(S); s = getCurrent(S); } } makeEmpty(S); top = getTime(G); while(getLength(S) < getOrder(G)){ low = 0; for(i=1;i<=getOrder(G);i++){ if(top > G->finish[i] && low < G->finish[i]){ low = G->finish[i]; s = i; } } insertBack(S, s); top = low; } }
int main(){ /*make list and output file*/ ListHndl TheList = newList(); FILE *out = fopen("out.out", "w"); /*test empty in empty case*/ if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); printf("testing insert one number\n"); insertAtFront(TheList,(unsigned long*)25728); printf("%lu\n",(unsigned long)getFirst(TheList)); printf("%lu\n",(unsigned long)getLast(TheList)); /*should have same value*/ printf("testing list with three numbers\n"); insertAtFront(TheList,(unsigned long*)1589458); insertAtBack(TheList,(unsigned long*)35762111234); printf("%lu\n",(unsigned long)getFirst(TheList)); /*test empty in full case*/ if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); /*test moving the current pointer around*/ moveFirst(TheList); moveNext(TheList); printf("%lu\n",(unsigned long)getCurrent(TheList)); moveLast(TheList); movePrev(TheList); printf("%lu\n",(unsigned long)getCurrent(TheList)); /*test printList*/ printList(out, TheList); /*test makeEmpty*/ makeEmpty(TheList); if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); /*test inserting functions*/ insertAtFront(TheList,(unsigned long*)2); insertAtFront(TheList,(unsigned long*)1); insertAtFront(TheList,(unsigned long*)4); insertAtBack(TheList,(unsigned long*)4); moveLast(TheList); insertBeforeCurrent(TheList,(unsigned long*)3); printList(out,TheList); deleteFirst(TheList); deleteCurrent(TheList); deleteLast(TheList); printList(out,TheList); makeEmpty(TheList); printList(out,TheList); /*free list and close output file*/ freeList(&TheList); fclose(out); return 0; }
/* BFS */ void BFS(GraphRef G, int s){ ListRef Q = newList(); int v, w, i; G->source = s; insertFront(Q, s); G->color[s] = 2; G->distance[s] = 0; while(getLength(Q) > 0){ moveTo(Q, 0); v = getCurrent(Q); G->color[v] = 3; deleteCurrent(Q); if(!isEmpty(G->adj[v])){ moveTo(G->adj[v], 0); for(i=0;i<getLength(G->adj[v]);i++){ w = getCurrent(G->adj[v]); if(G->color[w] < 2){ G->color[w] = 2; G->parent[w] = v; G->distance[w] = G->distance[v]+1; insertBack(Q, w); } if(i<getLength(G->adj[v])-1){ moveNext(G->adj[v]); } } } } freeList(&Q); }
TuringMachine& TuringMachine::operator()(TuringMachine& T, TuringMachine& F){ bool done = false; startMachine(); if (&getCurrent() != &getHaltTrue()){ done = false; T.setStrip(getStrip()); for (int i = 0; i < strlen(T.getStrip()) + 1 && !done; i++) if (getStrip()[i] != ' '){ T.head = &getStrip()[i]; done = true; } T.startMachine(); return T; } if (&getCurrent() != &getHaltFalse()){ done = false; F.setStrip(getStrip()); for (int i = 0; i < strlen(F.getStrip()) + 1 && !done; i++) if (getStrip()[i] != ' '){ F.head = &getStrip()[i]; done = true; } F.startMachine(); return F; } }
IGameScreen* Gengine::ScreenList::movePrevious() { IGameScreen* currentScreen = getCurrent(); if (currentScreen->getPreviousScreenIndex() != SCREEN_INDEX_NO_SCREEN) { m_currentScreenIndex = currentScreen->getPreviousScreenIndex(); } return getCurrent(); }
TEST(GLObject, Value) { setFlag = false; auto object = std::make_unique<mbgl::gl::Value<MockGLObject>>(); EXPECT_EQ(object->getCurrent(), false); EXPECT_FALSE(object->getDirty()); EXPECT_FALSE(setFlag); object->setDirty(); EXPECT_TRUE(object->getDirty()); *object = false; EXPECT_EQ(object->getCurrent(), false); EXPECT_FALSE(object->getDirty()); EXPECT_TRUE(setFlag); setFlag = false; *object = true; EXPECT_EQ(object->getCurrent(), true); EXPECT_FALSE(object->getDirty()); EXPECT_TRUE(setFlag); object->reset(); EXPECT_EQ(object->getCurrent(), false); EXPECT_FALSE(object->getDirty()); EXPECT_TRUE(setFlag); }
//Parses a function application form (f(a,b,c)) parse_part parse_funapp(parser_state state) { parse_part result; parse_part tmp; //The expr_lexid returned from this should be strict, since the function application form //clearly defines where the function is in the expression (see lexer.h) lexid exprid = EXPR_LEXID; exprid.attr.intval = 1; //Set strictness attribute to 1 exprid.loc = getCurrent(state).loc; result.tree = lexid_tree_init(exprid); result.tree = lexid_tree_addchild(result.tree, lexid_tree_init(getCurrent(state))); //get us past the opening paren state.index += 2; while (!lexid_eq(getCurrent(state), RPAREN_LEXID)) { tmp = parse_listitems(state,0); //flatten if there's just one element if (tmp.tree.children.size == 1) { result.tree = lexid_tree_addchild(result.tree, tmp.tree.children.begin[0]); lexid_tree_free(tmp.tree); } else { result.tree = lexid_tree_addchild(result.tree, tmp.tree); } state = tmp.state; if (lexid_eq(getCurrent(state), COMMA_LEXID)) { state = consume(COMMA_LEXID, state); } } state = consume(RPAREN_LEXID, state); result.state = state; return result; }
IGameScreen* Deep::ScreenList::moveNext() { IGameScreen* currentScreen = getCurrent(); if (currentScreen->getNextScreenIndex() != SCREEN_INDEX_NO_SCREEN) { m_currentScreenIndex = currentScreen->getNextScreenIndex(); } return getCurrent(); }
//parse blocklines until we hit an "end" //This always has strict ordering parse_part parse_blocklines(parser_state state) { parse_part result; parse_part tmp; lexid exprid = EXPR_LEXID; exprid.attr.intval = 1; //Set it to strict exprid.loc = getCurrent(state).loc; result.tree = lexid_tree_init(exprid); while ( state.index < state.program.size ? !lexid_eq(getCurrent(state), END_LEXID) : 0) { tmp = parse_blockline(state); if (tmp.tree.children.size == 1) { result.tree = lexid_tree_addchild(result.tree, tmp.tree.children.begin[0]); lexid_tree_free(tmp.tree); } else if (tmp.tree.children.size == 0) { lexid_tree_free(tmp.tree); } else { result.tree = lexid_tree_addchild(result.tree, tmp.tree); } state = tmp.state; } result.state = state; return result; }
paramStruct* InfoScreens::showEditParam(){ paramStruct* ret = getCurrent()->getCurrentEditParam(); if (ret == NULL) { ret = getCurrent()->movetoNextEditParam(); } editModeBlinkInfo.reset(); return ret; }
paramStruct* InfoScreens::showEditParam(){ // editModeBlinkInfo.setLastSelected(getCurrent()->getCurrentEditParam()); // paramStruct* ret = getCurrent()->movetoNextEditParam(); paramStruct* ret = getCurrent()->getCurrentEditParam(); if (ret == NULL) { ret = getCurrent()->movetoNextEditParam(); } editModeBlinkInfo.reset(); return ret; }
void nsFrameIterator::Next() { // recursive-oid method to get next frame nsIFrame *result = nsnull; nsIFrame *parent = getCurrent(); if (!parent) parent = getLast(); if (mType == eLeaf) { // Drill down to first leaf while ((result = GetFirstChild(parent))) { parent = result; } } else if (mType == ePreOrder) { result = GetFirstChild(parent); if (result) parent = result; } if (parent != getCurrent()) { result = parent; } else { while (parent) { result = GetNextSibling(parent); if (result) { if (mType != ePreOrder) { parent = result; while ((result = GetFirstChild(parent))) { parent = result; } result = parent; } break; } else { result = GetParentFrameNotPopup(parent); if (!result || IsRootFrame(result) || (mLockScroll && result->GetType() == nsGkAtoms::scrollFrame)) { result = nsnull; break; } if (mType == ePostOrder) break; parent = result; } } } setCurrent(result); if (!result) { setOffEdge(1); setLast(parent); } }
paramStruct* InfoScreens::moveToNextEditParam(){ editModeBlinkInfo.setLastSelected(getCurrent()->getCurrentEditParam()); if(delegatedMenuEvent) { if (delegatedMenuEvent(getCurrent()->getCurrentEditParam(), viewMode, InfoNextParam, "")) { return NULL; } } paramStruct* ret = getCurrent()->movetoNextEditParam(); editModeBlinkInfo.reset(); return ret; }
/* main program*/ int main(int argc, char *argv[]){ for(int i = 1; i < argc; i++){ // open file and read in numVerts and numQueries FILE* in = fopen(argv[i], "r"); int numVerts, numQueries; char tempLine[1024]; fgets(tempLine, 1024, in); sscanf(tempLine, "%d %d", &numVerts, &numQueries); // read in and make graph Graph Map = newGraph(numVerts); for(int i = 0; i < numVerts; i++){ fgets(tempLine, 1024, in); int vert = atoi(strtok(tempLine, " ")); char *tempTo = strtok(NULL, " "); while(tempTo != NULL){ addEdge(Map, vert, atoi(tempTo)); tempTo = strtok(NULL, " "); } } // process queries for(int i = 0; i < numQueries; i++){ int from, to; fscanf(in, "%d %d", &from, &to); doBFS(Map, from); if(getDistance(Map, to) == -1) printf("No path from %d to %d exists.\n\n", from, to); else{ printf("The shortest path from %d to %d requires %d edges: \n", from, to, getDistance(Map, to)); ListHndl L = getPathTo(Map, to); moveFirst(L); while(!atLast(L)){ printf("%d -> ", getCurrent(L)); moveNext(L); } printf("%d \n\n", getCurrent(L)); freeList(&L); } } /*free everythingggggggggggg*/ freeGraph(&Map); fclose(in); } /* end program */ return 0; }
void ofxGenericBarGraphView::updateCurrentText() { if ( _currentText ) { string text; if ( _replaceZeroCurrentText && getCurrent() == 0 ) { text = _replaceZeroCurrentTextWith; } else { text = ofToString( getCurrent() ); } _currentText->setText( text ); } }
parse_part parse_dotitem(parser_state state) { parse_part result; state.index += 1; lexid current = getCurrent(state); state.index -= 1; if (lexid_eq(LPAREN_LEXID, current)) { result = parse_funapp(state); } else { result.tree = lexid_tree_init(getCurrent(state)); result.state = state; result.state.index += 1; } return result; }
void ImageList::saveFilePicker() { QString path = QFileDialog::getSaveFileName(mwindow, tr("Save Image"), getCurrent()->getPath(), tr("Image Files (*.png *.jpg *.bmp)")); save(path); }
bool shgPhases::newHorizScrollPosition(int argc, TCLCONST char **argv) { if (!existsCurrent()) return false; float newFirst; bool anyChanges = processScrollCallback(interp, argc, argv, getHorizSBName(), getCurrent().getHorizSBOffset(), // <= 0 getCurrent().getTotalHorizPixUsed(), getCurrent().getVisibleHorizPix(), newFirst); if (anyChanges) anyChanges = getCurrent().adjustHorizSBOffset(newFirst); return anyChanges; }
// prints the list in it's entirety void printList(ListRef L) { L->current = L->first; while(L->current != NULL) { printf("%7d: %ld\n", getLength(L), getCurrent(L)); moveNext(L); } }
void doBFS(GraphRef g, int source){ ListRef list = newList(); initGraph(g); insertAfterLast(list, source); g->color[source]= 1; g->distance[source]=0; while(!isEmpty(list)){ int current = getFirst(list); if(current > g->numVertices){ deleteFirst(list); break; } ListRef edgeList = g->vertices[current]; moveFirst(edgeList); while(!offEnd(edgeList)){ int edge = getCurrent(edgeList); if(g->color[edge]==0){ g->distance[edge] = g->distance[current]+1; g->color[edge] = 1; g->parent[edge] = current; insertAfterLast(list, edge); } moveNext(edgeList); } deleteFirst(list); g->color[current] = 2; } makeEmpty(list); freeList(list); }
String InfoScreens::moveToNextValue() { String ret; paramStruct* param = getCurrent()->getCurrentEditParam(); String id = param->id; //temp value ret = *paramValueMap[param->id].val; if (!paramEditValueMap.contains(id)) { if(delegatedMenuEvent) { if (delegatedMenuEvent(param, viewMode, InfoNextValue, "")) { } else { debugf("no more data"); } } return ret; } paramDataValues* data = paramEditValueMap[id]; if (data == NULL) { debugf("data is null"); } String* d = data->getNextData(); if(delegatedMenuEvent) { if (delegatedMenuEvent(param, viewMode, InfoNextValue, *d)) { return ""; } } updateParamValue(id, *d); return ret; }
/* putEdgeArc */ void putEdgeArc(GraphRef G, int u, int v){ moveTo(G->adj[u], 0); while(1){ if(getCurrent(G->adj[u]) < v && getIndex(G->adj[u]) < getLength(G->adj[u])-1){ moveNext(G->adj[u]); } else if(getCurrent(G->adj[u]) > v ){ insertBeforeCurrent(G->adj[u], v); break; } else{ insertBack(G->adj[u], v); break; } } }
void ofxGenericBarGraphView::setCurrentTextVisible( bool visible ) { if ( visible ) { if ( !_currentText ) { _currentText = ofxGenericTextView::create( getFrame( ofPoint( 0, 0 ) ) ); if ( _currentText ) { //_currentText->setAutosizeFontToFitText( ofxGenericViewAutoresizingFull ); switch( _expand ) { case ofxGenericBarGraphViewExpandHorizontalRight: _currentText->setTextAlignment( ofxGenericTextHorizontalAlignmentLeft ); break; default: _currentText->setTextAlignment( ofxGenericTextHorizontalAlignmentRight ); break; } addChildView( _currentText ); _currentText->setText( ofToString( getCurrent() ) ); } } updateCurrentText(); } else { if ( _currentText ) { _currentText->removeFromParent(); _currentText = ofPtr< ofxGenericTextView >(); } } }
// Prints out all the links, starting at the current link going // backwards void printAll(ring *r) { setFirst(r); for (int i = getLength(r); i>0; i--) { printf("%d: %s\n", i, getCurrent(r)); shiftForward(r); } }
bool shgPhases::resize() { // returns true if a redraw is called for const bool ec = existsCurrent(); if (ec) getCurrent().resize(true); // true --> we are curr shg return ec; }
void BFS(GraphRef G, int s){ int i, u, tmp; G->source = s; for ( i = 1;i <= getOrder(G); i++){ G->color[i] = 'w'; G->discover[i] = INF; G->parent[i] = NIL; } G->color[s] = 'g'; G->discover[s] = 0; G->parent[s] = NIL; ListRef Q = newList(); insertFront( Q, s ); while( !isEmpty(Q) ){ u = getFront(Q); deleteFront(Q); moveTo(G->adjacency[u], 0); while ( !offEnd(G->adjacency[u]) ){ tmp = getCurrent(G->adjacency[u]); if ( G->color[tmp] == 'w'){ G->color[tmp] = 'g'; G->discover[tmp] = G->discover[u] + 1; G->parent[tmp] = u; insertBack( Q, tmp ); } moveNext(G->adjacency[u]); } G->color[u] = 'b'; } freeList(&Q); }
// Perform breadth first search on graph with given source. void doBFS(Graph *G, int source) { // Initialize graph first. for (int i = 0; i < G->numVertices; ++i) { G->color[i] = 0; // Set to white. G->distance[i] = 0; G->parent[i] = -1; } G->color[source] = 1; // Set to grey. G->distance[source] = 0; // Create a list Q and add source to it. ListHndl Q = newList(); insertAtBack(Q, source); while (!isEmpty(Q)) { //Dequeue and delete first element. int u = getFirst(Q); deleteFirst(Q); // Move current position to point at first. if (!isEmpty(G->vertices[u])) moveFirst(G->vertices[u]); //Traverse vertices of u. while (!offEnd(G->vertices[u])) { int v = getCurrent(G->vertices[u]); if (G->color[v] == 0) { // Check if V is white. G->color[v] = 1; // Color V grey. G->distance[v] = G->distance[u] + 1; G->parent[v] = u; insertAtBack(Q, v); } moveNext(G->vertices[u]); } G->color[u] = 2; // Color u black. } freeList(&Q); }
void bq34z100::CalibrateCurrentShunt(int16_t current) { if(current>-200 && current<200) return;//too small to use to calibrate //current is in milliamps if(current<0) current=-current; int16_t currentReading = getCurrent(); if(currentReading<0) currentReading = -currentReading; if(currentReading==0) currentReading=20; Serial.println(currentReading); readFlash(0x68, 15); delay(30); uint32_t curentGain = ((uint32_t)flashbytes[0])<<24 | ((uint32_t)flashbytes[1])<<16|((uint32_t)flashbytes[2])<<8|(uint32_t)flashbytes[3]; Serial.println(curentGain,DEC); float currentGainResistance = (4.768/XemicsTofloat(curentGain)); Serial.println(currentGainResistance); float newGain = (((float)currentReading)/((float)current)) * currentGainResistance; Serial.println(newGain); //we now have the new resistance calculated Serial.println("--"); chg104Table(0,newGain,newGain); //chg104Table(0,5,5); delay(30); }
void ScriptHandler::errorAndExit(pstring s) { fprintf(stderr, "Script error (line %d): %s\n(String buffer: [%s])\n", getLineByAddress(getCurrent(), true), (const char*) s, (const char*) string_buffer); exit(-1); }
bool shgPhases::processDoubleClick(int x, int y) { // returns true if a redraw is called for const bool ec = existsCurrent(); if (ec) getCurrent().processDoubleClick(x, y); return ec; }