0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CstrHashTraits.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
24 #ifndef HYPERTABLE_CSTR_HASH_TRAITS_H
25 #define HYPERTABLE_CSTR_HASH_TRAITS_H
26 
27 #include <Common/PageArena.h>
28 #include <Common/TclHash.h>
29 
30 namespace Hypertable {
31 
39 template <class HashT = TclHash2>
42 
43  struct hasher {
44  HashT hasher;
45 
46  size_t operator()(const char *s) const { return hasher(s); }
47  };
48 
49  struct key_equal {
50  bool
51  operator()(const char *a, const char *b) const {
52  return std::strcmp(a, b) == 0;
53  }
54  };
55 };
56 
57 inline size_t
58 hash_case_cstr(const char *s) {
59  size_t ret = 0;
60 
61  for (; *s; ++s)
62  ret += (ret << 3) + tolower((unsigned)*s);
63 
64  return ret;
65 }
66 
69 
70  struct hasher {
71  size_t
72  operator()(const char *s) const { return hash_case_cstr(s); }
73  };
74 
75  struct key_equal {
76  bool
77  operator()(const char *a, const char *b) const {
78  for (; tolower((unsigned)*a) == tolower((unsigned)*b); ++a, ++b)
79  if (!*a)
80  return true;
81 
82  return false;
83  }
84  };
85 };
86 
89 } // namespace Hypertable
90 
91 #endif // !HYPERTABLE_CSTR_HASH_TRAITS_H
bool operator()(const char *a, const char *b) const
PageArena memory allocator.
The PageArena allocator is simple and fast, avoiding individual mallocs/frees.
Definition: PageArena.h:69
size_t operator()(const char *s) const
Hypertable definitions
bool operator()(const char *a, const char *b) const
Implementations of the Tcl hash algorithm by John Ousterhout.
size_t operator()(const char *s) const
size_t hash_case_cstr(const char *s)
Traits for CstrHashMap/Set.