diff --git a/CMakeLists.txt b/CMakeLists.txt index 72fe5df..8d828dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,11 +69,16 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) add_compile_options(-Wall) -add_compile_options(-stdlib=libc++) add_compile_options(-g) add_compile_options(-O) + +add_compile_options(-stdlib=libc++) add_link_options(-stdlib=libc++) +# add_compile_options(-fno-omit-frame-pointer) +# add_compile_options(-fsanitize=address) +# add_link_options(-fsanitize=address) + # Add our dependencies # add_stream() diff --git a/include/core/sort/record_iterator.h b/include/core/sort/record_iterator.h index 0d83abf..870a10f 100644 --- a/include/core/sort/record_iterator.h +++ b/include/core/sort/record_iterator.h @@ -2,6 +2,7 @@ // #pragma once +#include #include #include @@ -76,7 +77,7 @@ struct RecordIterator { struct stack_value_type { stack_value_type(reference r) : size_(r.size()) - , data_(use_stack() ? &arr[0] : (storage_pointer)std::malloc(r.size())) { + , data_(use_stack() ? &arr[0] : (storage_pointer)std::malloc(sizeof(T) * r.size())) { std::copy(r.data(), r.data() + r.size(), data_); } @@ -121,7 +122,7 @@ struct RecordIterator { struct heap_value_type { heap_value_type(reference r) - : data_((storage_pointer)std::malloc(r.size())), + : data_((storage_pointer)std::malloc(sizeof(T) * r.size())), size_(r.size()) { std::copy(r.data(), r.data() + r.size(), data_); } diff --git a/src/tools/example0.cpp b/src/tools/example0.cpp index 8af37f2..a7b02b2 100644 --- a/src/tools/example0.cpp +++ b/src/tools/example0.cpp @@ -24,7 +24,7 @@ void output_records(const std::vector& data, int nrows, int ncols) { int main(int argc, const char *argv[]) { // Generate 10k records each with 7 integer numbered sequentially. - int nrows = 8, ncols = 5; + int nrows = 9, ncols = 5; std::vector data(nrows * ncols); std::generate(data.begin(), data.end(), [n=0]() mutable { return n++; }); cout << endl << "sequential: " << endl; @@ -36,7 +36,9 @@ int main(int argc, const char *argv[]) { output_records(data, nrows, ncols); // Sort the records - std::sort(begin_record(data, ncols), end_record(data, ncols), + RecordIterator begin(data.data(), ncols); + RecordIterator end(begin + nrows); + std::sort(begin, end, [](const int *a, const int *b) { return a[0] < b[0]; });