BOOST_FIXTURE_TEST_CASE_TEMPLATE(decrease_key_test, T, storage_types, RandomDataFixture<10>) { BinaryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(10); for (unsigned idx : order) { heap.Insert(ids[idx], weights[idx], data[idx]); } std::vector<TestNodeID> rids(ids); std::reverse(rids.begin(), rids.end()); for (auto id : rids) { TestNodeID min_id = heap.Min(); TestWeight min_weight = heap.GetKey(min_id); // decrease weight until we reach min weight while (weights[id] > min_weight) { heap.DecreaseKey(id, weights[id]); BOOST_CHECK_EQUAL(heap.Min(), min_id); BOOST_CHECK_EQUAL(heap.MinKey(), min_weight); weights[id]--; } // make weight smaller than min weights[id] -= 2; heap.DecreaseKey(id, weights[id]); BOOST_CHECK_EQUAL(heap.Min(), id); BOOST_CHECK_EQUAL(heap.MinKey(), weights[id]); } }
bool SipccSdpAttributeList::LoadRid(sdp_t* sdp, uint16_t level, SdpErrorHolder& errorHolder) { UniquePtr<SdpRidAttributeList> rids(new SdpRidAttributeList); for (uint16_t i = 1; i < UINT16_MAX; ++i) { const char* ridRaw = sdp_attr_get_simple_string(sdp, SDP_ATTR_RID, level, 0, i); if (!ridRaw) { break; } std::string error; size_t errorPos; if (!rids->PushEntry(ridRaw, &error, &errorPos)) { std::ostringstream fullError; fullError << error << " at column " << errorPos; errorHolder.AddParseError( sdp_attr_line_number(sdp, SDP_ATTR_RID, level, 0, i), fullError.str()); return false; } } if (!rids->mRids.empty()) { SetAttribute(rids.release()); } return true; }
/* static */ void JsepTrack::AddToMsection(const std::vector<JsConstraints>& constraintsList, sdp::Direction direction, SdpMediaSection* msection) { UniquePtr<SdpSimulcastAttribute> simulcast(new SdpSimulcastAttribute); UniquePtr<SdpRidAttributeList> rids(new SdpRidAttributeList); for (const JsConstraints& constraints : constraintsList) { if (!constraints.rid.empty()) { SdpRidAttributeList::Rid rid; rid.id = constraints.rid; rid.direction = direction; rids->mRids.push_back(rid); SdpSimulcastAttribute::Version version; version.choices.push_back(constraints.rid); if (direction == sdp::kSend) { simulcast->sendVersions.push_back(version); } else { simulcast->recvVersions.push_back(version); } } } if (!rids->mRids.empty()) { msection->GetAttributeList().SetAttribute(simulcast.release()); msection->GetAttributeList().SetAttribute(rids.release()); } }
///////////////////////////////////////////////////////////////// // Now test 'get' across nodes. // Normally the 'get' call is invoked by the parser, which expects a // value to come back. Note that the return must be asynchronous: // the parser cannot block since we need to execute MPI polling // operations on either side. ///////////////////////////////////////////////////////////////// void testParGet( Id tnId, vector< Id >& testIds ) { unsigned int myNode = MuMPI::INTRA_COMM().Get_rank(); unsigned int numNodes = MuMPI::INTRA_COMM().Get_size(); Slot parGetSlot = initShellCinfo()->getSlot( "parallel.getSrc" ); char name[20]; string sname; if ( myNode == 0 ) { cout << "\ntesting parallel get" << flush; } else { sprintf( name, "foo%d", myNode * 2 ); sname = name; set< string >( tnId.eref(), "name", sname ); } MuMPI::INTRA_COMM().Barrier(); Eref e = Id::shellId().eref(); Shell* sh = static_cast< Shell* >( e.data() ); vector< unsigned int > rids( numNodes, 0 ); vector< string > ret( numNodes ); unsigned int origSize = sh->freeRidStack_.size(); ASSERT( origSize > 0 , "Stack initialized properly" ); if ( myNode == 0 ) { for ( unsigned int i = 1; i < numNodes; i++ ) { rids[i] = openOffNodeValueRequest< string >( sh, &ret[i], 1 ); ASSERT( sh->freeRidStack_.size() == origSize - i, "stack in use" ); sendTo3< Id, string, unsigned int >( Id::shellId().eref(), parGetSlot, i - 1, testIds[i - 1], "name", rids[i] ); } } // Here we explicitly do what the closeOffNodeValueRequest handles. MuMPI::INTRA_COMM().Barrier(); // Cycle a few times to make sure all data gets back to node 0 for ( unsigned int i = 0; i < 5; i++ ) { pollPostmaster(); MuMPI::INTRA_COMM().Barrier(); } // Now go through to check all values have come back. if ( myNode == 0 ) { ASSERT( sh->freeRidStack_.size() == 1 + origSize - numNodes, "Stack still waiting" ); for ( unsigned int i = 1; i < numNodes; i++ ) { sprintf( name, "foo%d", i * 2 ); sname = name; ASSERT( sh->offNodeData_[ rids[i] ].numPending == 0, "Pending requests cleared" ); ASSERT( sh->offNodeData_[ rids[i] ].data == static_cast< void* >( &ret[i] ), "Pointing to strings" ); ASSERT( ret[ i ] == sname, "All values returned correctly" ); // Clean up the debris sh->offNodeData_[ rids[i] ].data = 0; sh->freeRidStack_.push_back( rids[i] ); } } }