Skip to content

Commit 20a42e2

Browse files
committed
fixed ASAN check on rmm-tree
1 parent 6578c9d commit 20a42e2

3 files changed

Lines changed: 88 additions & 53 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
name: Tests (Asan)
2-
3-
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
8-
9-
jobs:
10-
build-and-test:
11-
runs-on: ubuntu-latest
12-
13-
steps:
14-
- uses: actions/checkout@v4
15-
16-
- name: Create Build Directory
17-
run: mkdir build
18-
19-
- name: Configure CMake
20-
working-directory: ./build
21-
run: cmake -DDISABLE_AVX512=ON -DENABLE_ADDRESS_SANITIZER=ON -DPIXIE_BENCHMARKS=OFF ..
22-
23-
- name: Build Project
24-
working-directory: ./build
25-
run: make -j
26-
27-
- name: Run Unittests
28-
working-directory: ./build
29-
run: ./unittests
30-
31-
- name: Run LOUDS Tree Tests
32-
working-directory: ./build
33-
run: ./louds_tree_tests
34-
35-
- name: Run Benchmark Tests
36-
working-directory: ./build
37-
run: ./benchmark_tests
38-
39-
# TODO: fix RmM tests under Asan
40-
# - name: Run RmM Tree Tests
41-
# working-directory: ./build
42-
# run: ./test_rmm
43-
1+
name: Tests (Asan)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Create Build Directory
17+
run: mkdir build
18+
19+
- name: Configure CMake
20+
working-directory: ./build
21+
run: cmake -DDISABLE_AVX512=ON -DENABLE_ADDRESS_SANITIZER=ON -DPIXIE_BENCHMARKS=OFF ..
22+
23+
- name: Build Project
24+
working-directory: ./build
25+
run: make -j
26+
27+
- name: Run Unittests
28+
working-directory: ./build
29+
run: ./unittests
30+
31+
- name: Run LOUDS Tree Tests
32+
working-directory: ./build
33+
run: ./louds_tree_tests
34+
35+
- name: Run Benchmark Tests
36+
working-directory: ./build
37+
run: ./benchmark_tests
38+
39+
- name: Run RmM Tree Tests
40+
working-directory: ./build
41+
run: ./test_rmm
42+
4443
build-and-test-with-SDE:
4544
runs-on: ubuntu-latest
4645
timeout-minutes: 60
@@ -92,4 +91,4 @@ jobs:
9291
exit 0
9392
fi
9493
exit $rc
95-
94+

include/pixie/rmm_tree.h

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,26 +270,41 @@ class RmMTree {
270270
if (node_pattern10_count[node_index] < target_pattern_rank) {
271271
return npos;
272272
}
273+
const size_t tree_size = segment_size_bits.size() - 1;
273274
size_t segment_base = 0;
274275
while (node_index < first_leaf_index) {
275-
const size_t left_child = node_index << 1, right_child = left_child | 1;
276+
const size_t left_child = node_index << 1;
277+
const size_t left_segment_size =
278+
(left_child <= tree_size) ? segment_size_bits[left_child] : 0;
279+
if (left_segment_size == 0) {
280+
return npos;
281+
}
282+
283+
const size_t left_count = node_pattern10_count[left_child];
284+
if (left_count >= target_pattern_rank) {
285+
node_index = left_child;
286+
continue;
287+
}
288+
289+
size_t remaining_rank = target_pattern_rank - left_count;
290+
const size_t right_child = left_child | 1;
291+
const bool has_right =
292+
(right_child <= tree_size) && (segment_size_bits[right_child] != 0);
293+
if (!has_right) {
294+
return npos;
295+
}
296+
276297
const size_t crossing_pattern =
277298
(node_last_bit[left_child] == 1 && node_first_bit[right_child] == 0)
278299
? 1u
279300
: 0u;
280-
if (node_pattern10_count[left_child] >= target_pattern_rank) {
281-
node_index = left_child;
282-
continue;
283-
}
284-
size_t remaining_rank =
285-
target_pattern_rank - node_pattern10_count[left_child];
286301
if (crossing_pattern) {
287302
if (remaining_rank == 1) {
288-
return segment_base + segment_size_bits[left_child] - 1;
303+
return segment_base + left_segment_size - 1;
289304
}
290305
--remaining_rank;
291306
}
292-
segment_base += segment_size_bits[left_child];
307+
segment_base += left_segment_size;
293308
node_index = right_child;
294309
target_pattern_rank = remaining_rank;
295310
}

src/tests/test_rmm.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,27 @@ TEST(RmMEdgeCases, PartialLastLeafSelects) {
602602
expect_rank_select_equal(rm_select0, nv_select0, n);
603603
}
604604

605+
TEST(RmMEdgeCases, Select10OnIncompleteInternalNode) {
606+
constexpr size_t leaf_block_bits = 256;
607+
const size_t n = (leaf_block_bits * 2) + 32; // exactly 3 leaves
608+
std::string bits(n, '1');
609+
610+
// Put all "10" patterns into the last (partial) leaf.
611+
for (size_t i = leaf_block_bits * 2; i + 1 < n; i += 4) {
612+
bits[i] = '1';
613+
bits[i + 1] = '0';
614+
}
615+
616+
pixie::RmMTree rm(bits, leaf_block_bits);
617+
NaiveRmM nv(bits);
618+
619+
const size_t pairs10 = nv.rank10(n);
620+
ASSERT_GT(pairs10, 0u);
621+
for (size_t k = 1; k <= pairs10 + 1; ++k) {
622+
EXPECT_EQ(rm.select10(k), nv.select10(k)) << "select10 k=" << k;
623+
}
624+
}
625+
605626
/**
606627
* Invalid arguments should fail fast and return npos/0 as specified.
607628
* Covers bad ranks, bad ranges and out-of-bounds BP navigation calls.

0 commit comments

Comments
 (0)