Kea 2.7.6
hash.h
Go to the documentation of this file.
1// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef HASH_H
8#define HASH_H
9
10#include <cstddef>
11#include <cstdint>
12#include <string>
13
14namespace isc {
15namespace util {
16
19struct Hash64 {
27 static uint64_t hash(const uint8_t* data, size_t length) {
28 uint64_t hash = FNV_offset_basis;
29 for (size_t i = 0; i < length; ++i) {
30 hash = hash ^ data[i];
32 }
33 return (hash);
34 }
35
42 static uint64_t hash(const std::string& str) {
43 return (hash(reinterpret_cast<const uint8_t*>(str.c_str()),
44 str.size()));
45 }
46
48 static const uint64_t FNV_offset_basis = 14695981039346656037ull;
49
51 static const uint64_t FNV_prime = 1099511628211ull;
52};
53
54} // end of namespace isc::util
55} // end of namespace isc
56
57#endif
Defines the logger used by the top-level component of kea-lfc.
Hash implementation based on Fowler-Noll-Vo hash function.
Definition hash.h:19
static uint64_t hash(const uint8_t *data, size_t length)
Compute the hash.
Definition hash.h:27
static uint64_t hash(const std::string &str)
Compute the hash.
Definition hash.h:42
static const uint64_t FNV_prime
Prime.
Definition hash.h:51
static const uint64_t FNV_offset_basis
Offset basis.
Definition hash.h:48