xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Support/DJB.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- llvm/Support/DJB.h ---DJB Hash --------------------------*- C++ -*-===//
2 //
3 // 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
6 //
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 #include "llvm/Support/Compiler.h"
18 
19 namespace llvm {
20 
21 /// The Bernstein hash function used by the DWARF accelerator tables.
22 inline uint32_t djbHash(StringRef Buffer, uint32_t H = 5381) {
23   for (unsigned char C : Buffer.bytes())
24     H = (H << 5) + H + C;
25   return H;
26 }
27 
28 /// Computes the Bernstein hash after folding the input according to the Dwarf 5
29 /// standard case folding rules.
30 LLVM_ABI uint32_t caseFoldingDjbHash(StringRef Buffer, uint32_t H = 5381);
31 } // namespace llvm
32 
33 #endif // LLVM_SUPPORT_DJB_H
34