hash-table.h revision 228060
158551Skris/* This may look like C code, but it is really -*- C++ -*- */ 258551Skris 358551Skris/* Hash table used to check for duplicate keyword entries. 458551Skris 5228060Sbapt Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. 6228060Sbapt Written by Douglas C. Schmidt <schmidt@ics.uci.edu> 7228060Sbapt and Bruno Haible <bruno@clisp.org>. 858551Skris 9228060Sbapt This file is part of GNU GPERF. 1058551Skris 11228060Sbapt GNU GPERF is free software; you can redistribute it and/or modify 12228060Sbapt it under the terms of the GNU General Public License as published by 13228060Sbapt the Free Software Foundation; either version 2, or (at your option) 14228060Sbapt any later version. 1558551Skris 16228060Sbapt GNU GPERF is distributed in the hope that it will be useful, 17228060Sbapt but WITHOUT ANY WARRANTY; without even the implied warranty of 18228060Sbapt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19228060Sbapt GNU General Public License for more details. 2058551Skris 21228060Sbapt You should have received a copy of the GNU General Public License 22228060Sbapt along with this program; see the file COPYING. 23228060Sbapt If not, write to the Free Software Foundation, Inc., 24228060Sbapt 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 2558551Skris 2658551Skris#ifndef hash_table_h 2758551Skris#define hash_table_h 1 2858551Skris 29228060Sbapt#include "keyword.h" 3058551Skris 31228060Sbapt/* Hash table of KeywordExt* entries. 32228060Sbapt Two entries are considered equal if their _selchars are the same and 33228060Sbapt - if !ignore_length - if their _allchars_length are the same. */ 34228060Sbapt 3558551Skrisclass Hash_Table 3658551Skris{ 37228060Sbaptpublic: 38228060Sbapt /* Constructor. 39228060Sbapt size is the maximum number of entries. 40228060Sbapt ignore_length determines a detail in the comparison function. */ 41228060Sbapt Hash_Table (unsigned int size, bool ignore_length); 42228060Sbapt /* Destructor. */ 43228060Sbapt ~Hash_Table (); 44228060Sbapt /* Attempts to insert ITEM in the table. If there is already an equal 45228060Sbapt entry in it, returns it. Otherwise inserts ITEM and returns NULL. */ 46228060Sbapt KeywordExt * insert (KeywordExt *item); 47228060Sbapt /* Print the table's contents. */ 48228060Sbapt void dump () const; 49228060Sbapt 5058551Skrisprivate: 51228060Sbapt /* Vector of entries. */ 52228060Sbapt KeywordExt ** _table; 53228060Sbapt /* Size of the vector. */ 54228060Sbapt unsigned int _size; 55228060Sbapt /* log2(_size). */ 56228060Sbapt unsigned int _log_size; 57228060Sbapt /* A detail of the comparison function. */ 58228060Sbapt bool const _ignore_length; 59228060Sbapt /* Statistics: Number of collisions so far. */ 60228060Sbapt unsigned int _collisions; 6158551Skris 62228060Sbapt /* Compares two items. */ 63228060Sbapt bool equal (KeywordExt *item1, KeywordExt *item2) const; 6458551Skris}; 6558551Skris 6658551Skris#endif 67