sparrow 2.5.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
map_value.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <utility>
18
23
24namespace sparrow
25{
26 class map_array;
27
29 {
30 public:
31
36
37 using value_type = std::pair<key_type, mapped_type>;
38 using const_reference = std::pair<const_key_reference, const_mapped_reference>;
39 using size_type = std::size_t;
40
43 using const_reverser_iterator = std::reverse_iterator<const_iterator>;
44
45 map_value() = default;
47 const array_wrapper* flat_keys,
48 const array_wrapper* flat_items,
49 size_type index_begin,
50 size_type index_end,
51 bool keys_sorted
52 );
53
54 [[nodiscard]] bool empty() const noexcept;
55 [[nodiscard]] size_type size() const noexcept;
56
57 [[nodiscard]] const_mapped_reference at(const key_type& key) const;
58 [[nodiscard]] const_mapped_reference operator[](const key_type& key) const;
59
60 [[nodiscard]] bool contains(const key_type& key) const;
61 [[nodiscard]] const_iterator find(const key_type& key) const;
62
63 [[nodiscard]] const_iterator begin() const;
64 [[nodiscard]] const_iterator cbegin() const;
65
66 [[nodiscard]] const_iterator end() const;
67 [[nodiscard]] const_iterator cend() const;
68
69 [[nodiscard]] const_reverser_iterator rbegin() const;
70 [[nodiscard]] const_reverser_iterator crbegin() const;
71
72 [[nodiscard]] const_reverser_iterator rend() const;
73 [[nodiscard]] const_reverser_iterator crend() const;
74
75 private:
76
77 size_type find_index(const key_type& key) const noexcept;
78 const_reference value(size_type i) const;
79
80 const array_wrapper* p_flat_keys = nullptr;
81 const array_wrapper* p_flat_items = nullptr;
82 size_type m_index_begin = 0u;
83 size_type m_index_end = 0u;
84 bool m_keys_sorted = false;
85
86 friend class detail::layout_value_functor<const map_value, const_reference>;
87 friend class map_array;
88 };
89
91 bool operator==(const map_value& lhs, const map_value& rhs);
92}
93
94#if defined(__cpp_lib_format)
95
96template <>
97struct std::formatter<sparrow::map_value>
98{
99 constexpr auto parse(std::format_parse_context& ctx) -> decltype(ctx.begin())
100 {
101 return ctx.begin(); // Simple implementation
102 }
103
104 SPARROW_API auto format(const sparrow::map_value& value, std::format_context& ctx) const
105 -> decltype(ctx.out());
106};
107
108namespace sparrow
109{
110 SPARROW_API std::ostream& operator<<(std::ostream& os, const map_value& value);
111}
112
113#endif
Base class for array type erasure.
friend class map_array
Definition map_value.hpp:87
array_traits::const_reference const_key_reference
Definition map_value.hpp:33
const_iterator cbegin() const
const_iterator end() const
std::pair< key_type, mapped_type > value_type
Definition map_value.hpp:37
const_iterator cend() const
const_reverser_iterator crbegin() const
bool contains(const key_type &key) const
const_reverser_iterator rbegin() const
std::size_t size_type
Definition map_value.hpp:39
array_traits::const_reference const_mapped_reference
Definition map_value.hpp:35
bool empty() const noexcept
const_iterator begin() const
map_value(const array_wrapper *flat_keys, const array_wrapper *flat_items, size_type index_begin, size_type index_end, bool keys_sorted)
size_type size() const noexcept
const_mapped_reference at(const key_type &key) const
std::reverse_iterator< const_iterator > const_reverser_iterator
Definition map_value.hpp:43
std::pair< const_key_reference, const_mapped_reference > const_reference
Definition map_value.hpp:38
functor_index_iterator< functor_type > const_iterator
Definition map_value.hpp:42
const_reverser_iterator rend() const
detail::layout_value_functor< const map_value, const_reference > functor_type
Definition map_value.hpp:41
const_reverser_iterator crend() const
const_iterator find(const key_type &key) const
array_traits::value_type key_type
Definition map_value.hpp:32
array_traits::value_type mapped_type
Definition map_value.hpp:34
#define SPARROW_API
Definition config.hpp:38
std::ostream & operator<<(std::ostream &stream, primesum::uint128_t n)
The __int128_t type (GCC/Clang) is not well supported by the C++ standard library (in 2016) so we hav...
Definition int128_t.hpp:48
mpl::rename< mpl::unique< mpl::transform< detail::array_const_reference_t, all_base_types_t > >, nullable_variant > const_reference
mpl::rename< mpl::transform< detail::array_value_type_t, all_base_types_t >, nullable_variant > value_type