2011-09-19 01:42:16 +00:00
|
|
|
|
#pragma once
|
2010-03-12 18:25:35 +00:00
|
|
|
|
|
2016-05-27 20:18:34 +00:00
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <cmath>
|
2010-03-12 18:25:35 +00:00
|
|
|
|
|
2015-10-05 01:35:28 +00:00
|
|
|
|
#include <DB/Common/Exception.h>
|
2015-10-04 03:20:03 +00:00
|
|
|
|
#include <DB/Common/Arena.h>
|
2016-07-10 15:58:58 +00:00
|
|
|
|
#include <DB/Common/SipHash.h>
|
2010-03-12 18:25:35 +00:00
|
|
|
|
|
2015-10-12 07:05:54 +00:00
|
|
|
|
#include <DB/IO/WriteBuffer.h>
|
|
|
|
|
#include <DB/IO/WriteHelpers.h>
|
|
|
|
|
|
2010-03-12 18:25:35 +00:00
|
|
|
|
#include <DB/Columns/IColumn.h>
|
|
|
|
|
|
2016-01-13 21:05:11 +00:00
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
|
#include <emmintrin.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-03-12 18:25:35 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
|
namespace ErrorCodes
|
|
|
|
|
{
|
|
|
|
|
extern const int PARAMETER_OUT_OF_BOUND;
|
|
|
|
|
extern const int SIZES_OF_COLUMNS_DOESNT_MATCH;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-11 20:32:08 +00:00
|
|
|
|
|
2013-11-01 20:10:43 +00:00
|
|
|
|
/** Штука для сравнения чисел.
|
|
|
|
|
* Целые числа сравниваются как обычно.
|
|
|
|
|
* Числа с плавающей запятой сравниваются так, что NaN-ы всегда оказываются в конце
|
|
|
|
|
* (если этого не делать, то сортировка не работала бы вообще).
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct CompareHelper
|
|
|
|
|
{
|
|
|
|
|
static bool less(T a, T b) { return a < b; }
|
|
|
|
|
static bool greater(T a, T b) { return a > b; }
|
|
|
|
|
|
|
|
|
|
/** Сравнивает два числа. Выдаёт число меньше нуля, равное нулю, или больше нуля, если a < b, a == b, a > b, соответственно.
|
|
|
|
|
* Если одно из значений является NaN, то:
|
|
|
|
|
* - если nan_direction_hint == -1 - NaN считаются меньше всех чисел;
|
|
|
|
|
* - если nan_direction_hint == 1 - NaN считаются больше всех чисел;
|
|
|
|
|
* По-сути: nan_direction_hint == -1 говорит, что сравнение идёт для сортировки по убыванию.
|
|
|
|
|
*/
|
2013-11-07 19:50:53 +00:00
|
|
|
|
static int compare(T a, T b, int nan_direction_hint)
|
|
|
|
|
{
|
|
|
|
|
return a > b ? 1 : (a < b ? -1 : 0);
|
|
|
|
|
}
|
2013-11-01 20:10:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct FloatCompareHelper
|
|
|
|
|
{
|
|
|
|
|
static bool less(T a, T b)
|
|
|
|
|
{
|
2016-05-27 20:18:34 +00:00
|
|
|
|
if (unlikely(std::isnan(b)))
|
|
|
|
|
return !std::isnan(a);
|
2013-11-01 20:10:43 +00:00
|
|
|
|
return a < b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool greater(T a, T b)
|
|
|
|
|
{
|
2016-05-27 20:18:34 +00:00
|
|
|
|
if (unlikely(std::isnan(b)))
|
|
|
|
|
return !std::isnan(a);
|
2013-11-01 20:10:43 +00:00
|
|
|
|
return a > b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int compare(T a, T b, int nan_direction_hint)
|
|
|
|
|
{
|
2016-05-27 20:18:34 +00:00
|
|
|
|
bool isnan_a = std::isnan(a);
|
|
|
|
|
bool isnan_b = std::isnan(b);
|
2013-11-01 20:10:43 +00:00
|
|
|
|
if (unlikely(isnan_a || isnan_b))
|
|
|
|
|
{
|
|
|
|
|
if (isnan_a && isnan_b)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return isnan_a
|
|
|
|
|
? nan_direction_hint
|
|
|
|
|
: -nan_direction_hint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (T(0) < (a - b)) - ((a - b) < T(0));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <> struct CompareHelper<Float32> : public FloatCompareHelper<Float32> {};
|
|
|
|
|
template <> struct CompareHelper<Float64> : public FloatCompareHelper<Float64> {};
|
|
|
|
|
|
|
|
|
|
|
2015-02-13 01:17:44 +00:00
|
|
|
|
/** Для реализации функции get64.
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
inline UInt64 unionCastToUInt64(T x) { return x; }
|
|
|
|
|
|
|
|
|
|
template <> inline UInt64 unionCastToUInt64(Float64 x)
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
Float64 src;
|
|
|
|
|
UInt64 res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
src = x;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <> inline UInt64 unionCastToUInt64(Float32 x)
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
Float32 src;
|
|
|
|
|
UInt64 res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
|
src = x;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-28 09:20:42 +00:00
|
|
|
|
/// To be sure, that this function is zero-cost for non-floating point types.
|
|
|
|
|
template <typename T>
|
|
|
|
|
inline bool isNaN(T x)
|
|
|
|
|
{
|
2016-12-30 08:07:02 +00:00
|
|
|
|
return std::is_floating_point<T>::value ? std::isnan(x) : false;
|
2016-12-28 09:20:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
typename std::enable_if<std::is_floating_point<T>::value, T>::type NaNOrZero()
|
|
|
|
|
{
|
|
|
|
|
return std::numeric_limits<T>::quiet_NaN();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
typename std::enable_if<!std::is_floating_point<T>::value, T>::type NaNOrZero()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-12-16 05:27:38 +00:00
|
|
|
|
/** Шаблон столбцов, которые используют для хранения простой массив.
|
2010-03-12 18:25:35 +00:00
|
|
|
|
*/
|
2013-01-21 06:43:38 +00:00
|
|
|
|
template <typename T>
|
2014-10-29 01:18:50 +00:00
|
|
|
|
class ColumnVector final : public IColumn
|
2010-03-12 18:25:35 +00:00
|
|
|
|
{
|
2013-05-03 05:23:14 +00:00
|
|
|
|
private:
|
2016-05-28 10:35:44 +00:00
|
|
|
|
using Self = ColumnVector<T>;
|
2010-03-12 18:25:35 +00:00
|
|
|
|
public:
|
2016-05-28 10:35:44 +00:00
|
|
|
|
using value_type = T;
|
|
|
|
|
using Container_t = PaddedPODArray<value_type>;
|
2010-03-12 18:25:35 +00:00
|
|
|
|
|
2014-06-05 20:34:13 +00:00
|
|
|
|
ColumnVector() {}
|
2014-10-28 13:43:22 +00:00
|
|
|
|
ColumnVector(const size_t n) : data{n} {}
|
|
|
|
|
ColumnVector(const size_t n, const value_type x) : data{n, x} {}
|
2011-08-28 00:31:30 +00:00
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
bool isNumeric() const override { return IsNumber<T>::value; }
|
|
|
|
|
bool isFixed() const override { return IsNumber<T>::value; }
|
2011-08-21 03:41:37 +00:00
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
size_t sizeOfField() const override { return sizeof(T); }
|
2011-09-26 12:50:50 +00:00
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
size_t size() const override
|
2010-03-12 18:25:35 +00:00
|
|
|
|
{
|
|
|
|
|
return data.size();
|
|
|
|
|
}
|
2013-01-07 06:47:15 +00:00
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
StringRef getDataAt(size_t n) const override
|
2012-10-07 06:30:10 +00:00
|
|
|
|
{
|
|
|
|
|
return StringRef(reinterpret_cast<const char *>(&data[n]), sizeof(data[n]));
|
|
|
|
|
}
|
2014-05-01 00:17:02 +00:00
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
void insertFrom(const IColumn & src, size_t n) override
|
2012-12-16 00:52:06 +00:00
|
|
|
|
{
|
2013-05-03 05:23:14 +00:00
|
|
|
|
data.push_back(static_cast<const Self &>(src).getData()[n]);
|
2012-12-16 00:52:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
void insertData(const char * pos, size_t length) override
|
2013-02-16 20:15:45 +00:00
|
|
|
|
{
|
|
|
|
|
data.push_back(*reinterpret_cast<const T *>(pos));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
void insertDefault() override
|
2010-05-20 19:29:04 +00:00
|
|
|
|
{
|
|
|
|
|
data.push_back(T());
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
|
void popBack(size_t n) override
|
|
|
|
|
{
|
|
|
|
|
data.resize_assume_reserved(data.size() - n);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-04 03:17:36 +00:00
|
|
|
|
StringRef serializeValueIntoArena(size_t n, Arena & arena, char const *& begin) const override
|
|
|
|
|
{
|
|
|
|
|
auto pos = arena.allocContinue(sizeof(T), begin);
|
|
|
|
|
memcpy(pos, &data[n], sizeof(T));
|
|
|
|
|
return StringRef(pos, sizeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * deserializeAndInsertFromArena(const char * pos) override
|
|
|
|
|
{
|
|
|
|
|
data.push_back(*reinterpret_cast<const T *>(pos));
|
|
|
|
|
return pos + sizeof(T);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-10 15:58:58 +00:00
|
|
|
|
void updateHashWithValue(size_t n, SipHash & hash) const override
|
|
|
|
|
{
|
|
|
|
|
hash.update(reinterpret_cast<const char *>(&data[n]), sizeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
size_t byteSize() const override
|
2011-08-27 22:43:31 +00:00
|
|
|
|
{
|
|
|
|
|
return data.size() * sizeof(data[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 13:29:32 +00:00
|
|
|
|
void insert(const T value)
|
|
|
|
|
{
|
|
|
|
|
data.push_back(value);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
int compareAt(size_t n, size_t m, const IColumn & rhs_, int nan_direction_hint) const override
|
2011-09-04 00:22:19 +00:00
|
|
|
|
{
|
2013-11-01 20:10:43 +00:00
|
|
|
|
return CompareHelper<T>::compare(data[n], static_cast<const Self &>(rhs_).data[m], nan_direction_hint);
|
2011-09-04 00:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-26 11:05:38 +00:00
|
|
|
|
struct less
|
|
|
|
|
{
|
2013-05-03 05:23:14 +00:00
|
|
|
|
const Self & parent;
|
|
|
|
|
less(const Self & parent_) : parent(parent_) {}
|
2013-11-01 20:10:43 +00:00
|
|
|
|
bool operator()(size_t lhs, size_t rhs) const { return CompareHelper<T>::less(parent.data[lhs], parent.data[rhs]); }
|
2011-09-26 11:05:38 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-09-16 05:44:47 +00:00
|
|
|
|
struct greater
|
|
|
|
|
{
|
|
|
|
|
const Self & parent;
|
|
|
|
|
greater(const Self & parent_) : parent(parent_) {}
|
2013-11-01 20:10:43 +00:00
|
|
|
|
bool operator()(size_t lhs, size_t rhs) const { return CompareHelper<T>::greater(parent.data[lhs], parent.data[rhs]); }
|
2013-09-16 05:44:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
void getPermutation(bool reverse, size_t limit, Permutation & res) const override
|
2011-09-26 11:05:38 +00:00
|
|
|
|
{
|
|
|
|
|
size_t s = data.size();
|
2013-12-08 02:29:40 +00:00
|
|
|
|
res.resize(s);
|
2011-09-26 11:05:38 +00:00
|
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
|
res[i] = i;
|
|
|
|
|
|
2014-05-23 01:32:32 +00:00
|
|
|
|
if (limit >= s)
|
2013-09-16 05:44:47 +00:00
|
|
|
|
limit = 0;
|
|
|
|
|
|
|
|
|
|
if (limit)
|
|
|
|
|
{
|
|
|
|
|
if (reverse)
|
|
|
|
|
std::partial_sort(res.begin(), res.begin() + limit, res.end(), greater(*this));
|
|
|
|
|
else
|
|
|
|
|
std::partial_sort(res.begin(), res.begin() + limit, res.end(), less(*this));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (reverse)
|
|
|
|
|
std::sort(res.begin(), res.end(), greater(*this));
|
|
|
|
|
else
|
|
|
|
|
std::sort(res.begin(), res.end(), less(*this));
|
|
|
|
|
}
|
2011-09-26 11:05:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
void reserve(size_t n) override
|
2013-02-03 18:39:09 +00:00
|
|
|
|
{
|
|
|
|
|
data.reserve(n);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
std::string getName() const override { return "ColumnVector<" + TypeName<T>::get() + ">"; }
|
2013-02-08 23:41:05 +00:00
|
|
|
|
|
2016-08-16 11:26:17 +00:00
|
|
|
|
ColumnPtr cloneResized(size_t size) const override
|
2013-02-08 23:41:05 +00:00
|
|
|
|
{
|
2016-08-16 11:26:17 +00:00
|
|
|
|
ColumnPtr new_col_holder = std::make_shared<Self>();
|
|
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
|
{
|
|
|
|
|
auto & new_col = static_cast<Self &>(*new_col_holder);
|
|
|
|
|
new_col.data.resize(size);
|
|
|
|
|
|
|
|
|
|
size_t count = std::min(this->size(), size);
|
|
|
|
|
memcpy(&new_col.data[0], &data[0], count * sizeof(data[0]));
|
|
|
|
|
|
|
|
|
|
if (size > count)
|
|
|
|
|
memset(&new_col.data[count], value_type(), size - count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new_col_holder;
|
2013-02-08 23:41:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
Field operator[](size_t n) const override
|
2013-02-08 23:41:05 +00:00
|
|
|
|
{
|
2014-06-05 20:34:13 +00:00
|
|
|
|
return typename NearestFieldType<T>::Type(data[n]);
|
2013-02-08 23:41:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
void get(size_t n, Field & res) const override
|
2013-02-08 23:41:05 +00:00
|
|
|
|
{
|
2014-06-05 20:34:13 +00:00
|
|
|
|
res = typename NearestFieldType<T>::Type(data[n]);
|
2013-02-08 23:41:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 12:58:49 +00:00
|
|
|
|
const T & getElement(size_t n) const
|
2016-06-21 11:32:08 +00:00
|
|
|
|
{
|
|
|
|
|
return data[n];
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 12:58:49 +00:00
|
|
|
|
T & getElement(size_t n)
|
2016-06-21 11:32:08 +00:00
|
|
|
|
{
|
|
|
|
|
return data[n];
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 01:17:44 +00:00
|
|
|
|
UInt64 get64(size_t n) const override
|
|
|
|
|
{
|
|
|
|
|
return unionCastToUInt64(data[n]);
|
|
|
|
|
}
|
2014-05-01 00:17:02 +00:00
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
void insert(const Field & x) override
|
2013-02-08 23:41:05 +00:00
|
|
|
|
{
|
2014-06-05 20:34:13 +00:00
|
|
|
|
data.push_back(DB::get<typename NearestFieldType<T>::Type>(x));
|
2013-02-08 23:41:05 +00:00
|
|
|
|
}
|
2013-05-03 05:23:14 +00:00
|
|
|
|
|
2015-11-29 17:06:30 +00:00
|
|
|
|
void insertRangeFrom(const IColumn & src, size_t start, size_t length) override
|
2013-05-03 05:23:14 +00:00
|
|
|
|
{
|
2015-11-29 17:06:30 +00:00
|
|
|
|
const ColumnVector & src_vec = static_cast<const ColumnVector &>(src);
|
|
|
|
|
|
|
|
|
|
if (start + length > src_vec.data.size())
|
2013-05-03 05:23:14 +00:00
|
|
|
|
throw Exception("Parameters start = "
|
2014-12-15 05:23:44 +00:00
|
|
|
|
+ toString(start) + ", length = "
|
2015-11-29 17:06:30 +00:00
|
|
|
|
+ toString(length) + " are out of bound in ColumnVector::insertRangeFrom method"
|
|
|
|
|
" (data.size() = " + toString(src_vec.data.size()) + ").",
|
2014-12-15 05:23:44 +00:00
|
|
|
|
ErrorCodes::PARAMETER_OUT_OF_BOUND);
|
2013-05-03 05:23:14 +00:00
|
|
|
|
|
2015-11-29 17:06:30 +00:00
|
|
|
|
size_t old_size = data.size();
|
|
|
|
|
data.resize(old_size + length);
|
|
|
|
|
memcpy(&data[old_size], &src_vec.data[start], length * sizeof(data[0]));
|
2013-05-03 05:23:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-05 07:01:18 +00:00
|
|
|
|
ColumnPtr filter(const IColumn::Filter & filt, ssize_t result_size_hint) const override
|
2013-05-03 05:23:14 +00:00
|
|
|
|
{
|
2014-06-05 20:34:13 +00:00
|
|
|
|
size_t size = data.size();
|
2013-05-03 05:23:14 +00:00
|
|
|
|
if (size != filt.size())
|
|
|
|
|
throw Exception("Size of filter doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
2016-05-28 05:31:36 +00:00
|
|
|
|
std::shared_ptr<Self> res = std::make_shared<Self>();
|
|
|
|
|
typename Self::Container_t & res_data = res->getData();
|
2015-12-05 07:01:18 +00:00
|
|
|
|
|
|
|
|
|
if (result_size_hint)
|
|
|
|
|
res_data.reserve(result_size_hint > 0 ? result_size_hint : size);
|
2013-05-03 05:23:14 +00:00
|
|
|
|
|
2014-08-17 07:39:28 +00:00
|
|
|
|
const UInt8 * filt_pos = &filt[0];
|
|
|
|
|
const UInt8 * filt_end = filt_pos + size;
|
|
|
|
|
const T * data_pos = &data[0];
|
|
|
|
|
|
2016-01-13 21:05:11 +00:00
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
|
/** Чуть более оптимизированная версия.
|
|
|
|
|
* Исходит из допущения, что часто куски последовательно идущих значений
|
|
|
|
|
* полностью проходят или полностью не проходят фильтр.
|
|
|
|
|
* Поэтому, будем оптимистично проверять куски по SIMD_BYTES значений.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static constexpr size_t SIMD_BYTES = 16;
|
2014-08-28 07:49:27 +00:00
|
|
|
|
const __m128i zero16 = _mm_setzero_si128();
|
2016-01-13 21:05:11 +00:00
|
|
|
|
const UInt8 * filt_end_sse = filt_pos + size / SIMD_BYTES * SIMD_BYTES;
|
2014-08-17 09:18:47 +00:00
|
|
|
|
|
2014-08-17 07:39:28 +00:00
|
|
|
|
while (filt_pos < filt_end_sse)
|
|
|
|
|
{
|
2014-08-17 09:18:47 +00:00
|
|
|
|
int mask = _mm_movemask_epi8(_mm_cmpgt_epi8(_mm_loadu_si128(reinterpret_cast<const __m128i *>(filt_pos)), zero16));
|
2014-08-17 07:39:28 +00:00
|
|
|
|
|
|
|
|
|
if (0 == mask)
|
|
|
|
|
{
|
|
|
|
|
/// Ничего не вставляем.
|
|
|
|
|
}
|
|
|
|
|
else if (0xFFFF == mask)
|
|
|
|
|
{
|
2016-01-13 21:05:11 +00:00
|
|
|
|
res_data.insert(data_pos, data_pos + SIMD_BYTES);
|
2014-08-17 07:39:28 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-01-13 21:05:11 +00:00
|
|
|
|
for (size_t i = 0; i < SIMD_BYTES; ++i)
|
2014-08-17 07:39:28 +00:00
|
|
|
|
if (filt_pos[i])
|
|
|
|
|
res_data.push_back(data_pos[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-13 21:05:11 +00:00
|
|
|
|
filt_pos += SIMD_BYTES;
|
|
|
|
|
data_pos += SIMD_BYTES;
|
2014-08-17 07:39:28 +00:00
|
|
|
|
}
|
2016-01-13 21:05:11 +00:00
|
|
|
|
#endif
|
2014-08-17 07:39:28 +00:00
|
|
|
|
|
|
|
|
|
while (filt_pos < filt_end)
|
|
|
|
|
{
|
|
|
|
|
if (*filt_pos)
|
|
|
|
|
res_data.push_back(*data_pos);
|
|
|
|
|
|
|
|
|
|
++filt_pos;
|
|
|
|
|
++data_pos;
|
|
|
|
|
}
|
2013-05-03 05:23:14 +00:00
|
|
|
|
|
2014-08-17 07:39:28 +00:00
|
|
|
|
return res;
|
2013-05-03 05:23:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
ColumnPtr permute(const IColumn::Permutation & perm, size_t limit) const override
|
2013-05-03 05:23:14 +00:00
|
|
|
|
{
|
2014-06-05 20:34:13 +00:00
|
|
|
|
size_t size = data.size();
|
2013-05-03 05:23:14 +00:00
|
|
|
|
|
2013-09-16 05:44:47 +00:00
|
|
|
|
if (limit == 0)
|
|
|
|
|
limit = size;
|
|
|
|
|
else
|
|
|
|
|
limit = std::min(size, limit);
|
2014-06-05 20:34:13 +00:00
|
|
|
|
|
2013-09-16 05:44:47 +00:00
|
|
|
|
if (perm.size() < limit)
|
|
|
|
|
throw Exception("Size of permutation is less than required.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
2016-05-28 05:31:36 +00:00
|
|
|
|
std::shared_ptr<Self> res = std::make_shared<Self>(limit);
|
|
|
|
|
typename Self::Container_t & res_data = res->getData();
|
2013-09-16 05:44:47 +00:00
|
|
|
|
for (size_t i = 0; i < limit; ++i)
|
2014-06-05 20:34:13 +00:00
|
|
|
|
res_data[i] = data[perm[i]];
|
2013-05-03 05:23:14 +00:00
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 22:15:17 +00:00
|
|
|
|
ColumnPtr replicate(const IColumn::Offsets_t & offsets) const override
|
2013-05-03 05:23:14 +00:00
|
|
|
|
{
|
2014-06-05 20:34:13 +00:00
|
|
|
|
size_t size = data.size();
|
2013-05-03 05:23:14 +00:00
|
|
|
|
if (size != offsets.size())
|
|
|
|
|
throw Exception("Size of offsets doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
2014-08-20 04:57:03 +00:00
|
|
|
|
if (0 == size)
|
2016-05-28 05:31:36 +00:00
|
|
|
|
return std::make_shared<Self>();
|
2014-08-20 04:57:03 +00:00
|
|
|
|
|
2016-05-28 05:31:36 +00:00
|
|
|
|
std::shared_ptr<Self> res = std::make_shared<Self>();
|
|
|
|
|
typename Self::Container_t & res_data = res->getData();
|
2013-05-03 05:23:14 +00:00
|
|
|
|
res_data.reserve(offsets.back());
|
|
|
|
|
|
|
|
|
|
IColumn::Offset_t prev_offset = 0;
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
{
|
|
|
|
|
size_t size_to_replicate = offsets[i] - prev_offset;
|
|
|
|
|
prev_offset = offsets[i];
|
|
|
|
|
|
|
|
|
|
for (size_t j = 0; j < size_to_replicate; ++j)
|
2014-06-05 20:34:13 +00:00
|
|
|
|
res_data.push_back(data[i]);
|
2013-05-03 05:23:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2013-09-06 20:28:22 +00:00
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
|
void getExtremes(Field & min, Field & max) const override
|
2013-09-06 20:28:22 +00:00
|
|
|
|
{
|
2014-06-05 20:34:13 +00:00
|
|
|
|
size_t size = data.size();
|
2013-09-06 20:28:22 +00:00
|
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
|
{
|
|
|
|
|
min = typename NearestFieldType<T>::Type(0);
|
|
|
|
|
max = typename NearestFieldType<T>::Type(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-28 09:20:42 +00:00
|
|
|
|
bool has_value = false;
|
|
|
|
|
|
|
|
|
|
/** Skip all NaNs in extremes calculation.
|
|
|
|
|
* If all values are NaNs, then return NaN.
|
|
|
|
|
* NOTE: There exist many different NaNs.
|
|
|
|
|
* Different NaN could be returned: not bit-exact value as one of NaNs from column.
|
|
|
|
|
*/
|
2016-07-05 16:23:37 +00:00
|
|
|
|
|
2016-12-28 09:20:42 +00:00
|
|
|
|
T cur_min = NaNOrZero<T>();
|
|
|
|
|
T cur_max = NaNOrZero<T>();
|
|
|
|
|
|
|
|
|
|
for (const T x : data)
|
2016-07-05 16:23:37 +00:00
|
|
|
|
{
|
2016-12-28 09:20:42 +00:00
|
|
|
|
if (isNaN(x))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!has_value)
|
|
|
|
|
{
|
|
|
|
|
cur_min = x;
|
|
|
|
|
cur_max = x;
|
|
|
|
|
has_value = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x < cur_min)
|
|
|
|
|
cur_min = x;
|
2016-07-05 16:23:37 +00:00
|
|
|
|
|
2016-12-28 09:20:42 +00:00
|
|
|
|
if (x > cur_max)
|
|
|
|
|
cur_max = x;
|
2013-09-06 20:28:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
min = typename NearestFieldType<T>::Type(cur_min);
|
|
|
|
|
max = typename NearestFieldType<T>::Type(cur_max);
|
|
|
|
|
}
|
2016-08-10 19:12:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Более эффективные методы манипуляции */
|
|
|
|
|
Container_t & getData()
|
|
|
|
|
{
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Container_t & getData() const
|
|
|
|
|
{
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Container_t data;
|
2013-02-08 23:41:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2010-03-12 18:25:35 +00:00
|
|
|
|
}
|