本文整理汇总了C++中set::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ set::clear方法的具体用法?C++ set::clear怎么用?C++ set::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void WED_Select::GetSelectionSet(set<ISelectable *>& sel) const
{
sel.clear();
for (set<int>::const_iterator i = mSelected.begin(); i != mSelected.end(); ++i)
sel.insert(FetchPeer(*i));
}
示例2: CreatePosTx
bool CreatePosTx(const CBlockIndex *pPrevIndex, CBlock *pBlock, set<CKeyID>&setCreateKey, CAccountViewCache &view,
CTransactionDBCache &txCache, CScriptDBViewCache &scriptCache) {
set<CKeyID> setKeyID;
setKeyID.clear();
set<CAccount, CAccountComparator> setAcctInfo;
{
LOCK2(cs_main, pwalletMain->cs_wallet);
if((unsigned int)(chainActive.Tip()->nHeight + 1) != pBlock->GetHeight())
return false;
pwalletMain->GetKeys(setKeyID, true); // first:get keyID from pwalletMain
if (setKeyID.empty()) {
return ERRORMSG("CreatePosTx setKeyID empty");
}
LogPrint("INFO","CreatePosTx block time:%d\n", pBlock->GetTime());
for(const auto &keyid:setKeyID) { //second:get account by keyID
//find CAccount info by keyid
if(setCreateKey.size()) {
bool bfind = false;
for(auto &item: setCreateKey){
if(item == keyid){
bfind = true;
break;
}
}
if (!bfind)
continue;
}
CUserID userId = keyid;
CAccount acctInfo;
if (view.GetAccount(userId, acctInfo)) { // check acctInfo is or not allowed to mining ,
//available
// LogPrint("miner", "account info:regid=%s keyid=%s ncoinday=%lld isMiner=%d\n", acctInfo.regID.ToString(),
// acctInfo.keyID.ToString(), acctInfo.GetAccountPos(pBlock->nHeight), acctInfo.IsMiner(pBlock->nHeight));
if (acctInfo.IsRegister() && acctInfo.GetAccountPos(pBlock->GetHeight()) > 0 && acctInfo.IsMiner(pBlock->GetHeight())) {
setAcctInfo.insert(std::move(acctInfo));
// LogPrint("miner", "miner account info:%s\n", acctInfo.ToString());
}
}
}
}
if (setAcctInfo.empty()) {
setCreateKey.clear();
LogPrint("INFO", "CreatePosTx setSecureAcc empty");
return false;
}
uint64_t maxNonce = SysCfg().GetBlockMaxNonce(); //cacul times
uint256 prevblockhash = pPrevIndex->GetBlockHash();
const uint256 targetHash = CBigNum().SetCompact(pBlock->GetBits()).getuint256(); //target hash difficult
set<CAccount, CAccountComparator>::iterator iterAcct = setAcctInfo.begin();
for (;iterAcct!=setAcctInfo.end();++iterAcct) { //third: 根据不同的账户 ,去计算挖矿
CAccount &item = const_cast<CAccount&>(*iterAcct);
uint64_t posacc = item.GetAccountPos(pBlock->GetHeight());
if (0 == posacc) { //have no pos
LogPrint("ERROR", "CreatePosTx posacc zero\n");
continue;
}
LogPrint("miner", "miner account:%s\n", item.ToString());
// LogPrint("INFO", "target hash:%s\n", targetHash.ToString());
// LogPrint("INFO", "posacc:%d\n", posacc);
uint256 adjusthash = GetAdjustHash(targetHash, posacc, pBlock->GetHeight()-1); //adjust nbits
// LogPrint("INFO", "adjusthash:%s\n", adjusthash.ToString());
//need compute this block proofofwork
struct PosTxInfo postxinfo;
postxinfo.nVersion = pBlock->GetVersion();
postxinfo.hashPrevBlock = prevblockhash;
postxinfo.hashMerkleRoot = item.GetHash();
postxinfo.nValues = item.llValues;
postxinfo.nHeight = pBlock->GetHeight();
postxinfo.nFuel = pBlock->GetFuel();
postxinfo.nFuelRate = pBlock->GetFuelRate();
postxinfo.nTime = pBlock->GetTime(); //max(pPrevIndex->GetMedianTimePast() + 1, GetAdjustedTime());
unsigned int nNonce = 0;
for (; nNonce < maxNonce; ++nNonce) { //循环的 更改随机数,计算curhash看是否满足
postxinfo.nNonce = nNonce;
pBlock->SetNonce(nNonce);
uint256 curhash = postxinfo.GetHash();
if (UintToArith256(curhash) <= UintToArith256(adjusthash)) {
CRegID regid;
if (pAccountViewTip->GetRegId(item.keyID, regid)) {
CRewardTransaction *prtx = (CRewardTransaction *) pBlock->vptx[0].get();
prtx->account = regid; //存矿工的 账户ID
prtx->nHeight = pPrevIndex->nHeight+1;
pBlock->SetHashMerkleRoot(pBlock->BuildMerkleTree());
pBlock->SetHashPos(curhash);
LogPrint("INFO", "find pos tx hash succeed: \n"
" pos hash:%s \n"
"adjust hash:%s \r\n", curhash.GetHex(), adjusthash.GetHex());
vector<unsigned char> vSign;
if (pwalletMain->Sign(item.keyID, pBlock->SignatureHash(), vSign,
//.........这里部分代码省略.........
示例3: drillDown
//.........这里部分代码省略.........
ns += _db;
}
else {
string dir = root.branch_path().string();
if ( dir.find( "/" ) == string::npos )
ns += dir;
else
ns += dir.substr( dir.find_last_of( "/" ) + 1 );
if ( ns.size() == 0 )
ns = "test";
}
verify( ns.size() );
string oldCollName = root.leaf(); // Name of the collection that was dumped from
oldCollName = oldCollName.substr( 0 , oldCollName.find_last_of( "." ) );
if (use_coll) {
ns += "." + _coll;
}
else {
ns += "." + oldCollName;
}
if (oplogReplayLimit) {
error() << "The oplogLimit option cannot be used if "
<< "normal databases/collections exist in the dump directory."
<< endl;
exit(EXIT_FAILURE);
}
log() << "\tgoing into namespace [" << ns << "]" << endl;
if ( _drop ) {
if (root.leaf() != "system.users.bson" ) {
log() << "\t dropping" << endl;
conn().dropCollection( ns );
} else {
// Create map of the users currently in the DB
BSONObj fields = BSON("user" << 1);
scoped_ptr<DBClientCursor> cursor(conn().query(ns, Query(), 0, 0, &fields));
while (cursor->more()) {
BSONObj user = cursor->next();
_users.insert(user["user"].String());
}
}
}
BSONObj metadataObject;
if (_restoreOptions || _restoreIndexes) {
boost::filesystem::path metadataFile = (root.branch_path() / (oldCollName + ".metadata.json"));
if (!boost::filesystem::exists(metadataFile.string())) {
// This is fine because dumps from before 2.1 won't have a metadata file, just print a warning.
// System collections shouldn't have metadata so don't warn if that file is missing.
if (!startsWith(metadataFile.leaf(), "system.")) {
log() << metadataFile.string() << " not found. Skipping." << endl;
}
} else {
metadataObject = parseMetadataFile(metadataFile.string());
}
}
_curns = ns.c_str();
_curdb = NamespaceString(_curns).db;
_curcoll = NamespaceString(_curns).coll;
// If drop is not used, warn if the collection exists.
if (!_drop) {
scoped_ptr<DBClientCursor> cursor(conn().query(_curdb + ".system.namespaces",
Query(BSON("name" << ns))));
if (cursor->more()) {
// collection already exists show warning
warning() << "Restoring to " << ns << " without dropping. Restored data "
"will be inserted without raising errors; check your server log"
<< endl;
}
}
if (_restoreOptions && metadataObject.hasField("options")) {
// Try to create collection with given options
createCollectionWithOptions(metadataObject["options"].Obj());
}
processFile( root );
if (_drop && root.leaf() == "system.users.bson") {
// Delete any users that used to exist but weren't in the dump file
for (set<string>::iterator it = _users.begin(); it != _users.end(); ++it) {
BSONObj userMatch = BSON("user" << *it);
conn().remove(ns, Query(userMatch));
}
_users.clear();
}
if (_restoreIndexes && metadataObject.hasField("indexes")) {
vector<BSONElement> indexes = metadataObject["indexes"].Array();
for (vector<BSONElement>::iterator it = indexes.begin(); it != indexes.end(); ++it) {
createIndex((*it).Obj(), false);
}
}
}
示例4: ask
int ask(int s, int t)
{
st.clear();
dfs(s, t, 0ll);
return st.size();
}
示例5: getLegNStart
void ClassConfigInfo::getLegNStart(int leg, set<int> &sel) const {
if (size_t(leg) < legNStart.size() && !legNStart[leg].empty())
sel.insert(legNStart[leg].begin(), legNStart[leg].end());
else
sel.clear();
}
示例6: main
int main ()
{
#ifdef hasibpc
read("input.txt");
//write("output.txt");
#endif // hasibpc
int kases;
ll A, B, C;
sf("%d", &kases);
while(kases--)
{
sf("%d", &N);
v.clear();
s.clear();
loop(i, N)
{
sf("%lld %lld %lld", &A, &B, &C);
if( B == 0 )
{
ll g = __gcd(A, C);
//vdump(A);
//vdump(C);
//vdump(g);
s.insert(MP(A/g, C/g));
}
else
{
ll g1 = __gcd(A, B);
ll g2 = __gcd(C, B);
//vdump(g2);
v.pb(MP(MP(A/g1, B/g1), MP(C/g2, B/g2)) );
}
}
sort(all(v));
//vdump(v);
int mxCnt = SZ(s);
int tmpCnt = 0;
loop(i, SZ(v))
{
if(i == 0)
{
tmpCnt = 1;
}
else
{
if(v[i].fr == v[i-1].fr)
{
if(v[i].sc != v[i-1].sc)
{
tmpCnt++;
}
}
else
{
mxCnt = max(mxCnt, tmpCnt);
tmpCnt = 1;
}
}
}
mxCnt = max(mxCnt, tmpCnt);
pf("%d\n", mxCnt);
}
示例7: GC
GC() {
frame_list.push_front(&frame);
heap_list.clear();
heap_num = 0;
heap_max = 8;
}
示例8: solve
void solve() {
nodes.clear();
for (int i = 1; i <= n; i++) color[i] = plain;
dfs(1);
}
示例9: init
void init()
{
memset(node,'\0',sizeof(node));
memset(order,'\0',sizeof(order));
set_result.clear();
}
示例10: init_lookup_table
void init_lookup_table() { vis.clear(); }
示例11: subPathes
void myGraph::subPathes(set<int> &preNodeSet, vector<vector<int>> &Edge_t, set<int>& nodeSet, vector<int> &nodeRanks)
{
float maxlength=-100000;
int maxid=-1;
vector<vector<vector<int>>> maxPath;
bool haveHead=false;
set<int> headSet, endSet;
for(int i=0; i<Edge_t.size(); i++)
{
headSet.insert(Edge_t[i][0]); endSet.insert(Edge_t[i][1]);
}
for(set<int>::iterator it=nodeSet.begin(); it!=nodeSet.end(); it++)
{
int start=*it;
if(headSet.find(start)!=headSet.end() && endSet.find(start)==endSet.end()) //a top node
{
int length;
vector<vector<vector<int>>> path = getShortestPath(start, length, Edge_t); //edgeSet, nodeSet);
if(length > maxlength)
{
maxlength = length;
maxid = start;
maxPath=path;
}
haveHead=true;
}
}
if(!haveHead)
for(set<int>::iterator it=nodeSet.begin(); it!=nodeSet.end(); it++)
{
int start=*it;
{
int length;
vector<vector<vector<int>>> path = getShortestPath(start, length, Edge_t); //edgeSet[sid], nodeSet);
if(length > maxlength)
{
maxlength = length;
maxid = start;
maxPath=path;
}
haveHead=true;
}
}
//initial rank
//get the rank by redo the shortest path search for the minimal span tree
//Graph initG;
vector<vector<int>> Edge_i=maxPath[0];
for(int k=0; k<Edge_i.size(); k++)
{
//if(Edge[k][0]==etemp[0] || Edge[k][1]==etemp[1])
//add_edge(maxPath[k][0], maxPath[k][1], 1, initG);
Edge_i[k].push_back(1);
}
int length;
vector<vector<vector<int>>> initPath = getShortestPath(maxid, length, Edge_i);//, edgeSet[sid], nodeSet);
//iniPath should have rank info
vector<int> nodeRanks_t(nodeRanks.size(),20000);
nodeRanks_t[maxid]=0;
for(int k=0; k<initPath[0].size(); k++)
{
int v=initPath[0][k][1], d=initPath[0][k][initPath[0][k].size()-1];
nodeRanks_t[v]=d;
}
if(initPath[0].size()!=Edge_i.size())
{
//error
}
//reduce the searched graph
Edge_t=maxPath[1];
for(int i=0; i<maxPath[0].size(); i++)
{
preNodeSet.insert(maxPath[0][i][0]); preNodeSet.insert(maxPath[0][i][1]);
}
if(preNodeSet.size()==nodeSet.size())
{
nodeSet.clear();
}
else
{
for(int i=0; i<Edge_t.size(); i++)
{
nodeSet.insert(Edge_t[i][0]); nodeSet.insert(Edge_t[i][1]);
}
}
//reassign rank level to nodeRanks_t
int markid=-1, markLevel=20000, dL=20000;
for(int i=0; i<nodeRanks_t.size(); i++)
{
if(nodeRanks_t[i]!=20000 && nodeRanks[i]!=20000 && nodeRanks_t[i]!=nodeRanks[i])
{
markid=i;
dL = nodeRanks[i]-nodeRanks_t[i];
markLevel=nodeRanks_t[i];
}
}
if(markid>=0)
for(int i=0; i<nodeRanks_t.size(); i++)
//.........这里部分代码省略.........
示例12: GetTriangles
//----------------------------------------------------------------------------
void VETMesh::GetTriangles (set<Triangle>& rkTSet) const
{
rkTSet.clear();
for (MTCIter pkT = m_kTMap.begin(); pkT != m_kTMap.end(); pkT++)
rkTSet.insert(pkT->first);
}
示例13: GetEdges
//----------------------------------------------------------------------------
void VETMesh::GetEdges (set<Edge>& rkESet) const
{
rkESet.clear();
for (MECIter pkE = m_kEMap.begin(); pkE != m_kEMap.end(); pkE++)
rkESet.insert(pkE->first);
}
示例14: GetVertices
//----------------------------------------------------------------------------
void VETMesh::GetVertices (set<int>& rkVSet) const
{
rkVSet.clear();
for (MVCIter pkV = m_kVMap.begin(); pkV != m_kVMap.end(); pkV++)
rkVSet.insert(pkV->first);
}
示例15: get
set<Func> get(Func func) {
funcs.clear();
func.accept(this);
return funcs;
}