hash-table.h revision 256281
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 GNU GPERF 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 2, or (at your option) 14 any later version. 15 16 GNU GPERF 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; see the file COPYING. 23 If not, write to the Free Software Foundation, Inc., 24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 25 26#ifndef hash_table_h 27#define hash_table_h 1 28 29#include "keyword.h" 30 31/* Hash table of KeywordExt* entries. 32 Two entries are considered equal if their _selchars are the same and 33 - if !ignore_length - if their _allchars_length are the same. */ 34 35class Hash_Table 36{ 37public: 38 /* Constructor. 39 size is the maximum number of entries. 40 ignore_length determines a detail in the comparison function. */ 41 Hash_Table (unsigned int size, bool ignore_length); 42 /* Destructor. */ 43 ~Hash_Table (); 44 /* Attempts to insert ITEM in the table. If there is already an equal 45 entry in it, returns it. Otherwise inserts ITEM and returns NULL. */ 46 KeywordExt * insert (KeywordExt *item); 47 /* Print the table's contents. */ 48 void dump () const; 49 50private: 51 /* Vector of entries. */ 52 KeywordExt ** _table; 53 /* Size of the vector. */ 54 unsigned int _size; 55 /* log2(_size). */ 56 unsigned int _log_size; 57 /* A detail of the comparison function. */ 58 bool const _ignore_length; 59 /* Statistics: Number of collisions so far. */ 60 unsigned int _collisions; 61 62 /* Compares two items. */ 63 bool equal (KeywordExt *item1, KeywordExt *item2) const; 64}; 65 66#endif 67