Skip to content

Commit

Permalink
added hpx::merge
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 43ec447 commit 779b4d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions hpx-sys/include/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,22 @@ inline void hpx_sort_comp(rust::Vec<int32_t>& src, rust::Fn<bool(int32_t, int32_
src.push_back(item);
}
}

inline void hpx_merge(const rust::Vec<int32_t>& src1,
const rust::Vec<int32_t>& src2,
rust::Vec<int32_t>& dest) {
std::vector<int32_t> cpp_src1(src1.begin(), src1.end());
std::vector<int32_t> cpp_src2(src2.begin(), src2.end());
std::vector<int32_t> cpp_dest(cpp_src1.size() + cpp_src2.size());

hpx::merge(hpx::execution::par,
cpp_src1.begin(), cpp_src1.end(),
cpp_src2.begin(), cpp_src2.end(),
cpp_dest.begin());

dest.clear();
dest.reserve(cpp_dest.size());
for (const auto& item : cpp_dest) {
dest.push_back(item);
}
}
21 changes: 21 additions & 0 deletions hpx-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod ffi {
fn hpx_find(src: &Vec<i32>, value: i32) -> i64;
fn hpx_sort(src: &mut Vec<i32>);
fn hpx_sort_comp(src: &mut Vec<i32>, comp: fn(i32, i32) -> bool);
fn hpx_merge(src1: &Vec<i32>, src2: &Vec<i32>, dest: &mut Vec<i32>);
}
}

Expand Down Expand Up @@ -400,4 +401,24 @@ mod tests {
assert_eq!(result, 0);
}
}

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

let hpx_main = |_argc: i32, _argv: *mut *mut c_char| -> i32 {
let v1 = vec![1, 3, 5, 7, 9, 20, 100];
let v2 = vec![2, 4, 6, 8, 10, 97];
let mut dest = Vec::new();
ffi::hpx_merge(&v1, &v2, &mut dest);
assert_eq!(dest, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 97, 100]);
ffi::finalize()
};

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

0 comments on commit 779b4d8

Please sign in to comment.