void heapify(std::string& arr, int low, int high) { /*Start with middle element. Middle element is chosen in such a way that the last element of array is either its left child or right child*/ int midIdx = (high - low -1)/2; while (midIdx >= 0) { shiftRight(arr, midIdx, high); --midIdx; } return; }
void test_shift() { size_t field_size = 14; word *a = (word *)malloc(test_arr_size * sizeof(word)); printf("TEST SHIFT\n"); a[0] = 15; a[1] = 31; a[2] = 1; //wordSetBit(a,32,TRUE); printBinaryRepresentation2(a, test_arr_size, field_size); printf("\n"); shiftRight(a, test_arr_size, 36, 33); printBinaryRepresentation2(a, test_arr_size, field_size); free(a); }
void LeMemoria(uint16_t n) { extern uint8_t valores[2048]; uint16_t d; for (d = 0; d < n; d += 3) { while (valores[0] == 0 || valores[1] == 0) { EE241_ReadBlock(d, valores, 3); WAIT1_Waitms(1); } if (d + 3 < n) { shiftRight(valores, 2048, 3); valores[0] = valores[1] = valores[2] = 0; } } }
static IList *fastPascal(int n){ if(n == 1){ IList* list = newList(); list->addBack(1); // IList needs an 'add' method return list; } else{ IList* list = fastPascal(n-1); IList* list1 = shiftLeft(list); // need to keep track of object for clean up IList* list2 = shiftRight(list); // delete list; list = addList(list1,list2); delete list1; delete list2; return list; } }
// event handler for clicking on the game node bool GameNode::click(Graph<GameNode>& graph, Point& loc, MOUSE_CLICK_TYPE click) { // check location if (!_graphics.isPosIn(loc)) return false; bool last_antennot[NUM_OF_POSSIBLE_NEIGHBORS]; if (click == RIGHT) shiftRight(last_antennot); else shiftLeft(last_antennot); for (unsigned i = 0; i < NUM_OF_POSSIBLE_NEIGHBORS; i++) { /* if (last_antennot[i] == true && _antennot[i] == false && graph[_potentialNeighbors[i]].checkAntenna(i)) graph.remEdge(_my_index, _potentialNeighbors[i]); else if (last_antennot[i] == false && _antennot[i] == true && graph[_potentialNeighbors[i]].checkAntenna(i)) graph.addEdge(_my_index, _potentialNeighbors[i]); */ } return true; }
void SchedulePoint::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { if(disabled()) return; int oldTemp = temp; qreal oldX = pos().x(); // provide event handler for mouse move emit clicked(this); if(m_pressed == true) { if(m_yClickPos - m_weekHeight/4 > e->pos().y()) { m_yClickPos = e->pos().y(); increaseTemp(); } else if(m_yClickPos + m_weekHeight/4 < e->pos().y()) { m_yClickPos = e->pos().y(); decreaseTemp(); } if(m_xClickPos - m_timeBlockWidth > e->pos().x()) { //m_xClickPos = e->pos().x(); shiftLeft(); } else if(m_xClickPos + m_timeBlockWidth < e->pos().x()) { //m_xClickPos = e->pos().x(); shiftRight(); } } emit(shareAdjustment(temp-oldTemp, pos().x()-oldX)); e->accept(); }
inline static int16_t smith_waterman_farrar(Objeto*o, char *sec_database, int16_t long_sec_database){ int32_t * aux_Max; int16_t ret_max = 0; __m512i vGapOpen, vGapExtend, zero; __m512i vF, vH, vMax, vE_j, vAux0; int segLen = (64 / sizeof(int32_t)); int numSeg = (long_sec_ref + 63 / sizeof(int32_t)) / (64 / sizeof(int32_t)); int32_t cog[segLen] __attribute__((aligned(64))); int32_t ceg[segLen] __attribute__((aligned(64))); // for(int x=0;x<segLen;x++) { cog[x] = coste_open_gap; ceg[x] = coste_extend_gap; } vGapOpen = _mm512_load_epi32(cog); vGapExtend = _mm512_load_epi32(ceg); zero = _mm512_xor_epi32(zero, zero); vMax = _mm512_xor_epi32(vMax, vMax); // vMax = <0, 0, ..., 0> for(int j=0; j<long_profile; j++){ o->columnaPrevia_Max[j] = 0; //o->columna_Up[j] = 0; o->columna_Left[j] = 0; } for(int x=0; x<long_sec_database; x++){ // vF = <0, 0, ..., 0> vF = _mm512_xor_epi32(vF, vF); // vH = vHStore[numSeg - 1] << 1 vH = _mm512_load_epi32(o->columnaPrevia_Max + (numSeg - 1) * segLen); vH = shiftRight(vH); // int8_t pos_letra_database = letras[(int)(sec_database[x])]; //printf("Letra %d %c %d\n", x, sec_database[x], pos_letra_database); int32_t offset = pos_letra_database * long_profile; int j; for(j=0; j<numSeg; j++){ // vH = vH + vProfile[letra][j] int32_t * valor_match = profile + offset; offset += segLen; vAux0 = _mm512_load_epi32(valor_match); vH = _mm512_add_epi32(vH, vAux0); // vMax = max(vMax, vH); vMax = _mm512_max_epi32(vMax, vH); // vE[j] = max(vH, vE[j]) // vH = max(vH, vF) vE_j = _mm512_load_epi32(o->columna_Left + j*segLen); vH = _mm512_max_epi32(vH, vE_j); vH = _mm512_max_epi32(vH, vF); // vHStore[j] = vH _mm512_store_epi32(o->columnaActual_Max + j*segLen, vH); // vAux = vH - vGapOpen vAux0 = _mm512_sub_epi32(vH, vGapOpen); vAux0 = _mm512_max_epi32(vAux0, zero); // vE[j] = vE[j] - vGapExtend vE_j = _mm512_sub_epi32(vE_j, vGapExtend); vE_j = _mm512_max_epi32(vE_j, zero); // vE[j] = max(vE[j], vAux) vE_j = _mm512_max_epi32(vE_j, vAux0); _mm512_store_epi32(o->columna_Left + j*segLen, vE_j); // vF = vF - vGapExtend vF = _mm512_sub_epi32(vF, vGapExtend); vF = _mm512_max_epi32(vF, zero); // vF = max(vF, vAux) vF = _mm512_max_epi32(vF, vAux0); // vH = vHLoad[j] vH = _mm512_load_epi32(o->columnaPrevia_Max + j*segLen); } // Optimización de SWAT /* for(int x=0; x<long_profile; x++){ printf("vMax[%d]=%d\n", x, o->columnaActual_Max[x]); } printf("Numseg: %d\n", numSeg); displayV("F", vF); */ // vF = vF << 1 vF = shiftRight(vF); j = 0; do { // while(AnyElement(vF > vHStore[j] - vGapOpen vH = _mm512_load_epi32(o->columnaActual_Max + j*segLen); vAux0 = _mm512_sub_epi32(vH, vGapOpen); vAux0 = _mm512_max_epi32(vAux0, zero); __mmask16 mascara = _mm512_cmpgt_epi32_mask (vF, vAux0); if (mascara == 0) break; // vHStore[j] = max(vHStore[j], vF) vH = _mm512_max_epi32(vH, vF); _mm512_store_epi32(o->columnaActual_Max + j*segLen, vH); // vF = vF - vGapExtend vF = _mm512_sub_epi32(vF, vGapExtend); vF = _mm512_max_epi32(vF, zero); if (++j >= numSeg) { // vF = vF << 1 vF = shiftRight(vF); j = 0; } } while(1); // aux_Max = o->columnaActual_Max; o->columnaActual_Max = o->columnaPrevia_Max; o->columnaPrevia_Max = aux_Max; // } int32_t max[segLen] __attribute__((aligned(64))); _mm512_store_epi32(max, vMax); for(int x=1;x<segLen;x++) { if(max[0] < max[x]) max[0] = max[x]; } if (max[0] > 32767) max[0] = 32767; ret_max = max[0]; return ret_max; }
Chunk& shiftRight() { shiftRight(0, signal.size() / 2); shiftLeft(signal.size() / 2, signal.size()); return *this; }
int main(void) { int addScore, position, pauseSel; // Initializations PLL_Init(); // Clock set at 80 MHz LCD_Init(); Board_Init(); Input_Init(); DAC_Init(); Random_Init(NVIC_ST_CURRENT_R); Timer2_Init(80000000); // time interrupt Timer1_Init(2000); // sound interrupt EnableInterrupts(); generateRandomTile(); drawAllTiles(); writeScore(0); writeHighscore(0); writeTime(0); displayHighestTile(); while(1) { // draw arrow if ready if (arrowReady == 1) { // acknowledge flag arrowReady = 0; // draw arrow drawArrow(); } // write time if ready if (timeReady == 1) { // acknowledge flag timeReady = 0; // write time writeTime(elapsedTime); } // Play mode and button1 is pushed if(Button1 && !pauseMode && !gameOver) { // Play sound playSound = 1; // shift and merge tiles towards arrow position = getSliderPosition(); if (position == 1) { shiftLeft(); addScore = mergeLeft(); shiftLeft(); } else if (position == 2) { shiftUp(); addScore = mergeUp(); shiftUp(); } else if (position == 3) { shiftRight(); addScore = mergeRight(); shiftRight(); } else { shiftDown(); addScore = mergeDown(); shiftDown(); } eraseBoard(); drawAllTiles(); // update score score += addScore; addScore = 0; writeScore(score); displayHighestTile(); // delay before adding new tile delay(200); // create new tile if (countEmptyTiles() != 0) { generateRandomTile(); } drawAllTiles(); // update highest tile image displayHighestTile(); // check if game over if (checkGameOver() == 1) { gameOver = 1; } // unset flag Button1 = 0; } // button 2 is pause else if (Button2 && !gameOver && !pauseMode) { pauseMode = 1; pauseSel = 0; // disable arrow and timer NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); // draw pause mode screen drawPauseMode(); // acknowledge button Button2 = 0; // wait until button is pushed while (pauseMode) { // Button 1 selects current pause selection button if (Button1) { // acknowledge button Button1 = 0; Button2 = 0; pauseMode = 0; // if pause selection = "continue" (pauseSel = 0), continue with game if (pauseSel == 0) { // redraw screen eraseBoard(); drawAllTiles(); // enable gameplay NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } // if pause selection = "restart" (pauseSel = 0), end game else if (pauseSel == 1) { if (score > highscore) { writeHighscore(score); } score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } } // Button 2 changes pause selection else if (Button2) { Button2 = 0; if (pauseSel == 0) { pauseSel = 1; LCD_DrawRect(144,112,58,16,BLACK); LCD_DrawRect(222,112,51,16,WHITE); } else if (pauseSel == 1) { pauseSel = 0; LCD_DrawRect(222,112,51,16,BLACK); LCD_DrawRect(144,112,58,16,WHITE); } } } } // game over if (gameOver == 1) { NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(156,38,100,20,BLACK); LCD_SetTextColor(255,255,240); LCD_Goto(30,5); printf("GAME OVER"); while (Button1 == 0 && Button2 == 0) {} Button1 = 0; Button2 = 0; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); drawGameOver(score, elapsedTime); if (score > highscore) { writeHighscore(score); gameOverHighscore(score); } // wait til button is pushed while (Button1 == 0 && Button2 == 0) {} // acknowledge buttons Button1 = 0; Button2 = 0; // start new game score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; // finish game over mode gameOver = 0; } } }
/** * <p>Factorisation using Pollard's rho method</p> * <p> * Advanced algorithms, KTH – Project 1 * DD2440 “avag11” * </p> * <p> * Enter large integer that you want factorised into primes, exit with empty line * Each prime will be printed on a separate line each, directly after your input, * when the factorisation is complete. * </p> * * @author Mattias Andrée, [email protected], 900223-3253 * @author Joel Mickelin, [email protected], 880729-0070 * * @param argc Number of elements in argv * @param argv The command line used to start the program: the program followed by options */ int main(int argc, String argv[]) { unused argc; unused argv; //Creating seed list, evens are prime, odds are composites seeds = malloc((SEED_LIMIT + 1) * sizeof(llong)); *(seeds + 1) = 10000; *(seeds + 2) = 15319; *(seeds + 3) = 10001; *(seeds + 4) = 15401; *(seeds + 5) = 10002; *(seeds + 6) = 10007; *(seeds + 7) = 10003; *(seeds + 8) = 22541; *(seeds + 9) = 10004; *seeds = 0; //Integers Bignum q; mpz_init(q); //Quotient Bignum r; mpz_init(r); //Remainder int rootOrder; //The order of the integer = max {i : x↑i = integer} int fx; //The number of factors of small primes Bignum integer; mpz_init(integer); //Integer to factorise //Prime factor buffer long* bufptr = malloc(sizeof(long)); Buffer buffer = new_Buffer(1); //Constants, it is very important for speed to test this primes Bignum _3; mpz_init_set_ui(_3, 3); Bignum _5; mpz_init_set_ui(_5, 5); Bignum _7; mpz_init_set_ui(_7, 7); #define appendFactors(X) appendToBuffer(buffer, (*bufptr)++, X) #define printFactors printBuffer(buffer, *bufptr) while (readBignum(integer)) { *bufptr = 0; free(*buffer); *buffer = malloc(0); //Remove all factors of 2 if ((fx = lowestBit(integer)) > 0) { shiftRight(integer, integer, fx); if (fx & 1) appendFactors(STR_1(2)); if (fx & 2) appendFactors(STR_2(2)); if (fx & 4) appendFactors(STR_4(2)); if (fx & 8) appendFactors(STR_8(2)); if (fx & 16) appendFactors(STR_16(2)); if (fx & 32) appendFactors(STR_32(2)); if (fx & 64) appendFactors(STR_64(2)); //limit, 127 factors of 2, we will not reach that if (equals(integer, 1)) { printFactors; printf("\n"); continue; } } //Remove all factors of X #define factorIt(X) \ if (fx = contDiv(integer, integer, _##X, null, null, 0)) \ { \ if (fx & 1) appendFactors(STR_1(X)); \ if (fx & 2) appendFactors(STR_2(X)); \ if (fx & 4) appendFactors(STR_4(X)); \ if (fx & 8) appendFactors(STR_8(X)); \ if (fx & 16) appendFactors(STR_16(X)); \ if (fx & 32) appendFactors(STR_32(X)); \ if (fx & 64) appendFactors(STR_64(X)); \ \ if (equals(integer, 1)) \ { \ printFactors; \ printf("\n"); \ continue; \ } \ } factorIt(3) factorIt(5) //factorIt(7) if (isPrime(integer)) { printFactors; printf("%s\n\n", bignumToString(integer)); } else if (factorisePollardsRho(integer, 0, buffer, bufptr, 1)) { printFactors; printf("\n"); } else printf(FAIL); } free(bufptr); free(buffer); successful; }
int *insertion_sort( int x[],int size) { int i; int *masterArray; masterArray = malloc(sizeof(int) * size); int init = size/2; int numsRight = 0; int numsLeft = 0; for(i = 0; i < size; i++) { *(masterArray + i) = -1; } *(masterArray + init) = x[0]; for(i = 1; i < size ; i++) { int min = init - numsLeft; int max = init + numsRight; int cursor = min; //Start scan on min value /*Tracer Start int n = 0; for(n = min; n <= max; n++) printf("%d(%d) ", *(masterArray + n), n); printf("- cursor:%d\n", cursor);*/ //If lower than min, decrease and continue if(x[i] < *(masterArray + cursor)) { cursor--; } else { //Otherwise increment cursor until on top of the last number that is less than x[i] while(x[i] > *(masterArray + cursor) && *(masterArray + cursor) != -1) cursor++; } if(*(masterArray + cursor) == -1) { *(masterArray + cursor) = x[i]; if( cursor > init) numsRight++; else numsLeft++; } else { int diff = cursor - min; //Difference in position of cursor from initial int rightOffSet = 0; int leftOffSet = 0; leftOffSet = diff; //Diff represents number of values left of cursor rightOffSet = max - min - diff + 1; //Total count (max - min) minus numbers on left plus one for the number at "cursor", gives us numbers on right //printf("diff:%d, rightOffSet:%d, leftOffSet:%d\n",diff,rightOffSet,leftOffSet); //Check to see which side has more numbers on each side of the cursor if(rightOffSet > leftOffSet) { //Shift left, unless we've already reached lowerbound if(min > 0) { shiftLeft(masterArray, min, cursor, x[i]); numsLeft++; } else { shiftRight(masterArray, max, cursor, x[i]); numsRight++; } } else { //Shift right, unless we've already reached upperbound if(max <= size) { shiftRight(masterArray, max, cursor, x[i]); numsRight++; } else { shiftLeft(masterArray, min, cursor, x[i]); numsLeft++; } } } /*Tracer End for(n = init - numsLeft; n <= init + numsRight; n++) printf("%d(%d) ", *(masterArray + n), n); printf("- cursor:%d\n\n", cursor);*/ //if(i == 12) break; } return(masterArray); }
dlgMapper::dlgMapper( QWidget * parent, Host * pH, TMap * pM ) : QWidget( parent ) , mpMap( pM ) , mpHost( pH ) { setupUi(this); glWidget->mpMap = pM; mp2dMap->mpMap = pM; mp2dMap->mpHost = pH; repopulateAreas(); bubbles->setChecked( mpHost->mBubbleMode ); mp2dMap->mBubbleMode = mpHost->mBubbleMode; d3buttons->setVisible(false); roomSize->setValue(mpHost->mRoomSize*10); lineSize->setValue(mpHost->mLineSize); showInfo->setChecked( mpHost->mShowInfo ); mp2dMap->mShowInfo = mpHost->mShowInfo; showRoomIDs->setChecked( mpHost->mShowRoomID ); mp2dMap->mShowRoomID = mpHost->mShowRoomID; panel->setVisible(mpHost->mShowPanel); //searchList->setSelectionMode( QAbstractItemView::SingleSelection ); //connect(roomID, SIGNAL(returnPressed()), this, SLOT(goRoom())); connect(bubbles, SIGNAL(clicked()), this, SLOT(slot_bubbles())); connect(showInfo, SIGNAL(clicked()), this, SLOT(slot_info())); connect(ortho, SIGNAL(pressed()), glWidget, SLOT(fullView())); connect(singleLevel, SIGNAL(pressed()), glWidget, SLOT(singleView())); connect(increaseTop, SIGNAL(pressed()), glWidget, SLOT(increaseTop())); connect(increaseBottom, SIGNAL(pressed()), glWidget, SLOT(increaseBottom())); connect(reduceTop, SIGNAL(pressed()), glWidget, SLOT(reduceTop())); connect(reduceBottom, SIGNAL(pressed()), glWidget, SLOT(reduceBottom())); //connect(searchList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(choseRoom(QListWidgetItem*))); connect(shiftZup, SIGNAL(pressed()), mp2dMap, SLOT(shiftZup())); connect(shiftZdown, SIGNAL(pressed()), mp2dMap, SLOT(shiftZdown())); connect(shiftLeft, SIGNAL(pressed()), mp2dMap, SLOT(shiftLeft())); connect(shiftRight, SIGNAL(pressed()), mp2dMap, SLOT(shiftRight())); connect(shiftUp, SIGNAL(pressed()), mp2dMap, SLOT(shiftUp())); connect(shiftDown, SIGNAL(pressed()), mp2dMap, SLOT(shiftDown())); connect(shiftZup, SIGNAL(pressed()), glWidget, SLOT(shiftZup())); connect(shiftZdown, SIGNAL(pressed()), glWidget, SLOT(shiftZdown())); connect(shiftLeft, SIGNAL(pressed()), glWidget, SLOT(shiftLeft())); connect(shiftRight, SIGNAL(pressed()), glWidget, SLOT(shiftRight())); connect(shiftUp, SIGNAL(pressed()), glWidget, SLOT(shiftUp())); connect(shiftDown, SIGNAL(pressed()), glWidget, SLOT(shiftDown())); connect(showInfo, SIGNAL(clicked()), glWidget, SLOT(showInfo())); connect(showArea, SIGNAL(activated(QString)), mp2dMap, SLOT(switchArea(QString))); connect(showArea, SIGNAL(activated(QString)), glWidget, SLOT(showArea(QString))); connect(defaultView, SIGNAL(pressed()), glWidget, SLOT(defaultView())); connect(dim2,SIGNAL(pressed()), this, SLOT(show2dView())); connect(sideView, SIGNAL(pressed()), glWidget, SLOT(sideView())); connect(topView, SIGNAL(pressed()), glWidget, SLOT(topView())); connect(togglePanel, SIGNAL(pressed()), this, SLOT(slot_togglePanel())); connect(lineSize, SIGNAL(valueChanged(int)), this, SLOT(slot_lineSize(int))); connect(roomSize, SIGNAL(valueChanged(int)), this, SLOT(slot_roomSize(int))); connect(scale, SIGNAL(valueChanged(int)), glWidget, SLOT(setScale(int))); connect(xRot, SIGNAL(valueChanged(int)), glWidget, SLOT(setXRotation(int))); connect(yRot, SIGNAL(valueChanged(int)), glWidget, SLOT(setYRotation(int))); connect(zRot, SIGNAL(valueChanged(int)), glWidget, SLOT(setZRotation(int))); mpDownloader = new QNetworkAccessManager( this ); connect(mpDownloader, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); connect(showRoomIDs, SIGNAL(stateChanged(int)), this, SLOT(slot_toggleShowRoomIDs(int))); mp2dMap->mFontHeight = QFontMetrics( mpHost->mDisplayFont ).height(); glWidget->hide(); mpMap->customEnvColors[257] = mpHost->mRed_2; mpMap->customEnvColors[258] = mpHost->mGreen_2; mpMap->customEnvColors[259] = mpHost->mYellow_2; mpMap->customEnvColors[260] = mpHost->mBlue_2; mpMap->customEnvColors[261] = mpHost->mMagenta_2; mpMap->customEnvColors[262] = mpHost->mCyan_2; mpMap->customEnvColors[263] = mpHost->mWhite_2; mpMap->customEnvColors[264] = mpHost->mBlack_2; mpMap->customEnvColors[265] = mpHost->mLightRed_2; mpMap->customEnvColors[266] = mpHost->mLightGreen_2; mpMap->customEnvColors[267] = mpHost->mLightYellow_2; mpMap->customEnvColors[268] = mpHost->mLightBlue_2; mpMap->customEnvColors[269] = mpHost->mLightMagenta_2; mpMap->customEnvColors[270] = mpHost->mLightCyan_2; mpMap->customEnvColors[271] = mpHost->mLightWhite_2; mpMap->customEnvColors[272] = mpHost->mLightBlack_2; mp2dMap->init(); }
static void retsFromOdbc(void) { void *q, *q1; int i, l; int fd, flags; bool yearfirst, indata = false; long dt; /* temporarily hold date or time */ char *s; short c_type; /* C data type */ long input_length, output_length; char tbuf[20]; /* temp buf, for dates and times */ double fmoney; /* float version of money */ int blobcount = 0; bool fbc = fetchBlobColumns; /* no blobs unless proven otherwise */ rv_blobLoc = 0; rv_blobSize = nullint; if(!rv_numRets) errorPrint("@calling retsFromOdbc() with no returns pending"); stmt_text = "retsFromOdbc"; debugStatement(); /* count the blobs */ if(fbc) for(i = 0; i < rv_numRets; ++i) if(rv_type[i] == 'B' || rv_type[i] == 'T') ++blobcount; if(blobcount > 1) { i_puts(MSG_DBManyBlobs); fbc = false; } for(i = 0; i < rv_numRets; ++i) { if(!indata) { q = va_arg(sqlargs, void *); if(!q) { if(i) break; indata = true; } } if(indata) { if(rv_type[i] == 'S') { q = retstring[i]; rv_data[i].ptr = q; } else q = rv_data + i; } if((int)q < 1000 && (int)q > -1000) errorPrint("2retsFromOdbc, pointer too close to 0"); q1 = q; tbuf[0] = 0; output_length = 0; switch (rv_type[i]) { case 'S': c_type = SQL_C_CHAR; input_length = STRINGLEN + 1; *(char *)q = 0; /* null */ break; case 'C': c_type = SQL_C_CHAR; input_length = 2; *(char *)q = 0; /* null */ q1 = tbuf; break; case 'F': c_type = SQL_C_DOUBLE; input_length = 8; *(double *)q = nullfloat; /* null */ break; case 'N': c_type = SQL_C_SLONG; input_length = 4; *(long *)q = nullint; /* null */ break; case 'M': c_type = SQL_C_DOUBLE; input_length = 8; fmoney = nullfloat; q1 = &fmoney; break; case 'D': c_type = SQL_C_CHAR; input_length = 11; q1 = tbuf; break; case 'I': c_type = SQL_C_CHAR; input_length = 10; q1 = tbuf; break; case 'B': case 'T': c_type = SQL_C_BINARY; input_length = sizeof (blobbuf); q1 = blobbuf; *(long *)q = nullint; break; default: errorPrint("@retsFromOdbc, rv_type[%d] = %c", i, rv_type[i]); } /* switch */ if(everything_null || c_type == SQL_C_BINARY && !fbc) { rc = SQL_SUCCESS; output_length = SQL_NULL_DATA; } else { rc = SQLGetData(hstmt, (ushort) (i + 1), c_type, q1, input_length, &output_length); /* we'll deal with blob overflow later */ if(rc == SQL_SUCCESS_WITH_INFO && c_type == SQL_C_BINARY && output_length > sizeof (blobbuf)) rc = SQL_SUCCESS; if(errorTrap(0)) break; if(output_length == SQL_NO_TOTAL) errorPrint ("@retsFromOdbc cannot get size of data for column %d", i + 1); } /* Postprocess the return values. */ /* For instance, turn string dates into our own 4-byte format. */ s = tbuf; clipString(s); switch (rv_type[i]) { case 'C': *(char *)q = tbuf[0]; break; case 'S': clipString(q); break; case 'D': yearfirst = false; if(s[4] == '-') yearfirst = true; dt = stringDate(s, yearfirst); if(dt < 0) errorPrint("@database holds invalid date %s", s); *(long *)q = dt; break; case 'I': /* thanks to stringTime(), this works for either hh:mm or hh:mm:ss */ if(s[0] == 0) *(long *)q = nullint; else { /* Note that Informix introduces a leading space, how about ODBC? */ leftClipString(s); if(s[1] == ':') shiftRight(s, '0'); dt = stringTime(s); if(dt < 0) errorPrint("@database holds invalid time %s", s); *(long *)q = dt; } break; case 'M': if(fmoney == nullfloat) dt = nullint; else dt = fmoney * 100.0 + 0.5; *(long *)q = dt; break; case 'B': case 'T': if(output_length == SQL_NULL_DATA) break; /* note, 0 length blob is treated as a null blob */ if(output_length == 0) break; /* the size of the blob is returned, in an int. */ *(long *)q = output_length; rv_blobSize = output_length; if(isnullstring(rv_blobFile)) { /* the blob is always allocated; you have to free it! */ /* SQL doesn't null terminate its text blobs, but we do. */ rv_blobLoc = allocMem(output_length + 1); l = output_length; if(l > sizeof (blobbuf)) l = sizeof (blobbuf); memcpy(rv_blobLoc, blobbuf, l); if(l < output_length) { /* more to do */ long waste; rc = SQLGetData(hstmt, (ushort) (i + 1), c_type, (char *)rv_blobLoc + l, output_length - l, &waste); if(rc) { nzFree(rv_blobLoc); rv_blobLoc = 0; *(long *)q = nullint; errorTrap(0); goto breakloop; } /* error getting rest of blob */ } /* blob is larger than the buffer */ if(rv_type[i] == 'T') /* null terminate */ ((char *)rv_blobLoc)[output_length] = 0; break; } /* blob in memory */ /* at this point the blob is being dumped into a file */ flags = O_WRONLY | O_BINARY | O_CREAT | O_TRUNC; if(rv_blobAppend) flags = O_WRONLY | O_BINARY | O_CREAT | O_APPEND; fd = eopen(rv_blobFile, flags, 0666); rc = SQL_SUCCESS; while(true) { int outbytes; l = output_length; if(l > sizeof (blobbuf)) l = sizeof (blobbuf); outbytes = write(fd, blobbuf, l); if(outbytes < l) { close(fd); errorPrint("2cannot write to file %s, errno %d", rv_blobFile, errno); } if(l == output_length) break; /* get the next chunk from ODBC */ rc = SQLGetData(hstmt, (ushort) (i + 1), c_type, q1, input_length, &output_length); if(rc == SQL_SUCCESS_WITH_INFO && output_length > input_length) rc = SQL_SUCCESS; /* data truncation error */ } close(fd); errorTrap(0); break; } /* switch */ } /* loop over returned elements */
bool Node::aStarVisit(std::deque<Node*>* deque, std::vector<bool>* visitedNodes) { visitedNodes->at(stateNumber) = true; showFile(); if (gameWon()) { return true; } if (Node* n = shiftLeft()) { if (n->notVisited(visitedNodes)) { //n->setHeight(height+1); deque->push_back(n); child.push_back(n); } else { delete n; } } if (Node* n = shiftUp()) { if (n->notVisited(visitedNodes)) { //n->setHeight(height+1); deque->push_back(n); child.push_back(n); } else { delete n; } } if (Node* n = shiftRight()) { if (n->notVisited(visitedNodes)) { //n->setHeight(height+1); deque->push_back(n); child.push_back(n); } else { delete n; } } if (Node* n = shiftDown()) { if (n->notVisited(visitedNodes)) { //n->setHeight(height+1); deque->push_back(n); child.push_back(n); } else { delete n; } } return false; }
void schedulescreen::showButtons(schedulepoint *point) { // show left, right, up, and down buttons in correct position for any input conditions int i; // track which is the point that has been clicked on currentPoint = point; // show time indicated by position of current point currentTime->setText(currentPoint->time()); // first hide all 4 buttons, then we will make them reappear in the correct position hideButtons(); // create left arrow QPushButton *leftArrowButton = new QPushButton(); leftArrowButton->setFocusPolicy(Qt::NoFocus); leftArrowButton->setStyleSheet("background: rgba(0,0,0,0);" "border-image: url(:/Images/simple-black-square-icon-arrowleft.png) 1;"); leftArrowButton->setFixedSize(25,25); connect(leftArrowButton, SIGNAL(clicked()), this, SLOT(shiftLeft())); // create right arrow QPushButton *rightArrowButton = new QPushButton(); rightArrowButton->setFocusPolicy(Qt::NoFocus); rightArrowButton->setStyleSheet("background: rgba(0,0,0,0);" "border-image: url(:/Images/simple-black-square-icon-arrowright.png) 1;"); rightArrowButton->setFixedSize(25,25); connect(rightArrowButton, SIGNAL(clicked()),this,SLOT(shiftRight())); // create up arrow QPushButton *upArrowButton = new QPushButton(); upArrowButton->setFocusPolicy(Qt::NoFocus); upArrowButton->setStyleSheet("background: rgba(0,0,0,0);" "border-image: url(:/Images/simple-black-square-icon-arrowup.png) 1;"); upArrowButton->setFixedSize(25,25); connect(upArrowButton, SIGNAL(clicked()), this, SLOT(increaseTemp())); // create down arrow QPushButton *downArrowButton = new QPushButton(); downArrowButton->setFocusPolicy(Qt::NoFocus); downArrowButton->setStyleSheet("background: rgba(0,0,0,0);" "border-image: url(:/Images/simple-black-square-icon-arrowdown.png) 1;"); downArrowButton->setFixedSize(25,25); connect(downArrowButton, SIGNAL(clicked()), this, SLOT(decreaseTemp())); // create proxy widgets so that buttons can be added to graphics view proxyLeftButton = new QGraphicsProxyWidget(); proxyLeftButton->setWidget(leftArrowButton); proxyRightButton = new QGraphicsProxyWidget(); proxyRightButton->setWidget(rightArrowButton); proxyUpButton = new QGraphicsProxyWidget(); proxyUpButton->setWidget(upArrowButton); proxyDownButton = new QGraphicsProxyWidget(); proxyDownButton->setWidget(downArrowButton); // set position of left and right buttons on either side of currently selected point proxyLeftButton->setPos(QPoint(0.075 + (85 * (point->getID() % 4)), 25 + (22 * ((point->getID() / 4) % 7)))); scene->addItem(proxyLeftButton); proxyRightButton->setPos(QPoint(45.075 + (85 * (point->getID() % 4)), 25 + (22 * ((point->getID() / 4) % 7)))); scene->addItem(proxyRightButton); // set up and down buttons at the top and bottom of currently visible column for(i=0; i<7; i++) { if(pointList.at((point->getID()%4 + 4*i))->isVisible()) { proxyUpButton->setPos(QPoint(-13 + pointList.at(point->getID()%4 + 4*i)->pos().x(), -31 + pointList.at(point->getID()%4 +4*i)->pos().y())); break; } } scene->addItem(proxyUpButton); for(i=0; i<7; i++) { if(pointList.at((24+(point->getID()%4) - 4*i))->isVisible()) { // only works if last row is visible proxyDownButton->setPos(QPoint(-13 + pointList.at((24+(point->getID()%4) - 4*i))->pos().x(), 6 + pointList.at((24+(point->getID()%4) - 4*i))->pos().y())); break; } } scene->addItem(proxyDownButton); // if the point has already been moved, make sure buttons are created at the right spot if(point->getLocation()<0) { for(i=0; i>point->getLocation(); i--) { shiftHorizontalButtonsLeft(); } } else { for(i=0; i<point->getLocation(); i++) { shiftHorizontalButtonsRight(); } } // blur all columns except the currently selected column blur(); }
// returns true if this node or a descendent is the goal bool Node::depthVisit(std::vector<Node*>* vector, std::vector<bool>* visitedNodes) { visitedNodes->at(stateNumber) = true; //showFile(); if (gameWon()) { vector->pop_back(); return true; } if (Node* n = shiftLeft()) { if (n->notVisited(visitedNodes)) { child.push_back(n); vector->push_back(n); //n->setHeight(height+1); // if this child or a descendant is the goal stop returns true if (vector->back()->depthVisit(vector, visitedNodes)) { vector->pop_back(); return true; } } else { delete n; } } if (Node* n = shiftUp()) { if (n->notVisited(visitedNodes)) { child.push_back(n); vector->push_back(n); //n->setHeight(height+1); // if this child or a descendant is the goal stop returns true if (vector->back()->depthVisit(vector, visitedNodes)) { vector->pop_back(); return true; } } else { delete n; } } if (Node* n = shiftRight()) { if (n->notVisited(visitedNodes)) { child.push_back(n); vector->push_back(n); //n->setHeight(height+1); // if this child or a descendant is the goal stop returns true if (vector->back()->depthVisit(vector, visitedNodes)) { vector->pop_back(); return true; } } else { delete n; } } if (Node* n = shiftDown()) { if (n->notVisited(visitedNodes)) { child.push_back(n); vector->push_back(n); //n->setHeight(height+1); // if this child or a descendant is the goal stop returns true if (vector->back()->depthVisit(vector, visitedNodes)) { vector->pop_back(); return true; } } else { delete n; } } vector->pop_back(); return false; }
bool GuiCombat::CheckUserInput(JButton key) { if (NONE == cursor_pos) return false; DamagerDamaged* oldActive = active; int x,y; if(observer->getInput()->GetLeftClickCoordinates(x, y)) { // determine if OK button was clicked on if (ok.width) { if (didClickOnButton(ok, x, y)) { cursor_pos = OK; } } // position selected card if (BLK == cursor_pos) { DamagerDamaged* selectedCard = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y)); // find the index into the vector where the current selected card is. int c1 = 0, c2 = 0; int i = 0; for ( vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it) { if ( *it == selectedCard ) c2 = i; else if ( *it == active) c1 = i; i++; } // simulate pressing the "Left/Right D-Pad" control c1 - c2 times if ( c1 > c2 ) // card selected is to the left of the current active card { for (int x = 0; x < c1 - c2; x++) shiftLeft(); } else if ( c1 < c2 ) { for (int x = 0; x < c2 - c1; x++) shiftRight( oldActive ); } } } switch (key) { case JGE_BTN_OK: if (BLK == cursor_pos) { if (ORDER == step) observer->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); } else { signed damage = activeAtk->card->stepPower(step); for (vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); *it != active; ++it) damage -= (*it)->sumDamages(); signed now = active->sumDamages(); damage -= now; if (damage > 0) addOne(active, step); else if (activeAtk->card->has(Constants::DEATHTOUCH)) for (; now >= 1; --now) removeOne(active, step); else for (now -= active->card->toughness; now >= 0; --now) removeOne(active, step); } } else if (ATK == cursor_pos) { active = activeAtk->blockers.front(); active->zoom = kZoom_level3; cursor_pos = BLK; } else if (OK == cursor_pos) { clickOK(); } break; case JGE_BTN_CANCEL: if (BLK == cursor_pos) { oldActive->zoom = kZoom_level2; active = activeAtk; cursor_pos = ATK; } return true; case JGE_BTN_LEFT: shiftLeft(); break; case JGE_BTN_RIGHT: shiftRight( oldActive ); break; case JGE_BTN_DOWN: if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) break; removeOne(active, step); break; case JGE_BTN_UP: if (ORDER == step || BLK != cursor_pos) break; addOne(active, step); break; case JGE_BTN_PRI: active = activeAtk = NULL; cursor_pos = OK; break; case JGE_BTN_NEXT: if (!options[Options::REVERSETRIGGERS].number) return false; active = activeAtk = NULL; cursor_pos = OK; break; case JGE_BTN_PREV: if (options[Options::REVERSETRIGGERS].number) return false; active = activeAtk = NULL; cursor_pos = OK; break; default: ; } if (oldActive != active) { if (oldActive && oldActive != activeAtk) oldActive->zoom = kZoom_level2; if (active) active->zoom = kZoom_level3; if (ATK == cursor_pos) remaskBlkViews(dynamic_cast<AttackerDamaged*> (oldActive), static_cast<AttackerDamaged*> (active)); } if (OK == cursor_pos) ok.zoom = 1.5; else ok.zoom = kZoom_none; return true; }