Yes, I see now.  But your solution -- constructing string objects every time
the hash function is run -- is very slow.  I've submitted r259 with this
implementation instead:

template <>
struct hash<const char*> {
  inline size_t operator()(const char* str) const {
    size_t result = 0;
    for (; *str != '\0'; str++) {
      result = 5 * result + *str;
    }
    return result;
  }
};

On Mon, Dec 21, 2009 at 10:44 AM, Oleg Smolsky <oleg.smol...@gmail.com>wrote:

> Hey Kenton, you also need the two updated google::protobuf::hash<>
> specializations that ensure correct hashing of "const char *" and
> "std::string" keys.
>
> I've attached the complete header, so that you can read it without
> having to apply the patch.
>
> Oleg.
>
> On Mon, Dec 21, 2009 at 10:26 AM, Kenton Varda <ken...@google.com> wrote:
> > Thanks for the fix!  Unfortunately your re-ordering makes it hard for me
> to
> > see what actually changed.  Also, your style doesn't match the Google
> style
> > guide.
> > Is the following sufficient for hash.h, given your changes to
> stl_hash.m4?
> > Index: src/google/protobuf/stubs/hash.h
> > ===================================================================
> > --- src/google/protobuf/stubs/hash.h    (revision 258)
> > +++ src/google/protobuf/stubs/hash.h    (working copy)
> > @@ -152,14 +152,14 @@
> >  template <typename Key, typename Data,
> >            typename HashFcn = hash<Key>,
> >            typename EqualKey = std::equal_to<Key> >
> > -class hash_map : public HASH_NAMESPACE::hash_map<
> > +class hash_map : public HASH_NAMESPACE::HASH_MAP_CLASS<
> >      Key, Data, HashFcn, EqualKey> {
> >  };
> >  template <typename Key,
> >            typename HashFcn = hash<Key>,
> >            typename EqualKey = std::equal_to<Key> >
> > -class hash_set : public HASH_NAMESPACE::hash_set<
> > +class hash_set : public HASH_NAMESPACE::HASH_SET_CLASS<
> >      Key, HashFcn, EqualKey> {
> >  };
> >
> > On Wed, Dec 16, 2009 at 9:36 PM, Oleg Smolsky <oleg.smol...@gmail.com>
> > wrote:
> >>
> >> Hey Kenton, attached is a patch that clears "deprecated headers"
> >> warnings emitted when building protobuf with g++4.4.
> >>
> >> The fix has two parts:
> >> a) discover and use std::tr1::unordered_map when it is available
> >> b) ensure that string hashing is available and working
> >>
> >> I've tested the updated code with g++4.4, g++4.1 and g++3.4.
> >> Unfortunately the last two share the same old crusty libstdc++ due to
> >> the way Redhad built it...
> >>
> >> P.S. I've taken a liberty to reformat and re-order declarations in
> >> .../stubs/hash.h while debugging the hash issue.
> >>
> >> Oleg.
> >
> >
>

--

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.


Reply via email to