source: app/src/lib/symtab.h @ 2f8d6d8

Last change on this file since 2f8d6d8 was 25ae32e, checked in by obrebski <obrebski@…>, 16 years ago

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@4 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#ifndef _HashTable_h
2#define _HashTable_h
3//---------------------------------------------------------------------------
4#include <stddef.h>
5#include <string.h>
6//---------------------------------------------------------------------------
7int hash1(const char* s, int sz);
8int hash2(const char* s, int sz);
9//---------------------------------------------------------------------------
10
11class 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
21public:
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
47private:
48  static int first(unsigned int n);
49};
50
51//---------------------------------------------------------------------------
52#endif
Note: See TracBrowser for help on using the repository browser.