File size: 7,940 Bytes
9375c9a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
// Copyright (C) 2011 Davis E. King ([email protected])
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_HAsH_ABSTRACT_Hh_
#ifdef DLIB_HAsH_ABSTRACT_Hh_
#include "murmur_hash3_abstract.h"
#include <vector>
#include <string>
#include <map>
namespace dlib
{
// ----------------------------------------------------------------------------------------
uint32 hash (
const std::string& item,
uint32 seed = 0
);
/*!
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3() routine to compute the actual hash.
- This routine will always give the same hash value when presented
with the same input string.
!*/
// ----------------------------------------------------------------------------------------
uint32 hash (
const std::wstring& item,
uint32 seed = 0
);
/*!
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3() routine to compute the actual hash.
- Note that if the memory layout of the elements in item change between
hardware platforms then hash() will give different outputs. If you want
hash() to always give the same output for the same input then you must
ensure that elements of item always have the same layout in memory.
Typically this means using fixed width types and performing byte swapping
to account for endianness before passing item to hash().
!*/
// ----------------------------------------------------------------------------------------
template <typename T, typename alloc>
uint32 hash (
const std::vector<T,alloc>& item,
uint32 seed = 0
);
/*!
requires
- T is a standard layout type (e.g. a POD type like int, float,
or a simple struct).
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3() routine to compute the actual hash.
- Note that if the memory layout of the elements in item change between
hardware platforms then hash() will give different outputs. If you want
hash() to always give the same output for the same input then you must
ensure that elements of item always have the same layout in memory.
Typically this means using fixed width types and performing byte swapping
to account for endianness before passing item to hash().
!*/
// ----------------------------------------------------------------------------------------
template <typename T, typename U, typename alloc>
uint32 hash (
const std::vector<std::pair<T,U>,alloc>& item,
uint32 seed = 0
);
/*!
requires
- T and U are standard layout types (e.g. POD types like int, float,
or simple structs).
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3() routine to compute the actual hash.
- Note that if the memory layout of the elements in item change between
hardware platforms then hash() will give different outputs. If you want
hash() to always give the same output for the same input then you must
ensure that elements of item always have the same layout in memory.
Typically this means using fixed width types and performing byte swapping
to account for endianness before passing item to hash().
!*/
// ----------------------------------------------------------------------------------------
template <typename T, typename U, typename comp, typename alloc>
uint32 hash (
const std::map<T,U,comp,alloc>& item,
uint32 seed = 0
);
/*!
requires
- T and U are standard layout types (e.g. POD types like int, float,
or simple structs).
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3() routine to compute the actual hash.
- Note that if the memory layout of the elements in item change between
hardware platforms then hash() will give different outputs. If you want
hash() to always give the same output for the same input then you must
ensure that elements of item always have the same layout in memory.
Typically this means using fixed width types and performing byte swapping
to account for endianness before passing item to hash(). However, since
you can't modify the keys in a map you may have to copy it into a
std::vector and then work from there.
!*/
// ----------------------------------------------------------------------------------------
inline uint32 hash (
uint32 item,
uint32 seed = 0
);
/*!
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3_2() routine to compute the actual hash.
- This routine will always give the same hash value when presented
with the same input.
!*/
// ----------------------------------------------------------------------------------------
inline uint32 hash (
uint64 item,
uint32 seed = 0
);
/*!
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3_128bit_3() routine to compute the actual hash.
- This routine will always give the same hash value when presented
with the same input.
!*/
// ----------------------------------------------------------------------------------------
template <typename T, typename U>
uint32 hash (
const std::pair<T,U>& item,
uint32 seed = 0
);
/*!
requires
- hash() is defined for objects of type T and U
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- if (calling hash() on items of type T and U is always guaranteed to give the
same hash values when presented with the same input) then
- This routine will always give the same hash value when presented
with the same input.
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_HAsH_ABSTRACT_Hh_
|