This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 'master'
Release 1.1.0 See merge request ii887522/nitro!53
- Loading branch information
Showing
29 changed files
with
1,462 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
O�Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
O�Z�{� |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright ii887522 | ||
|
||
#ifndef NITRO_SRC_MAIN_FUNCTIONS_FS_EXT_H_ | ||
#define NITRO_SRC_MAIN_FUNCTIONS_FS_EXT_H_ | ||
|
||
#include <string> | ||
#include <fstream> | ||
|
||
using std::string; | ||
using std::ifstream; | ||
using std::ofstream; | ||
using std::ios; | ||
|
||
namespace ii887522::nitro { | ||
|
||
// Param filePath: it must exist | ||
template <typename T, template <typename> typename U> U<T> read(const string& filePath) { | ||
ifstream file{ filePath, ios::binary | ios::ate }; | ||
file.exceptions(file.failbit); | ||
U<T> fileContent(static_cast<unsigned int>(file.tellg()) / sizeof T); | ||
file.seekg(0u); | ||
file.read(reinterpret_cast<char*>(fileContent.data()), fileContent.size() * sizeof T); | ||
file.close(); | ||
return fileContent; | ||
} | ||
|
||
template <typename T, template <typename> typename U> void write(const string& filePath, const U<T>& objects) { | ||
ofstream file{ filePath, ios::binary }; | ||
file.write(reinterpret_cast<const char*>(objects.data()), objects.size() * sizeof T); | ||
file.close(); | ||
} | ||
|
||
} // namespace ii887522::nitro | ||
|
||
#endif // NITRO_SRC_MAIN_FUNCTIONS_FS_EXT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright ii887522 | ||
|
||
#include "math_ext.h" // NOLINT(build/include_subdir) | ||
#include <string> | ||
|
||
using std::string; | ||
|
||
namespace ii887522::nitro { | ||
|
||
bool isUint(const string& str) { | ||
for (const auto ch : str) { | ||
if (!isDigit(ch)) return false; | ||
} | ||
return true; | ||
} | ||
|
||
unsigned int parseUint(const string& uintStr) { | ||
auto result{ 0u }; | ||
auto placeValue{ 1u }; | ||
constexpr auto radix{ 10u }; | ||
for (auto i{ static_cast<int>(uintStr.length() - 1u) }; i >= 0; --i) { | ||
result += parseUint(uintStr[i]) * placeValue; | ||
placeValue *= radix; | ||
} | ||
return result; | ||
} | ||
|
||
} // namespace ii887522::nitro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright ii887522 | ||
|
||
#include "string_ext.h" // NOLINT(build/include_subdir) | ||
#include <string> | ||
|
||
using std::string; | ||
|
||
namespace ii887522::nitro { | ||
|
||
size_t getLastPathDelimiterI(const string& filePath) { | ||
auto result{ filePath.rfind('/') }; | ||
return result == string::npos ? filePath.rfind('\\') : result; | ||
} | ||
|
||
string getFileName(const string& filePath) { | ||
const auto lastPathDelimiterI{ getLastPathDelimiterI(filePath) }; | ||
return filePath.substr(lastPathDelimiterI + 1u, filePath.rfind('.') - lastPathDelimiterI - 1u); | ||
} | ||
|
||
void toUpperCase(string*const str) { | ||
for (auto& ch : *str) ch = toUpperCase(ch); | ||
} | ||
|
||
void toLowerCase(string*const str) { | ||
for (auto& ch : *str) ch = toLowerCase(ch); | ||
} | ||
|
||
} // namespace ii887522::nitro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright ii887522 | ||
|
||
#ifndef NITRO_SRC_MAIN_FUNCTIONS_STRING_EXT_H_ | ||
#define NITRO_SRC_MAIN_FUNCTIONS_STRING_EXT_H_ | ||
|
||
#include <string> | ||
|
||
using std::string; | ||
|
||
namespace ii887522::nitro { | ||
|
||
size_t getLastPathDelimiterI(const string& filePath); | ||
string getFileName(const string& filePath); | ||
|
||
constexpr char toUpperCase(const char ch) { | ||
return ch >= 'a' && ch <= 'z' ? ch - 32u : ch; | ||
} | ||
|
||
constexpr char toLowerCase(const char ch) { | ||
return ch >= 'A' && ch <= 'Z' ? ch + 32u : ch; | ||
} | ||
|
||
// Param str: it must not be assigned to nullptr or integer | ||
void toUpperCase(string*const str); | ||
|
||
// Param str: it must not be assigned to nullptr or integer | ||
void toLowerCase(string*const str); | ||
|
||
} // namespace ii887522::nitro | ||
|
||
#endif // NITRO_SRC_MAIN_FUNCTIONS_STRING_EXT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright ii887522 | ||
|
||
#ifndef NITRO_SRC_MAIN_FUNCTIONS_UTIL_H_ | ||
#define NITRO_SRC_MAIN_FUNCTIONS_UTIL_H_ | ||
|
||
#include <functional> | ||
#include <cstring> | ||
#include <string> | ||
#include "math_ext.h" // NOLINT(build/include_subdir) | ||
#include "../Struct/Range.h" | ||
|
||
using std::function; | ||
using std::string; | ||
|
||
namespace ii887522::nitro { | ||
|
||
template <typename T> constexpr void swap(T& l, T& r) { | ||
const T aux{ l }; | ||
l = r; | ||
r = aux; | ||
} | ||
|
||
// Param objects: it must not be assigned to nullptr or integer and must not be an empty vector | ||
// Param indices: min must be lower than objects.size(), max must be higher than or equal to min, | ||
// max can be higher than or equal to objects.size() | ||
// Param compare: it returns true if two objects passed in needs to be sorted | ||
template <typename T, template <typename> typename U> void insertionSort(U<T>*const objects, const Range<unsigned int>& indices = Range{ 0u, UINT_MAX }, | ||
const function<bool(const T&, const T&)>& compare = [](const T& l, const T& r) { | ||
return l > r; | ||
}) { | ||
const auto maxIndex{ min(indices.max, static_cast<unsigned int>(objects->size() - 1u)) }; | ||
for (auto i{ indices.min + 1u }; i <= maxIndex; ++i) { | ||
for (auto j{ i }; j > indices.min; --j) { | ||
if (compare((*objects)[j - 1u], (*objects)[j])) swap((*objects)[j - 1u], (*objects)[j]); | ||
else | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Param objects: it must not be assigned to nullptr or integer and must be an empty vector | ||
// Param startStep: | ||
// it is a starting number of consecutive items in objects that will become sorted | ||
// it must be a power of two and higher than 1 | ||
// Param compare: it returns true if two objects passed in needs to be sorted | ||
template <typename T, template <typename> typename U> void mergeSort(U<T>*const objects, const unsigned int startStep = 2u, const function<bool(const T&, const T&)>& compare = | ||
[](const T& l, const T& r) { | ||
return l > r; | ||
}) { | ||
U<T> aux(objects->size()); | ||
auto step{ startStep }; | ||
U<T>* currentObjects{ &aux }; | ||
U<T>* nextObjects{ objects }; | ||
while (true) { | ||
for (auto i{ 0u }; i < objects->size(); i += step) { | ||
auto l{ i }; | ||
auto r{ i + (step >> 1u) }; | ||
for (auto j{ i }; j != min(i + step, static_cast<unsigned int>(objects->size())); ++j) { | ||
if (r < objects->size() && r != i + step && (l == i + (step >> 1u) || compare((*nextObjects)[l], (*nextObjects)[r]))) { | ||
(*currentObjects)[j] = (*nextObjects)[r]; | ||
++r; | ||
} else { | ||
(*currentObjects)[j] = (*nextObjects)[l]; | ||
++l; | ||
} | ||
} | ||
} | ||
ii887522::nitro::swap(currentObjects, nextObjects); // NOLINT(build/include_what_you_use) | ||
if (step >= objects->size()) break; | ||
step <<= 1u; | ||
} | ||
if (currentObjects == objects) memcpy(objects->data(), aux.data(), objects->size() * sizeof T); | ||
} | ||
|
||
// Param objects: it must not be assigned to nullptr or integer and must not be an empty vector | ||
// Param runSize: | ||
// it is a number of consecutive items in objects that will become sorted | ||
// it must be higher than 0 | ||
// Param compare: it returns true if two objects passed in needs to be sorted | ||
template <typename T, template <typename> typename U> void insertionSorts(U<T>*const objects, const unsigned int runSize = UINT_MAX, const function<bool(const T&, const T&)>& compare = | ||
[](const T& l, const T& r) { | ||
return l > r; | ||
}) { | ||
for (auto i{ 0u }; i < objects->size(); i += runSize) insertionSort<T, U>(objects, Range{ i, i + runSize - 1u }, compare); | ||
} | ||
|
||
// Param objects: it must not be assigned to nullptr or integer and must not be an empty vector | ||
// Param compare: it returns true if two objects passed in needs to be sorted | ||
template <typename T, template <typename> typename U> void sort(U<T>*const objects, const function<bool(const T&, const T&)>& compare = [](const T& l, const T& r) { // NOLINT(build/include_what_you_use) | ||
return l > r; | ||
}) { | ||
constexpr auto runSize{ 32u }; | ||
insertionSorts<T, U>(objects, runSize, compare); | ||
mergeSort<T, U>(objects, runSize, compare); | ||
} | ||
|
||
} // namespace ii887522::nitro | ||
|
||
#endif // NITRO_SRC_MAIN_FUNCTIONS_UTIL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.