Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2024 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #include "shed/ops_internal.h" // IWYU pragma: export
12 :
13 : #include <etl/algorithm.h>
14 : #include <etl/error_handler.h>
15 :
16 : namespace shed
17 : {
18 : namespace internal
19 : {
20 18 : void move_while_impl(
21 : internal::multi_list::idx_type* const begin,
22 : internal::multi_list::idx_type* end,
23 : multi_list* const ml,
24 : size_t const dst,
25 : ::etl::delegate<bool(size_t, size_t)> const pred,
26 : ::etl::delegate<move_op(size_t)> const csfr)
27 : {
28 18 : ETL_ASSERT(end >= begin, ETL_ERROR_GENERIC("shed: invalid range"));
29 18 : if (begin == end)
30 : {
31 0 : return;
32 : }
33 18 : ETL_ASSERT(begin != nullptr, ETL_ERROR_GENERIC("shed: invalid range"));
34 18 : ::etl::make_heap(begin, end, pred);
35 :
36 18 : ETL_ASSERT(ml != nullptr, ETL_ERROR_GENERIC("shed: null multi_list"));
37 :
38 53 : while (begin != end)
39 : {
40 46 : ::etl::pop_heap(begin, end, pred);
41 46 : --end;
42 :
43 46 : auto const r = csfr(*end);
44 46 : if ((r == move_op::MOVE) || (r == move_op::MOVE_DONE))
45 : {
46 14 : ml->move_idx(*end, dst);
47 : }
48 46 : if ((r == move_op::SKIP_DONE) || (r == move_op::MOVE_DONE))
49 : {
50 11 : return;
51 : }
52 : }
53 : }
54 :
55 : } // namespace internal
56 : } // namespace shed
|