#ifndef _HLLSKETCHIMPL_INTERNAL_HPP_
#define _HLLSKETCHIMPL_INTERNAL_HPP_
#include "HllSketchImpl.hpp"
#include "HllSketchImplFactory.hpp"
namespace datasketches {
template<typename A>
HllSketchImpl<A>::HllSketchImpl(uint8_t lgConfigK, target_hll_type tgtHllType,
hll_mode mode, bool startFullSize)
: lgConfigK_(lgConfigK),
tgtHllType_(tgtHllType),
mode_(mode),
startFullSize_(startFullSize)
{
}
template<typename A>
HllSketchImpl<A>::~HllSketchImpl() {
}
template<typename A>
target_hll_type HllSketchImpl<A>::extractTgtHllType(uint8_t modeByte) {
switch ((modeByte >> 2) & 0x3) {
case 0:
return target_hll_type::HLL_4;
case 1:
return target_hll_type::HLL_6;
case 2:
return target_hll_type::HLL_8;
default:
throw std::invalid_argument("Invalid target HLL type");
}
}
template<typename A>
hll_mode HllSketchImpl<A>::extractCurMode(uint8_t modeByte) {
switch (modeByte & 0x3) {
case 0:
return hll_mode::LIST;
case 1:
return hll_mode::SET;
case 2:
return hll_mode::HLL;
default:
throw std::invalid_argument("Invalid current sketch mode");
}
}
template<typename A>
uint8_t HllSketchImpl<A>::makeFlagsByte(bool compact) const {
uint8_t flags = 0;
flags |= (isEmpty() ? hll_constants::EMPTY_FLAG_MASK : 0);
flags |= (compact ? hll_constants::COMPACT_FLAG_MASK : 0);
flags |= (isOutOfOrderFlag() ? hll_constants::OUT_OF_ORDER_FLAG_MASK : 0);
flags |= (startFullSize_ ? hll_constants::FULL_SIZE_FLAG_MASK : 0);
return flags;
}
template<typename A>
uint8_t HllSketchImpl<A>::makeModeByte() const {
uint8_t byte = 0;
switch (mode_) {
case LIST:
byte = 0;
break;
case SET:
byte = 1;
break;
case HLL:
byte = 2;
break;
}
switch (tgtHllType_) {
case HLL_4:
byte |= (0 << 2); break;
case HLL_6:
byte |= (1 << 2);
break;
case HLL_8:
byte |= (2 << 2);
break;
}
return byte;
}
template<typename A>
HllSketchImpl<A>* HllSketchImpl<A>::reset() {
return HllSketchImplFactory<A>::reset(this, startFullSize_);
}
template<typename A>
target_hll_type HllSketchImpl<A>::getTgtHllType() const {
return tgtHllType_;
}
template<typename A>
uint8_t HllSketchImpl<A>::getLgConfigK() const {
return lgConfigK_;
}
template<typename A>
hll_mode HllSketchImpl<A>::getCurMode() const {
return mode_;
}
template<typename A>
bool HllSketchImpl<A>::isStartFullSize() const {
return startFullSize_;
}
}
#endif