使用非连接存储(即!= vecs)和add_Edge()的最小boost aidgacency_list
Minimal boost adjacency_list with non-contiguous storage (i.e. != vecS) and add_edge()
我想为算法创建图形,该算法需要仅由adjacency_list
提供的图形概念。顶点ID本身是随机的size_t
's且无连接,因此使用向量作为基础存储是不可能的,但这确实是不是 compile:
#include <boost/graph/adjacency_list.hpp>
int main()
{
using namespace boost;
using out_edge_storage = setS;
// using vertex_storage = vecS; // compiles Ok
using vertex_storage = setS; // error: no matching function for call to 'add_edge'
using graph = adjacency_list<out_edge_storage, vertex_storage, undirectedS>;
graph g;
add_edge(3, 44, g);
add_edge(1024102400, 3, g); // uses too much space (bad_alloc) with vecS
}
我不需要任何额外的自定义顶点属性,也不需要在创建图表后修改图形。阅读文档[1]我找不到add_edge()
的额外要求的原因。
我将如何使用集合或哈希集合数据类型构造图形,并且在文档中可以找到我错过的详细信息?
/doc/adjacency_list.html(有关Adjacency_list VEC的其他stackoverflow问题(例如,此处(远非最小,没有帮助。(
我不需要任何额外的自定义顶点属性,也不需要在创建图表后修改图形。
好吧,也许不是在您的脑海中,但是由于向量索引不再以顶点ID的形式"倍增",因此您希望某个地方将这些数字附加到顶点描述符。
此恰好是您需要/渴望财产的理由。我建议内部属性如果您想要算法也会自动知道如何使用该数字来识别您的索引。
活在coliru
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
using graph = boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS,
boost::property<boost::vertex_index_t, size_t> >;
int main() {
graph g;
auto A = add_vertex(3, g);
auto B = add_vertex(44, g);
auto C = add_vertex(1024102400, g);
add_edge(A, B, g);
add_edge(C, A, g);
print_graph(g);
}
打印:
3 <--> 44 1024102400
44 <--> 3
1024102400 <--> 3
相关文章:
- 使用std::multimap迭代器创建std::list
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 如何在 C 中正确使用 libiconv 使其不会报告"Arg list too long"?
- C++中带有List类的迭代器Segfault
- 使用"std::unordereded_map"映射到"std::list"对象
- GCC对可能有效的代码抛出init list生存期警告
- 使用std::list创建循环链表
- 重载Singly Linked List中的赋值运算符
- '[](std::list& list)<int>{return std::move(list)}(list)' 是否保证将 'list' 留空?
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?
- 为什么这个 std::queue/指向结构的指针列表直到 List.Size() == 0 才释放内存?
- "std::list::splice(std::const_iterator pos, std::list&& other)"是否保证将"其他"留空?
- 从嵌套循环中的 std::list 中删除将返回访问冲突
- QStringList vs list<shared_ptr<QString>> 性能比较C++
- 包含 std::list 的结构体的 C++ 初始化
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- C++ assigment std::list:<typename>:itrator 在 main 中工作,但在方法中它不起作用
- 在基于范围的 for 循环期间插入 std::list 的后面
- 循环挂起迭代的 std::擦除 on std::list
- 如何增加以前由新运算符分配的 C++ std::list 数组的大小?