1 /** 2 * Copyright (c) 2021-2022 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 LIBPANDABASE_UTILS_ARENA_CONTAINERS_H 17 #define LIBPANDABASE_UTILS_ARENA_CONTAINERS_H 18 19 #include <deque> 20 #include <list> 21 #include <stack> 22 #include <queue> 23 #include <vector> 24 #include <set> 25 #include <string> 26 #include <map> 27 #include <unordered_map> 28 #include <unordered_set> 29 #include <functional> 30 31 #include "mem/arena_allocator.h" 32 #include "mem/arena_allocator_stl_adapter.h" 33 34 namespace panda { 35 36 template <class T, bool use_oom_handler = false> 37 using ArenaVector = std::vector<T, ArenaAllocatorAdapter<T, use_oom_handler>>; 38 template <class T, bool use_oom_handler = false> 39 using ArenaDeque = std::deque<T, ArenaAllocatorAdapter<T, use_oom_handler>>; 40 template <class T, bool use_oom_handler = false, class ArenaContainer = ArenaDeque<T, use_oom_handler>> 41 using ArenaStack = std::stack<T, ArenaContainer>; 42 template <class T, bool use_oom_handler = false, class ArenaContainer = ArenaDeque<T, use_oom_handler>> 43 using ArenaQueue = std::queue<T, ArenaContainer>; 44 template <class T, bool use_oom_handler = false> 45 using ArenaList = std::list<T, ArenaAllocatorAdapter<T, use_oom_handler>>; 46 template <class Key, class Compare = std::less<Key>, bool use_oom_handler = false> 47 using ArenaSet = std::set<Key, Compare, ArenaAllocatorAdapter<Key, use_oom_handler>>; 48 template <class Key, class T, class Compare = std::less<Key>, bool use_oom_handler = false> 49 using ArenaMap = std::map<Key, T, Compare, ArenaAllocatorAdapter<std::pair<const Key, T>, use_oom_handler>>; 50 template <class Key, class T, class Compare = std::less<Key>, bool use_oom_handler = false> 51 using ArenaMultiMap = std::multimap<Key, T, Compare, ArenaAllocatorAdapter<std::pair<const Key, T>, use_oom_handler>>; 52 template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, 53 bool use_oom_handler = false> 54 using ArenaUnorderedMultiMap = 55 std::unordered_multimap<Key, T, Hash, KeyEqual, ArenaAllocatorAdapter<std::pair<const Key, T>, use_oom_handler>>; 56 template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, 57 bool use_oom_handler = false> 58 using ArenaUnorderedMap = 59 std::unordered_map<Key, T, Hash, KeyEqual, ArenaAllocatorAdapter<std::pair<const Key, T>, false>>; 60 template <class Key1, class Key2, class T, bool use_oom_handler = false> 61 using ArenaDoubleUnorderedMap = 62 ArenaUnorderedMap<Key1, ArenaUnorderedMap<Key2, T, std::hash<Key2>, std::equal_to<Key2>, use_oom_handler>, 63 std::hash<Key1>, std::equal_to<Key1>, use_oom_handler>; 64 template <class Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, bool use_oom_handler = false> 65 using ArenaUnorderedSet = std::unordered_set<Key, Hash, KeyEqual, ArenaAllocatorAdapter<Key, use_oom_handler>>; 66 template <bool use_oom_handler = false> 67 using ArenaStringT = std::basic_string<char, std::char_traits<char>, ArenaAllocatorAdapter<char, use_oom_handler>>; 68 using ArenaString = ArenaStringT<false>; 69 70 } // namespace panda 71 72 #endif // LIBPANDABASE_UTILS_ARENA_CONTAINERS_H 73