[25ae32e] | 1 | #ifndef _HashTable_h |
---|
| 2 | #define _HashTable_h |
---|
| 3 | //--------------------------------------------------------------------------- |
---|
| 4 | #include <stddef.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | //--------------------------------------------------------------------------- |
---|
| 7 | int hash1(const char* s, int sz); |
---|
| 8 | int hash2(const char* s, int sz); |
---|
| 9 | //--------------------------------------------------------------------------- |
---|
| 10 | |
---|
| 11 | class SymbolTable |
---|
| 12 | { |
---|
| 13 | int _mx; |
---|
| 14 | int _sz; |
---|
| 15 | int _cnt; |
---|
| 16 | char** _key; |
---|
| 17 | char** _def; |
---|
| 18 | int* _defind; |
---|
| 19 | int* _hashind; // s¹ tu redundancje |
---|
| 20 | |
---|
| 21 | public: |
---|
| 22 | static const unsigned int MAXKEYLEN=2000; |
---|
| 23 | |
---|
| 24 | SymbolTable(int n, int (*h)(const char*,int), const char* filename=NULL); |
---|
| 25 | SymbolTable(int n, const char* filename=NULL); |
---|
| 26 | ~SymbolTable(); |
---|
| 27 | |
---|
| 28 | void clear(); |
---|
| 29 | |
---|
| 30 | int (*hash)(const char*, int); |
---|
| 31 | |
---|
| 32 | bool add_from_file(const char* filename); |
---|
| 33 | |
---|
| 34 | int add(const char* s); |
---|
| 35 | int operator[](const char* s); |
---|
| 36 | const char* operator[](int i){if(i<0||i>=_cnt)return NULL;else return _def[i];} |
---|
| 37 | int index(const char* s) { return this->operator[](s); }; |
---|
| 38 | int index(int i) { if(i<0||i>=_cnt) return -1; else return i; }; |
---|
| 39 | int hash_index(int i) { return _hashind[i]; } |
---|
| 40 | const char* symbol(int i) { if(i<0||i>=_cnt)return NULL; else return _def[i];} |
---|
| 41 | |
---|
| 42 | int capacity() { return _mx; } |
---|
| 43 | int size() { return _sz; } |
---|
| 44 | int count() { return _cnt; } |
---|
| 45 | float search_rate(); |
---|
| 46 | |
---|
| 47 | private: |
---|
| 48 | static int first(unsigned int n); |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | //--------------------------------------------------------------------------- |
---|
| 52 | #endif |
---|