Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shared_dynamic_string_map.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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 
18 
19 #ifndef PAGESPEED_KERNEL_SHAREDMEM_SHARED_DYNAMIC_STRING_MAP_H_
20 #define PAGESPEED_KERNEL_SHAREDMEM_SHARED_DYNAMIC_STRING_MAP_H_
21 
22 #include <cstddef>
23 
30 
31 namespace net_instaweb {
32 
33 class MessageHandler;
34 class Writer;
35 
36 struct Entry {
37  int value;
38  size_t string_offset;
39 };
40 
47  public:
52  SharedDynamicStringMap(size_t number_of_strings,
53  size_t average_string_length,
54  AbstractSharedMem* shm_runtime,
55  const GoogleString& filename_prefix,
56  const GoogleString& filename_suffix);
57 
62  bool InitSegment(bool parent, MessageHandler* message_handler);
63 
69  int IncrementElement(const StringPiece& string);
70 
73  int LookupElement(const StringPiece& string) const;
74 
76  void GetKeys(StringSet* strings);
77 
79  int GetNumberInserted() const;
80 
82  void GlobalCleanup(MessageHandler* message_handler);
83 
88  void Dump(Writer* writer, MessageHandler* message_handler);
89 
90  private:
91  void ClearSegment(MessageHandler* message_handler);
92 
114  int FindEntry(const StringPiece& string,
115  bool lock,
116  Entry** entry_pointer) const;
117  Entry* GetEntry(size_t n) const;
118  Entry* GetFirstEntry() const;
119 
121  AbstractMutex* GetMutex(size_t n) const;
127  int InsertString(const StringPiece& string, Entry* entry_pointer);
128  char* GetStringAtOffset(size_t offset) const;
129 
132  static size_t NextPowerOfTwo(size_t n);
133 
203 
204  size_t number_of_strings_;
205  size_t average_string_length_;
207  size_t mutex_size_;
208  size_t table_size_;
218  size_t mutex_offset_;
219  size_t strings_offset_;
220  size_t string_offset_offset_;
221  size_t number_inserted_offset_;
222  size_t table_offset_;
224  size_t total_size_;
225 
228  scoped_ptr<AbstractMutex> insert_string_mutex_;
229 
230  const GoogleString segment_name_;
231  AbstractSharedMem* shm_runtime_;
233 
234 
235 };
236 
237 }
238 
239 #endif
void Dump(Writer *writer, MessageHandler *message_handler)
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
int LookupElement(const StringPiece &string) const
Definition: shared_dynamic_string_map.h:36
int GetNumberInserted() const
Retrieve the number of strings inserted into the table.
Definition: scoped_ptr.h:30
void GetKeys(StringSet *strings)
Dumps table's strings into StringSet.
bool InitSegment(bool parent, MessageHandler *message_handler)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
SharedDynamicStringMap(size_t number_of_strings, size_t average_string_length, AbstractSharedMem *shm_runtime, const GoogleString &filename_prefix, const GoogleString &filename_suffix)
Definition: abstract_shared_mem.h:86
Definition: shared_dynamic_string_map.h:46
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: message_handler.h:39
int IncrementElement(const StringPiece &string)
void GlobalCleanup(MessageHandler *message_handler)
Destroy shared memory segment and other relevant clean-up.