-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathstring.h
More file actions
217 lines (159 loc) · 6.04 KB
/
string.h
File metadata and controls
217 lines (159 loc) · 6.04 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#pragma once
#include "column.h"
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <deque>
namespace clickhouse {
/**
* Represents column of fixed-length strings.
*/
class ColumnFixedString : public Column {
public:
using ValueType = std::string_view;
explicit ColumnFixedString(size_t n);
template <typename Values>
ColumnFixedString(size_t n, const Values & values)
: ColumnFixedString(n)
{
for (const auto & v : values)
Append(v);
}
/// Increase the capacity of the column for large block insertion.
void Reserve(size_t) override;
/// Appends one element to the column.
void Append(std::string_view str);
/// Returns element at given row number.
std::string_view At(size_t n) const;
/// Returns element at given row number.
inline std::string_view operator [] (size_t n) const { return At(n); }
/// Returns the max size of the fixed string
size_t FixedSize() const;
public:
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;
/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;
/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;
/// Clear column data .
void Clear() override;
/// Returns count of rows in the column.
size_t Size() const override;
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) const override;
ColumnRef CloneEmpty() const override;
void Swap(Column& other) override;
ItemView GetItem(size_t) const override;
private:
size_t string_size_;
std::string data_;
};
/**
* Represents column of variable-length strings.
*/
class ColumnString : public Column {
public:
// Type this column takes as argument of Append and returns with At() and operator[]
using ValueType = std::string_view;
ColumnString();
~ColumnString();
explicit ColumnString(size_t element_count);
explicit ColumnString(const std::vector<std::string> & data);
explicit ColumnString(std::vector<std::string>&& data);
ColumnString& operator=(const ColumnString&) = delete;
ColumnString(const ColumnString&) = delete;
/// Increase the capacity of the column for large block insertion.
void Reserve(size_t new_cap) override;
/// Appends one element to the column.
void Append(std::string_view str);
/// Appends one element to the column.
void Append(const char* str);
/// Appends one element to the column.
void Append(std::string&& steal_value);
/// Appends one element to the column.
/// If str lifetime is managed elsewhere and guaranteed to outlive the Block sent to the server
void AppendNoManagedLifetime(std::string_view str);
/// Returns element at given row number.
std::string_view At(size_t n) const;
/// Returns element at given row number.
inline std::string_view operator [] (size_t n) const { return At(n); }
public:
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;
/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;
/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;
/// Clear column data .
void Clear() override;
/// Returns count of rows in the column.
size_t Size() const override;
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) const override;
ColumnRef CloneEmpty() const override;
void Swap(Column& other) override;
ItemView GetItem(size_t) const override;
private:
void AppendUnsafe(std::string_view);
private:
struct Block;
std::vector<std::string_view> items_;
std::vector<Block> blocks_;
std::deque<std::string> append_data_;
};
/**
* Represents column of variable-length strings.
*/
class ColumnJSON : public Column {
public:
// Type this column takes as argument of Append and returns with At() and operator[]
using ValueType = std::string_view;
ColumnJSON();
~ColumnJSON();
explicit ColumnJSON(size_t element_count);
explicit ColumnJSON(const std::vector<std::string> & data);
explicit ColumnJSON(std::vector<std::string>&& data);
ColumnJSON& operator=(const ColumnJSON&) = delete;
ColumnJSON(const ColumnJSON&) = delete;
/// Increase the capacity of the column for large block insertion.
void Reserve(size_t new_cap) override;
/// Appends one element to the column.
void Append(std::string_view str);
/// Appends one element to the column.
void Append(const char* str);
/// Appends one element to the column.
void Append(std::string&& steal_value);
/// Appends one element to the column.
/// If str lifetime is managed elsewhere and guaranteed to outlive the Block sent to the server
void AppendNoManagedLifetime(std::string_view str);
/// Returns element at given row number.
std::string_view At(size_t n) const;
/// Returns element at given row number.
inline std::string_view operator [] (size_t n) const { return At(n); }
public:
/// Appends content of given column to the end of current one.
void Append(ColumnRef column) override;
/// Loads column data from input stream.
bool LoadBody(InputStream* input, size_t rows) override;
/// Saves column data to output stream.
void SaveBody(OutputStream* output) override;
/// Clear column data .
void Clear() override;
/// Returns count of rows in the column.
size_t Size() const override;
/// Makes slice of the current column.
ColumnRef Slice(size_t begin, size_t len) const override;
ColumnRef CloneEmpty() const override;
void Swap(Column& other) override;
ItemView GetItem(size_t) const override;
private:
void AppendUnsafe(std::string_view);
private:
struct Block;
std::vector<std::string_view> items_;
std::vector<Block> blocks_;
std::deque<std::string> append_data_;
};
}