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: Removed redundant template parameter for Map class as well Created Oct. 11, 2017, 6:27 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 size_t size_type;
32
33 private:
34 static const key_type KEY_INVALID = 0xFFFFFFFF;
35 static const key_type KEY_DELETED = 0xFFFFFFFE;
36
37 public:
38 key_type first;
39
40 Uint32SetEntry(key_type key = KEY_INVALID)
41 : first(key)
42 {
43 }
44
45 bool equals(key_type other) const
46 {
47 return first == other;
48 }
49
50 bool is_invalid() const
51 {
52 return first == KEY_INVALID;
53 }
54
55 bool is_deleted() const
56 {
57 return first == KEY_DELETED;
58 }
59
60 void erase()
61 {
62 first = KEY_INVALID;
63 }
64
65 static size_type hash(key_type key)
66 {
67 return key;
68 }
69 };
70
71 template<typename Value>
72 struct Uint32MapEntry : Uint32SetEntry
73 {
74 typedef Uint32SetEntry super;
75 typedef Value value_type;
76
77 Value second;
78
79 Uint32MapEntry(key_type key = key_type(), value_type value = value_type())
80 : Uint32SetEntry(key), second(value)
81 {
82 }
83
84 void erase()
85 {
86 super::erase();
87 second = value_type();
88 }
89 };
90 }
91
92 using Uint32Set = Set<Uint32Map_internal::Uint32SetEntry>;
93
94 template<typename Value>
95 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