Skip to content

Commit 6a04848

Browse files
authored
Merge pull request #365 from apache/minor_cleanup
Minor cleanup
2 parents 96897a6 + 586b3ed commit 6a04848

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

count/include/count_min_impl.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ auto count_min_sketch<W,A>::deserialize(std::istream& is, uint64_t seed, const A
359359

360360
template<typename W, typename A>
361361
size_t count_min_sketch<W,A>::get_serialized_size_bytes() const {
362-
// The header is always 2 bytes, whether empty or full
362+
// The header is always 2 longs, whether empty or full
363363
size_t preamble_longs = PREAMBLE_LONGS_SHORT;
364364

365365
// If the sketch is empty, we're done. Otherwise, we need the total weight
@@ -411,6 +411,8 @@ auto count_min_sketch<W,A>::serialize(unsigned header_size_bytes) const -> vecto
411411

412412
template<typename W, typename A>
413413
auto count_min_sketch<W,A>::deserialize(const void* bytes, size_t size, uint64_t seed, const A& allocator) -> count_min_sketch {
414+
ensure_minimum_memory(size, PREAMBLE_LONGS_SHORT * sizeof(uint64_t));
415+
414416
const char* ptr = static_cast<const char*>(bytes);
415417

416418
// First 8 bytes are 4 bytes of preamble and 4 unused bytes.
@@ -443,6 +445,8 @@ auto count_min_sketch<W,A>::deserialize(const void* bytes, size_t size, uint64_t
443445
const bool is_empty = (flags_byte & (1 << flags::IS_EMPTY)) > 0;
444446
if (is_empty) return c ; // sketch is empty, no need to read further.
445447

448+
ensure_minimum_memory(size, sizeof(W) * (1 + nbuckets * nhashes));
449+
446450
// Long 2 is the weight.
447451
W weight;
448452
ptr += copy_from_mem(ptr, weight) ;

density/include/density_sketch_impl.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,11 @@ density_sketch<T, K, A> density_sketch<T, K, A>::deserialize(const void* bytes,
354354

355355
// levels arrays
356356
Levels levels(allocator);
357-
int64_t num_to_read = num_retained; // num_retrained is uint32_t so this allows error checking
357+
int64_t num_to_read = num_retained; // num_retained is uint32_t so this allows error checking
358358
while (num_to_read > 0) {
359359
uint32_t level_size;
360360
ptr += copy_from_mem(ptr, level_size);
361+
ensure_minimum_memory(end_ptr - ptr, level_size * pt_size);
361362
Level lvl(allocator);
362363
lvl.reserve(level_size);
363364
for (uint32_t i = 0; i < level_size; ++i) {
@@ -442,7 +443,6 @@ string<A> density_sketch<T, K, A>::to_string(bool print_levels, bool print_items
442443

443444
if (print_items) {
444445
os << "### Density sketch data:" << std::endl;
445-
unsigned level = 0;
446446
for (unsigned height = 0; height < levels_.size(); ++height) {
447447
os << " level " << height << ": " << std::endl;
448448
for (const auto& point: levels_[height]) {
@@ -458,7 +458,6 @@ string<A> density_sketch<T, K, A>::to_string(bool print_levels, bool print_items
458458
}
459459
os << "]" << std::endl;
460460
}
461-
++level;
462461
}
463462
os << "### End sketch data" << std::endl;
464463
}

python/datasketches/TupleWrapper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
from abc import ABC, abstractmethod
1919

20-
from .TuplePolicy import TuplePolicy
2120
from _datasketches import _tuple_sketch, _compact_tuple_sketch, _update_tuple_sketch
2221
from _datasketches import _tuple_union, _tuple_intersection
2322
from _datasketches import _tuple_a_not_b, _tuple_jaccard_similarity
24-
from _datasketches import PyObjectSerDe, theta_sketch
23+
from _datasketches import PyObjectSerDe, theta_sketch, TuplePolicy
2524

2625
class tuple_sketch(ABC):
2726
"""An abstract base class representing a Tuple Sketch."""

python/include/py_object_lt.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/*
2626
This header defines a less than operator on generic python
27-
objects. The implementation calls the object's built-in __lr__()
27+
objects. The implementation calls the object's built-in __lt__()
2828
method. If that method is not defined, the call may fail.
2929
*/
3030

0 commit comments

Comments
 (0)