VTK  9.3.0
vtkIdList.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
15#ifndef vtkIdList_h
16#define vtkIdList_h
17
18#include "vtkCommonCoreModule.h" // For export macro
19#include "vtkObject.h"
20
21VTK_ABI_NAMESPACE_BEGIN
22class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
23{
24public:
26
29 static vtkIdList* New();
30 vtkTypeMacro(vtkIdList, vtkObject);
31 void PrintSelf(ostream& os, vtkIndent indent) override;
33
37 void Initialize();
38
44 int Allocate(vtkIdType sz, int strategy = 0);
45
49 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
50
54 vtkIdType GetId(vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds()) { return this->Ids[i]; }
55
60 {
61 for (int i = 0; i < this->NumberOfIds; i++)
62 if (this->Ids[i] == id)
63 return i;
64 return -1;
65 }
66
72
78 void SetId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
79 {
80 this->Ids[i] = vtkid;
81 }
82
87 void InsertId(vtkIdType i, vtkIdType vtkid) VTK_EXPECTS(0 <= i);
88
92 vtkIdType InsertNextId(vtkIdType vtkid);
93
99
104 void Sort();
105
110 void Fill(vtkIdType value);
111
115 vtkIdType* GetPointer(vtkIdType i) { return this->Ids + i; }
116
123
129 void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
130
134 void Reset() { this->NumberOfIds = 0; }
135
139 void Squeeze() { this->Resize(this->NumberOfIds); }
140
144 void DeepCopy(vtkIdList* ids);
145
149 void DeleteId(vtkIdType vtkid);
150
155 vtkIdType IsId(vtkIdType vtkid);
156
161 void IntersectWith(vtkIdList* otherIds);
162
168
169#ifndef __VTK_WRAP__
177#endif
178
180
183 vtkIdType* begin() { return this->Ids; }
184 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
185 const vtkIdType* begin() const { return this->Ids; }
186 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
188protected:
190 ~vtkIdList() override;
191
195 bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
200
205
206private:
207 vtkIdList(const vtkIdList&) = delete;
208 void operator=(const vtkIdList&) = delete;
209};
210
211// In-lined for performance
212inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
213{
214 if (i >= this->Size)
215 {
216 this->Resize(i + 1);
217 }
218 this->Ids[i] = vtkid;
219 if (i >= this->NumberOfIds)
220 {
221 this->NumberOfIds = i + 1;
222 }
223}
224
225// In-lined for performance
227{
228 if (this->NumberOfIds >= this->Size)
229 {
230 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
231 {
232 return this->NumberOfIds - 1;
233 }
234 }
235 this->Ids[this->NumberOfIds++] = vtkid;
236 return this->NumberOfIds - 1;
237}
238
240{
241 vtkIdType *ptr, i;
242 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
243 {
244 if (vtkid == *ptr)
245 {
246 return i;
247 }
248 }
249 return (-1);
250}
251
252VTK_ABI_NAMESPACE_END
253#endif
list of point or cell ids
Definition vtkIdList.h:23
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition vtkIdList.h:59
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition vtkIdList.h:203
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition vtkIdList.h:201
~vtkIdList() override
void Fill(vtkIdType value)
Fill the ids with the input value.
void SetArray(vtkIdType *array, vtkIdType size, bool save=true)
Specify an array of vtkIdType to use as the id list.
int Allocate(vtkIdType sz, int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
vtkIdType * WritePointer(vtkIdType i, vtkIdType number)
Get a pointer to a particular data index.
vtkIdType Size
Definition vtkIdList.h:202
vtkIdType * Resize(vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
void Squeeze()
Free any unused memory.
Definition vtkIdList.h:139
vtkIdType * end()
To support range-based for loops.
Definition vtkIdList.h:184
void InitializeMemory()
Release memory.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:49
void Initialize()
Release memory and restore to unallocated state.
bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds)
Allocate ids and set the number of ids.
vtkIdType InsertNextId(vtkIdType vtkid)
Add the id specified to the end of the list.
Definition vtkIdList.h:226
vtkIdType IsId(vtkIdType vtkid)
Return -1 if id specified is not contained in the list; otherwise return the position in the list.
Definition vtkIdList.h:239
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:134
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
void SetId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
Definition vtkIdList.h:78
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition vtkIdList.h:54
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition vtkIdList.h:183
bool ManageMemory
Definition vtkIdList.h:204
vtkIdType * Release()
This releases the ownership of the internal vtkIdType array and returns the pointer to it.
void InsertId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
Definition vtkIdList.h:212
const vtkIdType * end() const
To support range-based for loops.
Definition vtkIdList.h:186
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
vtkIdType InsertUniqueId(vtkIdType vtkid)
If id is not already in list, insert it and return location in list.
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:115
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
const vtkIdType * begin() const
To support range-based for loops.
Definition vtkIdList.h:185
a simple class to control print indentation
Definition vtkIndent.h:29
abstract base class for most VTK objects
Definition vtkObject.h:49
int vtkIdType
Definition vtkType.h:315
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)