#pragma once #include #include namespace DB { /** Функции - логические связки: and, or, not, xor. * Принимают любые числовые типы, возвращают UInt8, содержащий 0 или 1. */ template struct AndImpl { static void vector_vector(const PODArray & a, const PODArray & b, PODArray & c) { size_t size = a.size(); for (size_t i = 0; i < size; ++i) c[i] = a[i] && b[i]; } static void vector_constant(const PODArray & a, B b, PODArray & c) { size_t size = a.size(); for (size_t i = 0; i < size; ++i) c[i] = a[i] && b; } static void constant_vector(A a, const PODArray & b, PODArray & c) { size_t size = b.size(); for (size_t i = 0; i < size; ++i) c[i] = a && b[i]; } static void constant_constant(A a, B b, UInt8 & c) { c = a && b; } }; template struct OrImpl { static void vector_vector(const PODArray & a, const PODArray & b, PODArray & c) { size_t size = a.size(); for (size_t i = 0; i < size; ++i) c[i] = a[i] || b[i]; } static void vector_constant(const PODArray & a, B b, PODArray & c) { size_t size = a.size(); for (size_t i = 0; i < size; ++i) c[i] = a[i] || b; } static void constant_vector(A a, const PODArray & b, PODArray & c) { size_t size = b.size(); for (size_t i = 0; i < size; ++i) c[i] = a || b[i]; } static void constant_constant(A a, B b, UInt8 & c) { c = a || b; } }; template struct XorImpl { static void vector_vector(const PODArray & a, const PODArray & b, PODArray & c) { size_t size = a.size(); for (size_t i = 0; i < size; ++i) c[i] = (a[i] && !b[i]) || (!a[i] && b[i]); } static void vector_constant(const PODArray & a, B b, PODArray & c) { size_t size = a.size(); for (size_t i = 0; i < size; ++i) c[i] = (a[i] && !b) || (!a[i] && b); } static void constant_vector(A a, const PODArray & b, PODArray & c) { size_t size = b.size(); for (size_t i = 0; i < size; ++i) c[i] = (a && !b[i]) || (!a && b[i]); } static void constant_constant(A a, B b, UInt8 & c) { c = (a && !b) || (!a && b); } }; template struct NotImpl { static void vector(const PODArray & a, PODArray & c) { size_t size = a.size(); for (size_t i = 0; i < size; ++i) c[i] = !a[i]; } static void constant(A a, UInt8 & c) { c = !a; } }; template