| Index: compiled/IntMap.h |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/compiled/IntMap.h |
| @@ -0,0 +1,107 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-present eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +#pragma once |
| + |
| +#include <cstddef> |
| + |
| +#include "Map.h" |
| + |
| +namespace IntMap_internal |
| +{ |
| + struct IntSetEntry |
| + { |
| + typedef int key_type; |
|
sergei
2017/10/11 10:03:21
can it be more specific, e.g. uint32_t or int32_t
Wladimir Palant
2017/10/11 18:28:30
Done. Not going to add any template parameters how
sergei
2017/10/17 12:58:06
Acknowledged.
|
| + typedef size_t size_type; |
| + |
| + // The assumption here is that valid keys will always be non-negative |
|
sergei
2017/10/11 10:03:21
I would remove these comment, having a couple of r
Wladimir Palant
2017/10/11 18:28:30
Done. However, we need sentinel values at the edge
|
| + static const int KEY_INVALID = -1; |
|
sergei
2017/10/11 10:03:21
the type should be key_type, not int.
Wladimir Palant
2017/10/11 18:28:30
Done.
|
| + static const int KEY_DELETED = -2; |
|
hub
2017/10/10 20:37:53
Do these two const need to be public?
Wladimir Palant
2017/10/11 18:28:31
Done.
|
| + |
| + int first; |
|
sergei
2017/10/11 10:03:21
it should be key_type
Wladimir Palant
2017/10/11 18:28:30
Done.
|
| + |
| + IntSetEntry() |
| + : first(KEY_INVALID) |
| + { |
| + } |
| + |
| + IntSetEntry(key_type key) |
| + : first(key) |
| + { |
| + } |
| + |
| + bool equals(key_type other) const |
| + { |
| + return first == other; |
| + } |
| + |
| + bool is_invalid() const |
| + { |
| + return first == KEY_INVALID; |
| + } |
| + |
| + bool is_deleted() const |
| + { |
| + return first == KEY_DELETED; |
| + } |
| + |
| + void erase() |
| + { |
| + first = KEY_INVALID; |
| + } |
| + |
| + static size_type hash(key_type key) |
| + { |
| + return key; |
| + } |
| + }; |
| + |
| + template<typename Value> |
| + struct IntMapEntry : IntSetEntry |
|
sergei
2017/10/11 10:03:21
Maybe it's a premature generalization but I would
sergei
2017/10/11 10:05:11
IntSetEntry is of course from IntMap_internal.
Wladimir Palant
2017/10/11 18:28:30
Yes, probably premature generalization. Trouble is
sergei
2017/10/17 12:58:06
Acknowledged.
|
| + { |
| + typedef IntSetEntry super; |
| + typedef Value value_type; |
| + |
| + Value second; |
| + |
| + IntMapEntry() |
| + : IntSetEntry(), second() |
| + { |
| + } |
| + |
| + IntMapEntry(key_type key) |
| + : IntSetEntry(key), second() |
| + { |
| + } |
| + |
| + IntMapEntry(key_type key, value_type value) |
| + : IntSetEntry(key), second(value) |
| + { |
| + } |
| + |
| + void erase() |
| + { |
| + super::erase(); |
| + second = value_type(); |
| + } |
| + }; |
| +} |
| + |
| +using IntSet = Set<IntMap_internal::IntSetEntry>; |
| + |
| +template<typename Value> |
| +using IntMap = Map<IntMap_internal::IntMapEntry<Value>, Value>; |