MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / Iterator

Class Iterator

include/reactphysics3d/containers/Set.h:111–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109 * This class represents an iterator for the Set
110 */
111 class Iterator {
112
113 private:
114
115 /// Pointer to the set
116 const Set* mSet;
117
118 /// Index of the current bucket
119 uint64 mCurrentBucketIndex;
120
121 /// Index of the current entry
122 uint64 mCurrentEntryIndex;
123
124 /// Advance the iterator
125 void advance() {
126
127 assert(mCurrentBucketIndex < mSet->mHashSize);
128 assert(mCurrentEntryIndex < mSet->mNbAllocatedEntries);
129
130 // Try the next entry
131 if (mSet->mNextEntries[mCurrentEntryIndex] != INVALID_INDEX) {
132 mCurrentEntryIndex = mSet->mNextEntries[mCurrentEntryIndex];
133 return;
134 }
135
136 // Try to move to the next bucket
137 mCurrentEntryIndex = 0;
138 mCurrentBucketIndex++;
139 while(mCurrentBucketIndex < mSet->mHashSize && mSet->mBuckets[mCurrentBucketIndex] == INVALID_INDEX) {
140 mCurrentBucketIndex++;
141 }
142 if (mCurrentBucketIndex < mSet->mHashSize) {
143 mCurrentEntryIndex = mSet->mBuckets[mCurrentBucketIndex];
144 }
145 }
146
147 public:
148
149 // Iterator traits
150 using value_type = V;
151 using difference_type = std::ptrdiff_t;
152 using pointer = V*;
153 using reference = V&;
154 using iterator_category = std::forward_iterator_tag;
155
156 /// Constructor
157 Iterator() = default;
158
159 /// Constructor
160 Iterator(const Set* set, uint64 bucketIndex, uint64 entryIndex)
161 :mSet(set), mCurrentBucketIndex(bucketIndex), mCurrentEntryIndex(entryIndex) {
162
163 }
164
165 /// Deferencable
166 reference operator*() const {
167 assert(mCurrentEntryIndex < mSet->mNbAllocatedEntries);
168 assert(mCurrentEntryIndex != INVALID_INDEX);

Callers 4

removeMethod · 0.70
findMethod · 0.70
beginMethod · 0.70
endMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected