本文整理汇总了C++中multimap::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ multimap::empty方法的具体用法?C++ multimap::empty怎么用?C++ multimap::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multimap
的用法示例。
在下文中一共展示了multimap::empty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: timeout_alarm
void timeout_alarm(int) {
cout << "!timeout alarm" << endl;
struct timeval tv;
struct timezone tz;
multimap<long, client_timeout>::iterator i;
long ts;
for (i = timestamp_map.begin(); i != timestamp_map.end();) {
gettimeofday(&tv, &tz); // pobranie aktualnego czasu
ts = tv.tv_sec * 1000 + tv.tv_usec / 1000; // zamiana na ms
if (i->first > ts)
break;
map<int, resource_clients>::iterator j = resource_map.find(
i->second.resource_id);
list<client>::iterator k = find_by_pid(j->second.waiting_clients,
i->second.pid);
j->second.waiting_clients.erase(k); // usuniecie klienta z kolejki oczekujacych
send_response(i->second.pid, TIMEDOUT);
timestamp_map.erase(i++); // usuniecie klienta z kolejki timeout
try_grant(j); // proba przydzielenia zasobu
}
if (!timestamp_map.empty()) {
useconds_t alrm = (i->first - ts) * 1000;
ualarm(alrm, 0);
}
cout << "!end of timeout alarm" << endl;
}
示例2: checkBadDest
int Slave::checkBadDest(multimap<int64_t, Address>& sndspd, vector<Address>& bad)
{
bad.clear();
if (sndspd.empty())
return 0;
int m = sndspd.size() / 2;
multimap<int64_t, Address>::iterator p = sndspd.begin();
for (int i = 0; i < m; ++ i)
++ p;
int64_t median = p->first;
int locpos = 0;
for (multimap<int64_t, Address>::iterator i = sndspd.begin(); i != sndspd.end(); ++ i)
{
if (i->first > (median / 2))
return bad.size();
bad.push_back(i->second);
locpos ++;
}
return bad.size();
}
示例3: manageTickEvent
static void manageTickEvent(color_ostream& out) {
if (!df::global::world)
return;
unordered_set<EventHandler> toRemove;
int32_t tick = df::global::world->frame_counter;
while ( !tickQueue.empty() ) {
if ( tick < (*tickQueue.begin()).first )
break;
EventHandler handle = (*tickQueue.begin()).second;
tickQueue.erase(tickQueue.begin());
handle.eventHandler(out, (void*)tick);
toRemove.insert(handle);
}
if ( toRemove.empty() )
return;
for ( auto a = handlers[EventType::TICK].begin(); a != handlers[EventType::TICK].end(); ) {
EventHandler handle = (*a).second;
if ( toRemove.find(handle) == toRemove.end() ) {
a++;
continue;
}
a = handlers[EventType::TICK].erase(a);
toRemove.erase(handle);
if ( toRemove.empty() )
break;
}
}
示例4: manageTickEvent
static void manageTickEvent(color_ostream& out) {
uint32_t tick = DFHack::World::ReadCurrentYear()*ticksPerYear
+ DFHack::World::ReadCurrentTick();
while ( !tickQueue.empty() ) {
if ( tick < (*tickQueue.begin()).first )
break;
EventHandler handle = (*tickQueue.begin()).second;
tickQueue.erase(tickQueue.begin());
handle.eventHandler(out, (void*)tick);
}
}
示例5: ShortestJobFirst
list < Attivita > ShortestJobFirst ( multimap < int, Attivita > &Activities ){
list < Attivita > A;
multimap< int, Attivita >::iterator it_ActivitiesMap;
if(!Activities.empty()){ // Ci assicuriamo che la mappa sia piena
int N = Activities.size();
for(int turnaround = 1; turnaround<= N; turnaround++){
it_ActivitiesMap = Activities.begin(); // Si posiziona sul primo elemento della mappa
int i = 1;
for ( it_ActivitiesMap = Activities.begin(); i<=turnaround; it_ActivitiesMap++ ){
A.push_back(it_ActivitiesMap->second);
i++;
}
}
}
return(A);
}
示例6: Solver
/**
* Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
*/
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
{
// Templates
static multimap<txnouttype, CScript> mTemplates;
if (mTemplates.empty())
{
// Standard tx, sender provides pubkey, receiver adds signature
mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG));
// Uniqredit address tx, sender provides hash of pubkey, receiver provides signature and pubkey
mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG));
// Sender provides N pubkeys, receivers provides M signatures
mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
}
vSolutionsRet.clear();
// Shortcut for pay-to-script-hash, which are more constrained than the other types:
// it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
if (scriptPubKey.IsPayToScriptHash())
{
typeRet = TX_SCRIPTHASH;
vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
vSolutionsRet.push_back(hashBytes);
return true;
}
// Provably prunable, data-carrying output
//
// So long as script passes the IsUnspendable() test and all but the first
// byte passes the IsPushOnly() test we don't care what exactly is in the
// script.
if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && scriptPubKey.IsPushOnly(scriptPubKey.begin()+1)) {
typeRet = TX_NULL_DATA;
return true;
}
// Scan templates
const CScript& script1 = scriptPubKey;
BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates)
{
const CScript& script2 = tplate.second;
vSolutionsRet.clear();
opcodetype opcode1, opcode2;
vector<unsigned char> vch1, vch2;
// Compare
CScript::const_iterator pc1 = script1.begin();
CScript::const_iterator pc2 = script2.begin();
while (true)
{
if (pc1 == script1.end() && pc2 == script2.end())
{
// Found a match
typeRet = tplate.first;
if (typeRet == TX_MULTISIG)
{
// Additional checks for TX_MULTISIG:
unsigned char m = vSolutionsRet.front()[0];
unsigned char n = vSolutionsRet.back()[0];
if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n)
return false;
}
return true;
}
if (!script1.GetOp(pc1, opcode1, vch1))
break;
if (!script2.GetOp(pc2, opcode2, vch2))
break;
// Template matching opcodes:
if (opcode2 == OP_PUBKEYS)
{
while (vch1.size() >= 33 && vch1.size() <= 65)
{
vSolutionsRet.push_back(vch1);
if (!script1.GetOp(pc1, opcode1, vch1))
break;
}
if (!script2.GetOp(pc2, opcode2, vch2))
break;
// Normal situation is to fall through
// to other if/else statements
}
if (opcode2 == OP_PUBKEY)
{
if (vch1.size() < 33 || vch1.size() > 65)
break;
vSolutionsRet.push_back(vch1);
}
else if (opcode2 == OP_PUBKEYHASH)
{
if (vch1.size() != sizeof(uint160))
break;
//.........这里部分代码省略.........
示例7: main
int main() {
int n;
while(cin >> n >> ws) {
// reset.
vexp.clear();
vvar.clear();
vals.clear();
expr.clear();
vreq.assign(n, set<string>());
vidx.clear();
q.clear();
broken = false;
ans = 0;
result.clear();
// input and calculation.
for(int i = 0; i < n; ++i) {
//cout << "i = " << i << endl;
string s;
getline(cin, s);
int p = s.find(' ');
vvar.push_back(s.substr(0, p));
vexp.push_back(s.substr(p + 3));
//cout << "vvar = |" << vvar[i] << "|" << endl;
//cout << "vexp = |" << vexp[i] << "|" << endl;
// scratch all the reference variables.
// add sentienl to split.
istringstream iss(vexp.back());
string v;
while(iss >> v) {
// if variable gotcha.
if(isalpha(v[0])) {
// initialize variable list
vals[v] = 0;
expr[v] = "";
// add requirement link
vreq[i].insert(v);
// add index link, AVOID repeatly link.
if(vidx[v].size() == 0 || vidx[v].back() != i) {
vidx[v].push_back(i);
}
}
}
// if the value is clear.
if(vreq[i].size() == 0) {
i64 val = eval(vexp.back());
q.insert(make_pair(val, i));
}
}
// proccess
while(!q.empty()) {
// pop from priority queue.
i64 val = q.begin()->first;
int i = q.begin()->second;
q.erase(q.begin());
// get var.
string v = vvar[i];
if(vals[v] == 0) {
result.push_back(i);
vals[v] = val;
expr[v] = vexp[i];
for(int j = 0; j < vidx[v].size(); ++j) {
int k = vidx[v][j];
// kick the link.
vreq[k].erase(v);
//.........这里部分代码省略.........
示例8: solver
/**
* return public keys or hashes from scriptpubkey, for 'standard' transaction types.
*/
bool solver(const cscript& scriptpubkey, txnouttype& typeret, vector<vector<unsigned char> >& vsolutionsret)
{
// templates
static multimap<txnouttype, cscript> mtemplates;
if (mtemplates.empty())
{
// standard tx, sender provides pubkey, receiver adds signature
mtemplates.insert(make_pair(tx_pubkey, cscript() << op_pubkey << op_checksig));
// moorecoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
mtemplates.insert(make_pair(tx_pubkeyhash, cscript() << op_dup << op_hash160 << op_pubkeyhash << op_equalverify << op_checksig));
// sender provides n pubkeys, receivers provides m signatures
mtemplates.insert(make_pair(tx_multisig, cscript() << op_smallinteger << op_pubkeys << op_smallinteger << op_checkmultisig));
// empty, provably prunable, data-carrying output
if (getboolarg("-datacarrier", true))
mtemplates.insert(make_pair(tx_null_data, cscript() << op_return << op_smalldata));
mtemplates.insert(make_pair(tx_null_data, cscript() << op_return));
}
// shortcut for pay-to-script-hash, which are more constrained than the other types:
// it is always op_hash160 20 [20 byte hash] op_equal
if (scriptpubkey.ispaytoscripthash())
{
typeret = tx_scripthash;
vector<unsigned char> hashbytes(scriptpubkey.begin()+2, scriptpubkey.begin()+22);
vsolutionsret.push_back(hashbytes);
return true;
}
// scan templates
const cscript& script1 = scriptpubkey;
boost_foreach(const pairtype(txnouttype, cscript)& tplate, mtemplates)
{
const cscript& script2 = tplate.second;
vsolutionsret.clear();
opcodetype opcode1, opcode2;
vector<unsigned char> vch1, vch2;
// compare
cscript::const_iterator pc1 = script1.begin();
cscript::const_iterator pc2 = script2.begin();
while (true)
{
if (pc1 == script1.end() && pc2 == script2.end())
{
// found a match
typeret = tplate.first;
if (typeret == tx_multisig)
{
// additional checks for tx_multisig:
unsigned char m = vsolutionsret.front()[0];
unsigned char n = vsolutionsret.back()[0];
if (m < 1 || n < 1 || m > n || vsolutionsret.size()-2 != n)
return false;
}
return true;
}
if (!script1.getop(pc1, opcode1, vch1))
break;
if (!script2.getop(pc2, opcode2, vch2))
break;
// template matching opcodes:
if (opcode2 == op_pubkeys)
{
while (vch1.size() >= 33 && vch1.size() <= 65)
{
vsolutionsret.push_back(vch1);
if (!script1.getop(pc1, opcode1, vch1))
break;
}
if (!script2.getop(pc2, opcode2, vch2))
break;
// normal situation is to fall through
// to other if/else statements
}
if (opcode2 == op_pubkey)
{
if (vch1.size() < 33 || vch1.size() > 65)
break;
vsolutionsret.push_back(vch1);
}
else if (opcode2 == op_pubkeyhash)
{
if (vch1.size() != sizeof(uint160))
break;
vsolutionsret.push_back(vch1);
}
else if (opcode2 == op_smallinteger)
{ // single-byte small integer pushed onto vsolutions
if (opcode1 == op_0 ||
(opcode1 >= op_1 && opcode1 <= op_16))
{
//.........这里部分代码省略.........
示例9: filter
void STLRepository::filter( Resources& resources, const multimap< string, Bytes >& inclusive_filters, const multimap< string, Bytes >& exclusive_filters ) const
{
for ( auto resource = resources.begin( ); resource not_eq resources.end( ); )
{
bool failed = true;
for ( const auto filter : exclusive_filters )
{
failed = true;
const auto properties = resource->equal_range( filter.first );
for ( auto property = properties.first; property not_eq properties.second; property++ )
{
if ( property->second == filter.second )
{
failed = false;
break;
}
}
if ( failed )
{
break;
}
}
if ( failed and not exclusive_filters.empty( ) )
{
resource = resources.erase( resource );
continue;
}
if ( inclusive_filters.empty( ) )
{
resource++;
continue;
}
failed = true;
for ( auto filter_iterator = inclusive_filters.begin( ); filter_iterator not_eq inclusive_filters.end( ); filter_iterator++ )
{
failed = true;
const auto properties = resource->equal_range( filter_iterator->first );
const auto filters = inclusive_filters.equal_range( filter_iterator->first );
for ( auto filter = filters.first; filter not_eq filters.second; filter++ )
{
for ( auto property = properties.first; property not_eq properties.second; property++ )
{
if ( property->second == filter->second )
{
failed = false;
break;
}
}
if ( not failed )
{
break;
}
}
if ( failed )
{
break;
}
if ( filters.second not_eq inclusive_filters.end( ) )
{
filter_iterator = filters.second;
}
}
if ( failed )
{
resource = resources.erase( resource );
}
else
{
resource++;
}
}
}
示例10: Solver
/**
* Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
*/
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
{
// Templates
static multimap<txnouttype, CScript> mTemplates;
if (mTemplates.empty())
{
// Standard tx, sender provides pubkey, receiver adds signature
mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG));
// Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG));
// Sender provides N pubkeys, receivers provides M signatures
mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
// Empty, provably prunable, data-carrying output
if (GetBoolArg("-datacarrier", true))
mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN << OP_SMALLDATA));
mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN));
}
// Shortcut for pay-to-script-hash, which are more constrained than the other types:
// it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
if (scriptPubKey.IsPayToScriptHash())
{
typeRet = TX_SCRIPTHASH;
vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
vSolutionsRet.push_back(hashBytes);
return true;
}
if (IsCryptoConditionsEnabled()) {
// Shortcut for pay-to-crypto-condition
CScript ccSubScript = CScript();
std::vector<std::vector<unsigned char>> vParams;
if (scriptPubKey.IsPayToCryptoCondition(&ccSubScript, vParams))
{
if (scriptPubKey.MayAcceptCryptoCondition())
{
typeRet = TX_CRYPTOCONDITION;
vector<unsigned char> hashBytes; uint160 x; int32_t i; uint8_t hash20[20],*ptr;;
x = Hash160(ccSubScript);
memcpy(hash20,&x,20);
hashBytes.resize(20);
ptr = hashBytes.data();
for (i=0; i<20; i++)
ptr[i] = hash20[i];
vSolutionsRet.push_back(hashBytes);
if (vParams.size())
{
COptCCParams cp = COptCCParams(vParams[0]);
if (cp.IsValid())
{
for (auto k : cp.vKeys)
{
vSolutionsRet.push_back(std::vector<unsigned char>(k.begin(), k.end()));
}
}
}
return true;
}
return false;
}
}
// Scan templates
const CScript& script1 = scriptPubKey;
BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates)
{
const CScript& script2 = tplate.second;
vSolutionsRet.clear();
opcodetype opcode1, opcode2;
vector<unsigned char> vch1, vch2;
// Compare
CScript::const_iterator pc1 = script1.begin();
CScript::const_iterator pc2 = script2.begin();
while (true)
{
if (pc1 == script1.end() && pc2 == script2.end())
{
// Found a match
typeRet = tplate.first;
if (typeRet == TX_MULTISIG)
{
// Additional checks for TX_MULTISIG:
unsigned char m = vSolutionsRet.front()[0];
unsigned char n = vSolutionsRet.back()[0];
if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n)
return false;
}
return true;
}
if (!script1.GetOp(pc1, opcode1, vch1))
break;
if (!script2.GetOp(pc2, opcode2, vch2))
//.........这里部分代码省略.........