Skip to content

Commit

Permalink
Merge branch 'main' of github.com:oschonrock/binfuse
Browse files Browse the repository at this point in the history
  • Loading branch information
oschonrock committed Dec 19, 2024
2 parents afd3c26 + ab88dfc commit 7bdfb6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
9 changes: 7 additions & 2 deletions include/binfuse/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <format>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <span>
#include <sstream>
#include <stdexcept>
#include <string>
#include <system_error>
Expand Down Expand Up @@ -220,7 +220,12 @@ class persistent_filter : public filter<FilterType> {
return value;
}

[[nodiscard]] std::string type_id() const { return std::format("binfuse{:02d}", this->nbits); }
[[nodiscard]] std::string type_id() const {
std::string type_id;
std::stringstream type_id_stream(type_id);
type_id_stream << "binfuse" << std::setfill('0') << std::setw(2) << this->nbits;
return type_id_stream.str();
}

void sync()
requires(AccessMode == mio::access_mode::write)
Expand Down
30 changes: 19 additions & 11 deletions include/binfuse/sharded_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <format>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <stdexcept>
#include <string>
#include <system_error>
Expand Down Expand Up @@ -38,7 +39,7 @@ class sharded_filter : private sharded_mmap_base<AccessMode> {
public:
using shard_filter_t = filter<FilterType>;

static constexpr std::uint32_t nbits = shard_filter_t::nbits;
static constexpr std::uint32_t nbits = sizeof(typename ftype<FilterType>::fingerprint_t) * 8;

sharded_filter() = default;
explicit sharded_filter(std::filesystem::path path, std::uint8_t shard_bits = 8)
Expand Down Expand Up @@ -106,8 +107,8 @@ class sharded_filter : private sharded_mmap_base<AccessMode> {
requires(AccessMode == mio::access_mode::write)
{
if (shards_ == max_shards()) {
throw std::runtime_error(
std::format("sharded filter has reached max_shards of {}", max_shards()));
throw std::runtime_error("sharded filter has reached max_shards of " +
std::to_string(max_shards()));
}

std::uintmax_t new_size = ensure_header();
Expand All @@ -123,8 +124,8 @@ class sharded_filter : private sharded_mmap_base<AccessMode> {
auto old_filter_offset = get_from_map<offset_t>(filter_index_offset(prefix));

if (old_filter_offset != empty_offset) {
throw std::runtime_error(
std::format("there is already a filter in this file for prefix = {}", prefix));
throw std::runtime_error("there is already a filter in this file for prefix = " +
std::to_string(prefix));
}
copy_to_map(new_filter_offset, filter_index_offset(prefix)); // set up the index ptr
new_filter.serialize(
Expand Down Expand Up @@ -222,7 +223,12 @@ class sharded_filter : private sharded_mmap_base<AccessMode> {
return get_from_map<offset_t>(filter_index_offset(prefix));
}

[[nodiscard]] std::string type_id() const { return std::format("sbinfuse{:02d}", nbits); }
[[nodiscard]] std::string type_id() const {
std::string type_id;
std::stringstream type_id_stream(type_id);
type_id_stream << "sbinfuse" << std::setfill('0') << std::setw(2) << nbits;
return type_id_stream.str();
}

void sync()
requires(AccessMode == mio::access_mode::write)
Expand Down Expand Up @@ -254,8 +260,8 @@ class sharded_filter : private sharded_mmap_base<AccessMode> {
std::uint32_t check_max_shards = 0;
std::from_chars(&this->mmap[11], &this->mmap[15], check_max_shards);
if (check_max_shards != max_shards()) {
throw std::runtime_error(
std::format("wrong capacity: expected: {}, found: {}", max_shards(), check_max_shards));
throw std::runtime_error("wrong capacity: expected: " + std::to_string(max_shards()) +
", found: " + std::to_string(check_max_shards));
}
}

Expand All @@ -280,8 +286,10 @@ class sharded_filter : private sharded_mmap_base<AccessMode> {
void create_filetag()
requires(AccessMode == mio::access_mode::write)
{
const std::string tag = std::format("{}-{:04d}", type_id(), max_shards());
copy_str_to_map(tag, 0);
std::string tagstr;
std::stringstream tagstream(tagstr);
tagstream << type_id() << '-' << std::setfill('0') << std::setw(4) << max_shards();
copy_str_to_map(tagstream.str(), 0);
}

void create_index()
Expand Down

0 comments on commit 7bdfb6d

Please sign in to comment.