RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
NORangesSet.h
Go to the documentation of this file.
1
/*
2
RawSpeed - RAW file decoder.
3
4
Copyright (C) 2017-2021 Roman Lebedev
5
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
10
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
15
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#pragma once
22
23
#include "
adt/Range.h
"
24
#include <algorithm>
25
#include <cassert>
26
#include <cstddef>
27
#include <iterator>
28
#include <set>
// IWYU pragma: export
29
30
namespace
rawspeed
{
31
32
template
<
typename
T>
class
NORangesSet
final {
33
std::set<T>
elts
;
34
35
[[nodiscard]]
bool
36
rangeIsOverlappingExistingElementOfSortedSet
(
const
T
& newElt)
const
{
37
// If there are no elements in set, then the new element
38
// does not overlap any existing elements.
39
if
(
elts
.empty())
40
return
false
;
41
42
// Find the first element that is not less than the new element.
43
auto
p =
44
std::partition_point(
elts
.begin(),
elts
.end(),
45
[newElt](
const
T
& elt) { return elt < newElt; });
46
47
// If there is such an element, we must not overlap with it.
48
if
(p !=
elts
.end() &&
RangesOverlap
(newElt, *p))
49
return
true
;
50
51
// Now, is there an element before the element we found?
52
if
(p ==
elts
.begin())
53
return
false
;
54
55
// There is. We *also* must not overlap with that element too.
56
auto
prevBeforeP = std::prev(p);
57
return
RangesOverlap
(newElt, *prevBeforeP);
58
}
59
60
public
:
61
bool
insert
(
const
T
& newElt) {
62
if
(
rangeIsOverlappingExistingElementOfSortedSet
(newElt))
63
return
false
;
64
65
auto
i =
elts
.insert(newElt);
66
assert
(i.second &&
"Did not insert after all?"
);
67
(void)i;
68
return
true
;
69
}
70
71
[[nodiscard]] std::size_t
size
()
const
{
return
elts
.size(); }
72
};
73
74
}
// namespace rawspeed
Range.h
assert
assert(dim.area() >=area)
rawspeed::NORangesSet
Definition
NORangesSet.h:32
rawspeed::NORangesSet::elts
std::set< T > elts
Definition
NORangesSet.h:33
rawspeed::NORangesSet::insert
bool insert(const T &newElt)
Definition
NORangesSet.h:61
rawspeed::NORangesSet::rangeIsOverlappingExistingElementOfSortedSet
bool rangeIsOverlappingExistingElementOfSortedSet(const T &newElt) const
Definition
NORangesSet.h:36
rawspeed::NORangesSet::size
std::size_t size() const
Definition
NORangesSet.h:71
rawspeed
Definition
CoalescingOutputIteratorBenchmark.cpp:35
rawspeed::T
throw T(buf.data())
rawspeed::RangesOverlap
constexpr bool RAWSPEED_READNONE RangesOverlap(const T &lhs, const T &rhs)
Definition
Range.h:62
librawspeed
adt
NORangesSet.h
Generated by
1.15.0