EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
NameHash.h
1 // -*- c++ -*-
2 
3 #ifndef __NAME_HASH_H__
4 #define __NAME_HASH_H__
5 
6 // tools
7 #include "tools/ToolsConfig.h"
8 #include "tools/NoCopy.h"
9 
10 // storage
11 #include "storage/FileAllocator.h"
12 
15 
36 
37 class NameHash
38 {
39 public:
40 
42  static const uint32_t anchor_size = 8;
43 
50  NameHash(FileAllocator &fa, FileOffset anchor);
51 
56  void init(uint32_t ht_size=1009);
57 
60  void reattach();
61 
66  bool insert(const stdString &name, const stdString &ID_txt, FileOffset ID);
67 
69  class Entry
70  {
71  public:
72  virtual ~Entry();
73 
75  virtual const stdString &getName() const = 0;
76 
80  virtual const stdString &getIdTxt() const = 0;
81 
85  virtual FileOffset getId() const = 0;
86  };
87 
91  Entry *find(const stdString &name);
92 
94  class Iterator : public Entry
95  {
96  public:
97  virtual ~Iterator();
98 
100  virtual bool isValid() const = 0;
101 
105  virtual void next() = 0;
106  };
107 
112  Iterator *iterator();
113 
115  void showStats(FILE *f);
116 
117 private:
118 
119  friend class PrivateIterator;
120 
121  PROHIBIT_DEFAULT_COPY(NameHash);
122 
123  FileAllocator &fa;
124  FileOffset anchor; // Where offset gets deposited in file
125  uint32_t ht_size; // Hash Table size (entries, not bytes)
126  FileOffset table_offset; // Start of HT in file
127 
129  uint32_t hash(const stdString &name) const;
130 
134  FileOffset read_HT_entry(uint32_t hash_value) const;
135 
139  void write_HT_entry(uint32_t hash_value, FileOffset offset) const;
140 };
141 
143 
144 #endif
bool insert(const stdString &name, const stdString &ID_txt, FileOffset ID)
Insert name w/ ID.
static const uint32_t anchor_size
anchor size
Definition: NameHash.h:42
virtual const stdString & getIdTxt() const =0
ID string (for index file, that might be the data file name)
void init(uint32_t ht_size=1009)
Create a new hash table of given size.
Entry * find(const stdString &name)
Locate name and obtain its ID.
A file-based Hash table for strings.
Definition: NameHash.h:37
uint32_t FileOffset
FileOffset is used as a system independent type for, well, offsets into files.
Definition: StorageTypes.h:13
Maintains memory blocks within a file.
Definition: FileAllocator.h:22
One entry in the NameHash.
Definition: NameHash.h:69
virtual bool isValid() const =0
virtual void next()=0
Get next entry.
Iterator over names in the hash.
Definition: NameHash.h:94
void reattach()
Attach to existing hash table on error.
Iterator * iterator()
Start iterating over all entries (in table's order).
virtual FileOffset getId() const =0
ID code (for index file, that might be the file offset)
void showStats(FILE *f)
Generate info on table fill ratio and list length.
NameHash(FileAllocator &fa, FileOffset anchor)
Constructor.
virtual const stdString & getName() const =0
Channel Name.