Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
containers.h
1#pragma once
2#include "memory/external_allocator.h"
3#include "memory/fast_allocator.h"
4#include <deque>
5#include <forward_list>
6#include <functional>
7#include <list>
8#include <map>
9#include <queue>
10#include <set>
11#include <stack>
12#include <unordered_map>
13#include <vector>
14
15namespace deluge {
16// For most purposes containers relying on a fallback allocation strategy should be fine.
17// At some point this will probably move to a priority-based allocation system, so default template arguments
18// are used instead of hardcoded allocator selection.
19//
20// If we decide to require explicit allocation choice in the future, we can also remove the default argument and
21// fix any broken container uses, adding fallback_allocator to their template arguments or a different allocator
22// if appropriate.
23
24// Vector (resizeable variable-length array, unknown size)
25template <typename T, typename Alloc = memory::external_allocator<T>>
26using vector = std::vector<T, Alloc>;
27
28// Doubly-ended queue
29template <typename T, typename Alloc = memory::external_allocator<T>>
30using deque = std::deque<T, Alloc>;
31
32// Singly linked list
33template <typename T, typename Alloc = memory::external_allocator<T>>
34using forward_list = std::forward_list<T, Alloc>;
35
36// Doubly-linked list
37template <typename T, typename Alloc = memory::external_allocator<T>>
38using list = std::list<T, Alloc>;
39
40// Tree map
41template <typename Key, typename T, typename Alloc = memory::external_allocator<std::pair<const Key, T>>>
42using map = std::map<Key, T, std::less<Key>, Alloc>;
43
44// Hash map
45template <typename Key, typename T, typename Alloc = memory::external_allocator<std::pair<const Key, T>>>
46using unordered_map = std::unordered_map<Key, T, std::hash<Key>, std::equal_to<Key>, Alloc>;
47
48// Stack
49template <typename T, typename Alloc = memory::external_allocator<T>>
50using stack = std::stack<T, deque<T, Alloc>>;
51
52// Queue
53template <typename T, typename Alloc = memory::external_allocator<T>>
54using queue = std::queue<T, deque<T, Alloc>>;
55
56template <class T>
57using fast_list = std::list<T, memory::fast_allocator<T>>;
58
59// Vector (resizeable variable-length array, unknown size)
60template <typename T>
61using fast_vector = std::vector<T, memory::fast_allocator<T>>;
62
63template <typename T>
64using fast_priority_queue = std::priority_queue<T, fast_vector<T>>;
65
66template <class T, class Compare = std::less<T>>
67using fast_set = std::set<T, Compare, memory::fast_allocator<T>>;
68
69template <typename Key, typename T, class Compare = std::less<Key>>
70using fast_multimap = std::multimap<Key, T, Compare, memory::fast_allocator<std::pair<const Key, T>>>;
71
72template <typename Key, typename T, class Compare = std::equal_to<Key>>
73using fast_unordered_map =
74 std::unordered_map<Key, T, std::hash<Key>, Compare, memory::fast_allocator<std::pair<const Key, T>>>;
75
76template <typename Key, typename T, class Compare = std::less<Key>>
77using fast_map = std::map<Key, T, Compare, memory::fast_allocator<std::pair<const Key, T>>>;
78} // namespace deluge
A simple GMA wrapper that conforms to the C++ Allocator trait spec (see: https://en....
Definition fast_allocator.h:17