ObjFW
OFIndexSet.h
1 /*
2  * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
24 @class OFMutableData;
25 
30 {
31  OFMutableData *_ranges;
32  size_t _count;
33  OF_RESERVE_IVARS(OFIndexSet, 4)
34 }
35 
39 @property (readonly, nonatomic) size_t count;
40 
44 @property (readonly, nonatomic) size_t firstIndex;
45 
49 @property (readonly, nonatomic) size_t lastIndex;
50 
56 + (instancetype)indexSet;
57 
64 + (instancetype)indexSetWithIndexSet: (OFIndexSet *)indexSet;
65 
72 + (instancetype)indexSetWithIndex: (size_t)idx;
73 
80 + (instancetype)indexSetWithIndexesInRange: (OFRange)range;
81 
87 - (instancetype)init;
88 
95 - (instancetype)initWithIndexSet: (OFIndexSet *)indexSet;
96 
103 - (instancetype)initWithIndex: (size_t)idx;
104 
113 - (instancetype)initWithIndexesInRange: (OFRange)range;
114 
121 - (bool)containsIndex: (size_t)idx;
122 
129 - (bool)containsIndexesInRange: (OFRange)range;
130 
138 - (size_t)indexGreaterThanIndex: (size_t)idx;
139 
148 - (size_t)indexGreaterThanOrEqualToIndex: (size_t)idx;
149 
157 - (size_t)indexLessThanIndex: (size_t)idx;
158 
167 - (size_t)indexLessThanOrEqualToIndex: (size_t)idx;
168 
177 - (size_t)getIndexes: (size_t *)indexes
178  maxCount: (size_t)maxCount
179  inIndexRange: (nullable OFRange *)range;
180 
186 - (size_t)countOfIndexesInRange: (OFRange)range;
187 @end
188 
189 OF_ASSUME_NONNULL_END
190 
191 #import "OFMutableIndexSet.h"
The root class for all other classes inside ObjFW.
Definition: OFObject.h:954
A class storing a set of indexes as sorted ranges.
Definition: OFIndexSet.h:29
A protocol for the creation of mutable copies.
Definition: OFObject.h:1639
A protocol for the creation of copies.
Definition: OFObject.h:1618
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:31
A range.
Definition: OFObject.h:116