VTK  9.3.1
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 
21 VTK_ABI_NAMESPACE_BEGIN
22 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
23 {
24 public:
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 
71  void SetNumberOfIds(vtkIdType number);
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 
98  vtkIdType InsertUniqueId(vtkIdType vtkid);
99 
104  void Sort();
105 
110  void Fill(vtkIdType value);
111 
115  vtkIdType* GetPointer(vtkIdType i) { return this->Ids + i; }
116 
122  vtkIdType* WritePointer(vtkIdType i, vtkIdType number);
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 
167  vtkIdType* Resize(vtkIdType sz);
168 
169 #ifndef __VTK_WRAP__
170 
176  vtkIdType* Release();
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; }
188 protected:
189  vtkIdList();
190  ~vtkIdList() override;
191 
195  bool AllocateInternal(vtkIdType sz, vtkIdType numberOfIds);
199  void InitializeMemory();
200 
205 
206 private:
207  vtkIdList(const vtkIdList&) = delete;
208  void operator=(const vtkIdList&) = delete;
209 };
210 
211 // In-lined for performance
212 inline 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 
252 VTK_ABI_NAMESPACE_END
253 #endif
vtkIdType Size
Definition: vtkIdList.h:202
void SetId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:78
abstract base class for most VTK objects
Definition: vtkObject.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:139
vtkIdType * Ids
Definition: vtkIdList.h:203
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:134
vtkIdType * Resize(vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
void Sort(RandomIt bitr, RandomIt eitr, BackToFront< T > &me)
int vtkIdType
Definition: vtkType.h:315
vtkIdType NumberOfIds
Definition: vtkIdList.h:201
vtkIdType InsertNextId(vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:226
vtkIdType GetId(vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:54
a simple class to control print indentation
Definition: vtkIndent.h:28
list of point or cell ids
Definition: vtkIdList.h:22
const vtkIdType * end() const
To support range-based for loops.
Definition: vtkIdList.h:186
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:49
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
const vtkIdType * begin() const
To support range-based for loops.
Definition: vtkIdList.h:185
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:184
bool ManageMemory
Definition: vtkIdList.h:204
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:59
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void InsertId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:212
#define VTK_EXPECTS(x)
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:183
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:115