| 93 | /// Chunked array iterator. |
| 94 | /// </summary> |
| 95 | struct Iterator |
| 96 | { |
| 97 | friend ChunkedArray; |
| 98 | private: |
| 99 | ChunkedArray* _collection; |
| 100 | int32 _chunkIndex; |
| 101 | int32 _index; |
| 102 | |
| 103 | Iterator(const ChunkedArray* collection, const int32 index) |
| 104 | : _collection(const_cast<ChunkedArray*>(collection)) |
| 105 | , _chunkIndex(index / ChunkSize) |
| 106 | , _index(index % ChunkSize) |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | public: |
| 111 | Iterator() |
| 112 | : _collection(nullptr) |
| 113 | , _chunkIndex(INVALID_INDEX) |
| 114 | , _index(INVALID_INDEX) |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | Iterator(const Iterator& i) |
| 119 | : _collection(i._collection) |
| 120 | , _chunkIndex(i._chunkIndex) |
| 121 | , _index(i._index) |
| 122 | { |
| 123 | } |
| 124 | |
| 125 | Iterator(Iterator&& i) |
| 126 | : _collection(i._collection) |
| 127 | , _chunkIndex(i._chunkIndex) |
| 128 | , _index(i._index) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | public: |
| 133 | FORCE_INLINE int32 Index() const |
| 134 | { |
| 135 | return _chunkIndex * ChunkSize + _index; |
| 136 | } |
| 137 | |
| 138 | FORCE_INLINE bool IsEnd() const |
| 139 | { |
| 140 | return (_chunkIndex * ChunkSize + _index) == _collection->_count; |
| 141 | } |
| 142 | |
| 143 | FORCE_INLINE bool IsNotEnd() const |
| 144 | { |
| 145 | return (_chunkIndex * ChunkSize + _index) != _collection->_count; |
| 146 | } |
| 147 | |
| 148 | FORCE_INLINE T& operator*() const |
| 149 | { |
| 150 | return _collection->_chunks[_chunkIndex]->At(_index); |
| 151 | } |
| 152 | |