158551Skris/* This may look like C code, but it is really -*- C++ -*- */
258551Skris
358551Skris/* Hash table used to check for duplicate keyword entries.
458551Skris
5230237Sbapt   Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc.
6230237Sbapt   Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
7230237Sbapt   and Bruno Haible <bruno@clisp.org>.
858551Skris
9230237Sbapt   This file is part of GNU GPERF.
1058551Skris
11230237Sbapt   GNU GPERF is free software; you can redistribute it and/or modify
12230237Sbapt   it under the terms of the GNU General Public License as published by
13230237Sbapt   the Free Software Foundation; either version 2, or (at your option)
14230237Sbapt   any later version.
1558551Skris
16230237Sbapt   GNU GPERF is distributed in the hope that it will be useful,
17230237Sbapt   but WITHOUT ANY WARRANTY; without even the implied warranty of
18230237Sbapt   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19230237Sbapt   GNU General Public License for more details.
2058551Skris
21230237Sbapt   You should have received a copy of the GNU General Public License
22230237Sbapt   along with this program; see the file COPYING.
23230237Sbapt   If not, write to the Free Software Foundation, Inc.,
24230237Sbapt   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
2558551Skris
2658551Skris#ifndef hash_table_h
2758551Skris#define hash_table_h 1
2858551Skris
29230237Sbapt#include "keyword.h"
3058551Skris
31230237Sbapt/* Hash table of KeywordExt* entries.
32230237Sbapt   Two entries are considered equal if their _selchars are the same and
33230237Sbapt   - if !ignore_length - if their _allchars_length are the same.  */
34230237Sbapt
3558551Skrisclass Hash_Table
3658551Skris{
37230237Sbaptpublic:
38230237Sbapt  /* Constructor.
39230237Sbapt     size is the maximum number of entries.
40230237Sbapt     ignore_length determines a detail in the comparison function.  */
41230237Sbapt                        Hash_Table (unsigned int size, bool ignore_length);
42230237Sbapt  /* Destructor.  */
43230237Sbapt                        ~Hash_Table ();
44230237Sbapt  /* Attempts to insert ITEM in the table.  If there is already an equal
45230237Sbapt     entry in it, returns it.  Otherwise inserts ITEM and returns NULL.  */
46230237Sbapt  KeywordExt *          insert (KeywordExt *item);
47230237Sbapt  /* Print the table's contents.  */
48230237Sbapt  void                  dump () const;
49230237Sbapt
5058551Skrisprivate:
51230237Sbapt  /* Vector of entries.  */
52230237Sbapt  KeywordExt **         _table;
53230237Sbapt  /* Size of the vector.  */
54230237Sbapt  unsigned int          _size;
55230237Sbapt  /* log2(_size).  */
56230237Sbapt  unsigned int          _log_size;
57230237Sbapt  /* A detail of the comparison function.  */
58230237Sbapt  bool const            _ignore_length;
59230237Sbapt  /* Statistics: Number of collisions so far.  */
60230237Sbapt  unsigned int          _collisions;
6158551Skris
62230237Sbapt  /* Compares two items.  */
63230237Sbapt  bool                  equal (KeywordExt *item1, KeywordExt *item2) const;
6458551Skris};
6558551Skris
6658551Skris#endif
67