Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_map.hh
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
| #include <optional> | #include <optional> | ||||
| #include <unordered_map> | #include <unordered_map> | ||||
| #include "BLI_array.hh" | #include "BLI_array.hh" | ||||
| #include "BLI_hash.hh" | #include "BLI_hash.hh" | ||||
| #include "BLI_hash_tables.hh" | #include "BLI_hash_tables.hh" | ||||
| #include "BLI_map_slots.hh" | #include "BLI_map_slots.hh" | ||||
| #include "BLI_probing_strategies.hh" | #include "BLI_probing_strategies.hh" | ||||
| #include "BLI_task.hh" | |||||
| namespace blender { | namespace blender { | ||||
| template< | template< | ||||
| /** | /** | ||||
| * Type of the keys stored in the map. Keys have to be movable. Furthermore, the hash and | * Type of the keys stored in the map. Keys have to be movable. Furthermore, the hash and | ||||
| * is-equal functions have to support it. | * is-equal functions have to support it. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 562 Lines • ▼ Show 20 Lines | for (int64_t i = 0; i < size; i++) { | ||||
| if (slot.is_occupied()) { | if (slot.is_occupied()) { | ||||
| const Key &key = *slot.key(); | const Key &key = *slot.key(); | ||||
| const Value &value = *slot.value(); | const Value &value = *slot.value(); | ||||
| func(key, value); | func(key, value); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| template<typename FuncT> | |||||
| void parallel_foreach_item(const FuncT &func, const bool use_parallel = true) const | |||||
| { | |||||
| if (use_parallel) { | |||||
| threading::parallel_for_each(slots_, [func](const Slot &slot) { | |||||
| if (slot.is_occupied()) { | |||||
| const Key &key = *slot.key(); | |||||
| const Value &value = *slot.value(); | |||||
| func(key, value); | |||||
| } | |||||
| }); | |||||
| } | |||||
| else { | |||||
| this->foreach_item<FuncT>(func); | |||||
| } | |||||
| } | |||||
| /* Common base class for all iterators below. */ | /* Common base class for all iterators below. */ | ||||
| struct BaseIterator { | struct BaseIterator { | ||||
| public: | public: | ||||
| using iterator_category = std::forward_iterator_tag; | using iterator_category = std::forward_iterator_tag; | ||||
| using difference_type = std::ptrdiff_t; | using difference_type = std::ptrdiff_t; | ||||
| protected: | protected: | ||||
| /* We could have separate base iterators for const and non-const iterators, but that would add | /* We could have separate base iterators for const and non-const iterators, but that would add | ||||
| ▲ Show 20 Lines • Show All 692 Lines • Show Last 20 Lines | |||||