Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Split util.h to bit_util.h and time_util.h #1171

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[C++] Split util.h to bit_util.h and time_util.h
  • Loading branch information
PragmaTwice committed Nov 29, 2023
commit 2af45c60495e2c5a21c3e2dc895b32ac27084865
18 changes: 9 additions & 9 deletions src/fury/row/row.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include "arrow/api.h"
#include "arrow/status.h"
#include "fury/row/type.h"
#include "fury/util/bit_util.h"
#include "fury/util/buffer.h"
#include "fury/util/status.h"
#include "fury/util/util.h"

namespace fury {

Expand Down Expand Up @@ -165,8 +165,8 @@ class Row : public Getter, Setter {
int num_fields() const { return num_fields_; }

bool IsNullAt(int i) const override {
return BitUtil::GetBit(buffer_->data() + base_offset_,
static_cast<uint32_t>(i));
return util::GetBit(buffer_->data() + base_offset_,
static_cast<uint32_t>(i));
}

int GetOffset(int i) const override {
Expand All @@ -189,11 +189,11 @@ class Row : public Getter, Setter {
}

void SetNullAt(int i) override {
BitUtil::SetBit(buffer()->data() + base_offset_, i);
util::SetBit(buffer()->data() + base_offset_, i);
}

void SetNotNullAt(int i) override {
BitUtil::ClearBit(buffer()->data() + base_offset_, i);
util::ClearBit(buffer()->data() + base_offset_, i);
}

std::string ToString() const override;
Expand Down Expand Up @@ -237,8 +237,8 @@ class ArrayData : public Getter, Setter {
int num_elements() const { return num_elements_; }

bool IsNullAt(int i) const override {
return BitUtil::GetBit(buffer_->data() + base_offset_ + 8,
static_cast<uint32_t>(i));
return util::GetBit(buffer_->data() + base_offset_ + 8,
static_cast<uint32_t>(i));
}

int GetOffset(int i) const override {
Expand All @@ -261,13 +261,13 @@ class ArrayData : public Getter, Setter {
}

void SetNullAt(int i) override {
BitUtil::SetBit(buffer_->data() + base_offset_ + 8, i);
util::SetBit(buffer_->data() + base_offset_ + 8, i);
// we assume the corresponding column was already 0
// or will be set to 0 later by the caller side
}

void SetNotNullAt(int i) override {
BitUtil::ClearBit(buffer_->data() + base_offset_ + 8, i);
util::ClearBit(buffer_->data() + base_offset_ + 8, i);
}

std::string ToString() const override;
Expand Down
9 changes: 4 additions & 5 deletions src/fury/row/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ void Writer::ZeroOutPaddingBytes(uint32_t num_bytes) {
}

bool Writer::IsNullAt(int i) const {
return BitUtil::GetBit(buffer_->data() + starting_offset_ +
bytes_before_bitmap_,
static_cast<uint32_t>(i));
return util::GetBit(buffer_->data() + starting_offset_ + bytes_before_bitmap_,
static_cast<uint32_t>(i));
}

void Writer::WriteString(int i, std::string_view value) {
Expand All @@ -59,7 +58,7 @@ void Writer::WriteBytes(int i, const uint8_t *input, uint32_t length) {

void Writer::WriteUnaligned(int i, const uint8_t *input, uint32_t offset,
uint32_t num_bytes) {
int round_size = BitUtil::RoundNumberOfBytesToNearestWord(num_bytes);
int round_size = util::RoundNumberOfBytesToNearestWord(num_bytes);
buffer_->Grow(round_size);
ZeroOutPaddingBytes(num_bytes);
buffer_->UnsafePut(cursor(), input + offset, num_bytes);
Expand Down Expand Up @@ -206,7 +205,7 @@ void ArrayWriter::Reset(uint32_t num_elements) {
uint64_t data_size = num_elements_ * (uint64_t)element_size_;
FURY_CHECK(data_size < std::numeric_limits<int>::max());
int fixed_part_bytes =
BitUtil::RoundNumberOfBytesToNearestWord(static_cast<int>(data_size));
util::RoundNumberOfBytesToNearestWord(static_cast<int>(data_size));
assert((fixed_part_bytes >= data_size) && "too much elements");
buffer_->Grow(header_in_bytes_ + fixed_part_bytes);

Expand Down
9 changes: 4 additions & 5 deletions src/fury/row/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <vector>

#include "fury/row/row.h"
#include "fury/util/bit_util.h"
#include "fury/util/buffer.h"
#include "fury/util/logging.h"
#include "fury/util/util.h"

namespace fury {

Expand Down Expand Up @@ -59,13 +59,12 @@ class Writer {
void ZeroOutPaddingBytes(uint32_t num_bytes);

void SetNullAt(int i) {
BitUtil::SetBit(buffer_->data() + starting_offset_ + bytes_before_bitmap_,
i);
util::SetBit(buffer_->data() + starting_offset_ + bytes_before_bitmap_, i);
}

void SetNotNullAt(int i) {
BitUtil::ClearBit(buffer_->data() + starting_offset_ + bytes_before_bitmap_,
i);
util::ClearBit(buffer_->data() + starting_offset_ + bytes_before_bitmap_,
i);
}

bool IsNullAt(int i) const;
Expand Down
8 changes: 4 additions & 4 deletions src/fury/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ load("//bazel:fury.bzl", "COPTS")

cc_library(
name = "fury_util",
srcs = ["status.cc", "buffer.cc", "logging.cc", "util.cc"],
hdrs = ["status.h", "buffer.h", "logging.h", "util.h"],
srcs = glob(["*.cc"], exclude=["*test.cc"]),
hdrs = glob(["*.h"]),
strip_include_prefix = "/src",
copts = COPTS,
alwayslink=True,
Expand All @@ -21,8 +21,8 @@ cc_library(


cc_test(
name = "util_test",
srcs = ["util_test.cc"],
name = "time_util_test",
srcs = ["time_util_test.cc"],
copts = COPTS,
deps = [
":fury_util",
Expand Down
5 changes: 2 additions & 3 deletions src/fury/util/util.h → src/fury/util/bit_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

namespace fury {

namespace BitUtil {
namespace util {

//
// Byte-swap 16-bit, 32-bit and 64-bit values. based on arrow/util/bit-util.h
Expand Down Expand Up @@ -218,8 +218,7 @@ static inline std::string hex(uint8_t *data, int32_t length) {
}
return result;
}
} // namespace BitUtil

std::string FormatTimePoint(std::chrono::system_clock::time_point tp);
} // namespace util

} // namespace fury
2 changes: 1 addition & 1 deletion src/fury/util/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ std::string Buffer::ToString() const {
}

std::string Buffer::Hex() const {
return BitUtil::hex(data(), static_cast<int32_t>(size_));
return util::hex(data(), static_cast<int32_t>(size_));
}

bool AllocateBuffer(uint32_t size, std::shared_ptr<Buffer> *out) {
Expand Down
4 changes: 2 additions & 2 deletions src/fury/util/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <memory>
#include <string>

#include "fury/util/bit_util.h"
#include "fury/util/logging.h"
#include "fury/util/util.h"

namespace fury {

Expand Down Expand Up @@ -201,7 +201,7 @@ class Buffer {
// see
// https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md
// for discussion.
auto new_size = BitUtil::RoundNumberOfBytesToNearestWord(len * 2);
auto new_size = util::RoundNumberOfBytesToNearestWord(len * 2);
Reserve(new_size);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fury/util/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/stacktrace.h"
#include "absl/debugging/symbolize.h"
#include "fury/util/util.h"
#include "fury/util/time_util.h"
#include <unordered_map>
#include <vector>

Expand Down
2 changes: 2 additions & 0 deletions src/fury/util/util.cc → src/fury/util/time_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "fury/util/time_util.h"
#include <chrono>
#include <ctime>
#include <iomanip>
Expand All @@ -23,6 +24,7 @@
namespace fury {

using std::chrono::system_clock;

std::string FormatTimePoint(system_clock::time_point tp) {
std::stringstream ss;
time_t raw_time = system_clock::to_time_t(tp);
Expand Down
10 changes: 10 additions & 0 deletions src/fury/util/time_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <chrono>
#include <string>

namespace fury {

std::string FormatTimePoint(std::chrono::system_clock::time_point tp);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "fury/util/util.h"
#include "fury/util/time_util.h"
#include "gtest/gtest.h"

namespace fury {
Expand Down
Loading