Skip to content

Commit

Permalink
Remove gcc warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET committed Jan 10, 2025
1 parent 799d8fa commit 1ad6b0a
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 140 deletions.
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;

/**
* 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;
SPARROW_API [[nodiscard]] arrow_proxy& get_arrow_proxy();
SPARROW_API [[nodiscard]] 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 @@ -75,8 +75,8 @@ namespace sparrow
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
146 changes: 146 additions & 0 deletions src/layout/run_end_encoded_array.cpp
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;
}

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

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

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;
}

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;
}

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);
}

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);
}
}

0 comments on commit 1ad6b0a

Please sign in to comment.