Skip to content

Commit

Permalink
Fix missing symbol after refactoring and ran iwyu
Browse files Browse the repository at this point in the history
  • Loading branch information
chusitoo committed May 21, 2024
1 parent 4d8b7d6 commit 4a79e7a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .vscode/compile_commands.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{
"command": "clang++ test.cpp -lstdc++ -std=c++11 -Wall -Wextra -pedantic -Wold-style-cast -Wdelete-incomplete -Wformat-nonliteral -Wno-varargs -Wconversion -O2 -DFLATBUSH_SPAN -o test",
"command": "clang++ test.cpp -lstdc++ -std=c++11 -Wall -Wextra -Werror -Wpedantic -Wold-style-cast -Wdelete-incomplete -Wformat-nonliteral -Wno-varargs -Wconversion -O2 -DFLATBUSH_SPAN -o test",
"directory": "/flatbush",
"file": "/flatbush/test.cpp"
},
{
"command": "clang++ bench.cpp -lstdc++ -std=c++11 -Wall -Wextra -pedantic -Wold-style-cast -Wdelete-incomplete -Wformat-nonliteral -Wno-varargs -Wconversion -O2 -DFLATBUSH_SPAN -o bench",
"command": "clang++ bench.cpp -lstdc++ -std=c++11 -Wall -Wextra -Werror -Wpedantic -Wold-style-cast -Wdelete-incomplete -Wformat-nonliteral -Wno-varargs -Wconversion -O2 -DFLATBUSH_SPAN -o bench",
"directory": "/flatbush",
"file": "/flatbush/bench.cpp"
},
Expand Down
27 changes: 14 additions & 13 deletions flatbush.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ SOFTWARE.
#ifndef FLATBUSH_H_
#define FLATBUSH_H_

#include <algorithm>
#include <array>
#include <cmath>
#include <cstring>
#include <functional>
#include <limits>
#include <queue>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include <algorithm> // for max, min, upper_bound
#include <array> // for array
#include <cmath> // for isnan
#include <cstdint> // for uint32_t, uint8_t, uint16_t, int16_t, int32_t, int8_t
#include <cstring> // for size_t, memcpy
#include <functional> // for function
#include <limits> // for numeric_limits
#include <queue> // for queue, priority_queue
#include <stdexcept> // for invalid_argument
#include <string> // for operator+, to_string, allocator, basic_string, char_traits, string
#include <type_traits> // for enable_if, is_same, false_type, integral_constant
#include <utility> // for swap
#include <vector> // for vector

#ifndef FLATBUSH_SPAN
#include <span>
Expand All @@ -52,7 +53,7 @@ class span {
size_t mLen = 0;

public:
span() = default;
span() noexcept = default;
span(Type* iPtr, size_t iLen) noexcept : mPtr{iPtr}, mLen{iLen} {}
Type& operator[](size_t iIndex) noexcept { return mPtr[iIndex]; }
Type const& operator[](size_t iIndex) const noexcept { return mPtr[iIndex]; }
Expand Down
18 changes: 16 additions & 2 deletions fuzz_from.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ flatbush::Flatbush<ArrayType> createIndex(uint32_t iNumItems, uint16_t iNodeSize
return wIndex;
}

std::vector<size_t> calculateNumNodesPerLevel(uint32_t iNumItems, uint32_t iNodeSize) {
size_t wCount = iNumItems;
size_t wNumNodes = iNumItems;
std::vector<size_t> wLevelBounds{wNumNodes};

do {
wCount = (wCount + iNodeSize - 1) / iNodeSize;
wNumNodes += wCount;
wLevelBounds.push_back(wNumNodes);
} while (wCount > 1);

return wLevelBounds;
}

template <typename ArrayType>
int from(const uint8_t *iData, size_t iSize) {
if (iSize < flatbush::gHeaderByteSize) return 0;
Expand All @@ -50,10 +64,10 @@ int from(const uint8_t *iData, size_t iSize) {
if (wNodeSize < 2) return 0;

const auto wNumItems = *flatbush::detail::bit_cast<uint32_t *>(&iData[4]);
const auto &wLevelBounds = flatbush::detail::calculateNumNodesPerLevel(wNumItems, wNodeSize);
const auto &wLevelBounds = calculateNumNodesPerLevel(wNumItems, wNodeSize);
const auto wNumNodes = wLevelBounds.empty() ? wNumItems : wLevelBounds.back();
const auto wIndicesByteSize =
wNumNodes * ((wNumNodes >= 16384) ? sizeof(uint32_t) : sizeof(uint16_t));
wNumNodes * ((wNumNodes > flatbush::gMaxNumNodes) ? sizeof(uint32_t) : sizeof(uint16_t));
const auto wNodesByteSize = wNumNodes * sizeof(flatbush::Box<ArrayType>);
const auto wSize = flatbush::gHeaderByteSize + wNodesByteSize + wIndicesByteSize;
if (wSize != iSize) return 0;
Expand Down

0 comments on commit 4a79e7a

Please sign in to comment.