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