1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_RUNTIME_INCLUDE_MEM_PANDA_CONTAINERS_H_ 17 #define PANDA_RUNTIME_INCLUDE_MEM_PANDA_CONTAINERS_H_ 18 19 #include <deque> 20 #include <forward_list> 21 #include <list> 22 #include <map> 23 #include <queue> 24 #include <set> 25 #include <stack> 26 #include <unordered_map> 27 #include <unordered_set> 28 #include <vector> 29 30 #include "runtime/mem/allocator_adapter.h" 31 32 namespace panda { 33 34 template <class T> 35 using PandaForwardList = std::forward_list<T, mem::AllocatorAdapter<T>>; 36 // Thread local version of PandaForwardList 37 template <class T> 38 using PandaForwardListTL = std::forward_list<T, mem::AllocatorAdapter<T, mem::AllocScope::LOCAL>>; 39 40 template <class T> 41 using PandaList = std::list<T, mem::AllocatorAdapter<T>>; 42 // Thread local version of PandaList 43 template <class T> 44 using PandaListTL = std::list<T, mem::AllocatorAdapter<T, mem::AllocScope::LOCAL>>; 45 46 template <class T> 47 using PandaDeque = std::deque<T, mem::AllocatorAdapter<T>>; 48 // Thread local version of PandaDeque 49 template <class T> 50 using PandaDequeTL = std::deque<T, mem::AllocatorAdapter<T, mem::AllocScope::LOCAL>>; 51 52 template <class T, class PandaContainer = PandaDeque<T>> 53 using PandaQueue = std::queue<T, PandaContainer>; 54 // Thread local version of PandaQueue 55 template <class T, class PandaContainer = PandaDequeTL<T>> 56 using PandaQueueTL = std::queue<T, PandaContainer>; 57 58 template <class T, class PandaContainer = PandaDeque<T>> 59 using PandaStack = std::stack<T, PandaContainer>; 60 // Thread local version of PandaStack 61 template <class T, class PandaContainer = PandaDequeTL<T>> 62 using PandaStackTL = std::stack<T, PandaContainer>; 63 64 template <class Key, class KeyLess = std::less<Key>> 65 using PandaSet = std::set<Key, KeyLess, mem::AllocatorAdapter<Key>>; 66 // Thread local version of PandaSet 67 template <class Key, class KeyLess = std::less<Key>> 68 using PandaSetTL = std::set<Key, KeyLess, mem::AllocatorAdapter<Key, mem::AllocScope::LOCAL>>; 69 70 template <class Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>> 71 using PandaUnorderedSet = std::unordered_set<Key, Hash, KeyEqual, mem::AllocatorAdapter<Key>>; 72 // Thread local version of PandaUnorderedSet 73 template <class Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>> 74 using PandaUnorderedSetTL = std::unordered_set<Key, Hash, KeyEqual, mem::AllocatorAdapter<Key, mem::AllocScope::LOCAL>>; 75 76 template <class T> 77 using PandaVector = std::vector<T, mem::AllocatorAdapter<T>>; 78 // Thread local version of PandaVector 79 template <class T> 80 using PandaVectorTL = std::vector<T, mem::AllocatorAdapter<T, mem::AllocScope::LOCAL>>; 81 82 template <class T, class Container = PandaVector<T>, class Compare = std::less<typename Container::value_type>> 83 using PandaPriorityQueue = std::priority_queue<T, Container, Compare>; 84 // Thread local version of PandaPriorityQueue 85 template <class T, class Container = PandaVectorTL<T>, class Compare = std::less<typename Container::value_type>> 86 using PandaPriorityQueueTL = std::priority_queue<T, Container, Compare>; 87 88 template <class Key, class T, class Compare = std::less<>> 89 using PandaMap = std::map<Key, T, Compare, mem::AllocatorAdapter<std::pair<const Key, T>>>; 90 // Thread local version of PandaMap 91 template <class Key, class T, class Compare = std::less<>> 92 using PandaMapTL = std::map<Key, T, Compare, mem::AllocatorAdapter<std::pair<const Key, T>, mem::AllocScope::LOCAL>>; 93 94 template <class Key, class T, class Compare = std::less<>> 95 using PandaMultiMap = std::multimap<Key, T, Compare, mem::AllocatorAdapter<std::pair<const Key, T>>>; 96 // Thread local version of PandaMultiMap 97 template <class Key, class T, class Compare = std::less<>> 98 using PandaMultiMapTL = 99 std::multimap<Key, T, Compare, mem::AllocatorAdapter<std::pair<const Key, T>, mem::AllocScope::LOCAL>>; 100 101 template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>> 102 using PandaUnorderedMap = std::unordered_map<Key, T, Hash, KeyEqual, mem::AllocatorAdapter<std::pair<const Key, T>>>; 103 // Thread local version of PandaUnorderedMap 104 template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>> 105 using PandaUnorderedMapTL = 106 std::unordered_map<Key, T, Hash, KeyEqual, mem::AllocatorAdapter<std::pair<const Key, T>, mem::AllocScope::LOCAL>>; 107 108 template <class Key, class Value, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>> 109 using PandaUnorderedMultiMap = 110 std::unordered_multimap<Key, Value, Hash, KeyEqual, mem::AllocatorAdapter<std::pair<const Key, Value>>>; 111 // Thread local version of PandaUnorderedMultiMap 112 template <class Key, class Value, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>> 113 using PandaUnorderedMultiMapTL = 114 std::unordered_multimap<Key, Value, Hash, KeyEqual, 115 mem::AllocatorAdapter<std::pair<const Key, Value>, mem::AllocScope::LOCAL>>; 116 } // namespace panda 117 118 #endif // PANDA_RUNTIME_INCLUDE_MEM_PANDA_CONTAINERS_H_ 119