11 #ifndef odc_core_codec_String_H
12 #define odc_core_codec_String_H
26 template<
typename ByteOrder>
31 constexpr
static const char*
codec_name() {
return "chars"; }
45 std::unique_ptr<core::Codec>
clone()
override;
49 unsigned char*
encode(
unsigned char* p,
const double&
d)
override;
50 void decode(
double* out)
override;
60 void print(std::ostream &s)
const override;
73 template<
typename ByteOrder,
typename InternalCodec>
76 static_assert(std::is_same<typename InternalCodec::value_type, int64_t>::value,
"Safety check");
94 std::unique_ptr<core::Codec>
clone()
override {
116 unsigned char*
encode(
unsigned char* p,
const double&
d)
override {
121 size_t len = ::strnlen(
reinterpret_cast<const char*
>(&
d), this->
decodedSizeDoubles_*
sizeof(
double));
122 std::string s(
reinterpret_cast<const char*
>(&
d), len);
144 const std::string& s(this->
strings_[i]);
147 ::memcpy(
reinterpret_cast<char*
>(out), &s[0], std::min(s.length(), this->decodedSizeDoubles_*
sizeof(
double)));
182 if (s.length() != 0) {
196 ds.write(
static_cast<int32_t
>(this->
strings_.size()));
198 for (
size_t i = 0;
i < this->
strings_.size();
i++) {
200 ds.
write(
static_cast<int32_t
>(0));
201 ds.write(
static_cast<int32_t
>(
i));
213 template<
typename ByteOrder>
215 constexpr
static const char*
codec_name() {
return "int8_string"; }
221 template<
typename ByteOrder>
223 constexpr
static const char*
codec_name() {
return "int16_string"; }
233 template<
typename ByteOrder>
235 core::DataStreamCodec<ByteOrder>(
name,
type),
236 decodedSizeDoubles_(1) {}
238 template<
typename ByteOrder>
244 memcpy(p, &s, decodedSizeDoubles_*
sizeof(
double));
245 return p + (decodedSizeDoubles_*
sizeof(double));
248 template<
typename ByteOrder>
251 this->ds().readBytes(out,
sizeof(
double)*decodedSizeDoubles_);
254 template <
typename ByteOrder>
256 this->ds().advance(
sizeof(
double) * decodedSizeDoubles_);
259 template<
typename ByteOrder>
262 size_t len = ::strnlen(
reinterpret_cast<const char*
>(&v), decodedSizeDoubles_*
sizeof(
double));
263 std::string s(
reinterpret_cast<const char*
>(&v), len);
266 memcpy(buf, &v,
sizeof(
double));
267 buf[
sizeof(double)] = 0;
269 if (stringLookup_.find(s) == stringLookup_.end()) {
270 size_t index = strings_.size();
271 strings_.push_back(s);
272 stringLookup_[s] = index;
281 template<
typename ByteOrder>
286 ASSERT(nStrings == 0);
290 template<
typename ByteOrder>
294 ds.
write(
static_cast<int32_t
>(0));
297 template<
typename ByteOrder>
302 c.stringLookup_ = stringLookup_;
303 c.strings_ = strings_;
304 c.decodedSizeDoubles_ = decodedSizeDoubles_;
305 ASSERT(
c.min() == this->min_);
306 ASSERT(
c.max() == this->max_);
310 template<
typename ByteOrder>
314 strings_ =
c->strings_;
315 stringLookup_ =
c->stringLookup_;
318 template<
typename ByteOrder>
321 <<
", width=" << (decodedSizeDoubles_ *
sizeof(double))
322 <<
", #words=" << strings_.size();
static void count(void *counter, const double *data, size_t n)
static double integerMDI()
void print(std::ostream &s) const override
std::vector< std::string > strings_
void dataSizeDoubles(size_t count) override
std::unique_ptr< core::Codec > clone() override
unsigned char * encode(unsigned char *p, const double &d) override
void decode(double *out) override
size_t decodedSizeDoubles_
constexpr static const char * codec_name()
std::map< std::string, int64_t > stringLookup_
void gatherStats(const double &v) override
CodecChars(api::ColumnType type, const std::string &name=codec_name())
size_t numStrings() const override
void copyStrings(core::Codec &rhs) override
size_t dataSizeDoubles() const override
typename InternalCodec::value_type InternalInt
void clearDataStream() override
unsigned char * encode(unsigned char *p, const double &d) override
~IntStringCodecBase() override
std::unique_ptr< core::Codec > clone() override
IntStringCodecBase(api::ColumnType type, const std::string &name)
void setDataStream(core::DataStream< ByteOrder > &ds) override
void load(core::DataStream< ByteOrder > &ds) override
void save(core::DataStream< ByteOrder > &ds) override
void decode(double *out) override
const std::string & name() const
virtual std::unique_ptr< Codec > clone()
void clearDataStream() override
void setDataStream(GeneralDataStream &ds)
void save(GeneralDataStream &ds)
void load(GeneralDataStream &ds)
DataStream< ByteOrder > & ds()
void write(const T &elem)
CodecInt16String(api::ColumnType type)
~CodecInt16String() override
constexpr static const char * codec_name()
~CodecInt8String() override
constexpr static const char * codec_name()
CodecInt8String(api::ColumnType type)