]>
Commit | Line | Data |
---|---|---|
25436c30 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
25436c30 FC |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | #include "squid.h" | |
5218815a | 10 | #include "Algorithms.h" |
25436c30 | 11 | |
e37f2b5a | 12 | // private common implementation for SBuf hash variants |
ae72213d | 13 | static std::size_t |
e37f2b5a | 14 | SBufHashCommon_ (const SBuf & sbuf, bool caseInsensitive) noexcept |
25436c30 FC |
15 | { |
16 | //ripped and adapted from hash_string | |
17 | const char *s = sbuf.rawContent(); | |
18 | size_t rv = 0; | |
19 | SBuf::size_type len=sbuf.length(); | |
20 | while (len != 0) { | |
ae72213d | 21 | rv ^= 271 * (caseInsensitive? xtolower(*s) : *s); |
25436c30 FC |
22 | ++s; |
23 | --len; | |
24 | } | |
25 | return rv ^ (sbuf.length() * 271); | |
26 | } | |
132d9943 | 27 | |
ae72213d FC |
28 | std::size_t |
29 | std::hash<SBuf>::operator() (const SBuf & sbuf) const noexcept | |
30 | { | |
e37f2b5a | 31 | return SBufHashCommon_(sbuf, false); |
ae72213d FC |
32 | } |
33 | ||
34 | std::size_t | |
35 | CaseInsensitiveSBufHash::operator() (const SBuf & sbuf) const noexcept | |
36 | { | |
e37f2b5a | 37 | return SBufHashCommon_(sbuf, true); |
ae72213d FC |
38 | } |
39 |