Ninja
hash_map.h
Go to the documentation of this file.
1// Copyright 2011 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef NINJA_MAP_H_
16#define NINJA_MAP_H_
17
18#include <algorithm>
19#include <string.h>
20#include "string_piece.h"
21#include "util.h"
22
23#include "third_party/emhash/hash_table8.hpp"
25
26namespace std {
27template<>
28struct hash<StringPiece> {
30 typedef size_t result_type;
31
32 size_t operator()(StringPiece key) const {
33 return rapidhash(key.str_, key.len_);
34 }
35};
36}
37
38/// A template for hash_maps keyed by a StringPiece whose string is
39/// owned externally (typically by the values). Use like:
40/// ExternalStringHash<Foo*>::Type foos; to make foos into a hash
41/// mapping StringPiece => Foo*.
42template<typename V>
44 typedef emhash8::HashMap<StringPiece, V> Type;
45};
46
47#endif // NINJA_MAP_H_
Definition hash_map.h:26
RAPIDHASH_INLINE uint64_t rapidhash(const void *key, size_t len) RAPIDHASH_NOEXCEPT
Definition rapidhash.h:321
A template for hash_maps keyed by a StringPiece whose string is owned externally (typically by the va...
Definition hash_map.h:43
emhash8::HashMap< StringPiece, std::unique_ptr< LogEntry > > Type
Definition hash_map.h:44
StringPiece represents a slice of a string whose memory is managed externally.
const char * str_
StringPiece argument_type
Definition hash_map.h:29
size_t operator()(StringPiece key) const
Definition hash_map.h:32