本文整理汇总了C++中set::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ set::empty方法的具体用法?C++ set::empty怎么用?C++ set::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute_gap_new
bool compute_gap_new(
CodeRegion * cr,
Address addr,
set<Function *,Function::less> const& funcs,
set<Function *,Function::less>::const_iterator & beforeGap,
Address & gapStart,
Address & gapEnd,
bool &reset_iterator)
{
long MIN_GAP_SIZE = 15;
Address lowerBound = cr->offset();
Address upperBound = cr->offset() + cr->length();
if (funcs.empty()) {
if (addr >= upperBound) return false;
gapStart = addr + 1;
if (gapStart < lowerBound) gapStart = lowerBound;
gapEnd = upperBound;
reset_iterator = true;
return true;
} else if (addr < (*funcs.begin())->addr()) {
gapStart = addr + 1;
if (gapStart < lowerBound) gapStart = lowerBound;
gapEnd = (*funcs.begin())->addr();
reset_iterator = true;
return true;
} else {
reset_iterator = false;
set<Function *,Function::less>::const_iterator afterGap(beforeGap);
++afterGap;
while (true) {
gapStart = calc_end(*beforeGap);
if (afterGap == funcs.end() || (*afterGap)->addr() > upperBound)
gapEnd = upperBound;
else
gapEnd = (*afterGap)->addr();
if (addr >= gapEnd || (long)(gapEnd - gapStart) <= MIN_GAP_SIZE) {
if (afterGap == funcs.end()) return false;
beforeGap = afterGap;
++afterGap;
} else {
if (gapStart < addr + 1) gapStart = addr + 1;
break;
}
}
return true;
}
}
示例2: perform_inline
Expr perform_inline(Expr e, const map<string, Function> &env,
const set<string> &inlines,
const vector<string> &order) {
if (inlines.empty()) {
return e;
}
bool funcs_to_inline = false;
Expr inlined_expr = e;
do {
funcs_to_inline = false;
// Find all the function calls in the current expression.
FindAllCalls find;
inlined_expr.accept(&find);
const set<string> &calls_unsorted = find.funcs_called;
vector<string> calls(calls_unsorted.begin(), calls_unsorted.end());
// Sort 'calls' based on the realization order in descending order
// if provided (i.e. last to be realized comes first).
if (!order.empty()) {
std::sort(calls.begin(), calls.end(),
[&order](const string &lhs, const string &rhs){
const auto &iter_lhs = std::find(order.begin(), order.end(), lhs);
const auto &iter_rhs = std::find(order.begin(), order.end(), rhs);
return iter_lhs > iter_rhs;
}
);
}
// Check if any of the calls are in the set of functions to be inlined.
// Inline from the last function to be realized to avoid extra
// inlining works.
for (const auto &call : calls) {
if (inlines.find(call) != inlines.end()) {
Function prod_func = env.at(call);
// Impure functions cannot be inlined.
internal_assert(prod_func.is_pure());
// Inline the function call and set the flag to check for
// further inlining opportunities.
inlined_expr = inline_function(inlined_expr, prod_func);
funcs_to_inline = true;
break;
}
}
} while (funcs_to_inline);
return inlined_expr;
}
示例3: usage
string ProgramOptionsDescription::usage (set<string> help) const {
// footer with info about specific sections
string footer;
// we want all help, therefore use all help sections
bool helpAll = help.find("--HELP-ALL--") != help.end();
help.erase("--HELP-ALL--");
help.erase("--HELP--");
if (help.empty()) {
help.insert("help-default");
}
set<string> ho = helpOptions();
// remove help default
set<string> hd = ho;
hd.erase("help-default");
// add footer
if (helpAll) {
help = ho;
footer = "\nFor specific sections use: " + StringUtils::join(hd, ", ") + " or help";
}
else {
set<string> is;
set_difference(hd.begin(), hd.end(), help.begin(), help.end(), inserter(is, is.end()));
if (! is.empty()) {
footer = "\nFor more information use: " + StringUtils::join(is, ", ") + " or help-all";
}
}
// compute all relevant names
map<string, string> names;
fillAllNames(help, names);
size_t oWidth = 0;
for (auto const& name : names) {
size_t len = name.second.length();
if (oWidth < len) {
oWidth = len;
}
}
return usageString(help, names, oWidth) + footer;
}
示例4: TransformForSql
string TransformForSql(set<Ice::Long>& gids) {
ostringstream result;
if (gids.empty()) {
return result.str();
}
for(set<Ice::Long>::iterator itg = gids.begin(); itg!= gids.end(); ++itg) {
if(itg == gids.begin()) {
result << " ( " << *itg;
}else {
result <<" , " << *itg;
}
}
result << " ) ";
return result.str();
}
示例5: main
int main () {
int n, k, x;
while (scanf("%d", &n) == 1) {
S.clear();
while (n--) {
scanf("%d", &k);
if (k == 1) {
scanf("%d", &x);
S.insert(x);
} else if (k == 2 && !S.empty())
S.erase(S.begin());
else if (k == 3) {
if (S.empty())
printf("0\n");
else {
iter it = S.end();
it--;
printf("%d\n", *it);
}
}
}
}
return 0;
}
示例6:
const set<string>& HSolve::handledClasses()
{
static set<string> classes;
if (classes.empty())
{
classes.insert("CaConc");
classes.insert("ZombieCaConc");
classes.insert("HHChannel");
classes.insert("ZombieHHChannel");
classes.insert("Compartment");
classes.insert("SymCompartment");
classes.insert("ZombieCompartment");
}
return classes;
}
示例7: cal
int cal( int x )
{
if(s.empty())
return 0;
int a,b;
set<int>::iterator it = s.lower_bound(low[x]), itx = it;
if( it == s.end() || it == s.begin())
{
it = s.begin();
itx = s.end();
itx--;
}
else itx--;
return dis[x]-dis[lca(x,dfn[(*it)])]-dis[lca(x,dfn[(*itx)])]+dis[lca(dfn[(*it)],dfn[(*itx)])];
}
示例8: isFloodProne
static
bool isFloodProne(const map<s32, CharReach> &look,
const set<CharReach> &flood_reach) {
if (flood_reach.empty()) {
return false;
}
for (const CharReach &flood_cr : flood_reach) {
if (isFloodProne(look, flood_cr)) {
return true;
}
}
return false;
}
示例9: handle_pending_vertices
static
void handle_pending_vertices(GoughSSAVar *def, const GoughGraph &g,
const GoughGraphAux &aux,
set<GoughVertex> &pending_vertex,
set<const GoughSSAVar *> &rv) {
if (pending_vertex.empty()) {
return;
}
GoughVertex def_v = GoughGraph::null_vertex();
if (contains(aux.containing_v, def)) {
def_v = aux.containing_v.at(def);
}
ue2::unordered_set<GoughVertex> done;
while (!pending_vertex.empty()) {
GoughVertex current = *pending_vertex.begin();
pending_vertex.erase(current);
if (contains(done, current)) {
continue;
}
done.insert(current);
handle_pending_vertex(def_v, g, current, pending_vertex, rv);
}
}
示例10: construct1
void construct1() {
memset(cnt, 0, sizeof cnt);
for (int i = 0; i < m; ++i) {
++cnt[w[i]];
w[i] = -1;
}
fill(d+1, d+n, inf);
d[0] = 0;
st.insert(make_pair(d[0], 0));
int big = K-1;
while (cnt[big] == 0 && big > 0) --big;
while (!st.empty()) {
auto it = st.begin();
int cur = it->second;
st.erase(it);
set<int> pr;
for (int i = 0; i < K; ++i) {
if (cnt[i] <= 0) continue;
if (isPrime[d[cur] + i])
pr.insert(i);
}
for (int i : g[cur]) {
int other = u[i]^v[i]^cur;
if (w[i] == -1) {
while (!pr.empty()) {
auto ix = pr.begin();
if (cnt[*ix] <= 0)
pr.erase(ix);
else {
--cnt[*ix];
w[i] = *ix;
break;
}
}
if (w[i] == -1) {
while (cnt[big] == 0 && big > 0) --big;
w[i] = big;
--cnt[big];
}
}
if (d[other] > d[cur] + w[i]) {
st.erase(make_pair(d[other], other));
d[other] = d[cur] + w[i];
st.insert(make_pair(d[other], other));
}
}
}
}
示例11: produce_some_workers
void codevs_ai::produce_some_workers() { // {{{
constexpr int magic_resource = 170; // MAGIC:
if (100 < turn and not friend_base_ids.empty()) return;
if (magic_resource <= get_next_resource()) {
vector<pair<double,unit_id> > vs;
for (auto id : friend_viladge_ids) {
auto unit = units[id];
if (is_command_issued(id)) continue;
auto p = unit->get_pos();
double potential = 0;
bool idling_worker = false;
bool near_resource_possible = false;
constexpr int r = 30; // MAGIC:
// calculate potential
for (auto d : manhattan_range(r)) {
auto q = p + d;
if (not on_board(q)) continue;
if (next_resource_possible[q.y][q.x]) near_resource_possible = true;
potential += (next_resource_possible[q.y][q.x] ? 1 : -0.1) * 1 /(double) (r - manhattan(d) + 1); // MAGIC:
if (manhattan(d) == 0) {
for (auto it : next_at[p.y][p.x]) {
if (units[it]->kind == kind::worker) {
if (not is_command_issued(it)) {
idling_worker = true; break;
}
}
}
} else if (1 <= manhattan(d) and manhattan(d) <= 20) { // MAGIC:
for (auto it : next_at[q.y][q.x]) {
if (units[it]->kind == kind::worker and not resource_points.count(q)) {
if (not is_command_issued(id)) {
idling_worker = true; break;
}
}
}
}
if (idling_worker) break;
}
if (not idling_worker and near_resource_possible) vs.push_back(make_pair(potential,id));
}
sort(vs.begin(), vs.end());
while (not vs.empty() and magic_resource <= get_next_resource()) { // MAGIC:
unit_id id = vs.back().second;
vs.pop_back();
issue_command(id, command::worker);
}
}
} // }}}
示例12: dijkstra
inline void dijkstra(int src) {
fill(dist, dist + N, INF);
fill(par, par + N, -2);
dist[src] = 0;
par[src] = -1;
S.insert(mp(0, src));
while (!S.empty()) {
int v = S.begin()->second;
S.erase(S.begin());
for (pii edge : list[v])
relax(v, edge.second, edge.first);
}
}
示例13: ASSERT
~ObjectPool()
{
for (typename list<T *>::iterator it = m_pool.begin(); it != m_pool.end(); it++)
{
T * cur = *it;
#ifdef DEBUG
typename set<T *>::iterator its = m_checkerSet.find(cur);
ASSERT(its != m_checkerSet.end(), ("The same element returned twice or more!"));
m_checkerSet.erase(its);
#endif
delete cur;
}
#ifdef DEBUG
ASSERT(m_checkerSet.empty(), ("Alert! Don't all elements returned to pool!"));
#endif
}
示例14: defend
int defend(set<missile> fired, list<missile> mlist){
if(mlist.size() == 0) return 0;
missile m = mlist.front();
mlist.pop_front();
cout<<"m: "<<m.t<<", "<<m.f<<endl;
if(fired.empty()){
fired.insert(m);
int ret = defend(fired, mlist);
cout<<"res: "<<m.t<<", "<<m.f<<" = "<<ret+1<<endl;
return ret+1;
}
else{
set<missile>::iterator it;
for(it = fired.begin(); it != fired.end() && !valid(*it, m) && !same(*it, m); it++);
if(it != fired.end() && valid(*it, m)){
vector<missile> candidate;
for(set<missile>::iterator j = it; j != fired.end(); j++)
if(valid(*j, m)) candidate.push_back(*j);
fired.insert(m);
cout<<"----candidate----"<<endl;
for(vector<missile>::iterator j = candidate.begin(); j != candidate.end(); j++) cout<<j->t<<" : "<<j->f<<endl;
cout<<"----candidate----"<<endl;
int minval = INT_MAX;
for(int k = 0; k < candidate.size(); k++){
missile c = candidate[k];
fired.erase(c);
int val = defend(fired, mlist);
if(minval > val) minval = val;
fired.insert(c);
}
int ret = min(defend(fired, mlist)+1, minval);
cout<<"res: "<<m.t<<", "<<m.f<<" = "<<ret<<endl;
return ret;
}
else {
fired.insert(m);
int ret = defend(fired, mlist);
if(it == fired.end()) ret++;
cout<<"res: "<<m.t<<", "<<m.f<<" = "<<ret<<endl;
return ret;
}
}
}
示例15: move
void MyStrategy::move(const Trooper& self, const World& world,
const Game& game, Move& move) {
clock_t start_clock = clock();
if (empty_map.empty()) {
fill_empty_map(world, empty_map);
}
if (safety_map.empty()) {
init_safety_map(world);
}
if (explore_map.empty()) {
fill_empty_map(world, explore_map);
}
if (team_map.empty()) {
fill_empty_map(world, team_map);
}
update_explore_map(world);
update_team_map(world);
update_enemies(world, self);
if (obstacles.empty()) {
for (int x = 0; x < world.getWidth(); x++) {
for (int y = 0; y < world.getHeight(); y++) {
if (world.getCells().at(x).at(y) != FREE) {
obstacles.insert(Point(x, y));
}
}
}
}
validate_missions();
if (!is_mission_active(self)) {
auto mission = unique_ptr<Mission>(new MissionExplore(world));
assign_mission(self, std::move(mission));
}
evaluate_mission(game, world, self, move);
printf("TIME: %.4f\n", double(clock() - start_clock) / CLOCKS_PER_SEC);
draw_map(world, team_map, world.getTroopers(), self);
}