Skip to content

Commit

Permalink
Fix bug in heap value type.
Browse files Browse the repository at this point in the history
  • Loading branch information
melton1968 committed May 30, 2023
1 parent d10a78c commit 700cefa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions include/core/sort/record_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//

#pragma once
#include <iostream>
#include <iterator>
#include <algorithm>

Expand Down Expand Up @@ -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_);
}

Expand Down Expand Up @@ -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_);
}
Expand Down
6 changes: 4 additions & 2 deletions src/tools/example0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void output_records(const std::vector<int>& 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<int> data(nrows * ncols);
std::generate(data.begin(), data.end(), [n=0]() mutable { return n++; });
cout << endl << "sequential: " << endl;
Expand All @@ -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<int, false, true> begin(data.data(), ncols);
RecordIterator<int, false, true> end(begin + nrows);
std::sort(begin, end,
[](const int *a, const int *b) {
return a[0] < b[0];
});
Expand Down

0 comments on commit 700cefa

Please sign in to comment.