typedef boost::unordered_map<int, void*> OneDimentionalNodes;
typedef boost::unordered_map<int, OneDimentionalNodes> TwoDimentionalNodes;
TwoDimentionalNodes nodes;
這個有效嗎?二維無序圖
我不使用任何散列函數,因爲unordered_maps'的鍵是單個整數。它會編譯,但是當我像這樣迭代它時,它試圖訪問this-> hash_function()(k)時崩潰。
for (TwoDimentionalNodes::iterator it= nodes.begin(); it != nodes.end() ; ++it)
{
for(OneDimentionalNodes::iterator it2 = nodes[it->first].begin(); it2 != nodes[it->first].end() ; ++it2)
{
// do stuff
}
}
我也開放給其他容器用
- O(1)訪問
- O(n)的迭代
- 稀疏
Dimen * s *離子。另外,爲什麼不去'it2-> second.begin()'? – Puppy 2012-04-20 11:09:02
我也試過了2 - > second.begin()。這是相同的結果。 – mikbal 2012-04-20 11:10:41
您可以通過包含來使用std :: unordered_map,它帶有C++ 11,但與boost :: unordered_map相同。向我們展示你的'this-> hash_function()(k);'代碼 –
k06a
2012-04-20 11:11:00