Hello, everyone,
I am wondering what is the hash function that is used in
hash_map/hash_set. Can I replace it with my own
hash function? Any comments on this?
Thanks!
-Andy
|
|
0
|
|
|
|
Reply
|
yuyang08 (7)
|
9/2/2006 9:10:28 AM |
|
yuyang08@gmail.com wrote:
>
> I am wondering what is the hash function that is used in
> hash_map/hash_set. Can I replace it with my own
> hash function? Any comments on this?
>
By default, hash_map and hash_set use
namespace std {
namespace tr1 {
template <class Ty> struct hash
: unary_function<Ty, size_t>
{
size_t operator()(Ty val) const;
};
} }
This template is specialized for bool, all integer types, all
floating-point types, pointers, std::string, and std::wstring.
You can specialize it for any of your own types.
You can also use your own type as an argument to hash_map or hash_set.
For details, see section 5.6 of my book, "The C++ Standard Library
Extensions: a Tutorial and Reference."
|
|
0
|
|
|
|
Reply
|
petebecker (1324)
|
9/2/2006 2:42:12 PM
|
|
Pete Becker wrote:
> yuyang08@gmail.com wrote:
> >
> > I am wondering what is the hash function that is used in
> > hash_map/hash_set. Can I replace it with my own
> > hash function? Any comments on this?
> >
> By default, hash_map and hash_set use
>
> namespace std {
> namespace tr1 {
> template <class Ty> struct hash
> : unary_function<Ty, size_t>
> {
> size_t operator()(Ty val) const;
> };
> } }
>
> This template is specialized for bool, all integer types, all
> floating-point types, pointers, std::string, and std::wstring.
>
> You can specialize it for any of your own types.
>
> You can also use your own type as an argument to hash_map or hash_set.
>
> For details, see section 5.6 of my book, "The C++ Standard Library
> Extensions: a Tutorial and Reference."
If I'm not mistaken, section 5.6 of your book deals with the hash
function object for std::tr1::unordered_map and
std::tr1::unordered_set. hash_map and hash_set, which the OP refers
to, are implementation-specific extensions (from SGI, perhaps?), not
the new std::tr1 containers.
Best regards,
Tom
|
|
0
|
|
|
|
Reply
|
Thomas8675309 (484)
|
9/3/2006 2:25:43 AM
|
|
Thomas Tutone wrote:
>
> If I'm not mistaken, section 5.6 of your book deals with the hash
> function object for std::tr1::unordered_map and
> std::tr1::unordered_set. hash_map and hash_set, which the OP refers
> to, are implementation-specific extensions (from SGI, perhaps?), not
> the new std::tr1 containers.
>
You're right. Sorry for any confusion this caused.
|
|
0
|
|
|
|
Reply
|
petebecker (1324)
|
9/3/2006 11:26:33 AM
|
|
Pete Becker wrote:
> Thomas Tutone wrote:
>
>>
>> If I'm not mistaken, section 5.6 of your book deals with the hash
>> function object for std::tr1::unordered_map and
>> std::tr1::unordered_set. hash_map and hash_set, which the OP refers
>> to, are implementation-specific extensions (from SGI, perhaps?), not
>> the new std::tr1 containers.
>>
>
> You're right. Sorry for any confusion this caused.
I should add, though, that the specifications in TR1 for unordered_set
and unordered_map were designed to be compatible with existing
implementations of hash_set and hash_map. The Dinkumware implementations
of hash_set, hash_map, unordered_set, and unordered_map all share the
same underlying code.
|
|
0
|
|
|
|
Reply
|
petebecker (1324)
|
9/3/2006 12:01:31 PM
|
|
|
4 Replies
30 Views
(page loaded in 0.081 seconds)
|