iceberg-cpp
Loading...
Searching...
No Matches
struct_like_set.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <memory>
26#include <memory_resource>
27#include <unordered_set>
28#include <vector>
29
30#include "iceberg/iceberg_export.h"
31#include "iceberg/result.h"
33#include "iceberg/type_fwd.h"
34
35namespace iceberg {
36
47template <bool kValidate = true>
48class ICEBERG_TEMPLATE_CLASS_EXPORT StructLikeSet {
49 public:
50 static constexpr size_t kDefaultArenaInitialSize = 64 * 1024;
51
53 explicit StructLikeSet(const StructType& type,
54 size_t arena_initial_size = kDefaultArenaInitialSize);
55
57
59 Status Insert(const StructLike& row);
60
62 Result<bool> Contains(const StructLike& row) const;
63
65 bool IsEmpty() const;
66
68 size_t Size() const;
69
70 private:
72 struct KeyHash {
73 using is_transparent = void;
74 size_t operator()(const std::unique_ptr<StructLike>& p) const noexcept;
75 size_t operator()(const StructLike& s) const noexcept;
76 };
77
79 struct KeyEqual {
80 using is_transparent = void;
81 bool operator()(const std::unique_ptr<StructLike>& lhs,
82 const std::unique_ptr<StructLike>& rhs) const noexcept;
83 bool operator()(const StructLike& lhs,
84 const std::unique_ptr<StructLike>& rhs) const noexcept;
85 bool operator()(const std::unique_ptr<StructLike>& lhs,
86 const StructLike& rhs) const noexcept;
87 };
88
90 Result<std::unique_ptr<StructLike>> MakeArenaRow(const StructLike& row) const;
91
94 Result<Scalar> DeepCopyScalar(const Scalar& scalar) const;
95
97 std::string_view CopyToArena(std::string_view src) const;
98
99 std::vector<std::shared_ptr<Type>> field_types_;
100 mutable std::pmr::monotonic_buffer_resource arena_;
101 std::unordered_set<std::unique_ptr<StructLike>, KeyHash, KeyEqual> set_;
102};
103
104extern template class ICEBERG_EXTERN_TEMPLATE_CLASS_EXPORT StructLikeSet<true>;
105extern template class ICEBERG_EXTERN_TEMPLATE_CLASS_EXPORT StructLikeSet<false>;
106
107} // namespace iceberg
A set of StructLike rows with type-aware hashing and equality.
Definition struct_like_set.h:48
An immutable struct-like wrapper.
Definition struct_like.h:62
A data type representing a struct with nested fields.
Definition type.h:108
std::variant< std::monostate, bool, int32_t, int64_t, float, double, std::string_view, Decimal, std::shared_ptr< StructLike >, std::shared_ptr< ArrayLike >, std::shared_ptr< MapLike > > Scalar
A scalar value depending on its data type.
Definition struct_like.h:56