fix iterator concept implementation
This commit is contained in:
		
							parent
							
								
									8d98316a89
								
							
						
					
					
						commit
						748df0b21a
					
				| @ -40,39 +40,18 @@ protected: | |||||||
|         //make constructors explicit, so we do not mix random access and deallocation iterators.
 |         //make constructors explicit, so we do not mix random access and deallocation iterators.
 | ||||||
|         DeallocatingVectorIteratorState(); |         DeallocatingVectorIteratorState(); | ||||||
|     public: |     public: | ||||||
|         explicit DeallocatingVectorIteratorState(const DeallocatingVectorIteratorState &r) : mData(r.mData), mIndex(r.mIndex), mBucketList(r.mBucketList) {} |         explicit DeallocatingVectorIteratorState(const DeallocatingVectorIteratorState &r) : /*mData(r.mData),*/ mIndex(r.mIndex), mBucketList(r.mBucketList) {} | ||||||
|         //explicit DeallocatingVectorIteratorState(const ElementT * ptr, const std::size_t idx, const std::vector<ElementT *> & input_list) : mData(ptr), mIndex(idx), mBucketList(input_list) {}
 |         explicit DeallocatingVectorIteratorState(const std::size_t idx, std::vector<ElementT *> & input_list) : /*mData(DEALLOCATION_VECTOR_NULL_PTR),*/ mIndex(idx), mBucketList(input_list) { | ||||||
|         explicit DeallocatingVectorIteratorState(const std::size_t idx, std::vector<ElementT *> & input_list) : mData(DEALLOCATION_VECTOR_NULL_PTR), mIndex(idx), mBucketList(input_list) { |  | ||||||
|             setPointerForIndex(); |  | ||||||
|         } |         } | ||||||
|         ElementT * mData; |  | ||||||
|         std::size_t mIndex; |         std::size_t mIndex; | ||||||
|         std::vector<ElementT *> & mBucketList; |         std::vector<ElementT *> & mBucketList; | ||||||
| 
 | 
 | ||||||
|         inline void setPointerForIndex() { |  | ||||||
|             if(bucketSizeC*mBucketList.size() <= mIndex) { |  | ||||||
|                 mData = DEALLOCATION_VECTOR_NULL_PTR; |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             std::size_t _bucket = mIndex/bucketSizeC; |  | ||||||
|             std::size_t _index = mIndex%bucketSizeC; |  | ||||||
|             mData = &(mBucketList[_bucket][_index]); |  | ||||||
| 
 |  | ||||||
|             if(DeallocateC) { |  | ||||||
|                 //if we hopped over the border of the previous bucket, then delete that bucket.
 |  | ||||||
|                 if(0 == _index && _bucket) { |  | ||||||
|                     delete[] mBucketList[_bucket-1]; |  | ||||||
|                     mBucketList[_bucket-1] = DEALLOCATION_VECTOR_NULL_PTR; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|         } |  | ||||||
|         inline bool operator!=(const DeallocatingVectorIteratorState &other) { |         inline bool operator!=(const DeallocatingVectorIteratorState &other) { | ||||||
|             return (mData != other.mData) || (mIndex != other.mIndex) || (mBucketList != other.mBucketList); |             return mIndex != other.mIndex; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         inline bool operator==(const DeallocatingVectorIteratorState &other) { |         inline bool operator==(const DeallocatingVectorIteratorState &other) { | ||||||
|             return (mData == other.mData) && (mIndex == other.mIndex) && (mBucketList == other.mBucketList); |             return mIndex == other.mIndex; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         bool operator<(const DeallocatingVectorIteratorState &other) const { |         bool operator<(const DeallocatingVectorIteratorState &other) const { | ||||||
| @ -112,7 +91,6 @@ public: | |||||||
|     DeallocatingVectorIterator(const DeallocatingVectorIterator<T2> & r) : mState(r.mState) {} |     DeallocatingVectorIterator(const DeallocatingVectorIterator<T2> & r) : mState(r.mState) {} | ||||||
| 
 | 
 | ||||||
|     DeallocatingVectorIterator(std::size_t idx, std::vector<ElementT *> & input_list) : mState(idx, input_list) {} |     DeallocatingVectorIterator(std::size_t idx, std::vector<ElementT *> & input_list) : mState(idx, input_list) {} | ||||||
|     //DeallocatingVectorIterator(std::size_t idx, const std::vector<ElementT *> & input_list) : mState(idx, input_list) {}
 |  | ||||||
|     DeallocatingVectorIterator(const DeallocatingVectorIteratorState & r) : mState(r) {} |     DeallocatingVectorIterator(const DeallocatingVectorIteratorState & r) : mState(r) {} | ||||||
| 
 | 
 | ||||||
|     template<typename T2> |     template<typename T2> | ||||||
| @ -122,30 +100,32 @@ public: | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     inline DeallocatingVectorIterator& operator++() { //prefix
 |     inline DeallocatingVectorIterator& operator++() { //prefix
 | ||||||
| //        if(DeallocateC) assert(false);
 |         if(DeallocateC) assert(false); | ||||||
|         ++mState.mIndex; mState.setPointerForIndex(); return *this; |         ++mState.mIndex; | ||||||
|  |         return *this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     inline DeallocatingVectorIterator& operator--() { //prefix
 |     inline DeallocatingVectorIterator& operator--() { //prefix
 | ||||||
|         if(DeallocateC) assert(false); |         if(DeallocateC) assert(false); | ||||||
|         --mState.mIndex; mState.setPointerForIndex(); return *this; |         --mState.mIndex; | ||||||
|  |         return *this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     inline DeallocatingVectorIterator operator++(int) { //postfix
 |     inline DeallocatingVectorIterator operator++(int) { //postfix
 | ||||||
|         DeallocatingVectorIteratorState _myState(mState); |         DeallocatingVectorIteratorState _myState(mState); | ||||||
|         mState.mIndex++; mState.setPointerForIndex(); |         mState.mIndex++; | ||||||
|         return DeallocatingVectorIterator(_myState); |         return DeallocatingVectorIterator(_myState); | ||||||
|     } |     } | ||||||
|     inline DeallocatingVectorIterator operator--(int) { //postfix
 |     inline DeallocatingVectorIterator operator--(int) { //postfix
 | ||||||
|         if(DeallocateC) assert(false); |         if(DeallocateC) assert(false); | ||||||
|         DeallocatingVectorIteratorState _myState(mState); |         DeallocatingVectorIteratorState _myState(mState); | ||||||
|         mState.mIndex--; mState.setPointerForIndex(); |         mState.mIndex--; | ||||||
|         return DeallocatingVectorIterator(_myState); |         return DeallocatingVectorIterator(_myState); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     inline DeallocatingVectorIterator operator+(const difference_type& n) const { |     inline DeallocatingVectorIterator operator+(const difference_type& n) const { | ||||||
|         DeallocatingVectorIteratorState _myState(mState); |         DeallocatingVectorIteratorState _myState(mState); | ||||||
|         _myState.mIndex+=n; _myState.setPointerForIndex(); |         _myState.mIndex+=n; | ||||||
|         return DeallocatingVectorIterator(_myState); |         return DeallocatingVectorIterator(_myState); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -156,7 +136,7 @@ public: | |||||||
|     inline DeallocatingVectorIterator operator-(const difference_type& n) const { |     inline DeallocatingVectorIterator operator-(const difference_type& n) const { | ||||||
|         if(DeallocateC) assert(false); |         if(DeallocateC) assert(false); | ||||||
|         DeallocatingVectorIteratorState _myState(mState); |         DeallocatingVectorIteratorState _myState(mState); | ||||||
|         _myState.mIndex-=n; _myState.setPointerForIndex(); |         _myState.mIndex-=n; | ||||||
|         return DeallocatingVectorIterator(_myState); |         return DeallocatingVectorIterator(_myState); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -164,14 +144,17 @@ public: | |||||||
|         if(DeallocateC) assert(false); |         if(DeallocateC) assert(false); | ||||||
|         mState.mIndex-=n; return *this; |         mState.mIndex-=n; return *this; | ||||||
|     } |     } | ||||||
|     inline reference operator*() const { return *mState.mData; } | 
 | ||||||
|     inline pointer operator->() const { return mState.mData; } |     inline reference operator*() const { | ||||||
|     inline reference operator[](const difference_type &n) const { |         std::size_t _bucket = mState.mIndex/bucketSizeC; | ||||||
|         if(DeallocateC) assert(false); |         std::size_t _index = mState.mIndex%bucketSizeC; | ||||||
|         DeallocatingVectorIteratorState _myState(mState); |         return (mState.mBucketList[_bucket][_index]); | ||||||
|         _myState.mIndex += n; |     } | ||||||
|         _myState.setPointerForIndex; | 
 | ||||||
|         return _myState.mData; |     inline pointer operator->() const { | ||||||
|  |         std::size_t _bucket = mState.mIndex/bucketSizeC; | ||||||
|  |         std::size_t _index = mState.mIndex%bucketSizeC; | ||||||
|  |         return &(mState.mBucketList[_bucket][_index]); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     inline bool operator!=(const DeallocatingVectorIterator & other) { |     inline bool operator!=(const DeallocatingVectorIterator & other) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user