Skip to content

Commit c824e3a

Browse files
authored
Fix duplicate symbol issue in bit_vector.hpp. (#35)
* Add second (empty) file to catch duplicate symbols as reported in issue #34. * Fix declaration of `countr_zero` and switch to `inline constexpr`
1 parent ededd3e commit c824e3a

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ if (GTL_BUILD_TESTS)
149149

150150
## --------------- misc -----------------------------------------------
151151
gtl_cc_test(NAME lru_cache SRCS "tests/misc/lru_cache_test.cpp" DEPS ${GTL_GTEST_LIBS})
152-
gtl_cc_test(NAME bit_vector SRCS "tests/misc/bitvector_test.cpp" DEPS ${GTL_GTEST_LIBS})
152+
gtl_cc_test(NAME bit_vector SRCS "tests/misc/bitvector_test.cpp" "tests/misc/bitvector_test2.cpp" DEPS ${GTL_GTEST_LIBS})
153153
gtl_cc_test(NAME vector SRCS "tests/misc/vector_test.cpp" DEPS ${GTL_GTEST_LIBS})
154154
endif()
155155

include/gtl/bit_vector.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,31 @@ namespace gtl {
2525

2626
namespace bitv {
2727

28-
static constexpr size_t stride = 64;
29-
static constexpr uint64_t ones = (uint64_t)-1;
28+
inline constexpr size_t stride = 64;
29+
inline constexpr uint64_t ones = (uint64_t)-1;
3030

31-
static constexpr size_t mod(size_t n) { return (n & 0x3f); }
32-
static constexpr size_t slot(size_t n) { return n >> 6; }
33-
static constexpr size_t slot_cnt(size_t n) { return slot(n + 63); }
31+
inline constexpr size_t mod(size_t n) { return (n & 0x3f); }
32+
inline constexpr size_t slot(size_t n) { return n >> 6; }
33+
inline constexpr size_t slot_cnt(size_t n) { return slot(n + 63); }
3434

3535
// a mask for this bit in its slot
36-
static constexpr uint64_t bitmask(size_t n) { return (uint64_t)1 << mod(n); }
36+
inline constexpr uint64_t bitmask(size_t n) { return (uint64_t)1 << mod(n); }
3737

3838
// a mask for bits lower than n in slot
39-
static constexpr uint64_t lowmask(size_t n) { return bitmask(n) - 1; }
39+
inline constexpr uint64_t lowmask(size_t n) { return bitmask(n) - 1; }
4040

4141
// a mask for bits higher than n-1 in slot
42-
static constexpr uint64_t himask(size_t n) { return ~lowmask(n); }
42+
inline constexpr uint64_t himask(size_t n) { return ~lowmask(n); }
4343

44-
static constexpr size_t _popcount64(uint64_t y) {
44+
inline constexpr size_t _popcount64(uint64_t y) {
4545
// https://gist.github.com/enjoylife/4091854
4646
y -= ((y >> 1) & 0x5555555555555555ull);
4747
y = (y & 0x3333333333333333ull) + (y >> 2 & 0x3333333333333333ull);
4848
return ((y + (y >> 4)) & 0xf0f0f0f0f0f0f0full) * 0x101010101010101ull >> 56;
4949
}
5050

5151
// De Bruijn Multiplication With separated LS1B - author Kim Walisch (2012)
52-
unsigned countr_zero(uint64_t bb) {
52+
inline constexpr unsigned countr_zero(uint64_t bb) {
5353
const unsigned index64[64] = { 0, 47, 1, 56, 48, 27, 2, 60, 57, 49, 41, 37, 28, 16, 3, 61,
5454
54, 58, 35, 52, 50, 42, 21, 44, 38, 32, 29, 23, 17, 11, 4, 62,
5555
46, 55, 26, 59, 40, 36, 15, 53, 34, 51, 20, 43, 31, 22, 10, 45,

tests/misc/bitvector_test2.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ---------------------------------------------------------------------------
2+
// Copyright (c) 2022, Gregory Popovitch - [email protected]
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
// ---------------------------------------------------------------------------
10+
#include "gtest/gtest.h"
11+
#include <gtl/bit_vector.hpp>

0 commit comments

Comments
 (0)