Skip to content

Commit

Permalink
Add Vector<T>::raw_size(). (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Nov 25, 2014
1 parent 8ea0f8d commit b0419d1
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 47 deletions.
20 changes: 13 additions & 7 deletions include/grnxx/data_types/vector/bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Vector<Bool> {
explicit constexpr Vector(NA) : data_(nullptr), size_(NA()) {}

Bool operator[](Int i) const {
if (is_na() || (static_cast<uint64_t>(i.raw()) >=
static_cast<uint64_t>(size_.raw()))) {
if (is_na() || (static_cast<size_t>(i.raw()) >= raw_size())) {
return Bool::na();
}
return data_[i.raw()];
Expand All @@ -38,9 +37,12 @@ class Vector<Bool> {
constexpr Int size() const {
return size_;
}
constexpr size_t raw_size() const {
return size_.raw();
}

constexpr bool is_empty() const {
return size_.raw() == 0;
return raw_size() == 0;
}
constexpr bool is_na() const {
return size_.is_na();
Expand All @@ -50,15 +52,15 @@ class Vector<Bool> {
Bool operator==(const Vector &rhs) const {
Bool has_equal_size = (size_ == rhs.size_);
if (has_equal_size.is_true()) {
return Bool(std::memcmp(data_, rhs.data_, size_.raw()) == 0);
return Bool(std::memcmp(data_, rhs.data_, raw_size()) == 0);
}
return has_equal_size;
}
// TODO: The behavior of N/A in vector is not fixed yet (#107).
Bool operator!=(const Vector &rhs) const {
Bool has_not_equal_size = (size_ != rhs.size_);
if (has_not_equal_size.is_false()) {
return Bool(std::memcmp(data_, rhs.data_, size_.raw()) != 0);
return Bool(std::memcmp(data_, rhs.data_, raw_size()) != 0);
}
return has_not_equal_size;
}
Expand All @@ -70,7 +72,7 @@ class Vector<Bool> {
if (is_na()) {
return true;
}
return std::memcmp(data_, rhs.data_, size_.raw()) == 0;
return std::memcmp(data_, rhs.data_, raw_size()) == 0;
}
bool unmatch(const Vector &rhs) const {
if (size_.unmatch(rhs.size_)) {
Expand All @@ -79,7 +81,7 @@ class Vector<Bool> {
if (is_na()) {
return false;
}
return std::memcmp(data_, rhs.data_, size_.raw()) != 0;
return std::memcmp(data_, rhs.data_, raw_size()) != 0;
}

static constexpr DataType type() {
Expand All @@ -93,6 +95,10 @@ class Vector<Bool> {
return Vector(NA());
}

static constexpr size_t raw_na_size() {
return Int::na().raw();
}

private:
const Bool *data_;
Int size_;
Expand Down
20 changes: 13 additions & 7 deletions include/grnxx/data_types/vector/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Vector<Float> {
explicit constexpr Vector(NA) : data_(nullptr), size_(NA()) {}

Float operator[](Int i) const {
if (is_na() || (static_cast<uint64_t>(i.raw()) >=
static_cast<uint64_t>(size_.raw()))) {
if (is_na() || (static_cast<size_t>(i.raw()) >= raw_size())) {
return Float::na();
}
return data_[i.raw()];
Expand All @@ -40,9 +39,12 @@ class Vector<Float> {
constexpr Int size() const {
return size_;
}
constexpr size_t raw_size() const {
return size_.raw();
}

constexpr bool is_empty() const {
return size_.raw() == 0;
return raw_size() == 0;
}
constexpr bool is_na() const {
return size_.is_na();
Expand All @@ -52,7 +54,7 @@ class Vector<Float> {
Bool operator==(const Vector &rhs) const {
Bool has_equal_size = (size_ == rhs.size_);
if (has_equal_size.is_true()) {
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
if ((data_[i].raw() != rhs.data_[i].raw()) &&
(!data_[i].is_na() || !rhs.data_[i].is_na())) {
Expand All @@ -66,7 +68,7 @@ class Vector<Float> {
Bool operator!=(const Vector &rhs) const {
Bool has_not_equal_size = (size_ != rhs.size_);
if (has_not_equal_size.is_false()) {
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
if ((data_[i].raw() != rhs.data_[i].raw()) &&
(!data_[i].is_na() || !rhs.data_[i].is_na())) {
Expand All @@ -85,7 +87,7 @@ class Vector<Float> {
return true;
}
// TODO: This is because raw values are not normalized.
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
if (data_[i].unmatch(rhs.data_[i])) {
return false;
Expand All @@ -101,7 +103,7 @@ class Vector<Float> {
return false;
}
// TODO: This is because raw values are not normalized.
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
if (data_[i].unmatch(rhs.data_[i])) {
return true;
Expand All @@ -121,6 +123,10 @@ class Vector<Float> {
return Vector(NA());
}

static constexpr size_t raw_na_size() {
return Int::na().raw();
}

private:
const Float *data_;
Int size_;
Expand Down
22 changes: 13 additions & 9 deletions include/grnxx/data_types/vector/geo_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Vector<GeoPoint> {
explicit constexpr Vector(NA) : data_(nullptr), size_(NA()) {}

GeoPoint operator[](Int i) const {
if (is_na() || (static_cast<uint64_t>(i.raw()) >=
static_cast<uint64_t>(size_.raw()))) {
if (is_na() || (static_cast<size_t>(i.raw()) >= raw_size())) {
return GeoPoint::na();
}
return data_[i.raw()];
Expand All @@ -40,9 +39,12 @@ class Vector<GeoPoint> {
constexpr Int size() const {
return size_;
}
constexpr size_t raw_size() const {
return size_.raw();
}

constexpr bool is_empty() const {
return size_.raw() == 0;
return raw_size() == 0;
}
constexpr bool is_na() const {
return size_.is_na();
Expand All @@ -53,7 +55,7 @@ class Vector<GeoPoint> {
Bool has_equal_size = (size_ == rhs.size_);
if (has_equal_size.is_true()) {
return Bool(std::memcmp(data_, rhs.data_,
sizeof(GeoPoint) * size_.raw()) == 0);
sizeof(GeoPoint) * raw_size()) == 0);
}
return has_equal_size;
}
Expand All @@ -62,7 +64,7 @@ class Vector<GeoPoint> {
Bool has_not_equal_size = (size_ != rhs.size_);
if (has_not_equal_size.is_false()) {
return Bool(std::memcmp(data_, rhs.data_,
sizeof(GeoPoint) * size_.raw()) != 0);
sizeof(GeoPoint) * raw_size()) != 0);
}
return has_not_equal_size;
}
Expand All @@ -74,8 +76,7 @@ class Vector<GeoPoint> {
if (is_na()) {
return true;
}
return std::memcmp(data_, rhs.data_,
sizeof(GeoPoint) * size_.raw()) == 0;
return std::memcmp(data_, rhs.data_, sizeof(GeoPoint) * raw_size()) == 0;
}
bool unmatch(const Vector &rhs) const {
if (size_.unmatch(rhs.size_)) {
Expand All @@ -84,8 +85,7 @@ class Vector<GeoPoint> {
if (is_na()) {
return false;
}
return std::memcmp(data_, rhs.data_,
sizeof(GeoPoint) * size_.raw()) != 0;
return std::memcmp(data_, rhs.data_, sizeof(GeoPoint) * raw_size()) != 0;
}

static constexpr DataType type() {
Expand All @@ -99,6 +99,10 @@ class Vector<GeoPoint> {
return Vector(NA());
}

static constexpr size_t raw_na_size() {
return Int::na().raw();
}

private:
const GeoPoint *data_;
Int size_;
Expand Down
20 changes: 13 additions & 7 deletions include/grnxx/data_types/vector/int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Vector<Int> {
explicit constexpr Vector(NA) : data_(nullptr), size_(NA()) {}

Int operator[](Int i) const {
if (is_na() || (static_cast<uint64_t>(i.raw()) >=
static_cast<uint64_t>(size_.raw()))) {
if (is_na() || (static_cast<size_t>(i.raw()) >= raw_size())) {
return Int::na();
}
return data_[i.raw()];
Expand All @@ -38,9 +37,12 @@ class Vector<Int> {
constexpr Int size() const {
return size_;
}
constexpr size_t raw_size() const {
return size_.raw();
}

constexpr bool is_empty() const {
return size_.raw() == 0;
return raw_size() == 0;
}
constexpr bool is_na() const {
return size_.is_na();
Expand All @@ -51,7 +53,7 @@ class Vector<Int> {
Bool has_equal_size = (size_ == rhs.size_);
if (has_equal_size.is_true()) {
return Bool(std::memcmp(data_, rhs.data_,
sizeof(Int) * size_.raw()) == 0);
sizeof(Int) * raw_size()) == 0);
}
return has_equal_size;
}
Expand All @@ -60,7 +62,7 @@ class Vector<Int> {
Bool has_not_equal_size = (size_ != rhs.size_);
if (has_not_equal_size.is_false()) {
return Bool(std::memcmp(data_, rhs.data_,
sizeof(Int) * size_.raw()) != 0);
sizeof(Int) * raw_size()) != 0);
}
return has_not_equal_size;
}
Expand All @@ -72,7 +74,7 @@ class Vector<Int> {
if (is_na()) {
return true;
}
return std::memcmp(data_, rhs.data_, sizeof(Int) * size_.raw()) == 0;
return std::memcmp(data_, rhs.data_, sizeof(Int) * raw_size()) == 0;
}
bool unmatch(const Vector &rhs) const {
if (size_.unmatch(rhs.size_)) {
Expand All @@ -81,7 +83,7 @@ class Vector<Int> {
if (is_na()) {
return false;
}
return std::memcmp(data_, rhs.data_, sizeof(Int) * size_.raw()) != 0;
return std::memcmp(data_, rhs.data_, sizeof(Int) * raw_size()) != 0;
}

static constexpr DataType type() {
Expand All @@ -95,6 +97,10 @@ class Vector<Int> {
return Vector(NA());
}

static constexpr size_t raw_na_size() {
return Int::na().raw();
}

private:
const Int *data_;
Int size_;
Expand Down
20 changes: 13 additions & 7 deletions include/grnxx/data_types/vector/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class Vector<Text> {
data_(nullptr) {}

Text operator[](Int i) const {
if (is_na() || (static_cast<uint64_t>(i.raw()) >=
static_cast<uint64_t>(size_.raw()))) {
if (is_na() || (static_cast<size_t>(i.raw()) >= raw_size())) {
return Text::na();
}
if (is_direct_) {
Expand All @@ -51,9 +50,12 @@ class Vector<Text> {
constexpr Int size() const {
return size_;
}
constexpr size_t raw_size() const {
return size_.raw();
}

constexpr bool is_empty() const {
return size_.raw() == 0;
return raw_size() == 0;
}
constexpr bool is_na() const {
return size_.is_na();
Expand All @@ -63,7 +65,7 @@ class Vector<Text> {
Bool operator==(const Vector &rhs) const {
Bool has_equal_size = (size_ == rhs.size_);
if (has_equal_size.is_true()) {
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
Text lhs_text = (*this)[grnxx::Int(i)];
Text rhs_text = rhs[grnxx::Int(i)];
Expand All @@ -80,7 +82,7 @@ class Vector<Text> {
Bool operator!=(const Vector &rhs) const {
Bool has_not_equal_size = (size_ != rhs.size_);
if (has_not_equal_size.is_false()) {
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
Text lhs_text = (*this)[grnxx::Int(i)];
Text rhs_text = rhs[grnxx::Int(i)];
Expand All @@ -102,7 +104,7 @@ class Vector<Text> {
return true;
}
// TODO: This is because raw values are not normalized.
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
// TODO: This can be improved.
if (operator[](grnxx::Int(i)).unmatch(rhs[grnxx::Int(i)])) {
Expand All @@ -119,7 +121,7 @@ class Vector<Text> {
return false;
}
// TODO: This is because raw values are not normalized.
size_t size = size_.raw();
size_t size = raw_size();
for (size_t i = 0; i < size; ++i) {
// TODO: This can be improved.
if (operator[](grnxx::Int(i)).unmatch(rhs[grnxx::Int(i)])) {
Expand All @@ -140,6 +142,10 @@ class Vector<Text> {
return Vector(NA());
}

static constexpr size_t raw_na_size() {
return Int::na().raw();
}

private:
struct Header {
size_t offset;
Expand Down
2 changes: 1 addition & 1 deletion lib/grnxx/impl/column/vector/bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void Column<Vector<Bool>>::set(Int row_id, const Datum &datum) {
// }
// TODO: Error handling.
size_t offset = bodies_.size();
size_t size = new_value.size().raw();
size_t size = new_value.raw_size();
uint64_t header;
if (size < 0xFFFF) {
bodies_.resize(offset + size);
Expand Down
2 changes: 1 addition & 1 deletion lib/grnxx/impl/column/vector/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void Column<Vector<Float>>::set(Int row_id, const Datum &datum) {
// }
// TODO: Error handling.
size_t offset = bodies_.size();
size_t size = new_value.size().raw();
size_t size = new_value.raw_size();
uint64_t header;
if (size < 0xFFFF) {
bodies_.resize(offset + size);
Expand Down
2 changes: 1 addition & 1 deletion lib/grnxx/impl/column/vector/geo_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void Column<Vector<GeoPoint>>::set(Int row_id, const Datum &datum) {
// }
// TODO: Error handling.
size_t offset = bodies_.size();
size_t size = new_value.size().raw();
size_t size = new_value.raw_size();
uint64_t header;
if (size < 0xFFFF) {
bodies_.resize(offset + size);
Expand Down
Loading

0 comments on commit b0419d1

Please sign in to comment.