1 #ifndef ROTATING_BYTE_HASHER_CLASS
2 #define ROTATING_BYTE_HASHER_CLASS
4 /*****************************************************************************\
6 * Name : rotating_byte_hasher *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2001-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include "byte_hasher.h"
19 #include "checksums.h"
20 #include "hash_table.h"
22 #include <basis/definitions.h>
24 namespace structures {
26 //! Implements a hashing algorithm based on the contents stored in an object.
28 This will only be usable for key types that have flat members; keys with
29 pointers limit the meaning of the hash value, or destroy the meaning if the
30 pointer value can change between lookups. Note that objects based on RTTI
31 will probably never work with this either since the compiler stores extra
32 data as part of the binary form for those objects.
35 class rotating_byte_hasher : public virtual hashing_algorithm
38 virtual ~rotating_byte_hasher() {}
40 virtual basis::un_int hash(const void *key_data, int key_length) const
41 { return checksums::hash_bytes(key_data, key_length); }
42 //!< returns a value that can be used for indexing into a hash table.
43 /*!< the returned value is loosely based on the "key_data" and the
44 "key_length" we are provided with. note: do not use a huge key length
45 for this or your hash table will be very slow; the key should probably
46 be limited to 16 or less. */
48 virtual hashing_algorithm *clone() const
49 { return new rotating_byte_hasher; }
50 //!< implements cloning of the algorithm object.