本文整理汇总了C++中std::unordered_set类的典型用法代码示例。如果您正苦于以下问题:C++ unordered_set类的具体用法?C++ unordered_set怎么用?C++ unordered_set使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了unordered_set类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solve
box naive_icp::solve(box b, contractor & ctc, SMTConfig & config) {
thread_local static std::unordered_set<std::shared_ptr<constraint>> used_constraints;
used_constraints.clear();
thread_local static vector<box> solns;
thread_local static vector<box> box_stack;
solns.clear();
box_stack.clear();
box_stack.push_back(b);
do {
DREAL_LOG_INFO << "naive_icp::solve - loop"
<< "\t" << "box stack Size = " << box_stack.size();
b = box_stack.back();
box_stack.pop_back();
try {
ctc.prune(b, config);
auto this_used_constraints = ctc.used_constraints();
used_constraints.insert(this_used_constraints.begin(), this_used_constraints.end());
if (config.nra_use_stat) { config.nra_stat.increase_prune(); }
} catch (contractor_exception & e) {
// Do nothing
}
if (!b.is_empty()) {
tuple<int, box, box> splits = b.bisect(config.nra_precision);
if (config.nra_use_stat) { config.nra_stat.increase_branch(); }
int const i = get<0>(splits);
if (i >= 0) {
box const & first = get<1>(splits);
box const & second = get<2>(splits);
assert(first.get_idx_last_branched() == i);
assert(second.get_idx_last_branched() == i);
if (second.is_bisectable()) {
box_stack.push_back(second);
box_stack.push_back(first);
} else {
box_stack.push_back(first);
box_stack.push_back(second);
}
if (config.nra_proof) {
config.nra_proof_out << "[branched on "
<< b.get_name(i)
<< "]" << endl;
}
} else {
config.nra_found_soln++;
if (config.nra_multiple_soln > 1) {
// If --multiple_soln is used
output_solution(b, config, config.nra_found_soln);
}
if (config.nra_found_soln >= config.nra_multiple_soln) {
break;
}
solns.push_back(b);
}
}
} while (box_stack.size() > 0);
ctc.set_used_constraints(used_constraints);
if (config.nra_multiple_soln > 1 && solns.size() > 0) {
return solns.back();
} else {
assert(!b.is_empty() || box_stack.size() == 0);
return b;
}
}
示例2:
void ndt::typevar_type::get_vars(std::unordered_set<std::string> &vars) const
{
vars.insert(m_name.str());
}
示例3: index_object
void concept_indexer::index_object(object& o, model& m,
std::unordered_set<qname>& processed_qnames) {
BOOST_LOG_SEV(lg, debug) << "Indexing object: "
<< string_converter::convert(o.name());
if (processed_qnames.find(o.name()) != processed_qnames.end()) {
BOOST_LOG_SEV(lg, debug) << "Object already processed.";
return;
}
const auto i(o.relationships().find(relationship_types::modeled_concepts));
if (i == o.relationships().end() || i->second.empty()) {
processed_qnames.insert(o.name());
BOOST_LOG_SEV(lg, debug) << "Object models no concepts.";
return;
}
std::list<qname> expanded_refines;
for (auto& qn : i->second) {
auto& c(find_concept(qn, m));
expanded_refines.push_back(qn);
expanded_refines.insert(expanded_refines.end(),
c.refines().begin(), c.refines().end());
}
remove_duplicates(expanded_refines);
if (!o.is_child()) {
i->second = expanded_refines;
BOOST_LOG_SEV(lg, debug) << "Object has no parents, using reduced set.";
return;
}
std::set<qname> our_concepts;
our_concepts.insert(expanded_refines.begin(), expanded_refines.end());
std::set<qname> their_concepts;
for (const auto& qn : find_relationships(relationship_types::parents, o)) {
auto& parent(find_object(qn, m));
index_object(parent, m, processed_qnames);
auto& pr(parent.relationships());
const auto j(pr.find(relationship_types::modeled_concepts));
if (j == pr.end() || j->second.empty())
continue;
their_concepts.insert(j->second.begin(), j->second.end());
}
/* we want to only model concepts which have not yet been modeled
* by any of our parents.
*/
std::set<qname> result;
std::set_difference(our_concepts.begin(), our_concepts.end(),
their_concepts.begin(), their_concepts.end(),
std::inserter(result, result.end()));
/* reinsert all of the modeled concepts which are part of the set
* difference. we do this instead of just using the set difference
* directly to preserve order.
*/
BOOST_LOG_SEV(lg, debug) << "Object has parents, computing set difference.";
i->second.clear();
for (const auto& qn : expanded_refines) {
if (result.find(qn) != result.end())
i->second.push_back(qn);
}
BOOST_LOG_SEV(lg, debug) << "Finished indexing object.";
}
示例4: parse
static std::unique_ptr<QueryExpr>
parse(w_query*, const json_ref& term, CaseSensitivity caseSensitive) {
const char *pattern = nullptr, *scope = "basename";
const char *which =
caseSensitive == CaseSensitivity::CaseInSensitive ? "iname" : "name";
std::unordered_set<w_string> set;
if (!term.isArray()) {
throw QueryParseError("Expected array for '", which, "' term");
}
if (json_array_size(term) > 3) {
throw QueryParseError(
"Invalid number of arguments for '", which, "' term");
}
if (json_array_size(term) == 3) {
const auto& jscope = term.at(2);
if (!jscope.isString()) {
throw QueryParseError("Argument 3 to '", which, "' must be a string");
}
scope = json_string_value(jscope);
if (strcmp(scope, "basename") && strcmp(scope, "wholename")) {
throw QueryParseError(
"Invalid scope '", scope, "' for ", which, " expression");
}
}
const auto& name = term.at(1);
if (name.isArray()) {
uint32_t i;
for (i = 0; i < json_array_size(name); i++) {
if (!json_array_get(name, i).isString()) {
throw QueryParseError(
"Argument 2 to '",
which,
"' must be either a string or an array of string");
}
}
set.reserve(json_array_size(name));
for (i = 0; i < json_array_size(name); i++) {
w_string element;
const auto& jele = name.at(i);
auto ele = json_to_w_string(jele);
if (caseSensitive == CaseSensitivity::CaseInSensitive) {
element = ele.piece().asLowerCase(ele.type()).normalizeSeparators();
} else {
element = ele.normalizeSeparators();
}
set.insert(element);
}
} else if (name.isString()) {
pattern = json_string_value(name);
} else {
throw QueryParseError(
"Argument 2 to '",
which,
"' must be either a string or an array of string");
}
auto data = new NameExpr(std::move(set), caseSensitive,
!strcmp(scope, "wholename"));
if (pattern) {
data->name = json_to_w_string(name).normalizeSeparators();
}
return std::unique_ptr<QueryExpr>(data);
}
示例5: main
int main(int argc, char* argv[])
{
if (MPI_Init(&argc, &argv) != MPI_SUCCESS) {
cerr << "Coudln't initialize MPI." << endl;
abort();
}
MPI_Comm comm = MPI_COMM_WORLD;
int rank = 0, comm_size = 0;
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &comm_size);
float zoltan_version;
if (Zoltan_Initialize(argc, argv, &zoltan_version) != ZOLTAN_OK) {
cout << "Zoltan_Initialize failed" << endl;
abort();
}
Dccrg<std::array<int, 2>> grid;
const std::array<uint64_t, 3> grid_length = {{18, 18, 1}};
grid
.set_initial_length(grid_length)
.set_neighborhood_length(2)
.set_maximum_refinement_level(0)
.set_periodic(true, true, true)
.set_load_balancing_method("RANDOM")
.initialize(comm);
/*
Use a neighborhood like this in the z plane:
O.O.O
.....
O.X.O
.....
O.O.O
and play 4 interlaced games simultaneously.
*/
typedef dccrg::Types<3>::neighborhood_item_t neigh_t;
const std::vector<neigh_t> neighborhood{
{-2, -2, 0},
{-2, 0, 0},
{-2, 2, 0},
{ 0, -2, 0},
{ 0, 2, 0},
{ 2, -2, 0},
{ 2, 0, 0},
{ 2, 2, 0}
};
const int neighborhood_id = 1;
if (!grid.add_neighborhood(neighborhood_id, neighborhood)) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Couldn't set neighborhood"
<< std::endl;
abort();
}
// initial condition
const std::unordered_set<uint64_t> live_cells = get_live_cells(grid_length[0], 0);
for (const uint64_t cell: live_cells) {
auto* const cell_data = grid[cell];
if (cell_data != nullptr) {
(*cell_data)[0] = 1;
}
}
// every process outputs the game state into its own file
ostringstream basename, suffix(".vtk");
basename << "tests/user_neighborhood/general_neighborhood_" << rank << "_";
ofstream outfile, visit_file;
// visualize the game with visit -o game_of_life_test.visit
if (rank == 0) {
visit_file.open("tests/user_neighborhood/general_neighborhood.visit");
visit_file << "!NBLOCKS " << comm_size << endl;
}
#define TIME_STEPS 36
for (int step = 0; step < TIME_STEPS; step++) {
grid.balance_load();
grid.update_copies_of_remote_neighbors(neighborhood_id);
// check that the result is correct
if (step % 4 == 0) {
const std::unordered_set<uint64_t> live_cells = get_live_cells(grid_length[0], step);
for (const auto& cell: grid.local_cells(neighborhood_id)) {
if ((*cell.data)[0] == 0) {
if (live_cells.count(cell.id) > 0) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << cell.id
<< " shouldn't be alive on step " << step
<< endl;
abort();
}
} else {
if (live_cells.count(cell.id) == 0) {
std::cerr << __FILE__ << ":" << __LINE__
//.........这里部分代码省略.........
示例6: connect_face_to_chunks
void mesh::connect_face_to_chunks(
int f,
std::unordered_set<int> & to_add,
float step_distance,
std::unordered_set<int> & chunk
) {
using namespace std;
// If this polygon is surrounded by only polygons in the same chunk skip it
bool surrounded = true;
for (int n : neighbouring_triangles[f])
surrounded &= !(chunk.count(n) == 0);
if (surrounded)
return;
// Dijkstras
unordered_map<int, float> dist;
unordered_map<int, int> prev;
priority_queue<S> pq;
pq.push(S(f, 0.0f));
while(!pq.empty()) {
S min = pq.top();
pq.pop();
for (int n : neighbouring_triangles[min.face]) {
S alt(n, distance(f, n));
// Cuttoffs
// Max step distance is exceeded
if (alt.dist > step_distance)
continue;
if (dist.count(alt.face) == 0) {
dist.emplace(alt.face, alt.dist);
prev.emplace(alt.face, min.face);
pq.push(alt);
}
else if (alt.dist < dist[alt.face]) {
dist.emplace(alt.face, alt.dist);
prev.emplace(alt.face, min.face);
pq.push(alt);
}
}
}
for(auto kv : prev) {
// If the polygon is walkable AND not in the same chunk as the starting point
// if ((walkable_faces.count(kv.first) > 0) and chunk.count(kv.first) == 0) {
if (walkable_faces.count(kv.first) > 0) {
int curr = kv.first;
while (curr != f){
to_add.insert(prev[curr]);
if (prev.count(curr) > 0)
curr = prev[curr];
}
}
}
}
示例7: checkEntry
bool checkEntry(const InputMethodEntry &entry, const std::unordered_set<std::string> &inputMethods) {
return (entry.name().empty() || entry.uniqueName().empty() || entry.addon().empty() ||
inputMethods.count(entry.addon()) == 0)
? false
: true;
}
示例8: insert_data
static void insert_data(const T& data, std::unordered_set<T> &value)
{
value.insert(value.rbegin() , data);
}
示例9: setValues
void KeyMultiValueTagFilter::setValues(const std::unordered_set<std::string> & values)
{
setValues(values.cbegin(), values.cend());
}
示例10: clearErrors
//.........这里部分代码省略.........
int libxml_streams_IO_write(void* context, const char* buffer, int len) {
ITRACE(1, "libxml_IO_write({}, {}, {})\n", context, (void*)buffer, len);
Trace::Indent _i;
auto stream = getStream(context);
int64_t ret = stream->write(String(buffer, len, CopyString));
return (ret < INT_MAX) ? ret : -1;
}
int libxml_streams_IO_close(void* context) {
ITRACE(1, "libxml_IO_close({}), sweeping={}\n",
context, MemoryManager::sweeping());
Trace::Indent _i;
if (MemoryManager::sweeping()) {
// Stream wrappers close themselves on sweep, so there's nothing to do here
return 0;
}
return forgetStream(context) ? 0 : -1;
}
int libxml_streams_IO_nop_close(void* context) {
return 0;
}
static xmlExternalEntityLoader s_default_entity_loader = nullptr;
/*
* A whitelist of protocols allowed to be use in xml external entities. Note
* that accesses to this set are not synchronized, so it must not be modified
* after module initialization.
*/
static std::unordered_set<
const StringData*,
string_data_hash,
string_data_isame
> s_ext_entity_whitelist;
static bool allow_ext_entity_protocol(const String& protocol) {
return s_ext_entity_whitelist.count(protocol.get());
}
static xmlParserInputPtr libxml_ext_entity_loader(const char *url,
const char *id,
xmlParserCtxtPtr context) {
ITRACE(1, "libxml_ext_entity_loader({}, {}, {})\n",
url, id, (void*)context);
Trace::Indent _i;
auto protocol = Stream::getWrapperProtocol(url);
if (!allow_ext_entity_protocol(protocol)) {
raise_warning("Protocol '%s' for external XML entity '%s' is disabled for"
" security reasons. This may be changed using the"
" hhvm.libxml.ext_entity_whitelist ini setting.",
protocol.c_str(), url);
return nullptr;
}
return s_default_entity_loader(url, id, context);
}
static xmlParserInputBufferPtr
libxml_create_input_buffer(const char* URI, xmlCharEncoding enc) {
ITRACE(1, "libxml_create_input_buffer({}, {})\n", URI, static_cast<int>(enc));
Trace::Indent _i;
示例11: stealChunks
void TransactionContext::stealChunks(std::unordered_set<RevisionCacheChunk*>& target) {
target.clear();
_chunks.swap(target);
}
示例12: Compress
void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
RestrictionMap &restriction_map,
util::NodeBasedDynamicGraph &graph,
CompressedEdgeContainer &geometry_compressor)
{
const unsigned original_number_of_nodes = graph.GetNumberOfNodes();
const unsigned original_number_of_edges = graph.GetNumberOfEdges();
util::Percent progress(original_number_of_nodes);
for (const NodeID node_v : util::irange(0u, original_number_of_nodes))
{
progress.PrintStatus(node_v);
// only contract degree 2 vertices
if (2 != graph.GetOutDegree(node_v))
{
continue;
}
// don't contract barrier node
if (barrier_nodes.end() != barrier_nodes.find(node_v))
{
continue;
}
// check if v is a via node for a turn restriction, i.e. a 'directed' barrier node
if (restriction_map.IsViaNode(node_v))
{
continue;
}
// reverse_e2 forward_e2
// u <---------- v -----------> w
// ----------> <-----------
// forward_e1 reverse_e1
//
// Will be compressed to:
//
// reverse_e1
// u <---------- w
// ---------->
// forward_e1
//
// If the edges are compatible.
const bool reverse_edge_order = graph.GetEdgeData(graph.BeginEdges(node_v)).reversed;
const EdgeID forward_e2 = graph.BeginEdges(node_v) + reverse_edge_order;
BOOST_ASSERT(SPECIAL_EDGEID != forward_e2);
BOOST_ASSERT(forward_e2 >= graph.BeginEdges(node_v) && forward_e2 < graph.EndEdges(node_v));
const EdgeID reverse_e2 = graph.BeginEdges(node_v) + 1 - reverse_edge_order;
BOOST_ASSERT(SPECIAL_EDGEID != reverse_e2);
BOOST_ASSERT(reverse_e2 >= graph.BeginEdges(node_v) && reverse_e2 < graph.EndEdges(node_v));
const EdgeData &fwd_edge_data2 = graph.GetEdgeData(forward_e2);
const EdgeData &rev_edge_data2 = graph.GetEdgeData(reverse_e2);
const NodeID node_w = graph.GetTarget(forward_e2);
BOOST_ASSERT(SPECIAL_NODEID != node_w);
BOOST_ASSERT(node_v != node_w);
const NodeID node_u = graph.GetTarget(reverse_e2);
BOOST_ASSERT(SPECIAL_NODEID != node_u);
BOOST_ASSERT(node_u != node_v);
const EdgeID forward_e1 = graph.FindEdge(node_u, node_v);
BOOST_ASSERT(SPECIAL_EDGEID != forward_e1);
BOOST_ASSERT(node_v == graph.GetTarget(forward_e1));
const EdgeID reverse_e1 = graph.FindEdge(node_w, node_v);
BOOST_ASSERT(SPECIAL_EDGEID != reverse_e1);
BOOST_ASSERT(node_v == graph.GetTarget(reverse_e1));
const EdgeData &fwd_edge_data1 = graph.GetEdgeData(forward_e1);
const EdgeData &rev_edge_data1 = graph.GetEdgeData(reverse_e1);
if (graph.FindEdgeInEitherDirection(node_u, node_w) != SPECIAL_EDGEID)
{
continue;
}
// this case can happen if two ways with different names overlap
if (fwd_edge_data1.name_id != rev_edge_data1.name_id ||
fwd_edge_data2.name_id != rev_edge_data2.name_id)
{
continue;
}
if (fwd_edge_data1.IsCompatibleTo(fwd_edge_data2) &&
rev_edge_data1.IsCompatibleTo(rev_edge_data2))
{
BOOST_ASSERT(graph.GetEdgeData(forward_e1).name_id ==
graph.GetEdgeData(reverse_e1).name_id);
BOOST_ASSERT(graph.GetEdgeData(forward_e2).name_id ==
graph.GetEdgeData(reverse_e2).name_id);
// Do not compress edge if it crosses a traffic signal.
// This can't be done in IsCompatibleTo, becase we only store the
// traffic signals in the `traffic_lights` list, which EdgeData
// doesn't have access to.
const bool has_node_penalty = traffic_lights.find(node_v) != traffic_lights.end();
//.........这里部分代码省略.........
示例13: _assertion_is_explicit_nonnull_check
/* Calculate whether an assertion is a standard non-NULL check.
* e.g. (x != NULL), (x), (x != NULL && …) or (x && …).
*
* Insert the ValueDecls of the variables being checked into the provided
* unordered_set, and return the number of such insertions (this will be 0 if no
* variables are non-NULL checked). The returned number may be an over-estimate
* of the number of elements in the set, as it doesn’t account for
* duplicates. */
static unsigned int
_assertion_is_explicit_nonnull_check (Expr& assertion_expr,
const ASTContext& context,
std::unordered_set<const ValueDecl*>& ret)
{
DEBUG_EXPR (__func__ << ": ", assertion_expr);
switch ((int) assertion_expr.getStmtClass ()) {
case Expr::BinaryOperatorClass: {
BinaryOperator& bin_expr =
cast<BinaryOperator> (assertion_expr);
BinaryOperatorKind opcode = bin_expr.getOpcode ();
if (opcode == BinaryOperatorKind::BO_LAnd) {
/* LHS && RHS */
unsigned int lhs_count =
AssertionExtracter::assertion_is_nonnull_check (*(bin_expr.getLHS ()), context, ret);
unsigned int rhs_count =
AssertionExtracter::assertion_is_nonnull_check (*(bin_expr.getRHS ()), context, ret);
return lhs_count + rhs_count;
} else if (opcode == BinaryOperatorKind::BO_LOr) {
/* LHS || RHS */
std::unordered_set<const ValueDecl*> lhs_vars, rhs_vars;
unsigned int lhs_count =
AssertionExtracter::assertion_is_nonnull_check (*(bin_expr.getLHS ()), context, lhs_vars);
unsigned int rhs_count =
AssertionExtracter::assertion_is_nonnull_check (*(bin_expr.getRHS ()), context, rhs_vars);
std::set_intersection (lhs_vars.begin (),
lhs_vars.end (),
rhs_vars.begin (),
rhs_vars.end (),
std::inserter (ret, ret.end ()));
return lhs_count + rhs_count;
} else if (opcode == BinaryOperatorKind::BO_NE) {
/* LHS != RHS */
Expr* rhs = bin_expr.getRHS ();
Expr::NullPointerConstantKind k =
rhs->isNullPointerConstant (const_cast<ASTContext&> (context),
Expr::NullPointerConstantValueDependence::NPC_ValueDependentIsNotNull);
if (k != Expr::NullPointerConstantKind::NPCK_NotNull &&
bin_expr.getLHS ()->IgnoreParenCasts ()->getStmtClass () == Expr::DeclRefExprClass) {
DEBUG ("Found non-NULL check.");
ret.insert (cast<DeclRefExpr> (bin_expr.getLHS ()->IgnoreParenCasts ())->getDecl ());
return 1;
}
/* Either not a comparison to NULL, or the expr being
* compared is not a DeclRefExpr. */
return 0;
}
return 0;
}
case Expr::UnaryOperatorClass: {
/* A unary operator. For the moment, assume this isn't a
* non-null check.
*
* FIXME: In the future, define a proper program transformation
* to check for non-null checks, since we could have expressions
* like:
* !(my_var == NULL)
* or (more weirdly):
* ~(my_var == NULL)
*/
return 0;
}
case Expr::ConditionalOperatorClass: {
/* A conditional operator. For the moment, assume this isn’t a
* non-null check.
*
* FIXME: In the future, define a proper program transformation
* to check for non-null checks, since we could have expressions
* like:
* (x == NULL) ? TRUE : FALSE
*/
return 0;
}
case Expr::CStyleCastExprClass:
case Expr::ImplicitCastExprClass: {
/* A (explicit or implicit) cast. This can either be:
* (void*)0
* or
* (bool)my_var */
CastExpr& cast_expr = cast<CastExpr> (assertion_expr);
Expr* sub_expr = cast_expr.getSubExpr ()->IgnoreParenCasts ();
if (sub_expr->getStmtClass () == Expr::DeclRefExprClass) {
DEBUG ("Found non-NULL check.");
//.........这里部分代码省略.........
示例14: insert
void insert(const Reg& reg){
registers.insert(reg);
}
示例15: erase
void erase(const Reg& reg){
registers.erase(reg);
}