DJB.h 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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. #ifndef LLVM_SUPPORT_DJB_H
  13. #define LLVM_SUPPORT_DJB_H
  14. #include "llvm/ADT/StringRef.h"
  15. namespace llvm {
  16. /// The Bernstein hash function used by the DWARF accelerator tables.
  17. inline uint32_t djbHash(StringRef Buffer, uint32_t H = 5381) {
  18. for (unsigned char C : Buffer.bytes())
  19. H = (H << 5) + H + C;
  20. return H;
  21. }
  22. /// Computes the Bernstein hash after folding the input according to the Dwarf 5
  23. /// standard case folding rules.
  24. uint32_t caseFoldingDjbHash(StringRef Buffer, uint32_t H = 5381);
  25. } // namespace llvm
  26. #endif // LLVM_SUPPORT_DJB_H