Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cached_log.h
Go to the documentation of this file.
1// Copyright 2010-2024 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#ifndef OR_TOOLS_UTIL_CACHED_LOG_H_
15#define OR_TOOLS_UTIL_CACHED_LOG_H_
16
17#include <cstdint>
18#include <vector>
19
20namespace operations_research {
21// This class is used when manipulating search space estimations. It
22// provides fast access to log of a domain size.
23// Future Extensions:
24// - Sum of log on an array.
25// - Sum of log on an array with callback.
26
27class CachedLog {
28 public:
29 CachedLog();
30
31 // This type is neither copyable nor movable.
32 CachedLog(const CachedLog&) = delete;
33 CachedLog& operator=(const CachedLog&) = delete;
34
35 ~CachedLog();
36
37 // This method can only be called once, and with a cache_size > 0.
38 void Init(int cache_size);
39
40 // Returns the log2 of 'input'.
41 double Log2(int64_t input) const;
42
43 private:
44 std::vector<double> cache_;
45};
46} // namespace operations_research
47
48#endif // OR_TOOLS_UTIL_CACHED_LOG_H_
double Log2(int64_t input) const
Returns the log2 of 'input'.
Definition cached_log.cc:43
void Init(int cache_size)
This method can only be called once, and with a cache_size > 0.
Definition cached_log.cc:34
CachedLog(const CachedLog &)=delete
This type is neither copyable nor movable.
CachedLog & operator=(const CachedLog &)=delete
In SWIG mode, we don't want anything besides these top-level includes.
static int input(yyscan_t yyscanner)