| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #ifndef SRC_VM_HASH_SET_H_ | 5 #ifndef SRC_VM_HASH_SET_H_ |
| 6 #define SRC_VM_HASH_SET_H_ | 6 #define SRC_VM_HASH_SET_H_ |
| 7 | 7 |
| 8 #include "src/vm/hash_table.h" | 8 #include "src/vm/hash_table.h" |
| 9 | 9 |
| 10 namespace fletch { | 10 namespace dartino { |
| 11 | 11 |
| 12 template <typename Key> | 12 template <typename Key> |
| 13 struct SetKeyExtractor { | 13 struct SetKeyExtractor { |
| 14 static Key& GetKey(Key& key) { // NOLINT | 14 static Key& GetKey(Key& key) { // NOLINT |
| 15 return key; | 15 return key; |
| 16 } | 16 } |
| 17 | 17 |
| 18 static const Key& GetKey(const Key& key) { return key; } | 18 static const Key& GetKey(const Key& key) { return key; } |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 // UnorderedSet: | 21 // UnorderedSet: |
| 22 // Interface is kept as close as possible to std::unordered_map, but: | 22 // Interface is kept as close as possible to std::unordered_map, but: |
| 23 // * Only functions that can be expected to be tiny are inlined. | 23 // * Only functions that can be expected to be tiny are inlined. |
| 24 // * The Key type must be memcpy-able and castable to void* and the same size. | 24 // * The Key type must be memcpy-able and castable to void* and the same size. |
| 25 // * The hash code is just a cast to int. | 25 // * The hash code is just a cast to int. |
| 26 // * Not all methods are implemented. | 26 // * Not all methods are implemented. |
| 27 // * Iterators are invalidated on all inserts, even if the key was already | 27 // * Iterators are invalidated on all inserts, even if the key was already |
| 28 // present. | 28 // present. |
| 29 // * Google naming conventions are used (CamelCase classes and methods). | 29 // * Google naming conventions are used (CamelCase classes and methods). |
| 30 template <typename Key> | 30 template <typename Key> |
| 31 class HashSet : public UnorderedHashTable<Key, Key, SetKeyExtractor<Key>> {}; | 31 class HashSet : public UnorderedHashTable<Key, Key, SetKeyExtractor<Key>> {}; |
| 32 | 32 |
| 33 } // namespace fletch | 33 } // namespace dartino |
| 34 | 34 |
| 35 #endif // SRC_VM_HASH_SET_H_ | 35 #endif // SRC_VM_HASH_SET_H_ |
| OLD | NEW |