Google OR-Tools
v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cached_log.cc
Go to the documentation of this file.
1
// Copyright 2010-2025 Google LLC
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13
14
#include "
ortools/util/cached_log.h
"
15
16
#include "
ortools/base/logging.h
"
17
18
namespace
operations_research
{
19
20
CachedLog::CachedLog
() {}
21
22
CachedLog::~CachedLog
() {}
23
24
namespace
{
25
double
FastLog2(int64_t
input
) {
26
#if defined(_MSC_VER) || defined(__ANDROID__)
27
return
log(
static_cast<
double
>
(
input
)) / log(2.0L);
28
#else
29
return
log2(
input
);
30
#endif
31
}
32
}
// namespace
33
34
void
CachedLog::Init
(
int
size) {
35
CHECK(cache_.empty());
36
CHECK_GT(size, 0);
37
cache_.resize(size, 0.0);
38
for
(
int
i = 0; i < size; ++i) {
39
cache_[i] = FastLog2(i + 1);
40
}
41
}
42
43
double
CachedLog::Log2
(int64_t
input
)
const
{
44
CHECK_GE(
input
, 1);
45
if
(
input
<= cache_.size()) {
46
return
cache_[
input
- 1];
47
}
else
{
48
return
FastLog2(
input
);
49
}
50
}
51
52
}
// namespace operations_research
logging.h
cached_log.h
operations_research::CachedLog::Log2
double Log2(int64_t input) const
Definition
cached_log.cc:43
operations_research::CachedLog::Init
void Init(int cache_size)
Definition
cached_log.cc:34
operations_research::CachedLog::CachedLog
CachedLog()
Definition
cached_log.cc:20
operations_research::CachedLog::~CachedLog
~CachedLog()
Definition
cached_log.cc:22
operations_research
OR-Tools root namespace.
Definition
binary_indexed_tree.h:21
input
static int input(yyscan_t yyscanner)
ortools
util
cached_log.cc
Generated by
1.15.0