Google OR-Tools: ortools/util/cached_log.cc Source File

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9

10

11

12

13

15

17

19

21

23

24namespace {

25double 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}

33

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

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}

double Log2(int64_t input) const

Definition cached_log.cc:43

void Init(int cache_size)

Definition cached_log.cc:34

CachedLog()

Definition cached_log.cc:20

~CachedLog()

Definition cached_log.cc:22

static int input(yyscan_t yyscanner)