hash-table.h revision 267654
1133819Stjr/* This may look like C code, but it is really -*- C++ -*- */ 2133819Stjr 3133819Stjr/* Hash table used to check for duplicate keyword entries. 4133819Stjr 5133819Stjr Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. 6133819Stjr Written by Douglas C. Schmidt <schmidt@ics.uci.edu> 7133819Stjr and Bruno Haible <bruno@clisp.org>. 8133819Stjr 9133819Stjr This file is part of GNU GPERF. 10133819Stjr 11133819Stjr GNU GPERF is free software; you can redistribute it and/or modify 12133819Stjr it under the terms of the GNU General Public License as published by 13133819Stjr the Free Software Foundation; either version 2, or (at your option) 14133819Stjr any later version. 15133819Stjr 16133819Stjr GNU GPERF is distributed in the hope that it will be useful, 17133819Stjr but WITHOUT ANY WARRANTY; without even the implied warranty of 18133819Stjr MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19133819Stjr GNU General Public License for more details. 20133819Stjr 21133819Stjr You should have received a copy of the GNU General Public License 22133819Stjr along with this program; see the file COPYING. 23133819Stjr If not, write to the Free Software Foundation, Inc., 24133819Stjr 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 25133819Stjr 26133819Stjr#ifndef hash_table_h 27133819Stjr#define hash_table_h 1 28133819Stjr 29133819Stjr#include "keyword.h" 30133819Stjr 31133819Stjr/* Hash table of KeywordExt* entries. 32133819Stjr Two entries are considered equal if their _selchars are the same and 33133819Stjr - if !ignore_length - if their _allchars_length are the same. */ 34133819Stjr 35133819Stjrclass Hash_Table 36133819Stjr{ 37165832Snetchildpublic: 38165832Snetchild /* Constructor. 39162954Sphk size is the maximum number of entries. 40142057Sjhb ignore_length determines a detail in the comparison function. */ 41161310Snetchild Hash_Table (unsigned int size, bool ignore_length); 42133819Stjr /* Destructor. */ 43133819Stjr ~Hash_Table (); 44133819Stjr /* Attempts to insert ITEM in the table. If there is already an equal 45133819Stjr entry in it, returns it. Otherwise inserts ITEM and returns NULL. */ 46166729Sjkim KeywordExt * insert (KeywordExt *item); 47133819Stjr /* Print the table's contents. */ 48133819Stjr void dump () const; 49133819Stjr 50166188Sjeffprivate: 51133819Stjr /* Vector of entries. */ 52133819Stjr KeywordExt ** _table; 53133819Stjr /* Size of the vector. */ 54133819Stjr unsigned int _size; 55133819Stjr /* log2(_size). */ 56168035Sjkim unsigned int _log_size; 57166729Sjkim /* A detail of the comparison function. */ 58168035Sjkim bool const _ignore_length; 59168035Sjkim /* Statistics: Number of collisions so far. */ 60133819Stjr unsigned int _collisions; 61133819Stjr 62133819Stjr /* Compares two items. */ 63142057Sjhb bool equal (KeywordExt *item1, KeywordExt *item2) const; 64142057Sjhb}; 65133819Stjr 66133819Stjr#endif 67133819Stjr