summaryrefslogtreecommitdiff
path: root/sortlib.cuh
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-10-11 15:43:33 +0800
committerKunoiSayami <[email protected]>2022-10-11 15:43:33 +0800
commitde790c5f00751d28744c52ae3f43d986422b11a2 (patch)
treeeee62464e902bab62693825aa6a79798990584a1 /sortlib.cuh
parent5828d051e613e2b38c8da493d90ade7f44ec28de (diff)
feat: Optimize step to const
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'sortlib.cuh')
-rw-r--r--sortlib.cuh20
1 files changed, 10 insertions, 10 deletions
diff --git a/sortlib.cuh b/sortlib.cuh
index 1fdac9c..0aba73b 100644
--- a/sortlib.cuh
+++ b/sortlib.cuh
@@ -9,9 +9,10 @@ typedef unsigned long long key_type;
class CustomSort {
public:
explicit __device__ __host__ CustomSort(size_t length, int move_offset)
- : LENGTH(length), MOVE_OFFSET(move_offset - 1) {}
+ : LENGTH(length), MOVE_OFFSET(move_offset - 1),
+ STEP_LIMIT(fast_log(LENGTH)) {}
const size_t LENGTH;
- const int MOVE_OFFSET;
+ const int MOVE_OFFSET, STEP_LIMIT;
__device__ __host__ static size_t fast_log(size_t a) {
float t = a;
@@ -42,11 +43,11 @@ public:
const key_type *end,
const key_type val) {
- int step_limit = (int)fast_log(LENGTH);
+ // int step_limit = (int)fast_log(LENGTH);
key_type *last_known_point = start;
auto son = 0;
- for (int i = 0; i < step_limit; i++) {
+ for (int i = 0; i < STEP_LIMIT; i++) {
const auto next_level_start = start + (1 << (i + 1)) - 1;
// printf("start: %ld, last: %ld\n", next_level_start - start,
@@ -86,11 +87,11 @@ public:
// printf("custom version:\n");
auto it = this->binary_search(start, end, x);
// printf("search result: %ld\n", it - start);
- assert(it <= start + this->LENGTH);
+ // assert(it <= start + this->LENGTH);
/*if (it < start) {
printf("it: %p, start: %p\n", it, start);
}*/
- assert(it >= start);
+ // assert(it >= start);
auto prev_real_location = calculate_rank(it - start) - 1;
@@ -105,11 +106,10 @@ public:
auto it_prev = start + calculate_index(prev_real_location - 1) - 1;
- auto tmp = ((double)prev_real_location +
- (double)(x - *it_prev) / (double)(*it - *it_prev)) /
- (double)(this->LENGTH - 1);
+ return ((double)prev_real_location +
+ (double)(x - *it_prev) / (double)(*it - *it_prev)) /
+ (double)(this->LENGTH - 1);
// printf("tmp: %llu %lf %lu\n", *it - *it_prev, tmp, prev_real_location);
- return tmp;
}
__device__ __host__ key_type *