Kùzu C++ API
Loading...
Searching...
No Matches
group_collection.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "deserializer.h"
6#include "serializer.h"
7#include "types.h"
8#include "uniq_lock.h"
9
10namespace kuzu {
11namespace storage {
12
13template<class T>
15public:
17
19
21 lock();
22 deSer.deserializeVectorOfPtrs<T>(groups);
23 }
25 lock();
26 ser.serializeVectorOfPtrs<T>(groups);
27 }
28
29 void appendGroup(const common::UniqLock& lock, std::unique_ptr<T> group) {
30 KU_ASSERT(group);
33 groups.push_back(std::move(group));
34 }
38 if (groupIdx >= groups.size()) {
39 return nullptr;
40 }
41 return groups[groupIdx].get();
42 }
44 if (groupIdx >= groups.size()) {
45 return nullptr;
46 }
47 return groups[groupIdx].get();
48 }
50 std::unique_ptr<T> group) {
51 KU_ASSERT(group);
54 if (groupIdx >= groups.size()) {
55 groups.resize(groupIdx + 1);
56 }
57 groups[groupIdx] = std::move(group);
58 }
59
60 void resize(const common::UniqLock& lock, common::idx_t newSize) {
63 if (newSize <= groups.size()) {
64 return;
65 }
66 groups.resize(newSize);
67 }
68
72 return groups.empty();
73 }
77 return groups.size();
78 }
79
80 const std::vector<std::unique_ptr<T>>& getAllGroups(const common::UniqLock& lock) {
83 return groups;
84 }
85 std::unique_ptr<T> moveGroup(const common::UniqLock& lock, common::idx_t groupIdx) {
86 KU_ASSERT(groupIdx < groups.size());
89 return std::move(groups[groupIdx]);
90 }
94 if (groups.empty()) {
95 return nullptr;
96 }
97 return groups.front().get();
98 }
100 if (groups.empty()) {
101 return nullptr;
102 }
103 return groups.front().get();
104 }
108 if (groups.empty()) {
109 return nullptr;
110 }
111 return groups.back().get();
112 }
113
117 groups.clear();
118 }
119
120private:
121 std::mutex mtx;
122 std::vector<std::unique_ptr<T>> groups;
123};
124
125} // namespace storage
126} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
#define KU_UNUSED(expr)
Definition assert.h:30
Definition deserializer.h:15
void deserializeVectorOfPtrs(std::vector< std::unique_ptr< T > > &values)
Definition deserializer.h:80
Definition serializer.h:15
void serializeVectorOfPtrs(const std::vector< std::unique_ptr< T > > &values)
Definition serializer.h:80
Definition group_collection.h:14
const std::vector< std::unique_ptr< T > > & getAllGroups(const common::UniqLock &lock)
Definition group_collection.h:80
T * getGroupNoLock(common::idx_t groupIdx)
Definition group_collection.h:43
common::idx_t getNumGroups(const common::UniqLock &lock) const
Definition group_collection.h:74
T * getGroup(const common::UniqLock &lock, common::idx_t groupIdx)
Definition group_collection.h:35
T * getFirstGroup(const common::UniqLock &lock)
Definition group_collection.h:91
void loadGroups(common::Deserializer &deSer)
Definition group_collection.h:20
T * getFirstGroupNoLock()
Definition group_collection.h:99
void resize(const common::UniqLock &lock, common::idx_t newSize)
Definition group_collection.h:60
common::UniqLock lock()
Definition group_collection.h:18
T * getLastGroup(const common::UniqLock &lock)
Definition group_collection.h:105
void replaceGroup(const common::UniqLock &lock, common::idx_t groupIdx, std::unique_ptr< T > group)
Definition group_collection.h:49
void serializeGroups(common::Serializer &ser)
Definition group_collection.h:24
void appendGroup(const common::UniqLock &lock, std::unique_ptr< T > group)
Definition group_collection.h:29
bool isEmpty(const common::UniqLock &lock)
Definition group_collection.h:69
std::unique_ptr< T > moveGroup(const common::UniqLock &lock, common::idx_t groupIdx)
Definition group_collection.h:85
void clear(const common::UniqLock &lock)
Definition group_collection.h:114
GroupCollection()
Definition group_collection.h:16
uint32_t idx_t
Definition types.h:39
Definition alter_type.h:5
Definition uniq_lock.h:8
bool isLocked() const
Definition uniq_lock.h:20