/* This file is part of cardwords
   (c) 1998 1999 2000 Tobias Peters
   see file COPYING for the copyright terms.
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// cardwords_fasthashkey.hh

/* About CardWords_FastHashKey:
   As CardWords_WordKey and CardWords_Hashkey, CardWords_FastHashKey will be a
   key to a word(CardWords_String). Words containing the same letters in
   different orders will have the same key.

   CardWords_FastHashKey will be calculated the following way:
   Each Char gets a Key Value. All key values in a word will be added and a
   modulo division produces the hash key.

   CardWords_FastHashKey must be initialized with the hash table size, usualy
   a prime, and with the factor by which the key values differ.
   This factor will have the following meaning: If the factor is n, then a
   word consisting of n 'a'-s will have the same hash value as a word
   consisting of exactly 1 'b'.
*/
#ifndef CARDWORDS_FASTHASHKEY_HH
#define CARDWORDS_FASTHASHKEY_HH

#include "cardwords_char.hh"
namespace CardWords {
class String;

class FastHashKey {
public:
  FastHashKey ();
  FastHashKey (const String &);
  FastHashKey (const FastHashKey &);
  ~FastHashKey ();
  FastHashKey & operator = (const String &);
  FastHashKey & operator = (const FastHashKey &);

  FastHashKey & operator += (Char);
  FastHashKey & operator += (const String &);
  FastHashKey & operator += (const FastHashKey &);
  
  FastHashKey & operator -= (Char);
  FastHashKey & operator -= (const String &);
  FastHashKey & operator -= (const FastHashKey &);

  
  
  size_t hash(void);

  // calculate a hash value without an object instance:
  static size_t key_of (const String &);

  // equal_key function for stl's hash_multiset:
  static bool equal_key (const String &, const String &);

  // setting the hashing function parameters:
  static void init (size_t hash_table_size, size_t char_keys_factor);

  // the < operator is for storing the hash values in a set:
  bool operator < (const FastHashKey &) const;
  
private:

  static size_t noOfChars;
  static size_t hashSize;

  static size_t * hashTerms;

  size_t             hashVal;
public:
  // getting the hash_table_size:
  static size_t get_size(void) {return hashSize;}
};
}
#endif

