2011-02-02 25 views

cevap

23

Key = std::pair<int, int> ile std::tr1::hash<Key> için hiçbir uzmanlaşma yoktur çünkü bu olur. Sen tr1::unordered_map<Pair,bool> h; ilan etmeden önce Key = std::pair<int, int> ile std::tr1::hash<Key> uzmanlaşmak gerekir. Bu pair<int, int> karma nasıl bilmiyorum std çünkü olur.

aynı sorunla std::tr1::hash<>

template <> 
struct std::tr1::hash<std::pair<int, int> > { 
public: 
     size_t operator()(std::pair<int, int> x) const throw() { 
      size_t h = SOMETHING;//something with x 
      return h; 
     } 
}; 
+0

+1, bir ' unordered_map' bir karma tablosu. Bizim kütüphaneler birleştirilmeleri durumunda benim kütüphanede kullanmak üzere uzman ve size kütüphanede kullanılması için bu uzmanlaşmak ve bizim tanımları aynı değil çünkü eğer talihsiz – vz0

+15

, o zaman tanımsız davranış olsun. std :: tr1 :: hash' biraz az belirtilmişse, üçüncü şablon parametresi yerine 'unordered_map' yerine özel bir Hash sınıfı belirtmek mümkünse daha iyidir. –

+1

@Steve: ağrı yok, hiçbir kazanç :) –

0

Ran uzmanlaşmak nasıl bir örnek vardır takiben:

unordered_map <pair<x, y>, z> m1; 

Birkaç geçici çözümler şunlardır:

unordered_map <stringxy, z> m1; 
// the first and second of the pair merged to a string 
// though string parsing may be required, looks same complexity overall 

unordered_multimap <x, pair<y, z>> m1; 
// second of the pair of the key went into value. 
// time complexity slightly increases 

deque<deque<x>> d1; 
// here x & y are of same type, z is stored as: d1[x][y] = z 
// space required is x * y, however time complexity is O(1) 
İlgili konular