Skip to content
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
4 changes: 3 additions & 1 deletion src/false_positives.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ uint64_t BaseFPBits(uint32_t bits, uint32_t capacity) {

size_t ComputeCapacity(uint32_t bits, size_t max_elements, uint32_t fpbits) {
if (bits == 0) return 0;
uint64_t base_fpbits = BaseFPBits(bits, max_elements);
if (max_elements > 0xffffffff) return max_elements;
uint64_t base_fpbits = BaseFPBits(bits, static_cast<uint32_t>(max_elements));
// The fpbits provided by the base max_elements==capacity case are sufficient.
if (base_fpbits >= fpbits) return max_elements;
// Otherwise, increment capacity by ceil(fpbits / bits) beyond that.
Expand All @@ -90,6 +91,7 @@ size_t ComputeCapacity(uint32_t bits, size_t max_elements, uint32_t fpbits) {

size_t ComputeMaxElements(uint32_t bits, size_t capacity, uint32_t fpbits) {
if (bits == 0) return 0;
if (capacity > 0xffffffff) return capacity;
// Start with max_elements=capacity, and decrease max_elements until the corresponding capacity is capacity.
size_t max_elements = capacity;
while (true) {
Expand Down
2 changes: 1 addition & 1 deletion src/int_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class BitsInt {
static constexpr inline int TopBits(I val) {
static_assert(Count > 0, "BitsInt::TopBits needs Count > 0");
static_assert(Count <= BITS, "BitsInt::TopBits needs Offset <= BITS");
return val >> (BITS - Count);
return static_cast<int>(val >> (BITS - Count));
}

static inline constexpr I CondXorWith(I val, bool cond, I v) {
Expand Down
2 changes: 1 addition & 1 deletion src/minisketch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ size_t minisketch_merge(minisketch* sketch, const minisketch* other_sketch) {
ssize_t minisketch_decode(const minisketch* sketch, size_t max_elements, uint64_t* output) {
const Sketch* s = (const Sketch*)sketch;
s->Check();
return s->Decode(max_elements, output);
return s->Decode(static_cast<int>(max_elements), output);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmpf. Unsure what to do with this.

It really means that max_elements cannot exceed 2^31-1 (or 2^16-1 on arcane platforms), which is likely the case in real use cases. But then again the API uses size_t and ssize_t which imply larger.

I guess we should leave this as-is for now, and then separately have a good look at what would be needed to make the internal code support (s)size_t-sized sketches.

}

void minisketch_set_seed(minisketch* sketch, uint64_t seed) {
Expand Down
2 changes: 1 addition & 1 deletion src/sketch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Sketch
virtual ~Sketch() {}
virtual size_t Syndromes() const = 0;

virtual void Init(int syndromes) = 0;
virtual void Init(size_t syndromes) = 0;
virtual void Add(uint64_t element) = 0;
virtual void Serialize(unsigned char*) const = 0;
virtual void Deserialize(const unsigned char*) = 0;
Expand Down
9 changes: 5 additions & 4 deletions src/sketch_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ template<typename F>
void Sqr(std::vector<typename F::Elem>& poly, const F& field) {
if (poly.size() == 0) return;
poly.resize(poly.size() * 2 - 1);
for (int x = poly.size() - 1; x >= 0; --x) {
for (size_t i = 0; i < poly.size(); ++i) {
auto x = poly.size() - i - 1;
poly[x] = (x & 1) ? 0 : field.Sqr(poly[x / 2]);
}
}
Expand Down Expand Up @@ -297,7 +298,7 @@ std::vector<typename F::Elem> BerlekampMassey(const std::vector<typename F::Elem
auto discrepancy = syndromes[n];
for (size_t i = 1; i < current.size(); ++i) discrepancy ^= table[n - i](current[i]);
if (discrepancy != 0) {
int x = n + 1 - (current.size() - 1) - (prev.size() - 1);
int x = static_cast<int>(n + 1 - (current.size() - 1) - (prev.size() - 1));
if (!b_have_inv) {
b_inv = field.Inv(b);
b_have_inv = true;
Expand Down Expand Up @@ -366,7 +367,7 @@ class SketchImpl final : public Sketch
}

size_t Syndromes() const override { return m_syndromes.size(); }
void Init(int count) override { m_syndromes.assign(count, 0); }
void Init(size_t count) override { m_syndromes.assign(count, 0); }

void Add(uint64_t val) override
{
Expand Down Expand Up @@ -405,7 +406,7 @@ class SketchImpl final : public Sketch
for (const auto& root : roots) {
*(out++) = m_field.ToUint64(root);
}
return roots.size();
return static_cast<int>(roots.size());
}

size_t Merge(const Sketch* other_sketch) override
Expand Down