DJB.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/Support/DJB.h ---DJB Hash --------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file contains support for the DJ Bernstein hash function.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_SUPPORT_DJB_H
  18. #define LLVM_SUPPORT_DJB_H
  19. #include "llvm/ADT/StringRef.h"
  20. namespace llvm {
  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. /// Computes the Bernstein hash after folding the input according to the Dwarf 5
  28. /// standard case folding rules.
  29. uint32_t caseFoldingDjbHash(StringRef Buffer, uint32_t H = 5381);
  30. } // namespace llvm
  31. #endif // LLVM_SUPPORT_DJB_H
  32. #ifdef __GNUC__
  33. #pragma GCC diagnostic pop
  34. #endif