1 | /* This may look like C code, but it is really -*- C++ -*- */ |
2 | |
3 | /* Hash table used to check for duplicate keyword entries. |
4 | |
5 | Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. |
6 | Written by Douglas C. Schmidt <schmidt@ics.uci.edu> |
7 | and Bruno Haible <bruno@clisp.org>. |
8 | |
9 | This file is part of GNU GPERF. |
10 | |
11 | This program is free software: you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by |
13 | the Free Software Foundation; either version 3 of the License, or |
14 | (at your option) any later version. |
15 | |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | GNU General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU General Public License |
22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
23 | |
24 | #ifndef hash_table_h |
25 | #define hash_table_h 1 |
26 | |
27 | #include "keyword.h" |
28 | |
29 | /* Hash table of KeywordExt* entries. |
30 | Two entries are considered equal if their _selchars are the same and |
31 | - if !ignore_length - if their _allchars_length are the same. */ |
32 | |
33 | class Hash_Table |
34 | { |
35 | public: |
36 | /* Constructor. |
37 | size is the maximum number of entries. |
38 | ignore_length determines a detail in the comparison function. */ |
39 | Hash_Table (unsigned int size, bool ignore_length); |
40 | /* Destructor. */ |
41 | ~Hash_Table (); |
42 | /* Attempts to insert ITEM in the table. If there is already an equal |
43 | entry in it, returns it. Otherwise inserts ITEM and returns NULL. */ |
44 | KeywordExt * insert (KeywordExt *item); |
45 | /* Print the table's contents. */ |
46 | void dump () const; |
47 | |
48 | private: |
49 | /* Vector of entries. */ |
50 | KeywordExt ** _table; |
51 | /* Size of the vector. */ |
52 | unsigned int _size; |
53 | /* log2(_size). */ |
54 | unsigned int _log_size; |
55 | /* A detail of the comparison function. */ |
56 | bool const _ignore_length; |
57 | /* Statistics: Number of collisions so far. */ |
58 | unsigned int _collisions; |
59 | |
60 | /* Compares two items. */ |
61 | bool equal (KeywordExt *item1, KeywordExt *item2) const; |
62 | }; |
63 | |
64 | #endif |
65 | |