This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std::collate hash() still broken


hi

i noticed in gcc3.0.3 std::collate hash() was broken, so i checked cvs. the obvious bug had been fixed, but still leaving a more subtle one.  its a rotary hash.. it should be doing a full rotate instead of a fonky kindof rotate like it is now.  the thing it has right now will not work correctly.  try comparing hashes of "xxxx" to "xxxxxxxx" or something.. they're identical.

test program and patch:
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <string>

int main() {
  std::string str;
  std::cout << "String: ";
  std::getline(std::cin, str);

  const std::collate<char> &col
    = std::use_facet<std::collate<char> >(std::locale());

  const char *data = str.data();
  std::cout << "Hash: 0x" << std::hex
    << col.hash(data, data + str.size()) << '\n';
}

and the patch against current cvs:
diff -c -3 -p -r1.59 locale_facets.tcc
*** gcc+hax0r/libstdc++-v3/include/bits/locale_facets.tcc       6 Feb 2002 12:12:58 -0000       1.59
--- gcc+hax0r/libstdc++-v3/include/bits/locale_facets.tcc       10 Feb 2002 11:10:17 -0000
*************** namespace std
*** 1855,1861 ****
        unsigned long __val = 0;
        for (; __lo < __hi; ++__lo)
        __val = *__lo + ((__val << 7) |
!                      (__val >> (numeric_limits<unsigned long>::digits - 1)));
        return static_cast<long>(__val);
      }

--- 1855,1861 ----
        unsigned long __val = 0;
        for (; __lo < __hi; ++__lo)
        __val = *__lo + ((__val << 7) |
!                      (__val >> (numeric_limits<unsigned long>::digits - 7)));
        return static_cast<long>(__val);
      }


thanks for your kind attention,

AaronWL


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]