Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
symbol_table.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
19 
20 #ifndef PAGESPEED_KERNEL_BASE_SYMBOL_TABLE_H_
21 #define PAGESPEED_KERNEL_BASE_SYMBOL_TABLE_H_
22 
23 #include <cstddef>
24 #include <list>
25 #include <vector>
26 
32 
33 namespace net_instaweb {
34 
53 template<class CharTransform> class SymbolTable {
54  public:
55  SymbolTable();
56  ~SymbolTable() { Clear(); }
57 
60  void Clear();
61 
63  Atom Intern(const StringPiece& src);
64 
67  size_t string_bytes_allocated() const { return string_bytes_allocated_; }
68 
69  private:
71  struct Comparator {
72  bool operator()(const StringPiece& key_a, const StringPiece& key_b) const {
73  if (key_a.length() == key_b.length()) {
74  const char* a = key_a.data();
75  const char* b = key_b.data();
76  const char* a_end = a + key_a.length();
77  while (a < a_end) {
78  if (CharTransform::Normalize(*a) != CharTransform::Normalize(*b)) {
79  return false;
80  }
81  ++a;
82  ++b;
83  }
84  return true;
85  } else {
86  return false;
87  }
88  }
89  };
90 
91  struct Hash {
92  size_t operator()(const StringPiece& key) const {
93  return HashString<CharTransform, size_t>(key.data(), key.length());
94  }
95  };
96 
97  typedef dense_hash_map<StringPiece, StringPiece*,
98  Hash, Comparator> SymbolMap;
99  SymbolMap string_map_;
100 
104  std::list<StringPiece> pieces_;
105 
107  inline void NewStorage();
108 
123  std::vector<char*> storage_;
124  char* next_ptr_;
125  size_t string_bytes_allocated_;
126 
127 
128 };
129 
130 typedef SymbolTable<CaseFold> SymbolTableInsensitive;
131 typedef SymbolTable<CasePreserve> SymbolTableSensitive;
132 
133 }
134 
135 #endif
size_t string_bytes_allocated() const
Definition: symbol_table.h:67
Atom Intern(const StringPiece &src)
Remember a string in the table, returning it as an Atom.