PageRenderTime 30ms CodeModel.GetById 26ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llhash.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 72 lines | 36 code | 7 blank | 29 comment | 6 complexity | 58e585ddf0e16f2b0bb89ef560aeaa7c MD5 | raw file
 1/** 
 2 * @file llhash.h
 3 * @brief Wrapper for a hash function.
 4 *
 5 * $LicenseInfo:firstyear=2004&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#ifndef LL_LLHASH_H
28#define LL_LLHASH_H
29
30#include "llpreprocessor.h" // for GCC_VERSION
31
32#if (LL_WINDOWS)
33#include <hash_map>
34#include <algorithm>
35#elif LL_DARWIN || LL_LINUX
36#  if GCC_VERSION >= 40300 // gcc 4.3 and up
37#    include <backward/hashtable.h>
38#  elif GCC_VERSION >= 30400 // gcc 3.4 and up
39#    include <ext/hashtable.h>
40#  elif __GNUC__ >= 3
41#    include <ext/stl_hashtable.h>
42#  else
43#    include <hashtable.h>
44#  endif
45#elif LL_SOLARIS
46#include <ext/hashtable.h>
47#else
48#error Please define your platform.
49#endif
50
51// Warning - an earlier template-based version of this routine did not do
52// the correct thing on Windows.   Since this is only used to get
53// a string hash, it was converted to a regular routine and
54// unit tests added.
55
56inline size_t llhash( const char * value )
57{
58#if LL_WINDOWS
59	return stdext::hash_value(value);
60#elif ( (defined _STLPORT_VERSION) || ((LL_LINUX) && (__GNUC__ <= 2)) )
61	std::hash<const char *> H;
62	return H(value);
63#elif LL_DARWIN || LL_LINUX || LL_SOLARIS
64	__gnu_cxx::hash<const char *> H;
65	return H(value);
66#else
67#error Please define your platform.
68#endif
69}
70
71#endif
72