forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[opt](cache elimation) using step decending method to elimiate cache
- Loading branch information
1 parent
00be77e
commit cca827d
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <utility> | ||
|
||
#include "common/status.h" | ||
namespace doris { | ||
class AlgoUtil { | ||
// descent the value step by step not linear continuity | ||
double descent_by_step(int step_num, int64_t low_bound, int64_t high_bound, int64_t current) { | ||
if (current <= low_bound) { | ||
return 1; | ||
} | ||
if (current >= high_bound) { | ||
return 0; | ||
} | ||
if (high_bound <= low_bound) { | ||
// Invalid | ||
return 0; | ||
} | ||
int64_t step_size = (int64_t)std::floor((high_bound - low_bound) / step_num); | ||
int64_t used_step = (int64_t)std::ceil((current - low_bound) / step_size); | ||
int64_t left_step = step_num - used_step; | ||
return left_step / step_num; | ||
} | ||
}; | ||
} // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include <gtest/gtest-message.h> | ||
#include <gtest/gtest-test-part.h> | ||
|
||
#include <boost/utility/binary.hpp> | ||
#include <memory> | ||
|
||
#include "gtest/gtest_pred_impl.h" | ||
#include "util/algorithm_util.h" | ||
|
||
namespace doris { | ||
|
||
TEST(TestAlgoUtil, DescentByStep) { | ||
// double descent_by_step(int step_num, int64_t low_bound, int64_t high_bound, int64_t current) | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 100, 200, 101), 0.9); | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 100, 200, 99), 1); | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 200, 100, 101), 0); | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 100, 200, 111), 0.8); | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 100, 200, 188), 0.1); | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 100, 200, 100), 1); | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 100, 200, 200), 0); | ||
EXPECT_EQ(AlgoUtil::descent_by_step(10, 100, 200, 300), 0); | ||
} | ||
|
||
} // namespace doris |