Skip to content

Commit

Permalink
Using C++23 to reimplement sort by using zip
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmoein committed Nov 24, 2023
1 parent 6e382c3 commit a08bd0c
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 260 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ add_library(DataFrame::DataFrame ALIAS DataFrame)

target_sources(DataFrame PRIVATE src/Utils/DateTime.cc)

target_compile_features(DataFrame PUBLIC cxx_std_20)
target_compile_features(DataFrame PUBLIC cxx_std_23)
target_compile_definitions(
DataFrame
PRIVATE $<$<BOOL:${HMDF_HAVE_CLOCK_GETTIME}>:HMDF_HAVE_CLOCK_GETTIME>
Expand Down
4 changes: 2 additions & 2 deletions include/DataFrame/DataFrameTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,10 @@ struct RandGenParams {
std::size_t t_dist { 1 };
// The μ distribution parameter (the mean of the distribution)
//
double mean { 1.0 };
double mean { 0 };
// the σ distribution parameter (standard deviation)
//
double std { 0 };
double std { 1 };
// The λ distribution parameter (the rate parameter)
//
double lambda { 1.0 };
Expand Down
531 changes: 296 additions & 235 deletions include/DataFrame/Internals/DataFrame.tcc

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions include/DataFrame/Internals/DataFrame_functors.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ struct sort_functor_ : DataVec::template visitor_base<Ts ...> {
: sorted_idxs(si), idx_s(is) { }

const StlVecType<size_t> &sorted_idxs;
StlVecType<size_t> sorted_idxs_copy;
const size_t idx_s;
const size_t idx_s;

template<typename T2>
void operator() (T2 &vec);
Expand Down
3 changes: 1 addition & 2 deletions include/DataFrame/Internals/DataFrame_misc.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ template<typename T2>
void
DataFrame<I, H>::sort_functor_<Ts ...>::operator() (T2 &vec) {

sorted_idxs_copy = sorted_idxs;
_sort_by_sorted_index_(vec, sorted_idxs_copy, idx_s);
_sort_by_sorted_index_(vec, sorted_idxs, idx_s);
return;
}

Expand Down
31 changes: 16 additions & 15 deletions include/DataFrame/Internals/DataFrame_standalone.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -865,23 +865,24 @@ inline static O _remove_copy_if_(I first, I last, O d_first, PRE predicate) {

template<typename T, typename V>
static inline void
_sort_by_sorted_index_(T &to_be_sorted, V &sorting_idxs, size_t idx_s) {

if (idx_s > 0) {
idx_s -= 1;
for (size_t i = 0; i < idx_s; ++i) [[likely]] {
// while the element i is not yet in place
//
while (sorting_idxs[i] != sorting_idxs[sorting_idxs[i]]) {
// swap it with the element at its final place
//
const size_t j = sorting_idxs[i];

std::swap(to_be_sorted[j], to_be_sorted[sorting_idxs[j]]);
std::swap(sorting_idxs[i], sorting_idxs[j]);
_sort_by_sorted_index_(T &to_be_sorted, const V &sorting_idxs, size_t idx_s) {

std::vector<bool> done (idx_s, false);

for (std::size_t i = 0; i < idx_s; ++i) [[likely]]
if (! done[i]) {
done[i] = true;

std::size_t prev_j = i;
std::size_t j = sorting_idxs[i];

while (i != j) {
std::swap(to_be_sorted[prev_j], to_be_sorted[j]);
done[j] = true;
prev_j = j;
j = sorting_idxs[j];
}
}
}
}

// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.Linux.GCC64
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CXX = /usr/bin/g++
INCLUDES = -I/usr/include/c++/7 -I/usr/include

LFLAGS =
CXXFLAGS = -O3 $(INCLUDES) $(DEFINES) -std=c++20
CXXFLAGS = -O3 $(INCLUDES) $(DEFINES) -std=c++2b

PLATFORM_LIBS = -lpthread -ldl -lm -lstdc++

Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.Linux.GCC64D
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ CXX = /usr/bin/g++
INCLUDES = -I/usr/include/c++/7 -I/usr/inc17lude

LFLAGS =
CXXFLAGS = -g $(INCLUDES) $(DEFINES) -D_GLIBCXX_DEBUG -pedantic -Wall -Wextra -std=c++20
# CXXFLAGS = -g $(INCLUDES) $(DEFINES) -std=c++20
CXXFLAGS = -g $(INCLUDES) $(DEFINES) -D_GLIBCXX_DEBUG -pedantic -Wall -Wextra -std=c++2b
# CXXFLAGS = -g $(INCLUDES) $(DEFINES) -std=c++2b

PLATFORM_LIBS = -lpthread -ldl -lm -lstdc++ -fsanitize-address-use-after-scope -fsanitize=address

Expand Down

0 comments on commit a08bd0c

Please sign in to comment.