Skip to content

Commit

Permalink
Add some assertions and PHOBIC typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteHamster committed Apr 26, 2024
1 parent 388d03b commit 11af4c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/dense_partitioned_phf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ namespace pthash {
template <typename Hasher, typename Bucketer, typename Encoder, bool NeedsFreeArray,
pthash_search_type Search>
struct dense_partitioned_phf {
static_assert(std::is_base_of<dense_encoder, Encoder>::value,
"Needs a dense encoder for dense partitioned PTHash. Select another encoder.");
typedef Encoder encoder_type;
static constexpr bool needsFreeArray = NeedsFreeArray;

template <typename Iterator>
build_timings build_in_internal_memory(Iterator keys, const uint64_t num_keys,
build_configuration const& config) {
assert(Search == config.search);
assert(config.dense_partitioning == true);
assert(config.avg_partition_size < 10000); // Unlike partitioned, must use small partitions
internal_memory_builder_partitioned_phf<Hasher, Bucketer> builder;
auto timings = builder.build_from_keys(keys, num_keys, config);
timings.encoding_microseconds = build(builder, config);
Expand Down Expand Up @@ -132,4 +136,7 @@ struct dense_partitioned_phf {
ef_sequence<false> m_free_slots;
};

template <typename Hasher, typename Encoder>
using phobic = dense_partitioned_phf<Hasher, table_bucketer<opt_bucketer>,
dense_interleaved<Encoder>, false, pthash_search_type::add_displacement>;
} // namespace pthash
9 changes: 6 additions & 3 deletions include/encoders/dense_encoders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ struct diff {
Encoder m_encoder;
};

struct dense_encoder {
};

template <typename Encoder>
struct dense_mono {
struct dense_mono : dense_encoder {
template <typename Iterator>
void encode(Iterator begin, //
const uint64_t num_partitions, //
Expand Down Expand Up @@ -89,7 +92,7 @@ struct dense_mono {
};

template <typename Encoder>
struct dense_interleaved {
struct dense_interleaved : dense_encoder {
template <typename Iterator>
void encode(Iterator begin, //
const uint64_t num_partitions, //
Expand Down Expand Up @@ -151,7 +154,7 @@ struct dense_interleaved {
};

template <typename Front, typename Back, uint64_t numerator = 1, uint64_t denominator = 3>
struct dense_dual {
struct dense_dual : dense_encoder {
template <typename Iterator>
void encode(Iterator begin, //
const uint64_t num_partitions, //
Expand Down
2 changes: 2 additions & 0 deletions include/partitioned_phf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace pthash {
template <typename Hasher, typename Bucketer, typename Encoder, bool Minimal,
pthash_search_type Search>
struct partitioned_phf {
static_assert(!std::is_base_of<dense_encoder, Encoder>::value,
"Dense encoders are only for dense PTHash. Select another encoder.");
private:
struct partition {
template <typename Visitor>
Expand Down
2 changes: 2 additions & 0 deletions include/single_phf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace pthash {
template <typename Hasher, typename Bucketer, typename Encoder, bool Minimal,
pthash_search_type Search>
struct single_phf {
static_assert(!std::is_base_of<dense_encoder, Encoder>::value,
"Dense encoders are only for dense PTHash. Select another encoder.");
typedef Encoder encoder_type;
static constexpr bool minimal = Minimal;

Expand Down

0 comments on commit 11af4c4

Please sign in to comment.