本文整理汇总了C++中AssociativeContainer类的典型用法代码示例。如果您正苦于以下问题:C++ AssociativeContainer类的具体用法?C++ AssociativeContainer怎么用?C++ AssociativeContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AssociativeContainer类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: breadth_first_search
static void breadth_first_search(const GraphType& graph,
const VertexIndexType& source,
const int& k_steps,
AssociativeContainer& visited_vertices) {
/* CHECK: AssociativeContainer::value_type == VertexIndexType */
std::queue<VertexIndexType> even_epoch_queue;
std::queue<VertexIndexType> odd_epoch_queue;
std::queue<VertexIndexType>& current_queue = even_epoch_queue;
std::queue<VertexIndexType>& next_queue = odd_epoch_queue;
current_queue.push (source);
int step_number = 0;
while (step_number<k_steps) {
while (!current_queue.empty ()) {
const int vertex = current_queue.front ();
current_queue.pop ();
visited_vertices.insert (vertex);
for (int target_index=graph.begin(vertex);
target_index<graph.end(vertex);
++target_index) {
const int target = graph.get_target (target_index);
if (visited_vertices.end()==visited_vertices.find (target)) {
next_queue.push (target);
}
}
}
++step_number;
current_queue = (step_number&0x10)?even_epoch_queue:odd_epoch_queue;
next_queue = (step_number&0x01)?even_epoch_queue:odd_epoch_queue;
}
}
示例2: erase_if_dispatch
void erase_if_dispatch(AssociativeContainer& c, Predicate p,
associative_container_tag, stable_tag)
{
typename AssociativeContainer::iterator i, next;
for (i = next = c.begin(); next != c.end(); i = next) {
++next;
if (p(*i))
c.erase(i);
}
}
示例3: remove_if
void remove_if(AssociativeContainer& C, Predicate p)
{
typedef typename AssociativeContainer::iterator iterator;
iterator cur = C.begin();
const iterator last = C.end();
while ((cur = std::find_if(cur, last, p)) != last)
{
iterator tmp = cur++;
C.erase(tmp);
}
}
示例4: find_dispatch
typename AssociativeContainer::const_iterator
find_dispatch(const AssociativeContainer& c,
const Value& value,
associative_container_tag)
{
return c.find(value);
}
示例5: equal_range_dispatch
std::pair<typename AssociativeContainer::iterator,
typename AssociativeContainer::iterator>
equal_range_dispatch(AssociativeContainer& c,
const Value& value,
associative_container_tag)
{
return c.equal_range(value);
}
示例6: get
bool get(const AssociativeContainer& container,
const KeyType& key,
MappedType** ppValue)
{
if (!container.count(key))
return false;
*ppValue = &(const_cast<AssociativeContainer&>(container)[key]);
return true;
}
示例7: while
static void construct_adjacency_matrix
(const GraphType& graph,
const AssociativeContainer& vertices,
__gnu_cxx::hash_map<VertexIndexType, VertexIndexType>& label_map,
__gnu_cxx::hash_map<VertexIndexType, VertexIndexType>& reverse_label_map,
std::vector<EdgeWeightType>& adjacency_matrix) {
typedef typename AssociativeContainer::const_iterator
AssociativeContainerConstIterator;
/* resize the adjacency matrix to hold the adjacencies */
const int num_vertices = vertices.size ();
adjacency_matrix.resize (num_vertices*num_vertices, 0.0);
/* Create a map, which remaps the old vertices into new vertices */
VertexIndexType new_label=0;
AssociativeContainerConstIterator iter = vertices.begin();
AssociativeContainerConstIterator end = vertices.end();
while (iter!=end) {
const VertexIndexType current_vertex = *iter++;
label_map [current_vertex] = new_label;
reverse_label_map [new_label] = current_vertex;
++new_label;
}
assert (new_label==num_vertices);
/* now do the adjacencies */
iter = vertices.begin();
while (iter!=end) {
const VertexIndexType old_vertex = *iter++;
const VertexIndexType new_vertex = label_map [old_vertex];
for (int target_index=graph.begin(old_vertex);
target_index<graph.end(old_vertex);
++target_index) {
const VertexIndexType adjacent_vertex=graph.get_target (target_index);
/* only add the adjacency if the target is one of "vertices". */
if (vertices.end()!=vertices.find (adjacent_vertex)) {
const int element_offset =
(num_vertices*new_vertex) + label_map [adjacent_vertex];
adjacency_matrix [element_offset] = graph.get_weight (target_index);
}
}
}
}
示例8: push_dispatch
std::pair<typename AssociativeContainer::iterator, bool>
push_dispatch(AssociativeContainer& c, const T& v,
multiple_associative_container_tag)
{
return std::make_pair(c.insert(v), true);
}
示例9: erase_dispatch
void erase_dispatch(AssociativeContainer& c, const T& x,
associative_container_tag)
{
c.erase(x);
}
示例10: writeLatex
void writeLatex( AssociativeContainer & p,
bool draw_box = true,
bool dumpcout = false,
std::ostream & ostr = std::cout)
{
typedef typename AssociativeContainer::iterator Iterator;
Iterator it;
ostr << std::fixed << std::setprecision(8);
int sum = 0;
for(it = p.begin(); it != p.end(); it++)
{
sum += it->second;
}
// ##########
// create statistics plot
// a priori computation of the vertical position of the histogram bar names
//
long size_entries = p.size();
size_t key_size_max = 0;
double text_vertical_position = 0.0;
double box_vertical_size = 0.0;
double box_horizontal_size = 0.0;
for(it = p.begin(); it != p.end(); it++)
{
// determine the maximal key size of all entries
if( (it->first).size() > key_size_max )
key_size_max = (it->first).size();
// the reference is: for a key of 8 characters, the vspace is 40.0
// so conclude about the actual size of the key by using this ratio.
text_vertical_position = key_size_max * 40.0 / 8.0;
// determine the size of the pspicture box.
// use some reference ratios to derive a suitable size
box_vertical_size = text_vertical_position;
box_horizontal_size = size_entries * 4.0 / 3.0;
}
ostr << std::endl;
ostr << "%-----------" << std::endl;
ostr << "%%% PLOT %%%" << std::endl;
ostr << "%-----------" << std::endl;
ostr << "\\begin{minipage}[ht]{0.20\\textwidth}" << std::endl;
if(draw_box)
ostr << "\\fbox{" << std::endl;
ostr << "\\setlength{\\unitlength}{1cm}" << std::endl;
ostr << "\\psset{xunit=0.7cm, yunit=0.03017058cm}" << std::endl;
ostr << "\\begin{pspicture}(-1.0,-" << box_vertical_size << ")("<< box_horizontal_size <<",130)" << std::endl;
ostr << "\\psaxes[labels=y,Dx=1,Dy=50.](0,0)(" << size_entries << ",100)" << std::endl;
ostr << "\\pspolygon[fillcolor=black, fillstyle=solid](-0.08,104.55414013)(0,109.53290870)(0.08,104.55414013)" << std::endl;
int i=0;
for(it = p.begin(); it != p.end(); it++)
{
// detect underscores in the key and prefix them with a '\'
// so its latex conform
std::string key = gsse::check_for_special_characters(it->first);
double percentage = ( boost::lexical_cast<double>(it->second) / boost::lexical_cast<double>(sum))*100.0;
#ifdef DEBUG
std::cout << " key_size" << key_size << std::endl;
std::cout << " text_vertical_position: " << text_vertical_position << std::endl;
#endif
ostr.precision(2);
ostr << "\\psframe[linewidth=1pt, fillcolor=gray, fillstyle=solid] (" << i
<< ".30000000,0)(" << i << ".70000000," << percentage << ")" << std::endl;
ostr << "\\rput[bl](" << i++ << ".35000000,-" << text_vertical_position << "){\\rotateleft{\\footnotesize "
<< key << "}}" << std::endl;
}
ostr << "\\end{pspicture}" << std::endl;
if(draw_box)
ostr << "}" << std::endl;
ostr << "\\end{minipage}" << std::endl;
ostr << std::endl;
ostr << "%------------" << std::endl;
ostr << "%%% TABLE %%%" << std::endl;
ostr << "%------------" << std::endl;
// ##########
// create statistics table
ostr << "\\begin{minipage}[ht]{0.20\\textwidth}" << std::endl;
ostr << "\\begin{tabular}{crr}" << std::endl;
if(dumpcout)
{
std::cout << "## mesh classification: " << std::endl;
std::cout << "---------------------------------------------" << std::endl;
}
for(it = p.begin(); it != p.end(); it++)
//.........这里部分代码省略.........
示例11: erase_certainties
void erase_certainties(AssociativeContainer& c) {
BOOST_FOREACH(const Card& card, fixed_) {
c.erase(card);
}
示例12: const_constraints
void const_constraints(const AssociativeContainer& c) {
ci = c.find(k);
n = c.count(k);
cr = c.equal_range(k);
}