cprover
string_container.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Container for C-Strings
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "string_container.h"
13 
14 #include <cstring>
15 
17 
18 string_ptrt::string_ptrt(const char *_s):s(_s), len(strlen(_s))
19 {
20 }
21 
22 bool string_ptrt::operator==(const string_ptrt &other) const
23 {
24  if(len!=other.len)
25  return false;
26 
27  return len==0 || memcmp(s, other.s, len)==0;
28 }
29 
31 
33 {
34  // pre-allocate empty string -- this gets index 0
35  get("");
36 
37  // allocate strings
39 }
40 
42 {
43 }
44 
45 unsigned string_containert::get(const char *s)
46 {
47  string_ptrt string_ptr(s);
48 
49  hash_tablet::iterator it=hash_table.find(string_ptr);
50 
51  if(it!=hash_table.end())
52  return it->second;
53 
54  size_t r=hash_table.size();
55 
56  // these are stable
57  string_list.push_back(std::string(s));
58  string_ptrt result(string_list.back());
59 
60  hash_table[result]=r;
61 
62  // these are not
63  string_vector.push_back(&string_list.back());
64 
65  return r;
66 }
67 
68 unsigned string_containert::get(const std::string &s)
69 {
70  string_ptrt string_ptr(s);
71 
72  hash_tablet::iterator it=hash_table.find(string_ptr);
73 
74  if(it!=hash_table.end())
75  return it->second;
76 
77  size_t r=hash_table.size();
78 
79  // these are stable
80  string_list.push_back(s);
81  string_ptrt result(string_list.back());
82 
83  hash_table[result]=r;
84 
85  // these are not
86  string_vector.push_back(&string_list.back());
87 
88  return r;
89 }
const char * s
static int8_t r
Definition: irep_hash.h:59
hash_tablet hash_table
Container for C-Strings.
string_ptrt(const char *_s)
unsigned get(const char *s)
string_containert string_container
string_vectort string_vector
void initialize_string_container()
Definition: irep_ids.cpp:46
bool operator==(const string_ptrt &other) const
string_listt string_list