Skip to content

Commit

Permalink
added hpx::sort
Browse files Browse the repository at this point in the history
Signed-off-by: Dikshant <[email protected]>
  • Loading branch information
pingu-73 committed Jul 31, 2024
1 parent b646351 commit 354b234
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hpx-sys/include/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ inline int64_t hpx_find(const rust::Vec<int32_t>& src, int32_t value) {
}
return -1;
}

inline void hpx_sort(rust::Vec<int32_t>& src) {
std::vector<int32_t> cpp_vec(src.begin(), src.end());

hpx::sort(hpx::execution::par, cpp_vec.begin(), cpp_vec.end());

src.clear();
src.reserve(cpp_vec.size());
for (const auto& item : cpp_vec) {
src.push_back(item);
}
}
19 changes: 19 additions & 0 deletions hpx-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod ffi {
fn hpx_equal(slice1: &[i32], slice2: &[i32]) -> bool;
fn hpx_fill(src: &mut Vec<i32>, value: i32); // will only work for linear vectors
fn hpx_find(src: &Vec<i32>, value: i32) -> i64;
fn hpx_sort(src: &mut Vec<i32>);
}
}

Expand Down Expand Up @@ -347,4 +348,22 @@ mod tests {
assert_eq!(result, 0);
}
}

#[test]
#[serial]
fn test_hpx_sort() {
let (argc, mut argv) = create_c_args(&["test_hpx_sort"]);

let hpx_main = |_argc: i32, _argv: *mut *mut c_char| -> i32 {
let mut src = vec![5, 2, 8, 1, 9, 3, 7, 6, 4];
ffi::hpx_sort(&mut src);
assert_eq!(src, vec![1, 2, 3, 4, 5, 6, 7, 8, 9]);
ffi::finalize()
};

unsafe {
let result = ffi::init(hpx_main, argc, argv.as_mut_ptr());
assert_eq!(result, 0);
}
}
}

0 comments on commit 354b234

Please sign in to comment.