12 #ifndef ARRAYSTRUCTS_H_INCLUDED
13 #define ARRAYSTRUCTS_H_INCLUDED
20 #define TEST_ARRAYSTRUCT
38 #define _CRTDBG_MAP_ALLOC
50 #include <unordered_map>
52 #if defined(USE_BOOST) && defined(USE_STACKTRACE)
53 #include <boost/stacktrace.hpp>
54 namespace stacktrace = boost::stacktrace;
68 static const int __notfound = -1;
69 static const int __failure = -1;
70 static const int __success = 0;
74 inline bool __isfound(
int f)
76 return f != constants::__notfound;
82 template <
class T,
class Q,
class R =
int>
class HashedVector;
85 typedef unsigned int unsigned_int;
88 template <
class T>
int TestTemplate_ArrayStruct();
89 bool CompareFuncOut(std::function<
void()> func1, std::function<
void()> func2);
90 template <
typename T>
inline void sort(std::vector<T> &vec);
91 template <
typename T>
inline void unique(std::vector<T> &vec);
95 inline void set_intersection(std::vector<T> &targVec,
const std::vector<T> &vec1,
const std::vector<T> &vec2,
98 std::vector<int> FindSubList(
const std::vector<T> &keyFind,
const std::vector<T> &keyList,
99 std::unordered_multimap<T, int> &hashTable);
101 std::vector<int> FindSubList(
const std::vector<T> &keyFind,
const std::vector<T> &keyList,
102 const std::unordered_multimap<T, int> &hashTable);
103 template <
class T,
class Q>
104 void HashVector(
const std::vector<T> &elems, std::unordered_multimap<T, Q> &hashTable,
105 const std::vector<Q> &targElems = {});
106 template <
class T>
int FindSub(
const T &key,
const std::unordered_multimap<T, int> &hashTable);
107 template <
class T>
void ConcatenateVector(std::vector<T> &vecRoot,
const std::vector<T> &vecConcat);
108 template <
class T,
class R> std::vector<R> ReturnDataEqualRange(T key,
const std::unordered_multimap<T, R> &hashTable);
109 template <
class T,
class R>
110 void ReturnDataEqualRange(T key,
const std::unordered_multimap<T, R> &hashTable, std::vector<R> &subList);
119 bool readyforuse =
false;
120 bool isInMesh =
false;
122 std::vector<T> elems;
123 std::unordered_multimap<int, int> hashTable;
124 void ForceArrayReady();
128 maxIndex = elems.back().index;
135 friend int TestTemplate_ArrayStruct<T>();
138 void disp(
const std::vector<int> &subs)
const;
139 void disp(
int iStart,
int iEnd)
const;
140 int find(
int key,
bool noWarn =
false)
const;
141 std::vector<int> find_list(
const std::vector<int> &key,
bool noWarn =
false)
const;
142 inline int GetMaxIndex()
const;
143 inline void Init(
int n);
146 return (readyforuse);
150 void PopulateIndices();
153 void PrepareForUse();
154 void ChangeIndices(
int nVert,
int nEdge,
int nSurf,
int nVolu);
155 void write(FILE *fid)
const;
156 void read(FILE *fid);
157 void remove(std::vector<int> delInd);
158 void TightenConnectivity();
160 inline int size()
const;
161 inline int capacity()
const;
162 inline void assign(
int n, T &newelem);
163 inline void push_back(T &newelem);
164 inline void reserve(
int n);
167 void issafeaccess(
const int a)
170 if ((unsigned_int(a) >= elems.size()) || (0 > a))
172 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ << std::endl;
173 #ifdef USE_STACKTRACE
174 std::cerr << stacktrace::stacktrace() << std::endl;
176 std::cerr <<
"Attempt to access position " << a <<
" in std::vector of size " << elems.size() << std::endl;
183 const T *operator()(
const int a)
const
189 if ((unsigned_int(a) >= elems.size()) || (0 > a))
191 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ << std::endl;
192 #ifdef USE_STACKTRACE
193 std::cerr << stacktrace::stacktrace() << std::endl;
195 std::cerr <<
"Attempt to access position " << a <<
" in std::vector of size " << elems.size() << std::endl;
200 return (&(elems[a]));
202 const T *isearch(
const int b)
const
207 int a = this->find(b);
209 if ((unsigned_int(a) >= elems.size()) || (0 > a))
211 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ << std::endl;
212 #ifdef USE_STACKTRACE
213 std::cerr << stacktrace::stacktrace() << std::endl;
215 std::cerr <<
"Attempt to access index " << b <<
" at position " << a <<
" in std::vector of size "
216 << elems.size() << std::endl;
221 return (&(elems[a]));
224 T &operator[](
const int a)
228 if ((unsigned_int(a) >= elems.size()) | (0 > a))
230 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ << std::endl;
231 #ifdef USE_STACKTRACE
232 std::cerr << stacktrace::stacktrace() << std::endl;
234 std::cerr <<
"Attempt to access position " << a <<
" in std::vector of size " << elems.size() << std::endl;
252 std::unordered_multimap<int, int> hashParent;
253 int isHashParent = 0;
259 int findparent(
int key)
const;
260 void findsiblings(
int key, std::vector<int> &siblings)
const;
261 int countparent(
int key)
const
263 return (hashParent.count(key));
266 void DeHashParent(
const int pos);
267 bool memberIsHashParent(
const int pos)
const;
268 inline void Init(
int n);
270 inline void push_back(T &newelem);
273 void ForceArrayReady();
274 void PrepareForUse();
276 void remove(
const std::vector<int> &sub);
277 T &operator[](
const int a)
293 void ReturnModifInd(std::vector<int> &vecind);
294 void ReturnModifLog(std::vector<bool> &modiflog);
295 T &operator[](
const int a)
300 elems[a].isModif =
true;
309 std::unordered_multimap<T, R> hashTable;
312 inline void GenerateHash();
313 inline int find(
const T key)
const;
314 inline std::vector<int> findall(
const T key)
const;
315 inline int count(
const T key)
const;
316 std::vector<int> count(
const std::vector<T> &key)
const;
317 inline std::vector<int> find_list(
const std::vector<T> &key)
const;
318 bool operator()(
const Q &key)
const;
319 inline bool IsInVec(
const Q &key)
const;
320 T &operator[](
const int a)
324 const T &operator[](
const int a)
const
329 void reserve(
const size_t a)
331 this->vec.reserve(a);
332 this->hashTable.reserve(a);
334 void assign(
const size_t a,
const T &elm)
336 this->vec.assign(a, elm);
337 this->isHash =
false;
339 void push_back(
const T &elm)
341 this->vec.push_back(elm);
342 R t = this->vec.size() - 1;
343 this->hashTable.emplace(elm, t);
349 this->hashTable.clear();
353 return this->vec.size();
365 inline void GenerateHash();
378 S &operator()(
const T &elm)
381 if (pos == rsvs3d::constants::__notfound)
383 this->push_back(elm, S(0));
384 pos = this->size() - 1;
386 return this->targ[pos];
388 const S &operator()(
const T &elm)
const
391 if (pos == rsvs3d::constants::__notfound)
393 return this->defaultVal;
395 return this->targ[pos];
397 void reserve(
const size_t a)
400 this->vec.reserve(a);
402 void assign(
const size_t a,
const T &elmVec,
const S &elmTarg)
405 this->targ.assign(a, elmTarg);
407 void push_back(
const T &elmVec,
const S &elmTarg)
410 this->targ.push_back(elmTarg);
435 void operator=(
const std::vector<T> &a)
444 hashTable = a.hashTable;
446 T &operator[](
const int a)
450 if ((unsigned_int(a) >= vec.size()) | (0 > a))
452 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ << std::endl;
459 const T &operator[](
const int a)
const
463 if ((unsigned_int(a) >= vec.size()) | (0 > a))
465 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ << std::endl;
471 const T &isearch(
const int b)
const
476 int a = this->find(b);
478 if ((unsigned_int(a) >= vec.size()) | (0 > a))
480 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ << std::endl;
494 bool isBorder =
false;
496 virtual void disp()
const = 0;
497 virtual int Key()
const = 0;
498 virtual void ChangeIndices(
int nVert,
int nEdge,
int nSurf,
int nVolu) = 0;
499 virtual void PrepareForUse() = 0;
500 virtual bool isready(
bool isInMesh)
const = 0;
501 virtual void read(FILE *fid) = 0;
502 virtual void write(FILE *fid)
const = 0;
503 virtual void TightenConnectivity() = 0;
510 virtual int KeyParent()
const = 0;
519 bool returnIsModif()
const
526 template <
class T>
bool CompareDisp(T *mesh1, T *mesh2);
527 template <
class T>
int TestReadiness(T &stackT,
const char *txt,
bool errTarg,
bool errTargCheck);
528 template <
class T>
void DisplayVector(std::vector<T> vec);
529 template <
class T>
void DisplayVectorStatistics(std::vector<T> vec);
530 template <
class T>
void PrintVector(std::vector<T> vec, std::ostream &streamout);
532 template <
class T,
class R>
533 R ConcatenateVectorField(
const ArrayStruct<T> &arrayIn, R T::*mp,
const std::vector<int> &subList);
534 template <
class T,
class R>
535 std::vector<R> ConcatenateScalarField(
const ArrayStruct<T> &arrayIn, R T::*mp,
const std::vector<int> &subList);
536 template <
class T,
class R> R ConcatenateVectorField(
const ArrayStruct<T> &arrayIn, R T::*mp,
int rStart,
int rEnd);
538 template <
class T,
class R>
539 std::vector<R> ConcatenateScalarField(
const ArrayStruct<T> &arrayIn, R T::*mp,
int rStart,
int rEnd);
541 template <
class T,
class R,
class U,
class V>
542 void OperArrayStructMethod(
const ArrayStruct<T> &arrayIn,
const std::vector<int> &subList, R T::*mp, U &out, V oper);
543 template <
template <
class Q,
class R>
class T,
class Q,
class R>
void EraseKeyPair(T<Q, R> hashTable, Q key, R pos);
550 #include "arraystructures_incl.cpp"
Class for surface object in a mesh.
Namespace for general purpose tools of the RSVS project.
File for the implementation of the class template SnakStruct this .cpp file is INCLUDED as part of ar...
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_RANGE(M)
Throw a range_error.