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

Remove gcc warning #321

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ else()
${SPARROW_SOURCE_DIR}/arrow_array_schema_proxy.cpp
${SPARROW_SOURCE_DIR}/arrow_interface/arrow_array.cpp
${SPARROW_SOURCE_DIR}/arrow_interface/arrow_schema.cpp
${SPARROW_SOURCE_DIR}/layout/run_end_encoded_array.cpp
${SPARROW_SOURCE_DIR}/list_value.cpp
${SPARROW_SOURCE_DIR}/record_batch.cpp
${SPARROW_SOURCE_DIR}/run_encoded_array.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/sparrow/array_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace sparrow
/**
* Constructs an empty array.
*/
SPARROW_API array() = default;
array() = default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?Are default members considered as inline on Windows?


/**
* Constructs an \ref array from the given typed layout. The ownership
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#pragma once

#include "sparrow/array_api.hpp"
#include "sparrow/array_factory.hpp"
#include "sparrow/config/config.hpp"
#include "sparrow/layout/array_access.hpp"
#include "sparrow/layout/array_wrapper.hpp"
Expand Down Expand Up @@ -69,8 +68,8 @@ namespace sparrow
SPARROW_API run_end_encoded_array(const self_type&);
SPARROW_API self_type& operator=(const self_type&);

SPARROW_API run_end_encoded_array(self_type&&) = default;
SPARROW_API self_type& operator=(self_type&&) = default;
run_end_encoded_array(self_type&&) = default;
self_type& operator=(self_type&&) = default;

SPARROW_API array_traits::const_reference operator[](std::uint64_t i);
SPARROW_API array_traits::const_reference operator[](std::uint64_t i) const;
Expand Down Expand Up @@ -109,8 +108,8 @@ namespace sparrow
SPARROW_API static acc_length_ptr_variant_type get_acc_lengths_ptr(const array_wrapper& ar);
SPARROW_API std::uint64_t get_run_length(std::uint64_t run_index) const;

[[nodiscard]] arrow_proxy& get_arrow_proxy();
[[nodiscard]] const arrow_proxy& get_arrow_proxy() const;
[[nodiscard]] SPARROW_API arrow_proxy& get_arrow_proxy();
[[nodiscard]] SPARROW_API const arrow_proxy& get_arrow_proxy() const;

arrow_proxy m_proxy;
std::uint64_t m_encoded_length;
Expand All @@ -127,138 +126,6 @@ namespace sparrow

SPARROW_API
bool operator==(const run_end_encoded_array& lhs, const run_end_encoded_array& rhs);

/****************************************
* run_end_encoded_array implementation *
****************************************/

inline run_end_encoded_array::run_end_encoded_array(arrow_proxy proxy)
: m_proxy(std::move(proxy))
, m_encoded_length(m_proxy.children()[0].length())
, p_acc_lengths_array(array_factory(m_proxy.children()[0].view()))
, p_encoded_values_array(array_factory(m_proxy.children()[1].view()))
, m_acc_lengths(run_end_encoded_array::get_acc_lengths_ptr(*p_acc_lengths_array))
{
}

inline run_end_encoded_array::run_end_encoded_array(const self_type& rhs)
: run_end_encoded_array(rhs.m_proxy)
{
}

inline auto run_end_encoded_array::operator=(const self_type& rhs) -> self_type&
{
if (this != &rhs)
{
m_proxy = rhs.m_proxy;
m_encoded_length = rhs.m_encoded_length;
p_acc_lengths_array = array_factory(m_proxy.children()[0].view());
p_encoded_values_array = array_factory(m_proxy.children()[1].view());
m_acc_lengths = run_end_encoded_array::get_acc_lengths_ptr(*p_acc_lengths_array);
}
return *this;
}

inline auto run_end_encoded_array::size() const -> size_type
{
return m_proxy.length();
}

inline auto run_end_encoded_array::empty() const -> bool
{
return size() == 0;
}

inline std::optional<std::string_view> run_end_encoded_array::name() const
{
return m_proxy.name();
}

inline std::optional<std::string_view> run_end_encoded_array::metadata() const
{
return m_proxy.metadata();
}

inline auto run_end_encoded_array::get_run_length(std::uint64_t run_index) const -> std::uint64_t
{
auto ret = std::visit(
[run_index](auto&& acc_lengths_ptr) -> std::uint64_t
{
if (run_index == 0)
{
return static_cast<std::uint64_t>(acc_lengths_ptr[run_index]);
}
else
{
return static_cast<std::uint64_t>(
acc_lengths_ptr[run_index] - acc_lengths_ptr[run_index - 1]
);
}
},
m_acc_lengths
);
return ret;
}

inline arrow_proxy& run_end_encoded_array::get_arrow_proxy()
{
return m_proxy;
}

inline const arrow_proxy& run_end_encoded_array::get_arrow_proxy() const
{
return m_proxy;
}

inline auto run_end_encoded_array::operator[](std::uint64_t i) -> array_traits::const_reference
{
return static_cast<const run_end_encoded_array*>(this)->operator[](i);
}

inline auto run_end_encoded_array::begin() -> iterator
{
return iterator(this, 0, 0);
}

inline auto run_end_encoded_array::end() -> iterator
{
return iterator(this, size(), 0);
}

inline auto run_end_encoded_array::begin() const -> const_iterator
{
return this->cbegin();
}

inline auto run_end_encoded_array::end() const -> const_iterator
{
return this->cend();
}

inline auto run_end_encoded_array::cbegin() const -> const_iterator
{
return const_iterator(this, 0, 0);
}

inline auto run_end_encoded_array::cend() const -> const_iterator
{
return const_iterator(this, size(), 0);
}

inline auto run_end_encoded_array::front() const -> array_traits::const_reference
{
return operator[](0);
}

inline auto run_end_encoded_array::back() const -> array_traits::const_reference
{
return operator[](size() - 1);
}

inline bool operator==(const run_end_encoded_array& lhs, const run_end_encoded_array& rhs)
{
return std::ranges::equal(lhs, rhs);
}
} // namespace sparrow

#if defined(__cpp_lib_format)
Expand Down
4 changes: 2 additions & 2 deletions include/sparrow/record_batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* @snippet{trimleft} examples/record_batch_example.cpp use_record_batch
*/
class record_batch

Check warning on line 45 in include/sparrow/record_batch.hpp

View workflow job for this annotation

GitHub Actions / build

include/sparrow/record_batch.hpp:45:11 [cppcoreguidelines-special-member-functions]

class 'record_batch' defines a copy constructor, a copy assignment operator, a move constructor and a move assignment operator but does not define a destructor
{
public:

Expand Down Expand Up @@ -75,8 +75,8 @@
SPARROW_API record_batch(const record_batch&);
SPARROW_API record_batch& operator=(const record_batch&);

SPARROW_API record_batch(record_batch&&) = default;
SPARROW_API record_batch& operator=(record_batch&&) = default;
record_batch(record_batch&&) = default;
record_batch& operator=(record_batch&&) = default;

/**
* @returns the number of columns (i.e. arrays) in the \ref record_batch.
Expand Down Expand Up @@ -161,7 +161,7 @@
template <std::ranges::input_range NR, std::ranges::input_range CR>
requires(std::convertible_to<std::ranges::range_value_t<NR>, std::string>
and std::same_as<std::ranges::range_value_t<CR>, array>)
record_batch::record_batch(NR&& names, CR&& columns)

Check warning on line 164 in include/sparrow/record_batch.hpp

View workflow job for this annotation

GitHub Actions / build

include/sparrow/record_batch.hpp:164:37 [cppcoreguidelines-missing-std-forward]

forwarding reference parameter 'names' is never forwarded inside the function body

Check warning on line 164 in include/sparrow/record_batch.hpp

View workflow job for this annotation

GitHub Actions / build

include/sparrow/record_batch.hpp:164:49 [cppcoreguidelines-missing-std-forward]

forwarding reference parameter 'columns' is never forwarded inside the function body
: m_name_list(to_vector<name_type>(std::move(names)))
, m_array_list(to_vector<array>(std::move(columns)))
{
Expand Down
146 changes: 146 additions & 0 deletions src/layout/run_end_encoded_array.cpp
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the implementation code to a cpp file. This can be discussed. For performance reason, inlining could be preferable.

Copy link
Collaborator

@JohanMabille JohanMabille Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why that change? I don't have any strong opinion about it, but if we keep a cpp file, then the existing src/run_encoded_layout.cpp should be merged with it.

Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright 2024 Man Group Operations Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sparrow/layout/run_end_encoded_layout/run_end_encoded_array.hpp"

namespace sparrow
{
run_end_encoded_array::run_end_encoded_array(arrow_proxy proxy)
: m_proxy(std::move(proxy))
, m_encoded_length(m_proxy.children()[0].length())
, p_acc_lengths_array(array_factory(m_proxy.children()[0].view()))
, p_encoded_values_array(array_factory(m_proxy.children()[1].view()))
, m_acc_lengths(run_end_encoded_array::get_acc_lengths_ptr(*p_acc_lengths_array))
{
}

run_end_encoded_array::run_end_encoded_array(const self_type& rhs)
: run_end_encoded_array(rhs.m_proxy)
{
}

auto run_end_encoded_array::operator=(const self_type& rhs) -> self_type&
{
if (this != &rhs)
{
m_proxy = rhs.m_proxy;
m_encoded_length = rhs.m_encoded_length;
p_acc_lengths_array = array_factory(m_proxy.children()[0].view());
p_encoded_values_array = array_factory(m_proxy.children()[1].view());
m_acc_lengths = run_end_encoded_array::get_acc_lengths_ptr(*p_acc_lengths_array);
}
return *this;
}

auto run_end_encoded_array::size() const -> size_type
{
return m_proxy.length();
}

auto run_end_encoded_array::empty() const -> bool
{
return size() == 0;
}

Check warning on line 54 in src/layout/run_end_encoded_array.cpp

View check run for this annotation

Codecov / codecov/patch

src/layout/run_end_encoded_array.cpp#L52-L54

Added lines #L52 - L54 were not covered by tests

std::optional<std::string_view> run_end_encoded_array::name() const
{
return m_proxy.name();
}

Check warning on line 59 in src/layout/run_end_encoded_array.cpp

View check run for this annotation

Codecov / codecov/patch

src/layout/run_end_encoded_array.cpp#L57-L59

Added lines #L57 - L59 were not covered by tests

std::optional<std::string_view> run_end_encoded_array::metadata() const
{
return m_proxy.metadata();
}

Check warning on line 64 in src/layout/run_end_encoded_array.cpp

View check run for this annotation

Codecov / codecov/patch

src/layout/run_end_encoded_array.cpp#L62-L64

Added lines #L62 - L64 were not covered by tests

auto run_end_encoded_array::get_run_length(std::uint64_t run_index) const -> std::uint64_t
{
auto ret = std::visit(
[run_index](auto&& acc_lengths_ptr) -> std::uint64_t
{
if (run_index == 0)
{
return static_cast<std::uint64_t>(acc_lengths_ptr[run_index]);
}

Check warning on line 74 in src/layout/run_end_encoded_array.cpp

View check run for this annotation

Codecov / codecov/patch

src/layout/run_end_encoded_array.cpp#L74

Added line #L74 was not covered by tests
else
{
return static_cast<std::uint64_t>(
acc_lengths_ptr[run_index] - acc_lengths_ptr[run_index - 1]
);
}
},
m_acc_lengths
);
return ret;
}

arrow_proxy& run_end_encoded_array::get_arrow_proxy()
{
return m_proxy;
}

const arrow_proxy& run_end_encoded_array::get_arrow_proxy() const
{
return m_proxy;
}

Check warning on line 95 in src/layout/run_end_encoded_array.cpp

View check run for this annotation

Codecov / codecov/patch

src/layout/run_end_encoded_array.cpp#L93-L95

Added lines #L93 - L95 were not covered by tests

auto run_end_encoded_array::operator[](std::uint64_t i) -> array_traits::const_reference
{
return static_cast<const run_end_encoded_array*>(this)->operator[](i);
}

auto run_end_encoded_array::begin() -> iterator
{
return iterator(this, 0, 0);
}

auto run_end_encoded_array::end() -> iterator
{
return iterator(this, size(), 0);
}

auto run_end_encoded_array::begin() const -> const_iterator
{
return this->cbegin();
}

auto run_end_encoded_array::end() const -> const_iterator
{
return this->cend();
}

auto run_end_encoded_array::cbegin() const -> const_iterator
{
return const_iterator(this, 0, 0);
}

auto run_end_encoded_array::cend() const -> const_iterator
{
return const_iterator(this, size(), 0);
}

auto run_end_encoded_array::front() const -> array_traits::const_reference
{
return operator[](0);
}

Check warning on line 135 in src/layout/run_end_encoded_array.cpp

View check run for this annotation

Codecov / codecov/patch

src/layout/run_end_encoded_array.cpp#L133-L135

Added lines #L133 - L135 were not covered by tests

auto run_end_encoded_array::back() const -> array_traits::const_reference
{
return operator[](size() - 1);
}

bool operator==(const run_end_encoded_array& lhs, const run_end_encoded_array& rhs)
{
return std::ranges::equal(lhs, rhs);
}
}
Loading