STL hash_map
Hello,
i have a question concerning STL non-standard hash_maps under Visual Studio
2005:
Microsoft STL requires a "hash_compare" object for hash_maps:
template <class Key, class Type, class Traits=hash_compare<Key, less<Key> >,
class Allocator=allocator<pair <const Key, Type> > >
class hash_map
I derived a own class from hash_compare dealing with unsigned integers and
implemented the application operator() and a compare function:
class Timestamp_Hashing : public stdext::hash_compare <unsigned int>
{
public:
/// <summary>
/// Class constructor. The constructor takes two arguments, one defining the
quality of the hash map,
/// the other to adapt to a stream's dts struct.</summary>
Timestamp_Hashing (unsigned int HFactor, unsigned int FTimestamp = 0);
/// <summary>
/// This hash-function is used automatically by "hash_map" for determining
in which bucket to put a certain timestamp.</summary>
/// <param name="Timestamp"> The Timestamp for which the hash-value is to be
caclulated. </param>
/// <return> Returns a hash-value in form of the size_t type which can be
used by iterators.</return>
SIZE_T operator () (const unsigned int & Timestamp) const;
/// <summary>
/// This function is used automatically by "hash_map" for sorting the
timestamps contained in the buckets. </summary>
/// It receives two timestamps and return true if the first one is less the
the second one.
/// <param name="Timestamp1"> First timestamp.</param>
/// <param name="Timestamp1"> Second timestamp.</param>
/// <return> Returns true if Timestamp1 < Timestamp2 </return>
bool operator () (const unsigned int & Timestamp1, const unsigned int &
Timestamp2) const;
private:
// private variables used to save state during hash_map creation
unsigned int Hash_Factor;
unsigned int First_Timestamp;
};
As you can see my derived class Timestamp_Hashing has a constructor taking
two arguments.
I have planned to initiate a certain state of an object of class
Timestamp_Hashing through this constructor which influences the
hash_function.
If i create a hash_map by
stdext::hash_map < unsigned int, unsigned int, Timestamp_Hashing>;
everything compiles well but if i use
Timestamp_Hashing Hashy(10,20);
stdext::hash_map < unsigned int, unsigned int, Hashy>;
the compiler generated an error: Error 11 error C2923: 'stdext::hash_map' :
'Hashy' is not a valid template type argument for parameter '_Tr'.
So, how is it possible to pass a hash_compare/Timestamp_Hashing object with
a certain state to the hash_map constructor - is there a workaround?
Greetings and thx in advance.
Axel