void testCase1() { int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1, -2, -3 }; stdPQ<int> pq1(std::begin(arr), std::end(arr)); tsPQ<int> pq2(std::begin(arr), std::end(arr)); while (!pq1.empty() && !pq2.empty()) { assert(pq1.top() == pq2.top()); pq1.pop(); pq2.pop(); } assert(pq1.empty() && pq2.empty()); }
void TfrmRetrieveMain::createBoxes( const LCDbCryoJob & job, const LPDbBoxType & boxType ) { struct Box { LPDbBoxName record; std::set<int> projects; } current; std::map<short,Box> boxes; short size = boxType.getCapacity(); if( size < 1 ) { size = 100; // assume MVE boxes } // work out which projects each box belong to progress->Position = 0; for( const GridEntry & ge : rows ) { short boxNumber = (ge.new_pos-1) / size; boxes[ boxNumber ].projects.insert( ge.pid ); } for( auto & entry : boxes ) { const std::set<int> & projList = entry.second.projects; int projID = projList.size() == 1 ? *projList.begin() : 0; entry.second.record.setProjectCID( projID ); } // create records in central and project databases LQuery cq( LIMSDatabase::getCentralDb( ) ); for( auto & entry : boxes ) { const std::set<int> & projList = entry.second.projects; auto pi = projList.begin(); LQuery pq1( LIMSDatabase::getProjectDb( *pi ) ); LPDbBoxName & box = entry.second.record; if( !box.create( boxType, job.getBoxSet( ), pq1, cq ) ) { throw Exception( "Cannot create destination box" ); } while( ++pi != projList.end() ) { LQuery pq( LIMSDatabase::getProjectDb( *pi ) ); if( !box.saveRecord( pq, cq ) ) { throw Exception( "Cannot copy destination box" ); } } } // mark the cryovials for removal into the new boxes progress->Max = rows.size( ); StoreDAO dao; for( const GridEntry & ge : rows ) { short boxNumber = (ge.new_pos-1) / size; const LPDbBoxName & box = boxes[ boxNumber ].record; short position = ge.new_pos - (boxNumber * size); LQuery pq( LIMSDatabase::getProjectDb( ge.pid ) ); if( dao.addToRetrieval( job.getID( ), ge.cid, ge.pid, box.getID(), position ) ) { progress->StepIt( ); } else { throw Exception( "Cannot add cryovial(s)" ); } } }
int main() { clock_t start = clock(); int const DELETE_CT = 2; int const PRINTSIZE = 5; int const HOWMANY = 20; // How many values to read from each file. If HOWMANY = 0, read all values. // SkewHeap pq1("SkewHeap PQ1"); // LeftistHeap pq1("Leftist PQ1"); /*PQHeap pq1("Heap PQ1", 6000); PQHeap pq2("Heap PQ2", 6000); PQHeap pq3("Heap PQ3", 6000); PQHeap pq4("Heap PQ4", 6000); PQHeap pq5("Heap PQ5", 6000); PQHeap pq6("Heap PQ6", 6000);*/ SkewHeap pq1("SkewHeap PQ1"); SkewHeap pq2("SkewHeap PQ2"); SkewHeap pq3("SkewHeap PQ3"); SkewHeap pq4("SkewHeap PQ4"); SkewHeap pq5("SkewHeap PQ5"); SkewHeap pq6("SkewHeap PQ6"); /*Leftist pq1("LeftistHeap PQ1"); Leftist pq2("LeftistHeap PQ2"); Leftist pq3("LeftistHeap PQ3"); Leftist pq4("LeftistHeap PQ4"); Leftist pq5("LeftistHeapPQ5"); Leftist pq6("LeftistHeapPQ6");/**/ ifstream fin; fin.open("Prog5In.txt"); assert(fin); insertNext(pq1, fin, HOWMANY); insertNext(pq2, fin, HOWMANY); insertNext(pq3, fin, HOWMANY); insertNext(pq4, fin, HOWMANY); insertNext(pq5, fin, HOWMANY); insertNext(pq6, fin); cout << pq1.toString(PRINTSIZE); ofstream fout; fout.open("prog5out.txt"); cout << pq1.toString(PRINTSIZE); for (int ct = 0; ct < DELETE_CT && !pq1.isEmpty(); ct++){ ItemType big = pq1.deleteMax(); fout << " ** DELETED " << big.toString() << endl; cout << " ** DELETED " << big.toString() << endl; cout << pq1.toString(PRINTSIZE); }; for (int ct = 0; ct < DELETE_CT && !pq2.isEmpty(); ct++) { ItemType big = pq2.deleteMax(); fout << " ** DELETED " << big.toString() << endl; cout << " ** DELETED " << big.toString() << endl; }; cout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl; fout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl; cout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl; fout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl; pq1.merge(&pq2); cout << "After merge \n" << pq1.toString(PRINTSIZE) << endl; fout << "After merge \n" << pq1.toString(PRINTSIZE) << endl; cout << "After merge \n" << pq2.toString(PRINTSIZE) << endl; fout << "After merge \n" << pq2.toString(PRINTSIZE) << endl; pq3.merge(&pq4); cout << "After merge 3 and 4 \n" << pq3.toString(PRINTSIZE) << endl; pq5.merge(&pq6); cout << "After merge 5 and 6 \n" << pq5.toString(PRINTSIZE) << endl; pq1.merge(&pq3); cout << "After merge 1 and 3\n" << pq1.toString(PRINTSIZE) << endl; pq1.merge(&pq5); cout << "After merge 1 and 5\n" << pq1.toString(PRINTSIZE) << endl; clock_t time = clock() - start; cout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl; fout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl; fout.close(); }