OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_CONTAINERS_SMALL_MAP_H_ | 5 #ifndef BASE_CONTAINERS_SMALL_MAP_H_ |
6 #define BASE_CONTAINERS_SMALL_MAP_H_ | 6 #define BASE_CONTAINERS_SMALL_MAP_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 14 matching lines...) Expand all Loading... |
25 // -------------------------------- | 25 // -------------------------------- |
26 // | 26 // |
27 // - std::map should be the default if you're not sure, since it's the most | 27 // - std::map should be the default if you're not sure, since it's the most |
28 // difficult to mess up. Generally this is backed by a red-black tree. It | 28 // difficult to mess up. Generally this is backed by a red-black tree. It |
29 // will generate a lot of code (if you use a common key type like int or | 29 // will generate a lot of code (if you use a common key type like int or |
30 // string the linker will probably emiminate the duplicates). It will | 30 // string the linker will probably emiminate the duplicates). It will |
31 // do heap allocations for each element. | 31 // do heap allocations for each element. |
32 // | 32 // |
33 // - If you only ever keep a couple of items and have very simple usage, | 33 // - If you only ever keep a couple of items and have very simple usage, |
34 // consider whether a using a vector and brute-force searching it will be | 34 // consider whether a using a vector and brute-force searching it will be |
35 // the most efficient. It's not a lot of generated code (less then a | 35 // the most efficient. It's not a lot of generated code (less than a |
36 // red-black tree if your key is "weird" and not eliminated as duplicate of | 36 // red-black tree if your key is "weird" and not eliminated as duplicate of |
37 // something else) and will probably be faster and do fewer heap allocations | 37 // something else) and will probably be faster and do fewer heap allocations |
38 // than std::map if you have just a couple of items. | 38 // than std::map if you have just a couple of items. |
39 // | 39 // |
40 // - base::hash_map should be used if you need O(1) lookups. It may waste | 40 // - base::hash_map should be used if you need O(1) lookups. It may waste |
41 // space in the hash table, and it can be easy to write correct-looking | 41 // space in the hash table, and it can be easy to write correct-looking |
42 // code with the default hash function being wrong or poorly-behaving. | 42 // code with the default hash function being wrong or poorly-behaving. |
43 // | 43 // |
44 // - SmallMap combines the performance benefits of the brute-force-searched | 44 // - SmallMap combines the performance benefits of the brute-force-searched |
45 // vector for small cases (no extra heap allocations), but can efficiently | 45 // vector for small cases (no extra heap allocations), but can efficiently |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 typename Functor> | 644 typename Functor> |
645 inline bool SmallMap<NormalMap, kArraySize, EqualKey, | 645 inline bool SmallMap<NormalMap, kArraySize, EqualKey, |
646 Functor>::iterator::operator!=( | 646 Functor>::iterator::operator!=( |
647 const const_iterator& other) const { | 647 const const_iterator& other) const { |
648 return other != *this; | 648 return other != *this; |
649 } | 649 } |
650 | 650 |
651 } // namespace base | 651 } // namespace base |
652 | 652 |
653 #endif // BASE_CONTAINERS_SMALL_MAP_H_ | 653 #endif // BASE_CONTAINERS_SMALL_MAP_H_ |
OLD | NEW |