hash_map string key 忽略大小写

  1. hash_map string key 忽略大小写。
  2. 转自网络,没有测试是否可用

  3. #include <hash_map>
  4. #include <string>
  5. #include <algorithm>
  6. #include <cctype>
  7.  
  8. inline size_t __stl_hash_string(const char* __s)
  9. {
  10.     unsigned long __h = 0;
  11.     for ( ; *__s; ++__s)
  12.         __h = 5*__h + tolower(*__s);
  13.  
  14.     return size_t(__h);
  15. }
  16.  
  17. template<>
  18. struct stlport::hash<stlport::string>
  19. {
  20.     size_t operator()(const stlport::string& __s) const
  21.     {
  22.         return __stl_hash_string(__s.c_str());
  23.     }
  24. };
  25.  
  26. template<>
  27. struct stlport::equal_to<stlport::string>
  28.     : public stlport::binary_function<stlport::string , stlport::string , bool>
  29. {
  30.     bool operator()(const stlport::string& __x, const stlport::string& __y) const
  31.     {
  32.         return !_stricmp(__x.c_str() , __y.c_str());
  33.     }
  34. };
  35.  
  36. int _tmain(int argc, _TCHAR* argv[])
  37. {
  38.     stlport::hash_map<stlport::string , int> map;
  39.  
  40.     map.insert(stlport::make_pair("Test" , 123));
  41.  
  42.     stlport::hash_map<stlport::string , int>::iterator iter = map.find("teSt");
  43.     if(iter != map.end())
  44.         printf("Found!\n");
  45.  
  46.     return 0;
  47. }

评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值