Array<T> createSubArray(const Array<T> &parent, const vector<af_seq> &index, bool copy) { parent.eval(); dim4 dDims = parent.getDataDims(); dim4 dStrides = calcStrides(dDims); dim4 parent_strides = parent.strides(); if (dStrides != parent_strides) { const Array<T> parentCopy = copyArray(parent); return createSubArray(parentCopy, index, copy); } dim4 pDims = parent.dims(); dim4 dims = toDims(index, pDims); dim4 strides = toStride(index, dDims); // Find total offsets after indexing dim4 offsets = toOffset(index, pDims); dim_t offset = parent.getOffset(); for (int i = 0; i < 4; i++) offset += offsets[i] * parent_strides[i]; Array<T> out = Array<T>(parent, dims, offset, strides); if (!copy) return out; if (strides[0] != 1 || strides[1] < 0 || strides[2] < 0 || strides[3] < 0) { out = copyArray(out); } return out; }
void arrayInStruct(struct array * v0, struct array * * out) { struct s_unsignedS32_arr_unsignedS32_UD e0 = { .member1 = 0, .member2 = NULL }; uint32_t len1; struct s_unsignedS32_arr_unsignedS32_UD v2 = { .member1 = 0, .member2 = NULL }; uint32_t v1; (e0).member1 = getLength(v0); (e0).member2 = initArray((e0).member2, sizeof(uint32_t), getLength(v0)); copyArray((e0).member2, v0); (v2).member1 = (e0).member1; (v2).member2 = initArray((v2).member2, sizeof(uint32_t), getLength((e0).member2)); copyArray((v2).member2, (e0).member2); v1 = ((e0).member1 > 0); while (v1) { (v2).member1 = ((e0).member1 - 1); len1 = getLength((e0).member2); (v2).member2 = initArray((v2).member2, sizeof(uint32_t), len1); for (uint32_t v3 = 0; v3 < len1; v3 += 1) { at(uint32_t,(v2).member2,v3) = (at(uint32_t,(e0).member2,v3) + 5); } (e0).member1 = (v2).member1; (e0).member2 = initArray((e0).member2, sizeof(uint32_t), getLength((v2).member2)); copyArray((e0).member2, (v2).member2); v1 = ((e0).member1 > 0); } *out = initArray(*out, sizeof(uint32_t), getLength((e0).member2)); copyArray(*out, (e0).member2); }
void checkArray(int n, int oneZero[], int start[], int *dif, int resultArray1[], int resultArray2[]){ int difference = 0, *interim1 = calloc(n,sizeof(int)), *interim2 = calloc(n,sizeof(int)); int i = 0, j = 0, k = 0; for (i = 0, j = 0, k = 0; i<n; i++){ //splits array in two according to oneZero if(oneZero[i] == 1){ interim1[j] = start[i]; j++; } else if (oneZero[i] == 0) { interim2[k] = start[i]; k++; } } //assigns difference of two arrays and makes it absolute value difference = sumArray(n,interim1) - sumArray(n,interim2); difference = absoluteValue(difference); if (difference < *dif){ //checks new difference with old one *dif = difference; //if smaller assigns smaller value copyArray(n,resultArray1,interim1); //and new arrays copyArray(n,resultArray2,interim2); } free(interim1); free(interim2); }//checkArray
void Player::checkGesture(int hand[3]){ if(compareArray(hand, _hulk) && _userID == 200){ copyArray(_hulk, _gesture, 6); _charging = true; _chargingTimeMax = 1.0*_hulk[4]; _chargingAtkValue = 0; } else if(compareArray(hand, _spiderman) && _userID == 200){ copyArray(_spiderman, _gesture, 6); _charging = true; _chargingTimeMax = 1.0*_spiderman[4]; _chargingAtkValue = 0; } else if(compareArray(hand, _ironman) && _userID == 200){ copyArray(_ironman, _gesture, 6); _charging = true; _chargingTimeMax = 1.0*_ironman[4]; _chargingAtkValue = 0; } else if(compareArray(hand, _defence) && _userID == 100){ copyArray(_defence, _gesture, 6); _charging = true; _chargingTimeMax = 1.0*_defence[4]; _defValue = 0; } //otherwise set the gesture to none else{ copyArray(_none, _gesture, 6); //if you're at the maximum charge and have opened your palm to indicate sending the attack if(_charging){ _atkValue = _chargingAtkValue; _chargingTime = 0; _chargingTimeMax = 0; _charging = false; } } //if we're charging an attack or defence if(_charging){ //If you're at maximum charge but haven't sent the attack or the defense is at max charge //don't do anything if(_chargingTime >= _chargingTimeMax){ } else{ //if we're defending if(_gesture[0] == _defence[0] && _gesture[1] == _defence[1] && _gesture[2] == _defence[2]){ //defense scaled depending how long it's been charing. _defValue = (1.0*_gesture[3])*(_chargingTime/_chargingTimeMax); } //if we're attacking else{ _chargingAtkValue = (1.0*_gesture[3])*(_chargingTime/_chargingTimeMax); } //Increment charging time _chargingTime ++; } } }
void multimodel :: startRendering() { if (m_loader) { copyArray(m_loader->getVector("vertices"), m_position); copyArray(m_loader->getVector("texcoords"), m_texture); copyArray(m_loader->getVector("normals"), m_normal); copyArray(m_loader->getVector("colors"), m_color); } }
void handle_ANALOG(RF24NetworkHeader& header, short index_node, byte mode) { uint8_t command_rx[34]; uint8_t j, Ndata_received; uint8_t analog_pins[num_analog_pins]; //{2, 3}; uint16_t analog_states[num_analog_pins]; if (header.from_node == 00) //nothing if base return; if (index_node == -1) index_node = add_nodeFlash(header.from_node); //if index = -1, then add the node in the table and extract the new index // The 'T' message is just a ulong, containing the time network.read(header, command_rx, 32); // printf_P(PSTR("BASE has received ANALOG DATA from 0%o\n\r"), header.from_node); //command_rx[1] --> number of received data (1 data = 8 bit) Ndata_received = command_rx[1]; SystemNRF24LPins[index_node].ana_num = Ndata_received / 2; //16 bits if (mode == 0) { copyArray(command_rx, (uint8_t *)analog_states, 2, Ndata_received); //analog_states 16 bits IF_SERIAL_DEBUG_NRF(printf_P(PSTR("ANALOG VALUES, node: 0%o, index: %d, data:"), header.from_node, index_node)); IF_SERIAL_DEBUG_NRF(PrintVector(analog_states, Ndata_received / 2)); #if DEBUG_SERIAL_NRF24L == 1 float vcc_remote = ((float) SystemNRF24LPins[index_node].Supply) / 1000.0; Serial.print("Remote batt voltage: "); Serial.print(vcc_remote, 2); Serial.println("V"); #endif for (j = 0; j < Ndata_received / 2; j++) SystemNRF24LPins[index_node].AnaPin[j].state = analog_states[j]; } else if (mode == 1) { copyArray(command_rx, analog_pins, 2, Ndata_received); //analog_pins 8 bits IF_SERIAL_DEBUG_NRF(printf_P(PSTR("ANALOG PIN POSITION, node: 0%o, index: %d, data:"), header.from_node, index_node)); IF_SERIAL_DEBUG_NRF(PrintVector(analog_pins, Ndata_received)); SystemNRF24LPins[index_node].RNF24LAddr = header.from_node; for (j = 0; j < Ndata_received; j++) { SystemNRF24LPins[index_node].AnaPin[j].pin = analog_pins[j]; SystemNRF24LPins[index_node].AnaPin[j].used = true; } } }
void BPlusIndexP::splitAddLeaf(IndexPage* page, Index* index) { Logger* log = getLogger(NULL); //temporal arrays Index** tmpelements = (Index**)malloc(sizeof(Index*) * (BUCKET_MAX_ELEMENTS + 1)); //IndexPage** tmppointers = (IndexPage**)malloc(sizeof(IndexPage*) * (BUCKET_MAX_ELEMENTS + 2)); initializeArray((void**)tmpelements, BUCKET_MAX_ELEMENTS); copyArray((void**)page->elements, (void**)tmpelements, 0, BUCKET_MAX_ELEMENTS - 1, 0); int posToInsert = findInsertPositionArray(tmpelements, index, page->size, BUCKET_MAX_ELEMENTS); insertArray((void**)tmpelements, index, posToInsert, BUCKET_MAX_ELEMENTS + 1); // clean the previous "left" initializeArray((void**)page->elements, BUCKET_MAX_ELEMENTS); IndexPage* rightPage = new IndexPage(); int midPoint = (BUCKET_MAX_ELEMENTS / 2); copyArray((void**)tmpelements, (void**)page->elements, 0, midPoint, 0); page->size = (BUCKET_MAX_ELEMENTS / 2) + 1; // Clean up the elements moved to the rightPage for (int x = page->size; x < BUCKET_MAX_ELEMENTS; x++) { page->elements[x] = NULL; page->pointers[x + 1] = NULL; } // cleans the last one page->pointers[BUCKET_MAX_ELEMENTS] = NULL; refreshParentRelationship(page); //copyArray((void**)tmppointers, (void**)page->pointers, 0, midPoint + 1, 0); copyArray((void**)tmpelements, (void**)rightPage->elements, midPoint + 1, BUCKET_MAX_ELEMENTS, 0); rightPage->size = (BUCKET_MAX_ELEMENTS / 2) + 1; refreshParentRelationship(rightPage); //copyArray((void**)tmppointers, (void**)rightPage->pointers, midPoint + 2, BUCKET_MAX_ELEMENTS + 2, 0); // Promotion IndexPage* parentElement = page->parentElement; Index* copyElement = new Index(*rightPage->elements[0]); if (parentElement == NULL) { createRoot(copyElement, page, rightPage); } else { addElement(parentElement, copyElement, rightPage); } parentElement = rightPage->parentElement; free(tmpelements); refreshParentRelationship(parentElement); persistPage(page); persistPage(rightPage); persistPage(page->parentElement); }
void Image4uint8::copyGImage(const GImage& im) { switch (im.channels()) { case 1: copyArray(im.pixel1(), im.width(), im.height()); break; case 3: copyArray(im.pixel3(), im.width(), im.height()); break; case 4: copyArray(im.pixel4(), im.width(), im.height()); break; } }
void arrayInStructInStruct(struct s_2_unsignedS32_s_2_unsignedS32_arr_unsignedS32 * v0, struct s_2_unsignedS32_s_2_unsignedS32_arr_unsignedS32 * out) { (*out).member1 = (*v0).member1; ((*out).member2).member1 = ((*v0).member2).member1; ((*out).member2).member2 = initArray(((*out).member2).member2, sizeof(uint32_t), getLength(((*v0).member2).member2)); copyArray(((*out).member2).member2, ((*v0).member2).member2); }
void ivar_get_array_nontask( struct array *var, struct ivar iv ) { struct ivar_internals *ivi = iv.internals; struct array *ptr; log_2("ivar_get_array_nontask %p %p - enter\n", var, &iv); pthread_mutex_lock( &(ivi->mutex) ); if ( !ivi->full ) log_2("ivar_get_array_nontask %p %p - waiting for data\n", var, &iv); while(!ivi->full) { int err = pthread_cond_wait( &(ivi->cond), &(ivi->mutex) ); if (err) { exit(err); } } assert(ivi->full); pthread_mutex_unlock( &(ivi->mutex) ); if (NULL == ivi->data) { log_2("ivar_get_array_nontask %p %p - data uninitialized\n", var, &iv); } else { ptr = (struct array*)ivi->data; initArray( var, ptr->elemSize, ptr->length ); copyArray( var, ptr ); } log_2("ivar_get_array_nontask %p %p - leave\n", var, &iv); }
void QRGivensRotations(double ***A, double ***Q, double ***R) { double **G; int i, j; double c, s; mallocMatrix(&G); copyArray(R, A); setEye(Q); // Algorytm qr Givens rotations for(j=0; j<SIZE; j++) //kolumny for(i=SIZE - 1; i > j; i--) { //wiersze // #mozna zrownoleglic dwie instrukcje setEye(&G); givensRotation((*R)[i-1][j], (*R)[i][j], &c, &s); setMatrixG(&G, i, j, c, s); // #mozna zrownoleglic dwie instrukcje ponizej multiplyMatrixToSecondWithTransposition(&G, R); multiplyMatrixToFirst(Q, &G); } // printMatrix(&Q," Q ROZWIAZANIE"); // printMatrix(&R," R ROZWIAZANIE"); freeMatrix(&G); return; }
void icetGetIntegerv(IceTEnum pname, IceTInt *params) { struct IceTStateValue *value = icetGetState() + pname; int i; stateCheck(pname, icetGetState()); copyArray(IceTInt, params, value->type, value->data, value->num_entries); }
//One Variable is 32bit void handle_VARIABLE(RF24NetworkHeader& header, short index_node, byte mode) { uint8_t command_rx[34]; uint8_t j, Ndata_received; float variable_states[NRF24LMaxVariable]; if (header.from_node == 00) //nothing if base return; if (index_node == -1) index_node = add_nodeFlash(header.from_node); //if index = -1, then add the node in the table and extract the new index // IF_SERIAL_DEBUG_NRF(printf_P(PSTR("Payload: %d \n\r"), radio.getPayloadSize())); network.read(header, command_rx, 32); Ndata_received = command_rx[1]; //IF_SERIAL_DEBUG_NRF(PrintVector(command_rx, Ndata_received+2)); SystemNRF24LPins[index_node].var_num = Ndata_received / 4; //32 bits copyArray(command_rx, (uint8_t *)variable_states, 2, Ndata_received); //analog_states 16 bits IF_SERIAL_DEBUG_NRF(printf_P(PSTR("VARIABLE VALUES, node: 0%o, index: %d, data:"), header.from_node, index_node)); IF_SERIAL_DEBUG_NRF(PrintVector(variable_states, Ndata_received / 4)); for (j = 0; j < Ndata_received / 4; j++) SystemNRF24LPins[index_node].VarPin[j].value = variable_states[j]; }
void radixSort(int *a, int n, int *endResult) { /**Do we have to know the complete functions for tomorrow's test, or can we leave the assignments and comparisons out? I'm not even sure I wrote them correctly in this algorithm**/ int rank = 1,k; int highestRank = getLenghtOfMax(a, n); for (k = 0; k < highestRank; k++) { int j,i=0,step=0; for (i=0; i<10; i++) { for (j=0; j<n; j++) { comparisons++; if ((a[j]/rank)%10 == i) { *(endResult+step) = *(a+j); step++; assignments+=2; } } } copyArray(a, n, endResult); rank*=10; assignments++; } }
bool sendCommand (uint16_t to, unsigned char cmd, uint8_t *states, uint8_t num) { uint8_t tx_buffer[50]; radio.powerUp(); tx_buffer[0] = cmd; tx_buffer[1] = num; copyArray(states, tx_buffer + 2, 0, num); delay(100); RF24NetworkHeader header(/*to node*/ to, /*type*/ cmd /*Time*/); IF_SERIAL_DEBUG_NRF(printf_P(PSTR("---------------------------------\n\r"))); IF_SERIAL_DEBUG_NRF(printf_P(PSTR("SENSOR is sending to node 0%o...\n\r"), to)); bool ok = network.write(header, tx_buffer, num + 2); IF_SERIAL_DEBUG_NRF(PrintVector(tx_buffer, num + 2)); #if DEBUG_SERIAL_NRF24L == 1 if (ok) printf("Command ok\n\r"); else printf("Command failed\n\r"); // radio.powerDown(); #endif return (ok); }
void mergeSort(int * const array, int n) { printArray(array, n); if (n > 1){ mergeSort(array, n / 2); mergeSort(array + n / 2, n - n / 2); int cpar[n / 2], i, j; copyArray(array, cpar, n / 2); for (i = 0, j = 0; i < n / 2 && j < n - n / 2;){ if (*(cpar + i) < *(array + n / 2 + j)){ *(array + i + j) = *(cpar + i); ++i; } else{ *(array + i + j) = *(array + n / 2 + j); ++j; } if (j == n - n /2) { while(i < n / 2){ *(array + i + j) = *(cpar + i); ++i; } } } } printArray(array, n); }
Array<T> createSubArray(const Array<T>& parent, const std::vector<af_seq> &index, bool copy) { parent.eval(); dim4 dDims = parent.getDataDims(); dim4 pDims = parent.dims(); dim4 dims = toDims (index, pDims); dim4 offset = toOffset(index, dDims); dim4 stride = toStride (index, dDims); Array<T> out = Array<T>(parent, dims, offset, stride); if (!copy) return out; if (stride[0] != 1 || stride[1] < 0 || stride[2] < 0 || stride[3] < 0) { out = copyArray(out); } return out; }
static void transformImageToWorkArea( pfs::Array2D **workArea, float zoom, bool color, pfs::Array2D *X, pfs::Array2D *Y = NULL, pfs::Array2D *Z = NULL ) { int origCols, origRows; origCols = X->getCols(); origRows = X->getRows(); int workCols, workRows; workCols = min( (int)((float)X->getCols() * zoom), X->getCols() ); workRows = min( (int)((float)X->getRows() * zoom), X->getRows() ); int requiredChannels = color ? 3 : 1; // Reallocate work area arrays to fit new size { for( int c = 0; c < requiredChannels; c++ ) { if( workArea[c] == NULL || workArea[c]->getCols() != workCols || workArea[c]->getRows() != workRows ) { if( workArea[c] != NULL ) delete workArea[c]; workArea[c] = new pfs::Array2DImpl( workCols, workRows ); } } } //Copy | rescale & tranform image to work area if( color ) { if( workCols == origCols && workRows == origRows ) { copyArray( X, workArea[0] ); copyArray( Y, workArea[1] ); copyArray( Z, workArea[2] ); } else { scaleCopyArray( X, workArea[0] ); scaleCopyArray( Y, workArea[1] ); scaleCopyArray( Z, workArea[2] ); } pfs::transformColorSpace( pfs::CS_XYZ, workArea[0], workArea[1], workArea[2], pfs::CS_RGB, workArea[0], workArea[1], workArea[2] ); } else { if( workCols == origCols && workRows == origRows ) copyArray( X, workArea[0] ); else scaleCopyArray( X, workArea[0] ); } }
int main() { // initialize our variables, including a pointer to the beginning of // the array of input integers. // note its size will change as we input more and more numbers // we allocate one space for the first integer to be entered into int* arr = calloc(1, sizeof(int)); int* arrCopy; int size = 0; int searchValsSize = 0; int* searchVals = calloc(1, sizeof(int)); printf("enter numbers to fill an array, entering -999 when finished \n"); arr = read(arr, &size); arrCopy = copyArray(size, arr); qsort(arrCopy, size, sizeof(int), cmpfunc); printf("\nYour array: \n"); printArr(size, arr); printf("\nYour array sorted: \n"); printArr(size, arrCopy); printf("\nEnter a value to search for\n"); searchVals = read(searchVals, &searchValsSize); // for each search value, we pass the value to the search function and report how long it took and where it was printf("\nLinear Search Results: \n"); for(int i =0; i<searchValsSize; i++){ int* found = linSearch(arr, size, searchVals[i]); if(found[0] != -1) printf("found %d at position %d by making %d comparasins\n", searchVals[i], found[0], found[1]); else printf("Did not find %d by making %d comparasins\n", searchVals[i], found[1]); } // same thing as before, only now we use the sorted array to search through each time printf("\nBinary Search Results: \n"); for(int i =0; i<searchValsSize; i++){ int* found = binSearch(arrCopy, size, searchVals[i]); if(found[0] != -1) printf("found %d at position %d by making %d comparasins\n", searchVals[i], found[0], found[1]); else printf("Did not find %d by making %d comparasins\n", searchVals[i], found[1]); } return 0; }
VerbatimBlockComment *Parser::parseVerbatimBlock() { assert(Tok.is(tok::verbatim_block_begin)); VerbatimBlockComment *VB = S.actOnVerbatimBlockStart(Tok.getLocation(), Tok.getVerbatimBlockName()); consumeToken(); // Don't create an empty line if verbatim opening command is followed // by a newline. if (Tok.is(tok::newline)) consumeToken(); SmallVector<VerbatimBlockLineComment *, 8> Lines; while (Tok.is(tok::verbatim_block_line) || Tok.is(tok::newline)) { VerbatimBlockLineComment *Line; if (Tok.is(tok::verbatim_block_line)) { Line = S.actOnVerbatimBlockLine(Tok.getLocation(), Tok.getVerbatimBlockText()); consumeToken(); if (Tok.is(tok::newline)) { consumeToken(); } } else { // Empty line, just a tok::newline. Line = S.actOnVerbatimBlockLine(Tok.getLocation(), ""); consumeToken(); } Lines.push_back(Line); } if (Tok.is(tok::verbatim_block_end)) { VB = S.actOnVerbatimBlockFinish(VB, Tok.getLocation(), Tok.getVerbatimBlockName(), copyArray(llvm::makeArrayRef(Lines))); consumeToken(); } else { // Unterminated \\verbatim block VB = S.actOnVerbatimBlockFinish(VB, SourceLocation(), "", copyArray(llvm::makeArrayRef(Lines))); } return VB; }
void Array::addMemory() { int tmpSize = this->nSize; this->nSize = (int)ceil((double)this->nSize*1.5); int *temp = new int[this->nSize]; copyArray(this->pArray, temp, tmpSize); delete[] this->pArray; this->pArray = temp; }
InflaterHuffmanTree* InflaterDynHeader::buildLitLenTree() { char* litlenLens = new char[lnum]; copyArray(litdistLens, 0, litlenLens, 0, lnum); InflaterHuffmanTree* res = new InflaterHuffmanTree(litlenLens, lnum); delete [] litlenLens; return res; }
InflaterHuffmanTree* InflaterDynHeader::buildDistTree() { char* distLens = new char[dnum]; copyArray(litdistLens, lnum, distLens, 0, dnum); InflaterHuffmanTree* res = new InflaterHuffmanTree(distLens, dnum); delete [] distLens; return res; }
SEXP kz3d(SEXP x, SEXP window, SEXP iterations) { int i, j, l; SEXP ans, tmp, dim; SEXP index; int offset, offset_a; int m1, m2, m3; if (length(window)<3) {m1 = m2 = m3 = INTEGER_VALUE(window);} else {m1 = INTEGER(window)[0]; m2 = INTEGER(window)[1]; m3 = INTEGER(window)[2];} dim = GET_DIM(x); PROTECT(index = allocVector(INTSXP, LENGTH(dim))); PROTECT(ans = allocArray(REALSXP, dim)); PROTECT(tmp = allocArray(REALSXP, dim)); copyArray(ans, x); for(l=0; l<INTEGER_VALUE(iterations); l++) { copyArray(tmp, ans); for(INTEGER(index)[0]=0; INTEGER(index)[0]<INTEGER(dim)[0]; INTEGER(index)[0]++) { for(INTEGER(index)[1]=0; INTEGER(index)[1]<INTEGER(dim)[1]; INTEGER(index)[1]++) { for(INTEGER(index)[2]=0; INTEGER(index)[2]<INTEGER(dim)[2]; INTEGER(index)[2]++) { /* offset += INTEGER(index)[0]; offset += INTEGER(dim)[0]*INTEGER(index)[1]; offset += INTEGER(dim)[0]*INTEGER(dim)[1]*INTEGER(index)[2]; offset += INTEGER(dim)[0]*INTEGER(dim)[1]*INTEGER(dim)[2]*INTEGER(index)[3]; */ /* find offset into array */ for(i=0, offset=0; i<LENGTH(dim); i++) { for(j=0, offset_a=1; j<i; j++) { offset_a *= INTEGER(dim)[j]; } offset += offset_a * INTEGER(index)[i]; } REAL(ans)[offset] = averaged(tmp, index, m1, m2, m3); } } } } UNPROTECT(3); return ans; }
int main(){ int aSize = 0; cnt = 0; cout<<"Enter array size: ";cin>>aSize; int *strArray = new int[aSize]; int *orgArray = new int[aSize]; int search = aSize; //getArray(strArray,aSize); fillRand(strArray,aSize); printAr(strArray,aSize); copyArray(strArray,orgArray,aSize); cout<<"******** standard search **********"<<endl; cout<<"Found "<<search<<" at "; cout<<standardSearch(strArray,aSize, search); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; cout<<"******** binary search **********"<<endl; cout<<"Found "<<search<<" at "; selectionSort(strArray,aSize); cout<<binarySearch(strArray,aSize,search); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; copyArray(orgArray,strArray,aSize); cout<<"******** selection sort **********"<<endl; selectionSort(strArray,aSize); printAr(strArray,aSize); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; copyArray(orgArray,strArray,aSize); cout<<"******** insert sort **********"<<endl; insertSort(strArray,aSize); printAr(strArray,aSize); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; copyArray(orgArray,strArray,aSize); cout<<"******** Bubble sort **********"<<endl; BubbleSort(strArray,aSize); printAr(strArray,aSize); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; return 0; }
void ivar_get_array( struct array *var, struct ivar iv ) { struct array *ptr; log_2("ivar_get_array %p %p - enter\n", var, &iv); ivar_get_helper(iv.internals); ptr = (struct array*)iv.internals->data; assert(ptr); initArray( var, ptr->elemSize, ptr->length ); copyArray( var, ptr ); log_2("ivar_get_array %p %p - leave\n", var, &iv); }
void icetGetEnumv(IceTEnum pname, IceTEnum *params) { struct IceTStateValue *value = icetGetState() + pname; int i; stateCheck(pname, icetGetState()); if ((value->type == ICET_FLOAT) || (value->type == ICET_DOUBLE)) { icetRaiseError("Floating point values cannot be enumerations.", ICET_BAD_CAST); } copyArray(IceTEnum, params, value->type, value->data, value->num_entries); }
void CMergeSort::topDownSplitMerge(std::vector<double> * inputA, int iBegin, int iEnd, std::vector<double> * outputB) { int iMiddle; // for separating the array into two smaller array if (iEnd - iBegin < 2) // the array has maximum 1 number return; iMiddle = (iEnd + iBegin) / 2; topDownSplitMerge(inputA, iBegin, iMiddle, outputB); // left half topDownSplitMerge(inputA, iMiddle, iEnd, outputB); // right half topDownMerge(inputA, iBegin, iMiddle, iEnd, outputB); // merge two halves copyArray(inputA, iBegin, iEnd, outputB); }
void Image3unorm8::load(const String& filename) { shared_ptr<Image> image = Image::fromFile(filename); if (image->format() != ImageFormat::RGB8()) { image->convertToRGB8(); } switch (image->format()->code) { case ImageFormat::CODE_L8: copyArray(static_cast<const Color1unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height()); break; case ImageFormat::CODE_L32F: copyArray(static_cast<const Color1*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height()); break; case ImageFormat::CODE_RGB8: copyArray(static_cast<const Color3unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height()); break; case ImageFormat::CODE_RGB32F: copyArray(static_cast<const Color3*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height()); break; case ImageFormat::CODE_RGBA8: copyArray(static_cast<const Color4unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height()); break; case ImageFormat::CODE_RGBA32F: copyArray(static_cast<const Color4*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height()); break; default: debugAssertM(false, "Trying to load unsupported image format"); break; } setChanged(true); }
void ivar_put_array( struct ivar iv, struct array *d ) { struct ivar_internals *ivi = iv.internals; log_2("ivar_put_array %p %p - enter\n", &iv, d); pthread_mutex_lock( &(ivi->mutex) ); ivi->data = (void*)malloc( sizeof(struct array) ); initArray( ivi->data, d->elemSize, d->length ); copyArray( ivi->data, d ); ivi->full = 1; pthread_cond_broadcast( &(ivi->cond) ); pthread_mutex_unlock( &(ivi->mutex) ); log_2("ivar_put_array %p %p - leave\n", &iv, d); }