numeric.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include "column.h"
  3. namespace NClickHouse {
  4. /**
  5. * Represents various numeric columns.
  6. */
  7. template <typename T>
  8. class TColumnVector: public TColumn {
  9. public:
  10. static TIntrusivePtr<TColumnVector<T>> Create();
  11. static TIntrusivePtr<TColumnVector<T>> Create(const TVector<T>& data);
  12. static TIntrusivePtr<TColumnVector<T>> Create(TVector<T>&& data);
  13. /// Appends one element to the end of column.
  14. void Append(const T& value);
  15. /// Returns element at given row number.
  16. const T& At(size_t n) const;
  17. /// Returns element at given row number.
  18. const T& operator[](size_t n) const;
  19. /// Set element at given row number.
  20. void SetAt(size_t n, const T& value);
  21. public:
  22. /// Appends content of given column to the end of current one.
  23. void Append(TColumnRef column) override;
  24. /// Loads column data from input stream.
  25. bool Load(TCodedInputStream* input, size_t rows) override;
  26. /// Saves column data to output stream.
  27. void Save(TCodedOutputStream* output) override;
  28. /// Returns count of rows in the column.
  29. size_t Size() const override;
  30. /// Makes slice of the current column.
  31. TColumnRef Slice(size_t begin, size_t len) override;
  32. private:
  33. TColumnVector();
  34. TColumnVector(const TVector<T>& data);
  35. TColumnVector(TVector<T>&& data);
  36. TVector<T> Data_;
  37. };
  38. using TColumnUInt8 = TColumnVector<ui8>;
  39. using TColumnUInt16 = TColumnVector<ui16>;
  40. using TColumnUInt32 = TColumnVector<ui32>;
  41. using TColumnUInt64 = TColumnVector<ui64>;
  42. using TColumnInt8 = TColumnVector<i8>;
  43. using TColumnInt16 = TColumnVector<i16>;
  44. using TColumnInt32 = TColumnVector<i32>;
  45. using TColumnInt64 = TColumnVector<i64>;
  46. using TColumnFloat32 = TColumnVector<float>;
  47. using TColumnFloat64 = TColumnVector<double>;
  48. }