Hasher.H 2.76 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9 10 11 12
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

13 14 15 16
    OpenFOAM 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 3 of the License, or
    (at your option) any later version.
17 18 19 20 21 22 23

    OpenFOAM 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
24
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
25

26 27
InNamespace
    Foam
28 29 30 31 32 33 34 35 36

Description
    Misc. hashing functions, mostly from Bob Jenkins.

    The Jenkins hashing function(s) is similar in speed to Paul Hsieh's
    SuperFast hash, but is public domain, supports incremental hashing
    and has been reported to have better characteristics.
    It is also what postgresql seems to be using.

37
See also
38
    http://burtleburtle.net/bob/c/lookup3.c
39
    and HasherInt.H for a specialized version
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

SourceFiles
    Hasher.C

\*---------------------------------------------------------------------------*/

#ifndef Hasher_H
#define Hasher_H

#include <cstddef>

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
//- Bob Jenkins's 96-bit mixer hashing function (lookup3)
//  \param[in] data - a character stream
//  \param[in] len  - the number of bytes
//  \param[in] seed - the previous hash, or an arbitrary value
unsigned Hasher(const void* data, size_t len, unsigned seed = 0);


//- Hashing of bit-wise internal content of given data object.
//  For primitives and simple collections of primitives this is reasonable,
//  but ill-advised for more complex data structures.
template<class T>
inline unsigned HasherT(const T& obj, unsigned seed = 0)
{
    return Hasher(&obj, sizeof(obj), seed);
}
73 74 75 76 77 78 79 80 81 82

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //