blob: 8a04a324a5dc6cccaaa6af7b0e9b340f0755587e [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- llvm/Support/DJB.h ---DJB Hash --------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This file contains support for the DJ Bernstein hash function.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_DJB_H
14#define LLVM_SUPPORT_DJB_H
15
16#include "llvm/ADT/StringRef.h"
17
18namespace llvm {
19
20/// The Bernstein hash function used by the DWARF accelerator tables.
21inline uint32_t djbHash(StringRef Buffer, uint32_t H = 5381) {
22 for (unsigned char C : Buffer.bytes())
23 H = (H << 5) + H + C;
24 return H;
25}
26
27/// Computes the Bernstein hash after folding the input according to the Dwarf 5
28/// standard case folding rules.
29uint32_t caseFoldingDjbHash(StringRef Buffer, uint32_t H = 5381);
30} // namespace llvm
31
32#endif // LLVM_SUPPORT_DJB_H