1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/common/index_vector.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/constants.hpp"
12#include "duckdb/common/vector.hpp"
13
14namespace duckdb {
15
16template <class T, class INDEX_TYPE>
17class IndexVector {
18public:
19 void push_back(T element) {
20 internal_vector.push_back(std::move(element));
21 }
22
23 T &operator[](INDEX_TYPE idx) {
24 return internal_vector[idx.index];
25 }
26
27 const T &operator[](INDEX_TYPE idx) const {
28 return internal_vector[idx.index];
29 }
30
31 idx_t size() const {
32 return internal_vector.size();
33 }
34
35 bool empty() const {
36 return internal_vector.empty();
37 }
38
39 void reserve(idx_t size) {
40 internal_vector.reserve(size);
41 }
42
43 typename vector<T>::iterator begin() {
44 return internal_vector.begin();
45 }
46 typename vector<T>::iterator end() {
47 return internal_vector.end();
48 }
49 typename vector<T>::const_iterator cbegin() {
50 return internal_vector.cbegin();
51 }
52 typename vector<T>::const_iterator cend() {
53 return internal_vector.cend();
54 }
55 typename vector<T>::const_iterator begin() const {
56 return internal_vector.begin();
57 }
58 typename vector<T>::const_iterator end() const {
59 return internal_vector.end();
60 }
61
62private:
63 vector<T> internal_vector;
64};
65
66template <typename T>
67using physical_index_vector_t = IndexVector<T, PhysicalIndex>;
68
69template <typename T>
70using logical_index_vector_t = IndexVector<T, LogicalIndex>;
71
72} // namespace duckdb
73