KiCad PCB EDA Suite
Loading...
Searching...
No Matches
hashtables.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef HASHTABLES_H_
22#define HASHTABLES_H_
23
24#include <cstddef>
25#include <unordered_map>
26
27#include <wx/string.h>
28
29// First some utility classes and functions
30
31
42inline std::size_t KiHashCombine( std::size_t aSeed, std::size_t aValue )
43{
44 return aSeed ^ ( aValue + 0x9e3779b9 + ( aSeed << 6 ) + ( aSeed >> 2 ) );
45}
46
49{
50 bool operator()( const char* x, const char* y ) const
51 {
52 return !strcmp( x, y );
53 }
54};
55
56
60struct fnv_1a
61{
62 std::size_t operator()( const char* it ) const
63 {
64 std::size_t hash = 2166136261u;
65
66 for( ; *it; ++it )
67 {
68 hash ^= (unsigned char) *it;
69 hash *= 16777619;
70 }
71 return hash;
72 }
73};
74
75
93typedef std::unordered_map< const char*, int, fnv_1a, iequal_to > KEYWORD_MAP;
94
95
96#endif // HASHTABLES_H_
std::unordered_map< const char *, int, fnv_1a, iequal_to > KEYWORD_MAP
A hashtable made of a const char* and an int.
Definition hashtables.h:93
std::size_t KiHashCombine(std::size_t aSeed, std::size_t aValue)
Fold aValue into the running hash aSeed using the well-known Boost hash_combine mixing step.
Definition hashtables.h:42
Very fast and efficient hash function for "const char*" type, used in specialized KEYWORD_MAP below.
Definition hashtables.h:61
std::size_t operator()(const char *it) const
Definition hashtables.h:62
Equality test for "const char*" type used in very specialized KEYWORD_MAP below.
Definition hashtables.h:49
bool operator()(const char *x, const char *y) const
Definition hashtables.h:50