-
Notifications
You must be signed in to change notification settings - Fork 3
/
collection_types.h
61 lines (51 loc) · 1.32 KB
/
collection_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include "types.h"
#include "memory_types.h"
/// All collection types assume that they are used to store POD objects. I.e. they:
///
/// * Don't call constructors and destructors on elements.
/// * Move elements with memmove().
///
/// If you want to store items that are not PODs, use something other than these collection
/// classes.
namespace foundation
{
/// Dynamically resizable array of POD objects.
template<typename T> struct Array
{
Array(Allocator &a);
~Array();
Array(const Array &other);
Array &operator=(const Array &other);
T &operator[](uint32_t i);
const T &operator[](uint32_t i) const;
Allocator *_allocator;
uint32_t _size;
uint32_t _capacity;
T *_data;
};
/// A double-ended queue/ring buffer.
template <typename T> struct Queue
{
Queue(Allocator &a);
T &operator[](uint32_t i);
const T &operator[](uint32_t i) const;
Array<T> _data;
uint32_t _size;
uint32_t _offset;
};
/// Hash from an uint64_t to POD objects. If you want to use a generic key
/// object, use a hash function to map that object to an uint64_t.
template<typename T> struct Hash
{
public:
Hash(Allocator &a);
struct Entry {
uint64_t key;
uint32_t next;
T value;
};
Array<uint32_t> _hash;
Array<Entry> _data;
};
}