Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

H3HashFunction.h

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 ////////////////////////////////////////////////////////////////////
00003 //
00004 // Filename : H3HashFunction.h
00005 //
00006 // This file is a part of the UPPAAL toolkit.
00007 // Copyright (c) 1995 - 2004, Uppsala University and Aalborg University.
00008 // All right reserved.
00009 //
00010 // $Id: H3HashFunction.h,v 1.4 2005/01/25 18:30:22 adavid Exp $
00011 //
00012 ///////////////////////////////////////////////////////////////////
00013 
00014 #ifndef INCLUDE_H3_HASH_FUNCTION_H
00015 #define INCLUDE_H3_HASH_FUNCTION_H
00016 
00017 #include <base/inttypes.h>
00018 #include <cstddef>
00019 
00020 namespace hash 
00021 {
00022     /* Class for hashing generic streams of data using H3 hash functions.
00023      * This hasher produces arbitrty long hash values (multiple of 32-bits). 
00024      * The implemented hasher uses hash-functions from the H3-class which is a
00025      * universal_2 class of hash functions.
00026      */
00027     class H3HashFunction 
00028     {
00029     public:
00030         /** Constructor
00031          * @param function: Which hash function to use. 
00032          * @param width: The size of the hash value (in 32-bit words)
00033          * function.
00034          */
00035         H3HashFunction(uint32_t function, size_t width);
00036         
00037         /** Destructor
00038          */
00039         ~H3HashFunction();
00040         
00041         /** Get width of hash value
00042          * @return The width of the hash value. (In case you forgot)
00043          */
00044         size_t getWidth() const { return fWidth; }
00045 
00046         /** Compute the hash value for a given key.
00047          * @param vals: Pointer to the key.
00048          * @param length: The length of the key (in 32-bit words).
00049          * @param result: A buffer to store the hash value. The currently
00050          * stored value will be used as initial value.
00051          * @pre The buffer is large enough to hold the hash value.
00052          */
00053         void hash(const uint32_t *key, size_t lenght, uint32_t *result);
00054         void hash(const int32_t *key, size_t lenght, uint32_t *result);
00055         
00056     private:
00057         uint32_t **function;    ///< Hash function.
00058         size_t fWidth;        ///< Width of each hash value.
00059     };
00060 
00061     inline void H3HashFunction::hash(const int32_t *val,
00062                                      size_t len,
00063                                      uint32_t *res)
00064     {
00065         /* Wrapper only */
00066         hash(reinterpret_cast<const uint32_t *>(val), len, res);
00067     }
00068 
00069 }
00070 
00071 #endif /* INCLUDE_H3_HASH_FUNCTION_H */

Generated on Fri Jun 30 00:03:00 2006 for Module hash by  doxygen 1.4.2