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: Created Oct. 10, 2017, 2:25 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') | compiled/Map.h » ('J')
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
22 #include "Map.h"
23
24 namespace IntMap_internal
25 {
26 struct IntSetEntry
27 {
28 typedef int key_type;
29 typedef size_t size_type;
30
31 // The assumption here is that valid keys will always be non-negative
32 static const int KEY_INVALID = -1;
33 static const int KEY_DELETED = -2;
34
35 int first;
36
37 IntSetEntry()
38 : first(KEY_INVALID)
39 {
40 }
41
42 IntSetEntry(key_type key)
43 : first(key)
44 {
45 }
46
47 bool equals(key_type other) const
48 {
49 return first == other;
50 }
51
52 bool is_invalid() const
53 {
54 return first == KEY_INVALID;
55 }
56
57 bool is_deleted() const
58 {
59 return first == KEY_DELETED;
60 }
61
62 void erase()
63 {
64 first = KEY_INVALID;
65 }
66
67 static size_type hash(key_type key)
68 {
69 return key;
70 }
71 };
72
73 template<typename Value>
74 struct IntMapEntry : IntSetEntry
75 {
76 typedef IntSetEntry super;
77 typedef Value value_type;
78
79 Value second;
80
81 IntMapEntry()
82 : IntSetEntry(), second()
83 {
84 }
85
86 IntMapEntry(key_type key)
87 : IntSetEntry(key), second()
88 {
89 }
90
91 IntMapEntry(key_type key, value_type value)
92 : IntSetEntry(key), second(value)
93 {
94 }
95
96 void erase()
97 {
98 super::erase();
99 second = value_type();
100 }
101 };
102 }
103
104 class IntSet : public Set<IntMap_internal::IntSetEntry>
105 {
106 };
107
108 template<typename Value>
109 class IntMap : public Map<IntMap_internal::IntMapEntry<Value>, Value>
110 {
111 };
Wladimir Palant 2017/10/10 14:33:58 This class hasn't been tested yet beyond the fact
OLDNEW
« no previous file with comments | « no previous file | compiled/Map.h » ('j') | compiled/Map.h » ('J')

Powered by Google App Engine
This is Rietveld