Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/IntMap.h

Issue 29572731: Issue 5141 - Generalize Map class to allow non-strings as keys (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Addressed remaining nits Created Dec. 4, 2017, 6:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | compiled/Map.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #pragma once
19
20 #include <cstddef>
21 #include <climits>
22
23 #include "Map.h"
24
25 namespace Uint32Map_internal
26 {
27 struct Uint32SetEntry
28 {
29 public:
30 typedef uint32_t key_type;
31 typedef key_type key_type_cref;
32 typedef size_t size_type;
33
34 protected:
35 static const key_type KEY_INVALID = 0xFFFFFFFF;
36 static const key_type KEY_DELETED = 0xFFFFFFFE;
37
38 public:
39 key_type first;
40
41 Uint32SetEntry(key_type_cref key = KEY_INVALID)
42 : first(key)
43 {
44 }
45
46 bool equals(key_type_cref other) const
47 {
48 return first == other;
49 }
50
51 bool is_invalid() const
52 {
53 return first == KEY_INVALID;
54 }
55
56 bool is_deleted() const
57 {
58 return first == KEY_DELETED;
59 }
60
61 void erase()
62 {
63 first = KEY_INVALID;
64 }
65
66 static size_type hash(key_type_cref key)
67 {
68 return key;
69 }
70 };
71
72 template<typename Value>
73 struct Uint32MapEntry : Uint32SetEntry
74 {
75 typedef Uint32SetEntry super;
76 typedef Value value_type;
77
78 value_type second;
79
80 Uint32MapEntry(key_type_cref key = KEY_INVALID, value_type value = value_typ e())
81 : Uint32SetEntry(key), second(value)
82 {
83 }
84
85 void erase()
86 {
87 super::erase();
88 second = value_type();
89 }
90 };
91 }
92
93 using Uint32Set = Set<Uint32Map_internal::Uint32SetEntry>;
94
95 template<typename Value>
96 using Uint32Map = Map<Uint32Map_internal::Uint32MapEntry<Value>>;
OLDNEW
« no previous file with comments | « no previous file | compiled/Map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld