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 (C) 2012-2020 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef HASHTABLES_H_
26#define HASHTABLES_H_
27
28#include <unordered_map>
29
30#include <wx/string.h>
31
32// First some utility classes and functions
33
36{
37 bool operator()( const char* x, const char* y ) const
38 {
39 return !strcmp( x, y );
40 }
41};
42
43
47struct fnv_1a
48{
49 std::size_t operator()( const char* it ) const
50 {
51 std::size_t hash = 2166136261u;
52
53 for( ; *it; ++it )
54 {
55 hash ^= (unsigned char) *it;
56 hash *= 16777619;
57 }
58 return hash;
59 }
60};
61
62
63#ifdef SWIG
65#define DECL_HASH_FOR_SWIG( TypeName, KeyType, ValueType ) \
66 namespace std \
67 { \
68 % template( TypeName ) unordered_map<KeyType, ValueType>; \
69 } \
70 typedef std::unordered_map<KeyType, ValueType> TypeName;
71#else
73#define DECL_HASH_FOR_SWIG( TypeName, KeyType, ValueType ) \
74 typedef std::unordered_map<KeyType, ValueType> TypeName;
75#endif
76
77
95typedef std::unordered_map< const char*, int, fnv_1a, iequal_to > KEYWORD_MAP;
96
97
98#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:95
Very fast and efficient hash function for "const char*" type, used in specialized KEYWORD_MAP below.
Definition: hashtables.h:48
std::size_t operator()(const char *it) const
Definition: hashtables.h:49
Equality test for "const char*" type used in very specialized KEYWORD_MAP below.
Definition: hashtables.h:36
bool operator()(const char *x, const char *y) const
Definition: hashtables.h:37