Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type name #317

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions frozen/bits/pmh.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
#ifndef FROZEN_LETITGO_PMH_H
#define FROZEN_LETITGO_PMH_H

#include "frozen/bits/algorithms.h"
#include "frozen/bits/basic_types.h"

#include <array>
#include <cstdint>
#include <limits>

#include "frozen/bits/algorithms.h"
#include "frozen/bits/basic_types.h"

namespace frozen {

namespace bits {
Expand All @@ -47,7 +48,8 @@ struct bucket_size_compare {
// hash function.
// pmh_buckets represents the initial placement into buckets.

template <size_t M> struct pmh_buckets {
template <size_t M>
struct pmh_buckets {
// Step 0: Bucket max is 2 * sqrt M
// TODO: Come up with justification for this, should it not be O(log M)?
static constexpr auto bucket_max = 2 * (1u << (log(M) / 2));
Expand Down Expand Up @@ -135,14 +137,14 @@ constexpr bool all_different_from(cvector<T, N> &data, T &a) {
struct seed_or_index {
using value_type = uint64_t;

private:
private:
static constexpr value_type MINUS_ONE =
(std::numeric_limits<value_type>::max)();
static constexpr value_type HIGH_BIT = ~(MINUS_ONE >> 1);

value_type value_ = 0;

public:
public:
constexpr value_type value() const { return value_; }
constexpr bool is_seed() const { return value_ & HIGH_BIT; }

Expand All @@ -155,7 +157,8 @@ struct seed_or_index {
};

// Represents the perfect hash function created by pmh algorithm
template <std::size_t M, class Hasher> struct pmh_tables {
template <std::size_t M, class Hasher>
struct pmh_tables {
uint64_t first_seed_;
carray<seed_or_index, M> first_table_;
carray<std::size_t, M> second_table_;
Expand All @@ -175,7 +178,7 @@ template <std::size_t M, class Hasher> struct pmh_tables {
first_table_[hasher(key, static_cast<size_t>(first_seed_)) % M];
if (!d.is_seed()) {
return static_cast<std::size_t>(d.value());
} // this is narrowing uint64 -> size_t but should be fine
} // this is narrowing uint64 -> size_t but should be fine
else {
return second_table_[hasher(key, static_cast<std::size_t>(d.value())) %
M];
Expand All @@ -196,7 +199,7 @@ pmh_tables<M, Hash> constexpr make_pmh_tables(const carray<Item, N> &items,
auto buckets = step_one.get_sorted_buckets();

// G becomes the first hash table in the resulting pmh function
carray<seed_or_index, M> G; // Default constructed to "index 0"
carray<seed_or_index, M> G; // Default constructed to "index 0"

// H becomes the second hash table in the resulting pmh function
constexpr std::size_t UNUSED = (std::numeric_limits<std::size_t>::max)();
Expand All @@ -211,8 +214,8 @@ pmh_tables<M, Hash> constexpr make_pmh_tables(const carray<Item, N> &items,
// Store index to the (single) item in G
// assert(bucket.hash == hash(key(items[bucket[0]]), step_one.seed) % M);
G[bucket.hash] = {false, static_cast<uint64_t>(bucket[0])};
} else if (bsize > 1) {

}
else if (bsize > 1) {
// Repeatedly try different H of d until we find a hash function
// that places all items in the bucket into free slots
seed_or_index d{true, prg()};
Expand All @@ -235,8 +238,7 @@ pmh_tables<M, Hash> constexpr make_pmh_tables(const carray<Item, N> &items,
// Put successful seed in G, and put indices to items in their slots
// assert(bucket.hash == hash(key(items[bucket[0]]), step_one.seed) % M);
G[bucket.hash] = d;
for (std::size_t i = 0; i < bsize; ++i)
H[bucket_slots[i]] = bucket[i];
for (std::size_t i = 0; i < bsize; ++i) H[bucket_slots[i]] = bucket[i];
}
}

Expand All @@ -251,8 +253,8 @@ pmh_tables<M, Hash> constexpr make_pmh_tables(const carray<Item, N> &items,
return {step_one.seed, G, H, hash};
}

} // namespace bits
} // namespace bits

} // namespace frozen
} // namespace frozen

#endif
18 changes: 18 additions & 0 deletions iguana/pb_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,24 @@ IGUANA_INLINE constexpr std::string_view get_type_string() {
}
}
}
else if constexpr (std::is_same_v<T, iguana::sint32_t>) {
return "sint32";
}
else if constexpr (std::is_same_v<T, iguana::sint64_t>) {
return "sint64";
}
else if constexpr (std::is_same_v<T, iguana::fixed32_t>) {
return "fixed32";
}
else if constexpr (std::is_same_v<T, iguana::fixed64_t>) {
return "fixed64";
}
else if constexpr (std::is_same_v<T, iguana::sfixed32_t>) {
return "sfixed32";
}
else if constexpr (std::is_same_v<T, iguana::sfixed64_t>) {
return "sfixed64";
}
else if constexpr (std::is_same_v<T, std::string> ||
std::is_same_v<T, std::string_view>) {
return "string";
Expand Down
Loading