Android-cuttlefish cvd tool
disjoint_range_set.h
Go to the documentation of this file.
1//
2// Copyright (C) 2025 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15#pragma once
16
17#include <stdint.h>
18
19#include <memory>
20#include <optional>
21#include <utility>
22#include <vector>
23
24namespace cuttlefish {
25
27 public:
34
35 // Reports if all members from [start,end) are contained.
36 bool ContainsRange(uint64_t start, uint64_t end) const;
37 // Records that all numbers from [start,end) are contained.
38 void InsertRange(uint64_t start, uint64_t end);
39 // Returns the end of the range that `start` is a member of. Returns
40 // std::nullopt if `start` is not within a range.
41 std::optional<uint64_t> EndOfContainingRange(uint64_t start) const;
42
43 std::vector<std::pair<uint64_t, uint64_t>> AllRanges() const;
44
45 bool operator==(const DisjointRangeSet&) const;
46
47 private:
48 struct Impl;
49
50 std::unique_ptr<Impl> impl_;
51};
52
53} // namespace cuttlefish
Definition: disjoint_range_set.h:26
std::optional< uint64_t > EndOfContainingRange(uint64_t start) const
Definition: disjoint_range_set.cc:145
void InsertRange(uint64_t start, uint64_t end)
Definition: disjoint_range_set.cc:113
bool ContainsRange(uint64_t start, uint64_t end) const
Definition: disjoint_range_set.cc:96
DisjointRangeSet & operator=(const DisjointRangeSet &)
Definition: disjoint_range_set.cc:83
DisjointRangeSet()
Definition: disjoint_range_set.cc:72
bool operator==(const DisjointRangeSet &) const
Definition: disjoint_range_set.cc:168
std::unique_ptr< Impl > impl_
Definition: disjoint_range_set.h:50
std::vector< std::pair< uint64_t, uint64_t > > AllRanges() const
Definition: disjoint_range_set.cc:159
Definition: alloc_utils.cpp:23
Definition: disjoint_range_set.cc:68