Skip to content

Commit 097fe33

Browse files
committed
fix clang-tidy error
1 parent bc126e8 commit 097fe33

File tree

6 files changed

+128
-129
lines changed

6 files changed

+128
-129
lines changed

source/utils/Files.cpp

+46-46
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ namespace utils {
2020

2121
// WARNING: this only works with 4 byte types
2222
template <class T>
23-
bool createTestFileImpl(const string& file_name, uint64_t count,
23+
bool CreateTestFileImpl(const string& fileName, uint64_t count,
2424
function<T(int)> factory) {
2525
// Open file
26-
ofstream of(file_name, ios::binary);
26+
ofstream of(fileName, ios::binary);
2727
if (!of.is_open() || !of.good())
2828
return false;
2929

@@ -46,9 +46,9 @@ bool createTestFileImpl(const string& file_name, uint64_t count,
4646
}
4747

4848
template <class T>
49-
bool foreachInFileImpl(const string& file_name, function<void(T)> callback) {
49+
bool ForeachInFileImpl(const string& fileName, function<void(T)> callback) {
5050
// Open file
51-
ifstream in(file_name, ios::binary);
51+
ifstream in(fileName, ios::binary);
5252
if (!in.is_open() || !in.good())
5353
return false;
5454

@@ -63,52 +63,52 @@ bool foreachInFileImpl(const string& file_name, function<void(T)> callback) {
6363
return true;
6464
}
6565

66-
bool CreateTestFile(const string& file_name, uint64_t count,
66+
bool CreateTestFile(const string& fileName, uint64_t count,
6767
function<int32_t(int32_t)> factory) {
68-
return createTestFileImpl<int32_t>(file_name, count, factory);
68+
return CreateTestFileImpl<int32_t>(fileName, count, factory);
6969
}
7070

71-
bool ForeachInFile(const string& file_name, function<void(uint32_t)> callback) {
72-
return foreachInFileImpl<uint32_t>(file_name, callback);
71+
bool ForeachInFile(const string& fileName, function<void(uint32_t)> callback) {
72+
return ForeachInFileImpl<uint32_t>(fileName, callback);
7373
}
7474

75-
bool CreateDirectory(const string& directory_name) {
76-
return mkdir(directory_name.c_str(), 0666) == 0;
75+
bool CreateDirectory(const string& dirName) {
76+
return mkdir(dirName.c_str(), 0666) == 0;
7777
}
7878

79-
bool CreateFile(const string& file_name, const uint64_t bytes) {
80-
int file_fd = open(file_name.c_str(), O_CREAT | O_WRONLY, 0666);
81-
if (file_fd < 0) {
79+
bool CreateFile(const string& fileName, const uint64_t bytes) {
80+
int fileFd = open(fileName.c_str(), O_CREAT | O_WRONLY, 0666);
81+
if (fileFd < 0) {
8282
return false; // Use strerror(errno) to find error
8383
}
8484

85-
if (ftruncate(file_fd, bytes) != 0) {
85+
if (ftruncate(fileFd, bytes) != 0) {
8686
return false; // Use strerror(errno) to find error
8787
}
8888

89-
if (close(file_fd) != 0) {
89+
if (close(fileFd) != 0) {
9090
return false; // Use strerror(errno) to find error
9191
}
9292

9393
return true;
9494
}
9595

96-
bool CreateFile(const string& file_name, const string& content) {
97-
int file_fd = open(file_name.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666);
98-
if (file_fd < 0) {
96+
bool CreateFile(const string& fileName, const string& content) {
97+
int fileFd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666);
98+
if (fileFd < 0) {
9999
return false; // Use strerror(errno) to find error
100100
}
101101

102-
size_t written_bytes = write(file_fd, content.data(), content.size());
103-
return written_bytes == content.size();
102+
size_t writtenBytes = write(fileFd, content.data(), content.size());
103+
return writtenBytes == content.size();
104104
}
105105

106-
void DeleteFile(const std::string& file_name) {
107-
remove(file_name.c_str());
106+
void DeleteFile(const std::string& fileName) {
107+
remove(fileName.c_str());
108108
}
109109

110-
uint64_t GetFileLength(const string& file_name) {
111-
int fileFD = open(file_name.c_str(), O_RDWR);
110+
uint64_t GetFileLength(const string& fileName) {
111+
int fileFD = open(fileName.c_str(), O_RDWR);
112112
if (fileFD < 0) {
113113
cout << "Unable to open file"
114114
<< endl; // You can POSIX_CHECK errno to see what happend
@@ -125,35 +125,35 @@ uint64_t GetFileLength(const string& file_name) {
125125
return st.st_size;
126126
}
127127

128-
bool fileExists(const string& file_name) {
128+
bool FileExists(const string& fileName) {
129129
struct stat buffer;
130-
bool exists = (stat(file_name.c_str(), &buffer) == 0);
130+
bool exists = (stat(fileName.c_str(), &buffer) == 0);
131131
return exists && (buffer.st_mode & S_IFREG);
132132
}
133133

134-
bool directoryExists(const string& file_name) {
134+
bool DirectoryExists(const string& fileName) {
135135
struct stat buffer;
136-
bool exists = (stat(file_name.c_str(), &buffer) == 0);
136+
bool exists = (stat(fileName.c_str(), &buffer) == 0);
137137
return exists && (buffer.st_mode & S_IFDIR);
138138
}
139139

140-
bool pathExists(const string& file_name) {
140+
bool PathExists(const string& fileName) {
141141
struct stat buffer;
142-
bool exists = (stat(file_name.c_str(), &buffer) == 0);
142+
bool exists = (stat(fileName.c_str(), &buffer) == 0);
143143
return exists;
144144
}
145145

146-
string LoadFileToMemory(const string& file_name) {
147-
uint64_t length = GetFileLength(file_name);
146+
string LoadFileToMemory(const string& fileName) {
147+
uint64_t length = GetFileLength(fileName);
148148
string data(length, 'a');
149-
ifstream in(file_name);
149+
ifstream in(fileName);
150150
in.read(&data[0], length);
151151
return data;
152152
}
153153

154154
namespace {
155155

156-
uint64_t applyPrecision(uint64_t input, uint32_t precision) {
156+
uint64_t ApplyPrecision(uint64_t input, uint32_t precision) {
157157
uint32_t digits = log10(input) + 1;
158158
if (digits <= precision)
159159
return input;
@@ -166,7 +166,7 @@ uint64_t applyPrecision(uint64_t input, uint32_t precision) {
166166
string FormatTime(chrono::nanoseconds ns, uint32_t precision) {
167167
ostringstream os;
168168

169-
uint64_t timeSpan = applyPrecision(ns.count(), precision);
169+
uint64_t timeSpan = ApplyPrecision(ns.count(), precision);
170170

171171
// Convert to right unit
172172
if (timeSpan < 1000ll)
@@ -203,10 +203,10 @@ void PinThread(int socket) {
203203
(void)socket;
204204
}
205205

206-
void RunMultithreaded(uint32_t thread_count, function<void(uint32_t)> foo) {
206+
void RunMultithreaded(uint32_t threadCount, function<void(uint32_t)> foo) {
207207
atomic<bool> start(false);
208-
vector<unique_ptr<thread>> threads(thread_count);
209-
for (uint32_t i = 0; i < thread_count; i++) {
208+
vector<unique_ptr<thread>> threads(threadCount);
209+
for (uint32_t i = 0; i < threadCount; i++) {
210210
threads[i] = make_unique<thread>([i, &foo, &start]() {
211211
while (!start)
212212
;
@@ -230,8 +230,8 @@ uint8_t* AlignedAlloc(uint64_t alignment, uint64_t size) {
230230

231231
namespace {
232232

233-
array<char, 16> NUM_TO_HEX{{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
234-
'a', 'b', 'c', 'd', 'e', 'f'}};
233+
array<char, 16> numToHex{{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
234+
'b', 'c', 'd', 'e', 'f'}};
235235
uint8_t HexToNum(char c) {
236236
if ('a' <= c && c <= 'f') {
237237
return 10 + (c - 'a');
@@ -247,8 +247,8 @@ uint8_t HexToNum(char c) {
247247
const string DataToHex(const uint8_t* data, uint32_t len, bool spaces) {
248248
string result;
249249
for (uint32_t i = 0; i < len; i++) {
250-
result += NUM_TO_HEX[*(data + i) >> 4];
251-
result += NUM_TO_HEX[*(data + i) & 0x0f];
250+
result += numToHex[*(data + i) >> 4];
251+
result += numToHex[*(data + i) & 0x0f];
252252
if (spaces && i != len - 1)
253253
result += ' ';
254254
}
@@ -262,8 +262,8 @@ const string StringToHex(const string& str, bool spaces) {
262262
const vector<uint8_t> HexToData(const string& str, bool spaces) {
263263
assert(spaces || str.size() % 2 == 0);
264264

265-
uint32_t result_size = spaces ? ((str.size() + 1) / 3) : (str.size() / 2);
266-
vector<uint8_t> result(result_size);
265+
uint32_t resultSize = spaces ? ((str.size() + 1) / 3) : (str.size() / 2);
266+
vector<uint8_t> result(resultSize);
267267
for (uint32_t i = 0, out = 0; i < str.size(); i += 2, out++) {
268268
result[out] = (HexToNum(str[i]) << 4) | HexToNum(str[i + 1]);
269269
i += spaces ? 1 : 0;
@@ -275,8 +275,8 @@ const vector<uint8_t> HexToData(const string& str, bool spaces) {
275275
const string HexToString(const string& str, bool spaces) {
276276
assert(spaces || str.size() % 2 == 0);
277277

278-
uint32_t result_size = spaces ? ((str.size() + 1) / 3) : (str.size() / 2);
279-
string result(result_size, 'x');
278+
uint32_t resultSize = spaces ? ((str.size() + 1) / 3) : (str.size() / 2);
279+
string result(resultSize, 'x');
280280
for (uint32_t i = 0, out = 0; i < str.size(); i += 2, out++) {
281281
result[out] = (char)((HexToNum(str[i]) << 4) | HexToNum(str[i + 1]));
282282
i += spaces ? 1 : 0;

source/utils/Files.hpp

+44-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
// -------------------------------------------------------------------------------------
2+
33
#include <stdint.h>
44

55
#include <algorithm>
@@ -11,84 +11,84 @@
1111
#include <string>
1212
#include <utility>
1313
#include <vector>
14-
// -------------------------------------------------------------------------------------
14+
1515
namespace leanstore {
1616
namespace utils {
17-
// -------------------------------------------------------------------------------------
17+
1818
// Polyfill for offsetof for gcc
1919
#ifndef offsetof
2020
#define offsetof(type, member) __builtin_offsetof(type, member)
2121
#endif
22-
// -------------------------------------------------------------------------------------
23-
// Create a file with count entries created by the given factory function
22+
23+
/// Create a file with count entries created by the given factory function
2424
bool CreateTestFile(const std::string& fileName, uint64_t count,
2525
std::function<int32_t(int32_t)> factory);
26-
// -------------------------------------------------------------------------------------
26+
2727
// Read a file and invoke callback function on every entry
2828
bool ForeachInFile(const std::string& fileName,
2929
std::function<void(uint32_t)> callback);
30-
// -------------------------------------------------------------------------------------
30+
3131
// Create a file with random(not set) data of given size
32-
bool CreateDirectory(const std::string& directory_name);
32+
bool CreateDirectory(const std::string& dirName);
33+
3334
bool CreateFile(const std::string& fileName, const uint64_t bytes);
35+
3436
bool CreateFile(const std::string& fileName, const std::string& content);
35-
// -------------------------------------------------------------------------------------
37+
3638
// Delete the given file if it exists
3739
void DeleteFile(const std::string& fileName);
38-
// -------------------------------------------------------------------------------------
40+
3941
// Reads the length of the file
4042
uint64_t GetFileLength(const std::string& fileName);
41-
// -------------------------------------------------------------------------------------
43+
4244
// Checks if the given file exists
43-
bool fileExists(const std::string& fileName);
44-
bool directoryExists(const std::string& fileName);
45-
bool pathExists(const std::string& fileName);
46-
// -------------------------------------------------------------------------------------
47-
// Loads the complete file into memory
45+
bool FileExists(const std::string& fileName);
46+
47+
bool DirectoryExists(const std::string& fileName);
48+
49+
bool PathExists(const std::string& fileName);
50+
51+
/// Loads the complete file into memory
4852
std::string LoadFileToMemory(const std::string& fileName);
49-
// -------------------------------------------------------------------------------------
53+
5054
inline uint64_t FieldOffset(void* base, void* field) {
5155
assert(base <= field);
5256
return (uintptr_t)field - (uintptr_t)base;
5357
}
54-
// -------------------------------------------------------------------------------------
55-
// Converts the given time in ns into a usable unit depending on its size
58+
59+
/// Converts the given time in ns into a usable unit depending on its size
5660
std::string FormatTime(std::chrono::nanoseconds ns, uint32_t precision);
57-
// -------------------------------------------------------------------------------------
58-
// Check alignment
61+
62+
/// Check alignment
5963
template <uint32_t byteCount> bool IsAlignedAt(const void* ptr) {
6064
return ((uint64_t)ptr) % byteCount == 0;
6165
}
66+
6267
uint8_t* AlignedAlloc(uint64_t alignment, uint64_t size);
63-
// -------------------------------------------------------------------------------------
64-
// Converts the data to and from hex string
68+
69+
/// Converts the data to and from hex string
6570
const std::string DataToHex(const uint8_t* data, uint32_t len,
6671
bool spaces = false);
72+
6773
const std::string StringToHex(const std::string& str, bool spaces = false);
74+
6875
const std::vector<uint8_t> HexToData(const std::string& str,
6976
bool spaces = false);
77+
7078
const std::string HexToString(const std::string& str, bool spaces = false);
71-
// -------------------------------------------------------------------------------------
72-
// Converts the string to a lower/upper case string
73-
std::string ToLower(const std::string& str);
74-
std::string ToUpper(const std::string& str);
75-
bool IsLower(const std::string& str);
76-
bool IsUpper(const std::string& str);
77-
// -------------------------------------------------------------------------------------
78-
// Just returns the number of nano seconds since epoch
79-
uint64_t TimeSinceEpoch();
80-
// -------------------------------------------------------------------------------------
81-
// Generate a vector with random tuple ids
82-
// @param locality: a value between 0 and 100, indicating how many tuples should
83-
// be on the same page: 0 -> uniform distribution and 100 -> all tuples on the
84-
// same page
85-
// @param count: how many random tuple ids should be generated
86-
// @param repeat: the value which is used locality/100 % of the time
87-
// @param generator: called for all other values
79+
80+
/// Generate a vector with random tuple ids
81+
///
82+
/// @param locality: a value between 0 and 100, indicating how many tuples
83+
/// should be on the same page: 0 -> uniform distribution and 100 -> all tuples
84+
/// on the same page
85+
/// @param count: how many random tuple ids should be generated
86+
/// @param repeat: the value which is used locality/100 % of the time
87+
/// @param generator: called for all other values
8888
template <class T>
89-
std::vector<T>
90-
GenerateNonUniformDistribution(uint32_t locality, uint32_t count, T repeat,
91-
std::function<T(void)> generator) {
89+
std::vector<T> GenerateNonUniformDistribution(
90+
uint32_t locality, uint32_t count, T repeat,
91+
std::function<T(void)> generator) {
9292
assert(0 <= locality && locality <= 100);
9393
uint32_t sameTupleCount = count / 100 * locality;
9494
std::vector<T> result(count);
@@ -101,7 +101,6 @@ GenerateNonUniformDistribution(uint32_t locality, uint32_t count, T repeat,
101101
std::random_shuffle(result.begin(), result.end());
102102
return result;
103103
}
104-
// -------------------------------------------------------------------------------------
104+
105105
} // namespace utils
106106
} // namespace leanstore
107-
// -------------------------------------------------------------------------------------

tests/BTreeLLTest.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class BTreeLLTest : public ::testing::Test {
2727

2828
TEST_F(BTreeLLTest, BTreeLLCreate) {
2929
FLAGS_data_dir = "/tmp/BTreeLLTest/BTreeLLCreate";
30-
std::filesystem::path dir_path = FLAGS_data_dir;
31-
std::filesystem::remove_all(dir_path);
32-
std::filesystem::create_directories(dir_path);
30+
std::filesystem::path dirPath = FLAGS_data_dir;
31+
std::filesystem::remove_all(dirPath);
32+
std::filesystem::create_directories(dirPath);
3333

3434
FLAGS_worker_threads = 2;
3535
FLAGS_recover = false;
@@ -38,7 +38,7 @@ TEST_F(BTreeLLTest, BTreeLLCreate) {
3838
storage::btree::BTreeLL* another;
3939

4040
// create leanstore btree for table records
41-
auto btreeName = "testTree1";
41+
const auto* btreeName = "testTree1";
4242
auto btreeConfig = leanstore::storage::btree::BTreeGeneric::Config{
4343
.mEnableWal = FLAGS_wal,
4444
.mUseBulkInsert = FLAGS_bulk_insert,
@@ -71,9 +71,9 @@ TEST_F(BTreeLLTest, BTreeLLCreate) {
7171

7272
TEST_F(BTreeLLTest, BTreeLLInsertAndLookup) {
7373
FLAGS_data_dir = "/tmp/BTreeLLTest/BTreeLLInsertAndLookup";
74-
std::filesystem::path dir_path = FLAGS_data_dir;
75-
std::filesystem::remove_all(dir_path);
76-
std::filesystem::create_directories(dir_path);
74+
std::filesystem::path dirPath = FLAGS_data_dir;
75+
std::filesystem::remove_all(dirPath);
76+
std::filesystem::create_directories(dirPath);
7777
FLAGS_worker_threads = 2;
7878
FLAGS_recover = false;
7979
mLeanStore = std::make_unique<leanstore::LeanStore>();
@@ -89,7 +89,7 @@ TEST_F(BTreeLLTest, BTreeLLInsertAndLookup) {
8989
}
9090

9191
// create leanstore btree for table records
92-
auto btreeName = "testTree1";
92+
const auto* btreeName = "testTree1";
9393
auto btreeConfig = leanstore::storage::btree::BTreeGeneric::Config{
9494
.mEnableWal = FLAGS_wal,
9595
.mUseBulkInsert = FLAGS_bulk_insert,

0 commit comments

Comments
 (0)