blob: 6ebbec412297e04ca63e57d7e0643132f204c354 [file] [log] [blame]
// Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(PT-218): De-dupe this.
#include <stdint.h>
#include <string.h>
// FNV-1a Hash
#define FNV64_PRIME (1099511628211ULL)
#define FNV64_OFFSET_BASIS (14695981039346656037ULL)
static inline uint64_t fnv1a64(const void* ptr, size_t len) {
uint64_t n = FNV64_OFFSET_BASIS;
const uint8_t* data = (const uint8_t*)ptr;
while (len-- > 0) {
n = (n ^ (*data++)) * FNV64_PRIME;
return n;
#define fnv1a64str(str) fnv1a64(str, strlen(str))