| 6 | #define BASE_CONTAINERS_SMALL_MAP_H_ |
| 7 |
| 8 | #include <stddef.h> |
| 9 |
| 10 | #include <limits> |
| 11 | #include <map> |
| 12 | #include <new> |
| 13 | #include <string> |
| 14 | #include <unordered_map> |
| 15 | #include <utility> |
| 16 |
| 17 | #include "base/logging.h" |
| 18 |
| 19 | namespace { |
| 20 | constexpr size_t kUsingFullMapSentinel = std::numeric_limits<size_t>::max(); |
| 21 | } // namespace |
| 22 |
| 23 | namespace base { |
| 24 |
| 25 | // small_map is a container with a std::map-like interface. It starts out backed |
| 26 | // by an unsorted array but switches to some other container type if it grows |
| 27 | // beyond this fixed size. |
| 28 | // |
| 29 | // Please see //base/containers/README.md for an overview of which container |
| 30 | // to select. |
| 31 | // |
| 32 | // PROS |
| 33 | // |
| 34 | // - Good memory locality and low overhead for smaller maps. |
| 35 | // - Handles large maps without the degenerate performance of flat_map. |
| 36 | // |
| 37 | // CONS |
| 38 | // |
| 39 | // - Larger code size than the alternatives. |
| 40 | // |
| 41 | // IMPORTANT NOTES |
| 42 | // |
| 43 | // - Iterators are invalidated across mutations. |
| 44 | // |
| 45 | // DETAILS |
| 46 | // |
| 47 | // base::small_map will pick up the comparator from the underlying map type. In |
| 48 | // std::map only a "less" operator is defined, which requires us to do two |
| 49 | // comparisons per element when doing the brute-force search in the simple |
| 50 | // array. std::unordered_map has a key_equal function which will be used. |
| 51 | // |
| 52 | // We define default overrides for the common map types to avoid this |
| 53 | // double-compare, but you should be aware of this if you use your own operator< |
| 54 | // for your map and supply yor own version of == to the small_map. You can use |
| 55 | // regular operator== by just doing: |
| 56 | // |
| 57 | // base::small_map<std::map<MyKey, MyValue>, 4, std::equal_to<KyKey>> |
| 58 | // |
| 59 | // |
| 60 | // USAGE |
| 61 | // ----- |
| 62 | // |
| 63 | // NormalMap: The map type to fall back to. This also defines the key and value |
| 64 | // types for the small_map. |
| 65 | // kArraySize: The size of the initial array of results. This will be allocated |
| 66 | // with the small_map object rather than separately on the heap. |
| 67 | // Once the map grows beyond this size, the map type will be used |
| 68 | // instead. |
| 69 | // EqualKey: A functor which tests two keys for equality. If the wrapped map |
| 70 | // type has a "key_equal" member (unordered_map does), then that will |
| 71 | // be used by default. If the wrapped map type has a strict weak |
| 72 | // ordering "key_compare" (std::map does), that will be used to |
| 73 | // implement equality by default. |
| 74 | // MapInit: A functor that takes a NormalMap* and uses it to initialize the map. |
| 75 | // This functor will be called at most once per small_map, when the map |
| 76 | // exceeds the threshold of kArraySize and we are about to copy values |
| 77 | // from the array to the map. The functor *must* initialize the |
| 78 | // NormalMap* argument with placement new, since after it runs we |
| 79 | // assume that the NormalMap has been initialized. |
| 80 | // |
| 81 | // Example: |
| 82 | // base::small_map<std::map<string, int>> days; |
| 83 | // days["sunday" ] = 0; |
| 84 | // days["monday" ] = 1; |
| 85 | // days["tuesday" ] = 2; |
| 86 | // days["wednesday"] = 3; |
| 87 | // days["thursday" ] = 4; |
| 88 | // days["friday" ] = 5; |
| 89 | // days["saturday" ] = 6; |
| 90 |
| 91 | namespace internal { |
| 92 |
| 93 | template <typename NormalMap> |
| 94 | class small_map_default_init { |
| 95 | public: |
| 96 | void operator()(NormalMap* map) const { new (map) NormalMap(); } |
| 97 | }; |
| 98 |
| 99 | // has_key_equal<M>::value is true iff there exists a type M::key_equal. This is |
| 100 | // used to dispatch to one of the select_equal_key<> metafunctions below. |
| 101 | template <typename M> |
| 102 | struct has_key_equal { |
| 103 | typedef char sml; // "small" is sometimes #defined so we use an abbreviation. |
| 104 | typedef struct { char dummy[2]; } big; |
| 105 | // Two functions, one accepts types that have a key_equal member, and one that |
| 106 | // accepts anything. They each return a value of a different size, so we can |
| 107 | // determine at compile-time which function would have been called. |
| 108 | template <typename U> static big test(typename U::key_equal*); |
| 109 | template <typename> static sml test(...); |
| 110 | // Determines if M::key_equal exists by looking at the size of the return |
| 111 | // type of the compiler-chosen test() function. |
| 112 | static const bool value = (sizeof(test<M>(0)) == sizeof(big)); |
| 113 | }; |
| 114 | template <typename M> const bool has_key_equal<M>::value; |
| 115 |
| 116 | // Base template used for map types that do NOT have an M::key_equal member, |
| 117 | // e.g., std::map<>. These maps have a strict weak ordering comparator rather |
| 118 | // than an equality functor, so equality will be implemented in terms of that |
| 119 | // comparator. |
| 120 | // |
| 121 | // There's a partial specialization of this template below for map types that do |
| 122 | // have an M::key_equal member. |
| 123 | template <typename M, bool has_key_equal_value> |
| 124 | struct select_equal_key { |
| 125 | struct equal_key { |
| 126 | bool operator()(const typename M::key_type& left, |
| 127 | const typename M::key_type& right) { |
| 128 | // Implements equality in terms of a strict weak ordering comparator. |
| 129 | typename M::key_compare comp; |
| 130 | return !comp(left, right) && !comp(right, left); |
| 131 | } |
| 132 | }; |
| 133 | }; |
| 134 |
| 135 | // Partial template specialization handles case where M::key_equal exists, e.g., |
| 136 | // unordered_map<>. |
| 137 | template <typename M> |
| 138 | struct select_equal_key<M, true> { |
| 139 | typedef typename M::key_equal equal_key; |
| 140 | }; |
| 141 |
| 142 | } // namespace internal |
| 143 |
| 144 | template <typename NormalMap, |
| 145 | size_t kArraySize = 4, |
| 146 | typename EqualKey = typename internal::select_equal_key< |
| 147 | NormalMap, |
| 148 | internal::has_key_equal<NormalMap>::value>::equal_key, |
| 149 | typename MapInit = internal::small_map_default_init<NormalMap>> |
| 150 | class small_map { |
| 151 | static_assert(kArraySize > 0, "Initial size must be greater than 0"); |
| 152 | static_assert(kArraySize != kUsingFullMapSentinel, |
| 153 | "Initial size out of range"); |
| 154 |
| 155 | public: |
| 156 | typedef typename NormalMap::key_type key_type; |
| 157 | typedef typename NormalMap::mapped_type data_type; |
| 158 | typedef typename NormalMap::mapped_type mapped_type; |
| 159 | typedef typename NormalMap::value_type value_type; |
| 160 | typedef EqualKey key_equal; |
| 161 |
| 162 | small_map() : size_(0), functor_(MapInit()) {} |
| 163 |
| 164 | explicit small_map(const MapInit& functor) : size_(0), functor_(functor) {} |
| 165 |
| 166 | // Allow copy-constructor and assignment, since STL allows them too. |
| 167 | small_map(const small_map& src) { |
| 168 | // size_ and functor_ are initted in InitFrom() |
| 169 | InitFrom(src); |
| 170 | } |
| 171 |
| 172 | void operator=(const small_map& src) { |
| 173 | if (&src == this) return; |
| 174 |
| 175 | // This is not optimal. If src and dest are both using the small array, we |
| 176 | // could skip the teardown and reconstruct. One problem to be resolved is |
| 177 | // that the value_type itself is pair<const K, V>, and const K is not |
| 178 | // assignable. |
| 179 | Destroy(); |
| 180 | InitFrom(src); |
| 181 | } |
| 182 |
| 183 | ~small_map() { Destroy(); } |
| 184 |
| 185 | class const_iterator; |
| 186 |
| 187 | class iterator { |
| 188 | public: |
| 189 | typedef typename NormalMap::iterator::iterator_category iterator_category; |
| 190 | typedef typename NormalMap::iterator::value_type value_type; |
| 191 | typedef typename NormalMap::iterator::difference_type difference_type; |
| 192 | typedef typename NormalMap::iterator::pointer pointer; |
| 193 | typedef typename NormalMap::iterator::reference reference; |
| 194 |
| 195 | inline iterator() : array_iter_(nullptr) {} |
| 196 |
| 197 | inline iterator& operator++() { |
| 198 | if (array_iter_ != nullptr) { |
| 199 | ++array_iter_; |
| 200 | } else { |
| 201 | ++map_iter_; |
| 202 | } |
| 203 | return *this; |
| 204 | } |
| 205 |
| 206 | inline iterator operator++(int /*unused*/) { |
| 207 | iterator result(*this); |
| 208 | ++(*this); |
| 209 | return result; |
| 210 | } |
| 211 |
| 212 | inline iterator& operator--() { |
| 213 | if (array_iter_ != nullptr) { |
| 214 | --array_iter_; |
| 215 | } else { |
| 216 | --map_iter_; |
| 217 | } |
| 218 | return *this; |
| 219 | } |
| 220 |
| 221 | inline iterator operator--(int /*unused*/) { |
| 222 | iterator result(*this); |
| 223 | --(*this); |
| 224 | return result; |
| 225 | } |
| 226 |
| 227 | inline value_type* operator->() const { |
| 228 | return array_iter_ ? array_iter_ : map_iter_.operator->(); |
| 229 | } |
| 230 |
| 231 | inline value_type& operator*() const { |
| 232 | return array_iter_ ? *array_iter_ : *map_iter_; |
| 233 | } |
| 234 |
| 235 | inline bool operator==(const iterator& other) const { |
| 236 | if (array_iter_ != nullptr) { |
| 237 | return array_iter_ == other.array_iter_; |
| 238 | } else { |
| 239 | return other.array_iter_ == nullptr && map_iter_ == other.map_iter_; |
| 240 | } |
| 241 | } |
| 242 |
| 243 | inline bool operator!=(const iterator& other) const { |
| 244 | return !(*this == other); |
| 245 | } |
| 246 |
| 247 | bool operator==(const const_iterator& other) const; |
| 248 | bool operator!=(const const_iterator& other) const; |
| 249 |
| 250 | private: |
| 251 | friend class small_map; |
| 252 | friend class const_iterator; |
| 253 | inline explicit iterator(value_type* init) : array_iter_(init) {} |
| 254 | inline explicit iterator(const typename NormalMap::iterator& init) |
| 255 | : array_iter_(nullptr), map_iter_(init) {} |
| 256 |
| 257 | value_type* array_iter_; |
| 258 | typename NormalMap::iterator map_iter_; |
| 259 | }; |
| 260 |
| 261 | class const_iterator { |
| 262 | public: |
| 263 | typedef typename NormalMap::const_iterator::iterator_category |
| 264 | iterator_category; |
| 265 | typedef typename NormalMap::const_iterator::value_type value_type; |
| 266 | typedef typename NormalMap::const_iterator::difference_type difference_type; |
| 267 | typedef typename NormalMap::const_iterator::pointer pointer; |
| 268 | typedef typename NormalMap::const_iterator::reference reference; |
| 269 |
| 270 | inline const_iterator() : array_iter_(nullptr) {} |
| 271 |
| 272 | // Non-explicit constructor lets us convert regular iterators to const |
| 273 | // iterators. |
| 274 | inline const_iterator(const iterator& other) |
| 275 | : array_iter_(other.array_iter_), map_iter_(other.map_iter_) {} |
| 276 |
| 277 | inline const_iterator& operator++() { |
| 278 | if (array_iter_ != nullptr) { |
| 279 | ++array_iter_; |
| 280 | } else { |
| 281 | ++map_iter_; |
| 282 | } |
| 283 | return *this; |
| 284 | } |
| 285 |
| 286 | inline const_iterator operator++(int /*unused*/) { |
| 287 | const_iterator result(*this); |
| 288 | ++(*this); |
| 289 | return result; |
| 290 | } |
| 291 |
| 292 | inline const_iterator& operator--() { |
| 293 | if (array_iter_ != nullptr) { |
| 294 | --array_iter_; |
| 295 | } else { |
| 296 | --map_iter_; |
| 297 | } |
| 298 | return *this; |
| 299 | } |
| 300 |
| 301 | inline const_iterator operator--(int /*unused*/) { |
| 302 | const_iterator result(*this); |
| 303 | --(*this); |
| 304 | return result; |
| 305 | } |
| 306 |
| 307 | inline const value_type* operator->() const { |
| 308 | return array_iter_ ? array_iter_ : map_iter_.operator->(); |
| 309 | } |
| 310 |
| 311 | inline const value_type& operator*() const { |
| 312 | return array_iter_ ? *array_iter_ : *map_iter_; |
| 313 | } |
| 314 |
| 315 | inline bool operator==(const const_iterator& other) const { |
| 316 | if (array_iter_ != nullptr) { |
| 317 | return array_iter_ == other.array_iter_; |
| 318 | } |
| 319 | return other.array_iter_ == nullptr && map_iter_ == other.map_iter_; |
| 320 | } |
| 321 |
| 322 | inline bool operator!=(const const_iterator& other) const { |
| 323 | return !(*this == other); |
| 324 | } |
| 325 |
| 326 | private: |
| 327 | friend class small_map; |
| 328 | inline explicit const_iterator(const value_type* init) |
| 329 | : array_iter_(init) {} |
| 330 | inline explicit const_iterator( |
| 331 | const typename NormalMap::const_iterator& init) |
| 332 | : array_iter_(nullptr), map_iter_(init) {} |
| 333 |
| 334 | const value_type* array_iter_; |
| 335 | typename NormalMap::const_iterator map_iter_; |
| 336 | }; |
| 337 |
| 338 | iterator find(const key_type& key) { |
| 339 | key_equal compare; |
| 340 |
| 341 | if (UsingFullMap()) { |
| 342 | return iterator(map()->find(key)); |
| 343 | } |
| 344 |
| 345 | for (size_t i = 0; i < size_; ++i) { |
| 346 | if (compare(array_[i].first, key)) { |
| 347 | return iterator(array_ + i); |
| 348 | } |
| 349 | } |
| 350 | return iterator(array_ + size_); |
| 351 | } |
| 352 |
| 353 | const_iterator find(const key_type& key) const { |
| 354 | key_equal compare; |
| 355 |
| 356 | if (UsingFullMap()) { |
| 357 | return const_iterator(map()->find(key)); |
| 358 | } |
| 359 |
| 360 | for (size_t i = 0; i < size_; ++i) { |
| 361 | if (compare(array_[i].first, key)) { |
| 362 | return const_iterator(array_ + i); |
| 363 | } |
| 364 | } |
| 365 | return const_iterator(array_ + size_); |
| 366 | } |
| 367 |
| 368 | // Invalidates iterators. |
| 369 | data_type& operator[](const key_type& key) { |
| 370 | key_equal compare; |
| 371 |
| 372 | if (UsingFullMap()) { |
| 373 | return map_[key]; |
| 374 | } |
| 375 |
| 376 | // Search backwards to favor recently-added elements. |
| 377 | for (size_t i = size_; i > 0; --i) { |
| 378 | const size_t index = i - 1; |
| 379 | if (compare(array_[index].first, key)) { |
| 380 | return array_[index].second; |
| 381 | } |
| 382 | } |
| 383 |
| 384 | if (size_ == kArraySize) { |
| 385 | ConvertToRealMap(); |
| 386 | return map_[key]; |
| 387 | } |
| 388 |
| 389 | DCHECK(size_ < kArraySize); |
| 390 | new (&array_[size_]) value_type(key, data_type()); |
| 391 | return array_[size_++].second; |
| 392 | } |
| 393 |
| 394 | // Invalidates iterators. |
| 395 | std::pair<iterator, bool> insert(const value_type& x) { |
| 396 | key_equal compare; |
| 397 |
| 398 | if (UsingFullMap()) { |
| 399 | std::pair<typename NormalMap::iterator, bool> ret = map_.insert(x); |
| 400 | return std::make_pair(iterator(ret.first), ret.second); |
| 401 | } |
| 402 |
| 403 | for (size_t i = 0; i < size_; ++i) { |
| 404 | if (compare(array_[i].first, x.first)) { |
| 405 | return std::make_pair(iterator(array_ + i), false); |
| 406 | } |
| 407 | } |
| 408 |
| 409 | if (size_ == kArraySize) { |
| 410 | ConvertToRealMap(); // Invalidates all iterators! |
| 411 | std::pair<typename NormalMap::iterator, bool> ret = map_.insert(x); |
| 412 | return std::make_pair(iterator(ret.first), ret.second); |
| 413 | } |
| 414 |
| 415 | DCHECK(size_ < kArraySize); |
| 416 | new (&array_[size_]) value_type(x); |
| 417 | return std::make_pair(iterator(array_ + size_++), true); |
| 418 | } |
| 419 |
| 420 | // Invalidates iterators. |
| 421 | template <class InputIterator> |
| 422 | void insert(InputIterator f, InputIterator l) { |
| 423 | while (f != l) { |
| 424 | insert(*f); |
| 425 | ++f; |
| 426 | } |
| 427 | } |
| 428 |
| 429 | // Invalidates iterators. |
| 430 | template <typename... Args> |
| 431 | std::pair<iterator, bool> emplace(Args&&... args) { |
| 432 | key_equal compare; |
| 433 |
| 434 | if (UsingFullMap()) { |
| 435 | std::pair<typename NormalMap::iterator, bool> ret = |
| 436 | map_.emplace(std::forward<Args>(args)...); |
| 437 | return std::make_pair(iterator(ret.first), ret.second); |
| 438 | } |
| 439 |
| 440 | value_type x(std::forward<Args>(args)...); |
| 441 | for (size_t i = 0; i < size_; ++i) { |
| 442 | if (compare(array_[i].first, x.first)) { |
| 443 | return std::make_pair(iterator(array_ + i), false); |
| 444 | } |
| 445 | } |
| 446 |
| 447 | if (size_ == kArraySize) { |
| 448 | ConvertToRealMap(); // Invalidates all iterators! |
| 449 | std::pair<typename NormalMap::iterator, bool> ret = |
| 450 | map_.emplace(std::move(x)); |
| 451 | return std::make_pair(iterator(ret.first), ret.second); |
| 452 | } |
| 453 |
| 454 | DCHECK(size_ < kArraySize); |
| 455 | new (&array_[size_]) value_type(std::move(x)); |
| 456 | return std::make_pair(iterator(array_ + size_++), true); |
| 457 | } |
| 458 |
| 459 | iterator begin() { |
| 460 | return UsingFullMap() ? iterator(map_.begin()) : iterator(array_); |
| 461 | } |
| 462 |
| 463 | const_iterator begin() const { |
| 464 | return UsingFullMap() ? const_iterator(map_.begin()) |
| 465 | : const_iterator(array_); |
| 466 | } |
| 467 |
| 468 | iterator end() { |
| 469 | return UsingFullMap() ? iterator(map_.end()) : iterator(array_ + size_); |
| 470 | } |
| 471 |
| 472 | const_iterator end() const { |
| 473 | return UsingFullMap() ? const_iterator(map_.end()) |
| 474 | : const_iterator(array_ + size_); |
| 475 | } |
| 476 |
| 477 | void clear() { |
| 478 | if (UsingFullMap()) { |
| 479 | map_.~NormalMap(); |
| 480 | } else { |
| 481 | for (size_t i = 0; i < size_; ++i) { |
| 482 | array_[i].~value_type(); |
| 483 | } |
| 484 | } |
| 485 | size_ = 0; |
| 486 | } |
| 487 |
| 488 | // Invalidates iterators. Returns iterator following the last removed element. |
| 489 | iterator erase(const iterator& position) { |
| 490 | if (UsingFullMap()) { |
| 491 | return iterator(map_.erase(position.map_iter_)); |
| 492 | } |
| 493 |
| 494 | size_t i = position.array_iter_ - array_; |
| 495 | // TODO(crbug.com/817982): When we have a checked iterator, this CHECK might |
| 496 | // not be necessary. |
| 497 | CHECK_LE(i, size_); |
| 498 | array_[i].~value_type(); |
| 499 | --size_; |
| 500 | if (i != size_) { |
| 501 | new (&array_[i]) value_type(std::move(array_[size_])); |
| 502 | array_[size_].~value_type(); |
| 503 | return iterator(array_ + i); |
| 504 | } |
| 505 | return end(); |
| 506 | } |
| 507 |
| 508 | size_t erase(const key_type& key) { |
| 509 | iterator iter = find(key); |
| 510 | if (iter == end()) { |
| 511 | return 0; |
| 512 | } |
| 513 | erase(iter); |
| 514 | return 1; |
| 515 | } |
| 516 |
| 517 | size_t count(const key_type& key) const { |
| 518 | return (find(key) == end()) ? 0 : 1; |
| 519 | } |
| 520 |
| 521 | size_t size() const { return UsingFullMap() ? map_.size() : size_; } |
| 522 |
| 523 | bool empty() const { return UsingFullMap() ? map_.empty() : size_ == 0; } |
| 524 |
| 525 | // Returns true if we have fallen back to using the underlying map |
| 526 | // representation. |
| 527 | bool UsingFullMap() const { return size_ == kUsingFullMapSentinel; } |
| 528 |
| 529 | inline NormalMap* map() { |
| 530 | CHECK(UsingFullMap()); |
| 531 | return &map_; |
| 532 | } |
| 533 |
| 534 | inline const NormalMap* map() const { |
| 535 | CHECK(UsingFullMap()); |
| 536 | return &map_; |
| 537 | } |
| 538 |
| 539 | private: |
| 540 | // When `size_ == kUsingFullMapSentinel`, we have switched storage strategies |
| 541 | // from `array_[kArraySize] to `NormalMap map_`. See ConvertToRealMap and |
| 542 | // UsingFullMap. |
| 543 | size_t size_; |
| 544 |
| 545 | MapInit functor_; |
| 546 |
| 547 | // We want to call constructors and destructors manually, but we don't want |
| 548 | // to allocate and deallocate the memory used for them separately. Since |
| 549 | // array_ and map_ are mutually exclusive, we'll put them in a union. |
| 550 | union { |
| 551 | value_type array_[kArraySize]; |
| 552 | NormalMap map_; |
| 553 | }; |
| 554 |
| 555 | void ConvertToRealMap() { |
| 556 | // Storage for the elements in the temporary array. This is intentionally |
| 557 | // declared as a union to avoid having to default-construct |kArraySize| |
| 558 | // elements, only to move construct over them in the initial loop. |
| 559 | union Storage { |
| 560 | Storage() {} |
| 561 | ~Storage() {} |
| 562 | value_type array[kArraySize]; |
| 563 | } temp; |
| 564 |
| 565 | // Move the current elements into a temporary array. |
| 566 | for (size_t i = 0; i < kArraySize; ++i) { |
| 567 | new (&temp.array[i]) value_type(std::move(array_[i])); |
| 568 | array_[i].~value_type(); |
| 569 | } |
| 570 |
| 571 | // Initialize the map. |
| 572 | size_ = kUsingFullMapSentinel; |
| 573 | functor_(&map_); |
| 574 |
| 575 | // Insert elements into it. |
| 576 | for (size_t i = 0; i < kArraySize; ++i) { |
| 577 | map_.insert(std::move(temp.array[i])); |
| 578 | temp.array[i].~value_type(); |
| 579 | } |
| 580 | } |
| 581 |
| 582 | // Helpers for constructors and destructors. |
| 583 | void InitFrom(const small_map& src) { |
| 584 | functor_ = src.functor_; |
| 585 | size_ = src.size_; |
| 586 | if (src.UsingFullMap()) { |
| 587 | functor_(&map_); |
| 588 | map_ = src.map_; |
| 589 | } else { |
| 590 | for (size_t i = 0; i < size_; ++i) { |
| 591 | new (&array_[i]) value_type(src.array_[i]); |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 |
| 596 | void Destroy() { |
| 597 | if (UsingFullMap()) { |
| 598 | map_.~NormalMap(); |
| 599 | } else { |
| 600 | for (size_t i = 0; i < size_; ++i) { |
| 601 | array_[i].~value_type(); |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | }; |
| 606 |
| 607 | template <typename NormalMap, |
| 608 | size_t kArraySize, |
| 609 | typename EqualKey, |
| 610 | typename Functor> |
| 611 | inline bool small_map<NormalMap, kArraySize, EqualKey, Functor>::iterator:: |
| 612 | operator==(const const_iterator& other) const { |
| 613 | return other == *this; |
| 614 | } |
| 615 |
| 616 | template <typename NormalMap, |
| 617 | size_t kArraySize, |
| 618 | typename EqualKey, |
| 619 | typename Functor> |
| 620 | inline bool small_map<NormalMap, kArraySize, EqualKey, Functor>::iterator:: |
| 621 | operator!=(const const_iterator& other) const { |
| 622 | return other != *this; |
| 623 | } |
| 624 |
| 625 | } // namespace base |
| 626 |
| 627 | #endif // BASE_CONTAINERS_SMALL_MAP_H_ |
| 628 |