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

Class Iterator

include/reactphysics3d/containers/Map.h:112–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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