21 #ifndef EVTSTRINGHASH_HH 22 #define EVTSTRINGHASH_HH 30 inline void add(
const std::string& str, T* data );
31 inline T*
get(
const std::string& str );
37 inline int hash(
const std::string& str );
48 typedef std::string** EvtStringPtrPtr;
51 _strings =
new EvtStringPtrPtr[_size];
52 _data =
new TPtrPtr[_size];
53 _entries =
new int[_size];
57 for ( i = 0; i < _size; i++ ) {
66 for ( i = 0; i < _size; i++ ) {
68 for ( j = 0; j < _entries[i]; j++ ) {
69 delete _strings[i][j];
71 if ( _entries[i] > 0 ) {
85 int ihash = hash( str );
87 typedef std::string* EvtStringPtr;
90 std::string** newstrings =
new EvtStringPtr[_entries[ihash] + 1];
91 T** newdata =
new TPtr[_entries[ihash] + 1];
95 for ( i = 0; i < _entries[ihash]; i++ ) {
96 newstrings[i] = _strings[ihash][i];
97 newdata[i] = _data[ihash][i];
100 newstrings[_entries[ihash]] =
new std::string;
101 *( newstrings[_entries[ihash]] ) = str;
102 newdata[_entries[ihash]] = data;
104 if ( _entries[ihash] != 0 ) {
105 delete[] _strings[ihash];
106 delete[] _data[ihash];
111 _strings[ihash] = newstrings;
112 _data[ihash] = newdata;
118 int ihash = hash( str );
122 for ( i = 0; i < _entries[ihash]; i++ ) {
123 if ( *( _strings[ihash][i] ) == str )
124 return _data[ihash][i];
133 const char* cstr = str.c_str();
139 while ( cstr[i] != 0 ) {
140 value += (int)cstr[i];
144 return value % _size;
int hash(const std::string &str)
void add(const std::string &str, T *data)
T * get(const std::string &str)