Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
felixguendling committed Nov 3, 2024
1 parent 2d28485 commit ead580d
Showing 5 changed files with 110 additions and 111 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
-Wno-deprecated-declarations
-Wno-ctad-maybe-unsupported
-Wno-self-assign-overloaded
-Wno-switch-default
-Werror
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
55 changes: 26 additions & 29 deletions fuzz/rtree_verification.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <cista/containers/mmap_vec.h>
#include <cista/mmap.h>
#include <cinttypes>
#include <cstring>
#include <iostream>

#include "cista/containers/mmap_vec.h"
#include "cista/containers/rtree.h"
#include "cista/mmap.h"
#include "cista/serialization.h"

extern "C" {
#include <stdatomic.h>
#include "dependencies/rtree_c/rtree_c.h"
}

@@ -21,8 +22,8 @@ struct ctx_entry {

bool operator==(ctx_entry other) const {
cista_rtree rt;
return rt.rect_.coord_t_equal(this->min, other.min) &&
rt.rect_.coord_t_equal(this->max, other.max) &&
return rt.m_.rect_.coord_t_equal(this->min, other.min) &&
rt.m_.rect_.coord_t_equal(this->max, other.max) &&
this->data == other.data;
}
};
@@ -149,30 +150,31 @@ int test_bench(uint8_t const* data, size_t size) {
iter_ref_ctx ctx{};
ctx.count = 0;
ctx.expected_value = 0;
uut_tree.search(coord_min, coord_max,
[coord_min, coord_max, &ctx, &uut_tree](
cista_rtree::coord_t const& min_temp,
cista_rtree::coord_t const& max_temp, uint32_t data) {
if (uut_tree.rect_.coord_t_equal(coord_min, min_temp) &&
uut_tree.rect_.coord_t_equal(coord_max, max_temp)) {
ctx.expected_value++;
ctx_entry input_entry{};
input_entry.min = min_temp;
input_entry.max = max_temp;
input_entry.data = data;
ctx.found_entries.emplace_back(input_entry);
}
return true;
});
uut_tree.search(
coord_min, coord_max,
[coord_min, coord_max, &ctx, &uut_tree](
cista_rtree::coord_t const& min_temp,
cista_rtree::coord_t const& max_temp, uint32_t data) {
if (uut_tree.m_.rect_.coord_t_equal(coord_min, min_temp) &&
uut_tree.m_.rect_.coord_t_equal(coord_max, max_temp)) {
ctx.expected_value++;
ctx_entry input_entry{};
input_entry.min = min_temp;
input_entry.max = max_temp;
input_entry.data = data;
ctx.found_entries.emplace_back(input_entry);
}
return true;
});

ctx.expected_value_mm = 0;
cista_mm_rtree.search(
coord_min, coord_max,
[coord_min, coord_max, &ctx, &cista_mm_rtree](
cista_rtree::coord_t const& min_temp,
cista_rtree::coord_t const& max_temp, uint32_t data) {
if (cista_mm_rtree.rect_.coord_t_equal(coord_min, min_temp) &&
cista_mm_rtree.rect_.coord_t_equal(coord_max, max_temp)) {
if (cista_mm_rtree.m_.rect_.coord_t_equal(coord_min, min_temp) &&
cista_mm_rtree.m_.rect_.coord_t_equal(coord_max, max_temp)) {
ctx.expected_value_mm++;
ctx_entry input_entry{};
input_entry.min = min_temp;
@@ -210,20 +212,15 @@ int test_bench(uint8_t const* data, size_t size) {
}

if (op == SAVE_LOAD) {
std::fstream file;
file.open("mmap_rtree_header.bin", std::ios::binary | std::ios::out);
cista_mm_rtree.write_header_bin(file);
file.close();
cista_mm_rtree.write_meta("mmap_rtree_header.bin");

auto save_load_file = cista::mmap{"./mmap_rtree_nodes.bin",
cista::mmap::protection::MODIFY};
cista_mm_rtree.nodes_ =
cista::mmap_vec_map<mm_rtree::node_idx_t, mm_rtree::node>{
std::move(save_load_file)};

file.open("mmap_rtree_header.bin", std::ios::binary | std::ios::in);
cista_mm_rtree.read_header_bin(file);
file.close();
cista_mm_rtree.read_meta("mmap_rtree_header.bin");
}

current_position = current_position + 21;
6 changes: 3 additions & 3 deletions include/cista/containers/rtree.h
Original file line number Diff line number Diff line change
@@ -288,7 +288,7 @@ struct rtree {
new_root.rects_[1] = get_node(right).bounding_box();
new_root.children_[0] = m_.root_;
new_root.children_[1] = right;
m_.root_ = m_.root_idx;
m_.root_ = new_root_idx;
new_root.count_ = 2;
++m_.height_;
}
@@ -544,7 +544,7 @@ struct rtree {

template <typename Fn>
void delete_0(coord_t const& min, coord_t const& max, Fn&& fn) {
auto const input_rect = rect{min, max};
auto input_rect = rect{min, max};

if (m_.root_ == node_idx_t::invalid()) {
return;
@@ -610,7 +610,7 @@ struct rtree {
}

void write_meta(std::filesystem::path const& p) { write(p, m_); }
void read_meta(std::filesystem::path const& p) { m_ = *read(p); }
void read_meta(std::filesystem::path const& p) { m_ = *read<meta>(p); }

struct meta {
rect rect_;
7 changes: 6 additions & 1 deletion include/cista/io.h
Original file line number Diff line number Diff line change
@@ -3,13 +3,18 @@
#include <filesystem>

#include "cista/memory_holder.h"
#include "cista/serialization.h"

namespace cista {

constexpr auto const kDefaultMode =
mode::WITH_STATIC_VERSION | mode::WITH_INTEGRITY;

template <mode const Mode, typename Target, typename T>
void serialize(Target& t, T& value);

template <typename T, mode const Mode, typename Container>
auto deserialize(Container& c);

template <mode Mode = kDefaultMode, typename T>
void write(std::filesystem::path const& p, T const& w) {
auto mmap =
Loading

0 comments on commit ead580d

Please sign in to comment.