Skip to content

Commit

Permalink
Rework cudf::io::text::byte_range_info class member functions (#16518)
Browse files Browse the repository at this point in the history
Adds `const` declarations to appropriate member functions in class `cudf::io::text::byte_range_info` and moves the ctor implementation to .cpp file.
This helps with using the `byte_range_info` objects in `const` variables and inside of `const` functions.

Found while working on #15983

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Muhammad Haseeb (https://github.com/mhaseeb123)
  - Bradley Dice (https://github.com/bdice)

URL: #16518
  • Loading branch information
davidwendt authored Aug 13, 2024
1 parent e5f8dd3 commit 7178bf2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
21 changes: 8 additions & 13 deletions cpp/include/cudf/io/text/byte_range_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#pragma once

#include <cudf/utilities/error.hpp>
#include <cudf/utilities/export.hpp>

#include <cstdint>
Expand All @@ -40,53 +39,49 @@ class byte_range_info {
int64_t _size{}; ///< size in bytes

public:
constexpr byte_range_info() = default;
byte_range_info() = default;
/**
* @brief Constructs a byte_range_info object
*
* @param offset offset in bytes
* @param size size in bytes
*/
constexpr byte_range_info(int64_t offset, int64_t size) : _offset(offset), _size(size)
{
CUDF_EXPECTS(offset >= 0, "offset must be non-negative");
CUDF_EXPECTS(size >= 0, "size must be non-negative");
}
byte_range_info(int64_t offset, int64_t size);

/**
* @brief Copy constructor
*
* @param other byte_range_info object to copy
*/
constexpr byte_range_info(byte_range_info const& other) noexcept = default;
byte_range_info(byte_range_info const& other) noexcept = default;
/**
* @brief Copy assignment operator
*
* @param other byte_range_info object to copy
* @return this object after copying
*/
constexpr byte_range_info& operator=(byte_range_info const& other) noexcept = default;
byte_range_info& operator=(byte_range_info const& other) noexcept = default;

/**
* @brief Get the offset in bytes
*
* @return Offset in bytes
*/
[[nodiscard]] constexpr int64_t offset() { return _offset; }
[[nodiscard]] int64_t offset() const { return _offset; }

/**
* @brief Get the size in bytes
*
* @return Size in bytes
*/
[[nodiscard]] constexpr int64_t size() { return _size; }
[[nodiscard]] int64_t size() const { return _size; }

/**
* @brief Returns whether the span is empty.
*
* @return true iff the span is empty, i.e. `size() == 0`
* @return true iff the range is empty, i.e. `size() == 0`
*/
[[nodiscard]] constexpr bool empty() { return size() == 0; }
[[nodiscard]] bool is_empty() const { return size() == 0; }
};

/**
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/io/text/byte_range_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@

#include <cudf/detail/utilities/integer_utils.hpp>
#include <cudf/io/text/byte_range_info.hpp>
#include <cudf/utilities/error.hpp>

#include <limits>

namespace cudf {
namespace io {
namespace text {

byte_range_info::byte_range_info(int64_t offset, int64_t size) : _offset(offset), _size(size)
{
CUDF_EXPECTS(offset >= 0, "offset must be non-negative");
CUDF_EXPECTS(size >= 0, "size must be non-negative");
}

byte_range_info create_byte_range_info_max() { return {0, std::numeric_limits<int64_t>::max()}; }

std::vector<byte_range_info> create_byte_range_infos_consecutive(int64_t total_bytes,
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/io/text/multibyte_split.cu
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ std::unique_ptr<cudf::column> multibyte_split(cudf::io::text::data_chunk_source
{
CUDF_FUNC_RANGE();

if (byte_range.empty()) { return make_empty_column(type_id::STRING); }
if (byte_range.is_empty()) { return make_empty_column(type_id::STRING); }

auto device_delim = cudf::string_scalar(delimiter, true, stream, mr);

Expand Down

0 comments on commit 7178bf2

Please sign in to comment.