<commit_before>// Copyright (c) 2010-14 Bifrost Entertainment AS and <NAME>
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)

#ifndef COMMON_VECTOR_H_
#define COMMON_VECTOR_H_

#include <cstring>
#include <new>
#include <utility>

#include "Common/Debug.h"
#include "Common/NonCopyable.h"

/// Simple vector class, mimicking std::vector.
///
/// This class is mainly for the lack of full STL implementation on some
/// platforms, such as Android. (And because we don't like iterators.)
template<typename T>
class Vector : private NonCopyable<Vector<T> >
{
public:
	Vector(const size_t reserve = 4);
	Vector(Vector<T> &&);
	~Vector();

	/// Returns the element stored at index.
	inline T& at(const size_t i);

	/// Returns the last element.
	inline T& back();

	/// Returns a pointer to the first element.
	inline T* begin() const;

	/// Returns size of allocated storage capacity.
	inline size_t capacity() const;

	/// Empties the vector.
	void clear();

	/// Returns a pointer to the end of the vector.
	inline T* end() const;

	/// Erases the element at index while preserving the order.
	void erase(const size_t i);

	/// Finds an element with given value.
	/// \param value  The value of the element to find.
	/// \return Index to the first element whose value matches; -1 otherwise.
	int find(const T &value) const;

	/// Adds an element to the vector.
	void push_back(const T &element);

	/// Adds an element to the vector.
	void push_back(T &&element);

	/// Quick erases the element at index by swapping it out with the last
	/// element. Don't use this if you need to maintain the element order.
	void qerase(const size_t i);

	/// Quick removes a value from the vector by swapping it out with the last
	/// element. Deletes only the first element found by \c find(). Don't use
	/// this if you need to maintain the element order.
	/// \param value  The value to remove.
	void qremove(const T &value);

	/// Removes a value from the vector while preserving the order of elements.
	/// Deletes only the first element found by \c find().
	/// \param value  The value to remove.
	void remove(const T &value);

	/// Increases or decreases the capacity of the vector.
	/// \note On failure, the vector will remain untouched.
	/// \param i  The size of the new capacity. If less than the number of
	///           elements in the container, the container is simply tightened.
	void reserve(size_t i);

	/// Returns the number of elements in this vector.
	inline size_t size() const;

	inline bool operator==(const Vector<T> &) const;

	/// Returns the element stored at index.
	inline T& operator[](const size_t i) const;

private:
	size_t count;     ///< Number of elements in the array.
	size_t reserved;  ///< Size of allocated memory.
	T *c_array;       ///< Actual C-array.
};

template<typename T>
Vector<T>::Vector(const size_t reserve)
    : count(0), reserved(0), c_array(nullptr)
{
	this->reserve(reserve);
}

template<typename T>
Vector<T>::Vector(Vector<T> &&v)
    : count(v.count), reserved(v.reserved), c_array(v.c_array)
{
	v.count = 0;
	v.reserved = 0;
	v.c_array = nullptr;
}

template<typename T>
Vector<T>::~Vector()
{
	this->clear();
	operator delete(this->c_array);
}

template<typename T>
T& Vector<T>::at(const size_t i)
{
	return (*this)[i];
}
<commit_msg>Reordered Vector members for better cache locality.<commit_after>// Copyright (c) 2010-14 Bifrost Entertainment AS and <NAME>
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)

#ifndef COMMON_VECTOR_H_
#define COMMON_VECTOR_H_

#include <cstring>
#include <new>
#include <utility>

#include "Common/Debug.h"
#include "Common/NonCopyable.h"

/// Simple vector class, mimicking std::vector.
///
/// This class is mainly for the lack of full STL implementation on some
/// platforms, such as Android. (And because we don't like iterators.)
template<typename T>
class Vector : private NonCopyable<Vector<T> >
{
public:
	Vector(const size_t reserve = 4);
	Vector(Vector<T> &&);
	~Vector();

	/// Returns the element stored at index.
	inline T& at(const size_t i);

	/// Returns the last element.
	inline T& back();

	/// Returns a pointer to the first element.
	inline T* begin() const;

	/// Returns size of allocated storage capacity.
	inline size_t capacity() const;

	/// Empties the vector.
	void clear();

	/// Returns a pointer to the end of the vector.
	inline T* end() const;

	/// Erases the element at index while preserving the order.
	void erase(const size_t i);

	/// Finds an element with given value.
	/// \param value  The value of the element to find.
	/// \return Index to the first element whose value matches; -1 otherwise.
	int find(const T &value) const;

	/// Adds an element to the vector.
	void push_back(const T &element);

	/// Adds an element to the vector.
	void push_back(T &&element);

	/// Quick erases the element at index by swapping it out with the last
	/// element. Don't use this if you need to maintain the element order.
	void qerase(const size_t i);

	/// Quick removes a value from the vector by swapping it out with the last
	/// element. Deletes only the first element found by \c find(). Don't use
	/// this if you need to maintain the element order.
	/// \param value  The value to remove.
	void qremove(const T &value);

	/// Removes a value from the vector while preserving the order of elements.
	/// Deletes only the first element found by \c find().
	/// \param value  The value to remove.
	void remove(const T &value);

	/// Increases or decreases the capacity of the vector.
	/// \note On failure, the vector will remain untouched.
	/// \param i  The size of the new capacity. If less than the number of
	///           elements in the container, the container is simply tightened.
	void reserve(size_t i);

	/// Returns the number of elements in this vector.
	inline size_t size() const;

	inline bool operator==(const Vector<T> &) const;

	/// Returns the element stored at index.
	inline T& operator[](const size_t i) const;

private:
	T *c_array;       ///< Actual C-array.
	size_t count;     ///< Number of elements in the array.
	size_t reserved;  ///< Size of allocated memory.
};

template<typename T>
Vector<T>::Vector(const size_t reserve)
    : c_array(nullptr), count(0), reserved(0)
{
	this->reserve(reserve);
}

template<typename T>
Vector<T>::Vector(Vector<T> &&v)
    : count(v.count), reserved(v.reserved), c_array(v.c_array)
{
	v.count = 0;
	v.reserved = 0;
	v.c_array = nullptr;
}

template<typename T>
Vector<T>::~Vector()
{
	this->clear();
	operator delete(this->c_array);
}

template<typename T>
T& Vector<T>::at(const size_t i)
{
	return (*this)[i];
}

{'fraction_non_alphanumeric': 0.12021938926771421, 'fraction_numerical': 0.0035576638007708272, 'mean_word_length': 3.3529032258064517, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5789494', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2069, 'n_words': 862}