##CIRCULAR_VECTOR## A STL-Compliant Circular Vector (Container) Data Structure written in C++
Shares similaries to a Circular Buffer Data Structure, except allows access to all elements in the container.
Contains all the same member functions as C++98 std::vector from the STL, except for vector::insert and vector::erase. Newly introduced member functions include: push_front and pop_front which unlike the counterpart operations in std::vector are O(1) time (Constant).
##CONSTRUCTORS:##
explicit circular_vector(size_type capacity = kDefaultCapacity);
- Empty container constructor (default constructor). Constructs an empty container, with no elements. With a specified amount of reserved space.
- The starting allocated storage reserve
- With negative capacity values
explicit circular_vector(size_type n, const value_type &val, const allocator_type &alloc = allocator_type());
- Fill constructor. Constructs a container with @a n elements. Each element is a copy of @a val.
- The size and capacity of the %circular_vector
- The data value to fill the %circular_vector
- With negative size values
template <class InputIterator>;
circular_vector(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());
- Range constructor. Constructs a container with as many elements as the range [first,last), with each element constructed from its corresponding element in that range, in the same order.
- The initial position to start the copy from
- The final exclusive position of the copy range
circular_vector(const circular_vector &x);
- Copy constructor. Constructs a container with a copy of each of the elements in x, in the same order.
- Another vector object of the same type (with the same class template arguments T and Alloc), whose contents are copied.
- Upon catching any exception while assigning memory
circular_vector &operator = (const self_type &x);;
- Move constructor. Assigns new contents to the container, replacing its current contents, and modifying its size accordingly.
- A vector object of the same type (i.e., with the same template parameters, T and Alloc).
##DESTRUCTORS:##
- Destroys all container elements, and deallocates all the storage capacity allocated by the vector using its allocator.
##ITERATORS:##
iterator begin();- An iterator pointing to array\_[0], i.e. the first element
- Iterator should be repositioned upon capacity reallocation or after push_front call
iterator end();- An iterator pointing to array\_[size()], i.e. past-the-end element
- Iterator should be repositioned upon capacity reallocation or after push_back call
reverse_iterator rbegin();- Returns a reverse iterator pointing to the last element in the vector (i.e., its reverse beginning). Reverse iterators iterate backwards: increasing them moves them towards the beginning of the container. rbegin points to the element right before the one that would be pointed to by member end. Notice that unlike member vector::back, which returns a reference to this same element, this function returns a reverse random access iterator.
- Iterator should be repositioned upon capacity reallocation or after push_back call
reverse_iterator rend();- Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector (which is considered its reverse end). The range between vector::rbegin and vector::rend contains all the elements of the vector (in reverse order).
- Iterator should be repositioned upon capacity reallocation or after push_front call
##ALLOCATORS:##
allocator_type get_allocator() const;
- Returns a copy of the allocator object associated with the @circular_vector
- Read-only (constant) allocator
##CAPACITIES:##
size_type size() const;
- Returns the amount of elements in the %circular_vector
- Read-only (constant) circular size
size_type max_size() const;
- Returns the maximum number of elements that the %circular_vector can hold during dynamic allocation mode
- Read-only (constant) maximum size
void resize(size_type n, const value_type &val = value_type());
- Resizes the %circular_vector to specified size
- Number of elements the %circular_vector should contain.
- The value of the element to fill the extra size
- This function changes the actual content of the container by inserting or erasing elements from it (unless @a n = size()). If the number is smaller than the %circular_vector's current size the %circular_vector is truncated, otherwise default (or specified) elements are appended until size reaches @a n size. If capacity needs to increase => capacity becomes @a n. Capacity never shrinks.
size_type capacity() const;
- Returns size of allocated storage capacity
bool empty() const;
- Returns true if there are elements in the %circular_vector
- Read-only (constant) True iff end index is in default state
void reserve(size_type n);
- Request that the %circular_vector capacity be at least enough to contain @a n elements. This function has no effect on the %circular_vector size and cannot alter its elements.
- If @a n is greater than the current %circular_vector capacity, the function causes the container to reallocate its storage increasing its capacity to @a n (or greater). O(n) time and space required when this occurs
##MODIFIERS:##
template <typename iter> void assign(iter start, iter last);
- Fills a %circular_vector with copies of the elements in the range \[start, last)
- An input iterator
- An input iterator
- The assignment completely changes the %circular_vector and the resulting %circular_vector's size is the same as the number of elements assigned. Old data will be lost.
- Fills a %circular_vector with the specified value in the range \[0, n)
- Number of elements to be assigned
- Value to be assigned
- The assignment completely changes the %circular_vector and the resulting %circular_vector's size is the same as the number of elements assigned. Old data will be lost.
void pop_front();
- Removes the first indexed element
- Undefined behaviour when calling on an empty %circular_vector
void pop_back();
- Removes the last indexed element
- Undefined behaviour when calling on an empty %circular_vector
void push_front(const value_type &val);
- Adds an element to the head of the %circular_vector and decrements the start index
- Element to be added
- If capacity has been reached, the function causes the container to reallocate its storage increasing its capacity to 1.5 * capacity. O(n) time and space required when this occurs.
void push_back(const value_type &val);
- Adds an element to the tail of the %circular_vector
- Element to be added
- If capacity has been reached, the function causes the container to reallocate its storage increasing its capacity to 1.5 * capacity. O(n) time and space required when this occurs.
void swap(circular_vector &x);
- Exchanges the content of the container by the content of x, which is another %circular_vector object of the same type. Sizes may differ.
- The %circular_vector of the same type to swap with.
void clear();
- Removes all elements from the @circular_vector (which are destroyed), leaving the container with a size of 0.
- If the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
##ELEMENT ACCESS:##
reference operator [] (size_type n);
- Provides access to the data contained in %circular_vector
- The index of the element for which data should be accessed
- Read/write reference to data
- Calling this function with an argument @a n that is out of range causes undefined behaviour.
const_reference operator [] (size_type n) const;
- Provides access to the data contained in %circular_vector
- The index of the element for which data should be accessed
- Read/write reference to data
- Calling this function with an argument @a n that is out of range causes undefined behaviour
reference at(size_type n);
- Provides access to the data contained in %circular_vector
- The index of the element for which data should be accessed
- Read/write reference to data
- If @a n is an invalid index
const_reference at(size_type n) const;
- Provides access to the data contained in %circular_vector
- The index of the element for which data should be accessed
- Read-only (constant) reference to data
- If @a n is an invalid index
reference front();
- Read/Write reference to the first indexed element in %circular_vector
- Calling this function on an empty container causes undefined behaviour
const_reference front() const;
- Read-only (constant) reference to the first indexed element in %circular_vector
- Calling this function on an empty container causes undefined behaviour
reference back();
- Read/Write reference to the last indexed element in %circular_vector
- Calling this function on an empty container causes undefined behaviour
const_reference back() const;
- Read-only (constant) reference to the last indexed element in %circular_vector
- Calling this function on an empty container causes undefined behaviour