-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoffsetvector.h
More file actions
48 lines (38 loc) · 817 Bytes
/
offsetvector.h
File metadata and controls
48 lines (38 loc) · 817 Bytes
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
#ifndef JWUTIL_OFFSETVECTOR_H
#define JWUTIL_OFFSETVECTOR_H
#include <deque>
namespace jw_util
{
template <typename Type>
class OffsetVector
{
public:
OffsetVector()
{}
Type &operator[](typename std::deque<Type>::size_type i)
{
if (items.empty())
{
items.emplace_back();
offset = i;
return items.front();
}
if (i < offset)
{
items.insert(items.begin(), offset - i, Type());
offset = i;
return items.front();
}
i -= offset;
if (i >= items.size())
{
items.resize(i + 1);
}
return items[i];
}
protected:
typename std::deque<Type>::size_type offset;
std::deque<Type> items;
};
}
#endif // JWUTIL_OFFSETVECTOR_H