summaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/string_hash.cpp
blob: f58d081c58aef75ba9bc9a8f5f726f5d0d53bbdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "string_hash.h"

namespace vespalib {

uint32_t hash_code(const char *str, size_t len) {
    uint32_t hash = 0;
    for (size_t i = 0; i < len; ++i) {
        hash = (hash << 5) - hash + str[i];
    }
    return hash;
}

uint32_t hash_code(vespalib::stringref str) {
    return hash_code(str.data(), str.size());
}

} // namespace vespalib