LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include <climits> | 21 #include <climits> |
22 | 22 |
23 #include "Map.h" | 23 #include "Map.h" |
24 | 24 |
25 namespace Uint32Map_internal | 25 namespace Uint32Map_internal |
26 { | 26 { |
27 struct Uint32SetEntry | 27 struct Uint32SetEntry |
28 { | 28 { |
29 public: | 29 public: |
30 typedef uint32_t key_type; | 30 typedef uint32_t key_type; |
| 31 typedef key_type key_type_cref; |
31 typedef size_t size_type; | 32 typedef size_t size_type; |
32 | 33 |
33 private: | 34 protected: |
34 static const key_type KEY_INVALID = 0xFFFFFFFF; | 35 static const key_type KEY_INVALID = 0xFFFFFFFF; |
35 static const key_type KEY_DELETED = 0xFFFFFFFE; | 36 static const key_type KEY_DELETED = 0xFFFFFFFE; |
36 | 37 |
37 public: | 38 public: |
38 key_type first; | 39 key_type first; |
39 | 40 |
40 Uint32SetEntry(key_type key = KEY_INVALID) | 41 Uint32SetEntry(key_type_cref key = KEY_INVALID) |
41 : first(key) | 42 : first(key) |
42 { | 43 { |
43 } | 44 } |
44 | 45 |
45 bool equals(key_type other) const | 46 bool equals(key_type_cref other) const |
46 { | 47 { |
47 return first == other; | 48 return first == other; |
48 } | 49 } |
49 | 50 |
50 bool is_invalid() const | 51 bool is_invalid() const |
51 { | 52 { |
52 return first == KEY_INVALID; | 53 return first == KEY_INVALID; |
53 } | 54 } |
54 | 55 |
55 bool is_deleted() const | 56 bool is_deleted() const |
56 { | 57 { |
57 return first == KEY_DELETED; | 58 return first == KEY_DELETED; |
58 } | 59 } |
59 | 60 |
60 void erase() | 61 void erase() |
61 { | 62 { |
62 first = KEY_INVALID; | 63 first = KEY_INVALID; |
63 } | 64 } |
64 | 65 |
65 static size_type hash(key_type key) | 66 static size_type hash(key_type_cref key) |
66 { | 67 { |
67 return key; | 68 return key; |
68 } | 69 } |
69 }; | 70 }; |
70 | 71 |
71 template<typename Value> | 72 template<typename Value> |
72 struct Uint32MapEntry : Uint32SetEntry | 73 struct Uint32MapEntry : Uint32SetEntry |
73 { | 74 { |
74 typedef Uint32SetEntry super; | 75 typedef Uint32SetEntry super; |
75 typedef Value value_type; | 76 typedef Value value_type; |
76 | 77 |
77 Value second; | 78 value_type second; |
78 | 79 |
79 Uint32MapEntry(key_type key = key_type(), value_type value = value_type()) | 80 Uint32MapEntry(key_type_cref key = KEY_INVALID, value_type value = value_typ
e()) |
80 : Uint32SetEntry(key), second(value) | 81 : Uint32SetEntry(key), second(value) |
81 { | 82 { |
82 } | 83 } |
83 | 84 |
84 void erase() | 85 void erase() |
85 { | 86 { |
86 super::erase(); | 87 super::erase(); |
87 second = value_type(); | 88 second = value_type(); |
88 } | 89 } |
89 }; | 90 }; |
90 } | 91 } |
91 | 92 |
92 using Uint32Set = Set<Uint32Map_internal::Uint32SetEntry>; | 93 using Uint32Set = Set<Uint32Map_internal::Uint32SetEntry>; |
93 | 94 |
94 template<typename Value> | 95 template<typename Value> |
95 using Uint32Map = Map<Uint32Map_internal::Uint32MapEntry<Value>>; | 96 using Uint32Map = Map<Uint32Map_internal::Uint32MapEntry<Value>>; |
LEFT | RIGHT |