38 #ifndef LIBPMEMOBJ_CPP_CONTIGUOUS_ITERATOR_HPP 39 #define LIBPMEMOBJ_CPP_CONTIGUOUS_ITERATOR_HPP 57 template <
typename Iterator,
typename Reference,
typename Po
inter>
88 static_cast<Iterator *>(
this)->change_by(1);
89 return *static_cast<Iterator *>(
this);
98 Iterator tmp(*static_cast<Iterator *>(
this));
99 static_cast<Iterator *>(
this)->change_by(1);
109 static_cast<Iterator *>(
this)->change_by(-1);
110 return *static_cast<Iterator *>(
this);
119 Iterator tmp(*static_cast<Iterator *>(
this));
120 static_cast<Iterator *>(
this)->change_by(-1);
130 static_cast<Iterator *>(
this)->change_by(n);
131 return *static_cast<Iterator *>(
this);
140 static_cast<Iterator *>(
this)->change_by(-n);
141 return *static_cast<Iterator *>(
this);
150 Iterator tmp(*static_cast<const Iterator *>(
this));
161 Iterator tmp(*static_cast<const Iterator *>(
this));
169 friend std::ptrdiff_t
172 return lhs.ptr - rhs.ptr;
219 template <
typename T>
222 using iterator_category = std::random_access_iterator_tag;
223 using value_type = T;
224 using difference_type = std::ptrdiff_t;
225 using reference = T &;
235 pointer data =
nullptr,
236 std::size_t size = 0,
237 std::size_t snapshot_size = 1)
241 snapshot_size(snapshot_size)
245 if (snapshot_size && ptr)
252 operator const T *()
const 264 detail::conditional_add_to_tx(&this->ptr[n], 1,
265 POBJ_XADD_ASSUME_INITIALIZED);
275 std::swap(lhs.ptr, rhs.ptr);
276 std::swap(lhs.data, rhs.data);
277 std::swap(lhs.size, rhs.size);
278 std::swap(lhs.snapshot_size, rhs.snapshot_size);
281 template <
typename Iterator,
typename Reference,
typename Po
inter>
286 change_by(std::ptrdiff_t n)
288 conditional_snapshot_range(this->ptr, n);
298 conditional_snapshot_range(pointer ptr, difference_type diff)
300 if (snapshot_size == 0)
303 auto new_ptr = ptr + diff;
306 if (new_ptr < data || new_ptr >= data + size)
310 if (static_cast<std::size_t>(ptr - data) / snapshot_size ==
311 static_cast<std::size_t>(new_ptr - data) / snapshot_size)
314 snapshot_range(new_ptr);
318 snapshot_range(pointer ptr)
322 ptr - static_cast<uint64_t>(ptr - data) % snapshot_size;
323 auto range_size = snapshot_size;
325 if (range_begin + range_size > data + size)
326 range_size = static_cast<uint64_t>(data + size -
329 verify_range(range_begin, range_size);
332 detail::conditional_add_to_tx(range_begin, range_size,
333 POBJ_XADD_ASSUME_INITIALIZED);
338 verify_range(pointer range_begin, uint64_t range_size)
340 auto range_offset = static_cast<uint64_t>(range_begin - data);
342 assert(range_begin >= data);
343 assert(range_offset % snapshot_size == 0);
344 assert((range_offset + range_size) % snapshot_size == 0 ||
345 range_begin + range_size == data + size);
351 std::size_t snapshot_size;
358 template <
typename T>
361 using iterator_category = std::random_access_iterator_tag;
362 using value_type = T;
363 using difference_type = std::ptrdiff_t;
364 using reference = T &;
380 operator const T *()
const 391 detail::conditional_add_to_tx(this->ptr, 1,
392 POBJ_XADD_ASSUME_INITIALIZED);
402 detail::conditional_add_to_tx(this->ptr, 1,
403 POBJ_XADD_ASSUME_INITIALIZED);
414 detail::conditional_add_to_tx(&this->ptr[n], 1,
415 POBJ_XADD_ASSUME_INITIALIZED);
425 std::swap(lhs.ptr, rhs.ptr);
Iterator & operator++()
Prefix increment operator.
Definition: contiguous_iterator.hpp:86
friend void swap(basic_contiguous_iterator &lhs, basic_contiguous_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:423
Iterator operator-(std::ptrdiff_t n) const
Subtraction operator overload for integral type.
Definition: contiguous_iterator.hpp:159
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:262
friend void swap(range_snapshotting_iterator &lhs, range_snapshotting_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:273
Base class for iterators which satisfies RandomAccessIterator and operate on contiguous memory.
Definition: contiguous_iterator.hpp:58
Pointer operator->() const
Arrow operator.
Definition: contiguous_iterator.hpp:77
pointer operator->() const
Arrow operator which adds underlying element to a transactions.
Definition: contiguous_iterator.hpp:400
void change_by(std::ptrdiff_t n)
Function for changing underlying pointer.
Definition: contiguous_iterator.hpp:196
reference operator *() const
Dereference operator which adds dereferenced element to a transaction.
Definition: contiguous_iterator.hpp:389
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:412
Commonly used functionality.
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:220
Iterator operator+(std::ptrdiff_t n) const
Addition operator.
Definition: contiguous_iterator.hpp:148
range_snapshotting_iterator(pointer ptr=nullptr, pointer data=nullptr, std::size_t size=0, std::size_t snapshot_size=1)
Constructor taking pointer to data, pointer to the beginning of the array and snapshot_size.
Definition: contiguous_iterator.hpp:234
constexpr contiguous_iterator(Pointer begin)
Constructor taking a pointer.
Definition: contiguous_iterator.hpp:62
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:359
Reference operator *() const
Dereference operator.
Definition: contiguous_iterator.hpp:69
basic_contiguous_iterator(pointer ptr=nullptr)
Constructor taking pointer and snapshotting function as arguments.
Definition: contiguous_iterator.hpp:373
Iterator operator++(int)
Postfix increment operator.
Definition: contiguous_iterator.hpp:96
friend std::ptrdiff_t operator-(const Iterator &lhs, const Iterator &rhs)
Subtraction operator overload Iterator type.
Definition: contiguous_iterator.hpp:170
Reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:178
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:43
Iterator & operator--()
Prefix decrement operator.
Definition: contiguous_iterator.hpp:107
Iterator & operator+=(std::ptrdiff_t n)
Addition assignment operator.
Definition: contiguous_iterator.hpp:128
Iterator operator--(int)
Postfix decrement operator.
Definition: contiguous_iterator.hpp:117
Iterator & operator-=(std::ptrdiff_t n)
Subtraction assignment operator.
Definition: contiguous_iterator.hpp:138