// This one is public so main can use it. void initialize() { instrTable.instructionCount = 0; initializeTable(&symbolTable); initializeTable(&jumpTable); initializeStack(&stack); }
void initializeAllTables(){ initialTable = (MappingTable*) malloc(sizeof(MappingTable)); initializeTable(initialTable); int i; for(i = 0; i < NUMOFSYMBOL; i++){ tables[i] = (MappingTable*) malloc(sizeof(MappingTable)); initializeTable(tables[i]); } }
int main() { HashTable H; H = initializeTable(353); int i; int key; Position P; ////insertKey(1,H); //insertKey(2,H); //insertKey(3,H); ////deleteKey(1,H); //deleteKey(2,H); //deleteKey(3,H); for(i=0; i<100; i++) { key = i; insertKey(key, H); } //deleteKey(100, H); //for(i=99; i>=0; i--) // deleteKey(i, H); P = FindKey(6,H); printf("Index %d is found\n",P); PrintHashTable(H); DestroyTable(H); std::cout<<std::endl; }
int main() { HashTable h; unsigned pos; h = initializeTable(17); if (h == NULL) { return 1; } printf("h->tableSize:%d\n", h->tableSize); insert(18, h); insert(35, h); pos = find(36, h); if (h->theCell[pos].info != Legitimate) { printf("Not found.\n"); } else { printf("found:%d\n", h->theCell[pos].val); } return 0; }
StockManagementWindow::StockManagementWindow(QWidget *parent) : IPartner(parent), ui(new Ui::StockManagementWindow), m_currentPage(0) { ui->setupUi(this); initializeTable(); }
reservationHistoryDialog::reservationHistoryDialog(QWidget *parent, viewParameters *parameters_) : QDialog(parent), ui(new Ui::reservationHistoryDialog), parameters(parameters_) { ui->setupUi(this); initializeTable(); this->setFixedSize(this->width(),this->height()); }
/*Function to run the alogrithm * pref = 1 -> Run swapNext * pref = 2 -> Run swapToFront */ void runAdaptiveReRank(FILE* input, FILE* output, int pref){ unsigned char c; //Call function to initialize the mapping table initializeTable(symbolTable); initializeTable(rankTable); number_of_symbols = 0; c = fgetc(input); while(!feof(input)){ if(pref == 1){ swapNextReRank(output, c); } else if(pref == 2){ swapToFrontReRank(output, c); } c = fgetc(input); } }
// creates an environment. Environment *createFrame(Environment *parent){ Environment *frame = (Environment *)malloc(sizeof(Environment)); frame->parent = parent; HashTable *table = initializeTable(32); Value *value = (Value *)malloc(sizeof(Value)); value->type = tableType; value->tableValue = table; frame->bindings = value; return frame; }
int main() { tableType mytable; printf("Initializing table\n"); initializeTable(&mytable); printf("Storing 3 into A\n"); store(&mytable, "A", 3); printf("Storing 4 into B\n"); store(&mytable, "B", 4); printf("Storing 5 into C\n"); store(&mytable, "C", 5); printf("Retrieving A..."); int x = retrieve(&mytable, "A"); if (x == 3) printf("success\n"); else printf("********** ERROR\n"); printf("Retrieving B..."); x = retrieve(&mytable, "B"); if (x == 4) printf("success\n"); else printf("********** ERROR\n"); printf("Retrieving C..."); x = retrieve(&mytable, "C"); if (x == 5) printf("success\n"); else printf("********** ERROR\n"); printf("Retrieving B..."); x = retrieve(&mytable, "B"); if (x == 4) printf("success\n"); else printf("********** ERROR\n"); printf("Storing 24 into B\n"); store(&mytable, "B", 24); printf("Retrieving B..."); x = retrieve(&mytable, "B"); if (x == 24) printf("success\n"); else printf("********** ERROR\n"); printf("Printing table...\n"); printTable(&mytable); }
//rehash all elements from one table to another using reHash function defined above int actualRehash(HashTable *h){ //rehash every element of the table SizeOfTable = SizeOfTable * 2; HashTable newHash; initializeTable(&newHash); for (int i = 2; i < SizeOfTable/2; i++){ reHash(h,&newHash,i); } destroyHashTable(h); //destroy the old table (*h) = newHash; return 0; }
Value *deepCopyTable(Value * value){ assert(value!=NULL); assert(value->type==tableType); int i; Value *returnValue = (Value *)malloc(sizeof(Value)); returnValue->type = tableType; returnValue->tableValue = initializeTable(value->tableValue->capacity); for (i=0;i<value->tableValue->capacity;i++){ if ((value->tableValue->entries)[i].car){ if (((value->tableValue->entries)[i].car)->type == symbolType){ insertItem(returnValue->tableValue, ((value->tableValue->entries)[i].car)->symbolValue, (value->tableValue->entries)[i].cdr); } } } return returnValue; }
int main() { Student table[SIZE]; int ch; int flag = 1; initializeTable(table); do { printf("\n 1. Add Record "); printf("\n 2. Modify Record "); printf("\n 3. Delete Record "); printf("\n 4. Search Record "); printf("\n 5. View All Record "); printf("\n 6. Exit "); printf("\n Enter Choice "); scanf("%d", &ch); switch(ch) { case 1: //add record addRecord(table); break; case 2: //modify record modify(table); break; case 3: //delete record deleteRecord(table); break; case 4: //search record search(table); break; case 5: //view all records viewAll(table); break; case 6: //exit flag = 0; break; default: printf("\n Wrong choice "); break; }//switch }while(flag == 1); return 0; }
// Project Entry Point // main // no parameters taken // expects input via STDIN (redirect or direct entry) // input shall conform to 3 integers per line, spaced with whitespace void main() { ProcessTable pTable; initializeTable(&pTable); //int j; //for (j=0; j<pTable.size; j++) // printf("PID: %d\n", pTable.pid[j]); // do fcfs FirstCome(pTable); // do shortest job ShortestJob(pTable); // do shortest remaining job ShortestRemaining(pTable); // do round robin RoundRobin(pTable, 0); RoundRobin(pTable, 0.4); }
int main (int argc, char **argv) { if (argc != 3) { std::cerr << "usage: " << argv[0] << " input-source output-llvm\n"; return 1; } char *sourceFileName = argv[1]; char *destFileName = argv[2]; std::ifstream src (sourceFileName); if (!src.good()) { std::cerr << sourceFileName << ": " << strerror(errno) << "\n"; return 1; } std::ofstream dest (destFileName); if (!dest.good()) { std::cerr << destFileName << ": " << strerror(errno) << "\n"; return 1; } emitDeclarations(dest); emitMainFunctionProlog(dest); initializeTable(); char ch, lastCh; src >> lastCh; int repeatCount = 1; for (src >> ch; !src.eof (); src >> ch, ++repeatCount) if (ch != lastCh) { consume (lastCh, repeatCount, dest); lastCh = ch; repeatCount = 0; } consume (lastCh, repeatCount, dest); emitMainFunctionEpilog(dest); src.close(); dest.close(); return 0; }
/* Auto doubling the hash table if the size of the hash table reaches 2/3 of the capacity, where 2/3 is the load factor. */ int autoDouble(HashTable* table){ //assert(1==2); if (table){ int oldCapacity = table->capacity; int i; HashTable* newTable = initializeTable(table->capacity*2); for (i=0;i<oldCapacity;i++){ if ((table->entries)[i].car){ if (((table->entries)[i].car)->type == symbolType){ insertItem(newTable, ((table->entries)[i].car)->symbolValue, (table->entries)[i].cdr); } } } cleanupTable(table); table->entries = newTable->entries; free(newTable); return 1; }else{ return 0; } }
LoginWindow::LoginWindow(QWidget *parent, QTranslator *pTranslator, QTimer *pInactivityTimer, const CentralWidgetCallback &callback) : IPartner(parent), ui(new Ui::LoginWindow), m_currentPage(0), m_password(), m_username(-1), m_pTranslator(pTranslator), m_pInactivityTimer(pInactivityTimer), m_switchCentralWidgetCallback(callback) { ui->setupUi(this); initializeTable(); // load code build QFile versionFile(":VERSION"); versionFile.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream versionStream(&versionFile); versionStream.setCodec("UTF-8"); QString versionStr = versionStream.readAll(); this->ui->versionLabel->setText(QString("code build %1").arg(versionStr)); // connect QTimer timeout event this->connect(m_pInactivityTimer, &QTimer::timeout, std::bind(&LoginWindow::onInactivityTimeout, this)); }
hashTree::hashTree(const char * fileName): root(nullptr), table(nullptr) { initializeTable(); ifstream inFile; data vendor; char tempName[100]; char tempPhone[100]; char tempProduct[100]; char tempEvents[100]; inFile.open(fileName); if(!inFile) { cerr << "Unable to open \"" << fileName << "\"" << endl; exit(2); } inFile.get(tempName, 100, ';'); while(!inFile.eof()) { inFile.ignore(100, ';'); inFile.get(tempPhone, 100, ';'); inFile.ignore(100, ';'); inFile.get(tempProduct, 100, ';'); inFile.ignore(100, ';'); inFile.get(tempEvents, 100, '\n'); inFile.ignore(100, '\n'); vendor.setName(tempName); vendor.setPhone(tempPhone); vendor.setProduct(tempProduct); vendor.setEvents(tempEvents); add(vendor); inFile.get(tempName, 100, ';'); } }
MHLabelsStore::MHLabelsStore(const char* storeName, const char* storePath, int funambolSavedVersionNumber, int funambolCurrentVersionNumber, bool init) : MHStore(storeName, storePath) { if (init) { if (store_status == store_status_not_initialized) { initializeStaticQueries(); // db file was just created: init table LOG.debug("%s: initializing table for store %s", __FUNCTION__, store_name.c_str()); if (!initializeTable()) { LOG.debug("%s: initializing store %s for db: %s", __FUNCTION__, store_name.c_str(), sqlite3_errmsg(db)); } // ignoring error in initialize_table (can't catch the 'error already exist') store_status = store_status_initialized; if (funambolSavedVersionNumber != funambolCurrentVersionNumber) { //upgrade(funambolSavedVersionNumber, funambolCurrentVersionNumber); } } } }
TabulatedKernel<ndim>::TabulatedKernel(string KernelName, int resaux): SphKernel<ndim>() { res = resaux; kernel = SphKernel<ndim>::KernelFactory (KernelName); this->kernrange = kernel->kernrange; this->kernrangesqd = kernel->kernrangesqd; this->invkernrange = kernel->invkernrange; resinvkernrange = res/this->kernrange; resinvkernrangesqd = res/this->kernrangesqd; this->kernnorm = kernel->kernnorm; // Allocate memory tableW0 = new FLOAT[res]; tableW1 = new FLOAT[res]; tableWomega = new FLOAT[res]; tableWzeta = new FLOAT[res]; tableWgrav = new FLOAT[res]; tableWpot = new FLOAT[res]; tableW0_s2 = new FLOAT[res]; tableWomega_s2 = new FLOAT[res]; tableWzeta_s2 = new FLOAT[res]; tableLOS = new FLOAT[res]; // Initialize the tables initializeTable(tableW0,&SphKernel<ndim>::w0); initializeTable(tableW1,&SphKernel<ndim>::w1); initializeTable(tableWomega,&SphKernel<ndim>::womega); initializeTable(tableWzeta,&SphKernel<ndim>::wzeta); initializeTable(tableWgrav,&SphKernel<ndim>::wgrav); initializeTable(tableWpot,&SphKernel<ndim>::wpot); initializeTableSqd(tableW0_s2,&SphKernel<ndim>::w0); initializeTableSqd(tableWomega_s2,&SphKernel<ndim>::womega); initializeTableSqd(tableWzeta_s2,&SphKernel<ndim>::wzeta); initializeTableLOS(); // Delete kernel object now that we don't need it anymore delete kernel; }
int user_db::initializeDb( const std::string& db_path ) { int ret = m_db.initialize_db(db_path); ret = initializeTable(); return ret; }
void decompressLZW(byte *compressed, byte *uncompressed, int *outSize, int maxOutSize) { *outSize = -1; if (maxOutSize < 16) return; int32_t inSize = 0; memcpy(&inSize, compressed, sizeof(int32_t)); int maxCharInInput = compressed[4]; if (maxCharInInput == 0) maxCharInInput = 256; int bitPos = 40; int outPos = 0; LZWStruct *table = typed_malloc(LZWStruct, MAX_LZW_TABLE_SIZE); initializeTable(table); int current, last = -1; int currentTableSize = maxCharInInput + 1; int currentBitWidth = 1; while ((1 << currentBitWidth) < currentTableSize) currentBitWidth++; while (bitPos < inSize) { if ((1 << currentBitWidth) < currentTableSize + 1) { currentBitWidth++; if (currentBitWidth > MAX_LZW_BITLENGTH) { initializeTable(table); currentTableSize = maxCharInInput + 1; currentBitWidth = 1; while ((1 << currentBitWidth) < currentTableSize) currentBitWidth++; last = -1; } } READ_N_BITS(current, currentBitWidth, compressed, bitPos); bitPos += currentBitWidth; assert(current <= currentTableSize); int newPos, length = 0; if (current == currentTableSize) { assert(last >= 0); for (int cur = last; cur >= 0; cur = table[cur].parent) length++; if (outPos + length >= maxOutSize) { free(table); return; } newPos = outPos + length + 1; for (int cur = last; cur >= 0; cur = table[cur].parent) uncompressed[outPos + (--length)] = table[cur].content; uncompressed[newPos - 1] = uncompressed[outPos]; } else { for (int cur = current; cur >= 0; cur = table[cur].parent) length++; if (outPos + length > maxOutSize) { free(table); return; } newPos = outPos + length; for (int cur = current; cur >= 0; cur = table[cur].parent) uncompressed[outPos + (--length)] = table[cur].content; } int16_t c = uncompressed[outPos]; outPos = newPos; if (last >= 0) { currentTableSize++; while ((1 << currentBitWidth) < currentTableSize) currentBitWidth++; table[currentTableSize - 1].content = c; table[currentTableSize - 1].parent = last; table[currentTableSize - 1].firstChild = -1; table[currentTableSize - 1].nextSibling = table[last].firstChild; table[last].firstChild = currentTableSize - 1; } last = current; } // end while (bitPos < inSize) free(table); *outSize = outPos; } // end of decompressLZW(...)
void compressLZW(byte *uncompressed, byte *compressed, int inSize, int *outSize, int maxOutSize) { *outSize = -1; if (maxOutSize < 16) return; int maxCharInInput = 0; for (int i = 0; i < inSize; i++) if (uncompressed[i] > maxCharInInput) maxCharInInput = uncompressed[i]; if (maxCharInInput > 250) maxCharInInput = 256; LZWStruct *table = typed_malloc(LZWStruct, MAX_LZW_TABLE_SIZE); initializeTable(table); int current = -1; int currentTableSize = maxCharInInput + 1; int currentBitWidth = 1; while ((1 << currentBitWidth) < currentTableSize) currentBitWidth++; int32_t inPos = 0; int32_t bitPos = 40; maxOutSize *= 8; while (inPos < inSize) { if (bitPos + MAX_LZW_BITLENGTH >= maxOutSize) { free(table); return; } if (current < 0) current = uncompressed[inPos++]; else { int16_t c = uncompressed[inPos++]; int child = table[current].firstChild; while (child >= 0) { if (table[child].content == c) break; child = table[child].nextSibling; } if (child >= 0) current = child; else { WRITE_N_BITS(current, currentBitWidth, compressed, bitPos); bitPos += currentBitWidth; currentTableSize++; if ((1 << currentBitWidth) < currentTableSize) { currentBitWidth++; if (currentBitWidth > MAX_LZW_BITLENGTH) { initializeTable(table); currentTableSize = maxCharInInput + 1; currentBitWidth = 1; while ((1 << currentBitWidth) < currentTableSize) currentBitWidth++; current = c; continue; } } table[currentTableSize - 1].content = c; table[currentTableSize - 1].parent = current; table[currentTableSize - 1].firstChild = -1; table[currentTableSize - 1].nextSibling = table[current].firstChild; table[current].firstChild = currentTableSize - 1; current = c; } } } free(table); if (current >= 0) { if (bitPos + MAX_LZW_BITLENGTH >= maxOutSize) return; WRITE_N_BITS(current, currentBitWidth, compressed, bitPos); bitPos += currentBitWidth; } memcpy(compressed, &bitPos, sizeof(bitPos)); compressed[4] = maxCharInInput & 0xFF; *outSize = (bitPos + 7) / 8; } // end of compressLZW(...)
void SelectSiteDialog::setImportedSites(QList<QSharedPointer<Site> > &sites) { importedSites = sites; initializeTable(); }
availableRoomsWindow::availableRoomsWindow(QWidget *parent, viewParameters *parameters_) : QMainWindow(parent), ui(new Ui::availableRoomsWindow), parameters(parameters_) { ui->setupUi(this); setGeometry( QStyle::alignedRect( Qt::LeftToRight, Qt::AlignCenter, size(), qApp->desktop()->availableGeometry() ) ); initializeTable(); configureInputs(); updateBookButton(); this->setFixedSize(this->width(),this->height()); bookingDlg = new bookingDialog(this, parameters); loginDlg = new loginDialog(this, parameters); reservationsDlg = new reservationsDialog(this, parameters); roomsDlg = new roomsDialog(this, parameters); reservationHistoryDlg = new reservationHistoryDialog(this, parameters); staffDlg = new staffDialog(this, parameters); login(); connect( ui->tableView->selectionModel(), SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ), this, SLOT( selectionChanged( const QItemSelection&, const QItemSelection&) ) ); connect( parameters->availableRoomsMdl, SIGNAL( dataChanged(QModelIndex,QModelIndex) ), this, SLOT( updateBookButton() ) ); connect( parameters->availableRoomsMdl, SIGNAL( dataChanged(QModelIndex,QModelIndex) ), this, SLOT( updateMaxGuestNumber() ) ); connect( ui->actionManage_reservations, SIGNAL( triggered() ), this, SLOT( manageReservationsTriggered() ) ); connect( ui->actionEdit_users__data, SIGNAL( triggered() ), this, SLOT( editUsersDataTriggered() ) ); connect( ui->actionLog_Out, SIGNAL( triggered() ), this, SLOT( login() ) ); connect( ui->actionEdit_rooms_data, SIGNAL( triggered() ), this, SLOT( showRoomsDialog() ) ); connect( ui->actionReservations_history, SIGNAL( triggered() ), this, SLOT( showReservationHistoryDialog() ) ); connect( ui->actionEdit_users__data, SIGNAL( triggered() ), this, SLOT( showStaffDialog() ) ); }
hashTable::hashTable(){ capacity = DEFAULT_CAPACITY; initializeTable(); return; }