<commit_before>/*
Copyright (c) 2013 <NAME>, <NAME>
Copyright (c) 2012 <NAME>, <NAME>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#pragma once

#include "Allocator.h"
#include "Types.h"
#include "Assert.h"

namespace crown
{

/// Dynamic array of objects.
/// @note
/// Calls constructors and destructors, not suitable for performance-critical stuff.
/// If your data is POD, use List<T> instead.
template <typename T>
class Vector
{
public:

	/// Does not allocate memory.
						Vector(Allocator& allocator);

	/// Allocates capacity * sizeof(T) bytes.
						Vector(Allocator& allocator, uint32_t capacity);
						Vector(const Vector<T>& other);
						~Vector();

	/// Random access by index
	T&					operator[](uint32_t index);

	/// Random access by index
	const T&			operator[](uint32_t index) const;

	/// Returns whether the vector is empty
	bool				empty() const;

	/// Returns the number of items in the vector
	uint32_t			size() const;

	/// Returns the maximum number of items the array can hold
	uint32_t			capacity() const;

	/// Resizes the vector to the given @a size.
	/// @note
	/// Old items will be copied to the newly created vector.
	/// If the new capacity is smaller than the previous one, the
	/// vector will be truncated.
	void				resize(uint32_t size);

	/// Reserves space in the vector for at least @a capacity items.
	void				reserve(uint32_t capacity);

	/// Sets the vector capacity
	void				set_capacity(uint32_t capacity);

	/// Grows the vector to contain at least @a min_capacity items
	void				grow(uint32_t min_capacity);

	/// Condenses the array so that the capacity matches the actual number
	/// of items in the vector.
	void				condense();

	/// Appends an item to the vector and returns its index.
	uint32_t			push_back(const T& item);

	/// Removes the last item from the vector.
	void				pop_back();

	/// Appends @a count @a items to the vector and returns the number
	/// of items in the vector after the append operation.
	uint32_t			push(const T* items, uint32_t count);

	/// Clears the content of the vector.
	/// @note
	/// Does not free memory nor call destructors, it only zeroes
	/// the number of items in the vector for efficiency.
	void				clear();

	/// Copies the content of the @a other vector into this one.
	const Vector<T>&		operator=(const Vector<T>& other);

	T*					begin();
	const T*			begin() const;
	T*					end();
	const T*			end() const;

	T&					front();
	const T&			front() const;
	T&					back();
	const T&			back() const;

private:

	Allocator*			m_allocator;
	uint32_t			m_capacity;
	uint32_t			m_size;
	T*					m_array;
};

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::Vector(Allocator& allocator)
	: m_allocator(allocator), m_capacity(0), m_size(0), m_array(NULL)
{
}

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::Vector(Allocator& allocator, uint32_t capacity)
	: m_allocator(allocator), m_capacity(0), m_size(0), m_array(NULL)
{
	resize(capacity);
}

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::Vector(const Vector<T>& other)
	: m_allocator(other.m_allocator), m_capacity(0), m_size(0), m_array(NULL)
{
	*this = other;
}

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::~Vector()
{
	if (m_array)
	{
		for (uint32_t i = 0; i < m_size; i++)
		{
			m_array[i].~T();
		}
		m_allocator->deallocate(m_array);
	}
}<commit_msg>Fix missing & in vector initialization list<commit_after>/*
Copyright (c) 2013 <NAME>, <NAME>
Copyright (c) 2012 <NAME>, <NAME>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#pragma once

#include "Allocator.h"
#include "Types.h"
#include "Assert.h"

namespace crown
{

/// Dynamic array of objects.
/// @note
/// Calls constructors and destructors, not suitable for performance-critical stuff.
/// If your data is POD, use List<T> instead.
template <typename T>
class Vector
{
public:

	/// Does not allocate memory.
						Vector(Allocator& allocator);

	/// Allocates capacity * sizeof(T) bytes.
						Vector(Allocator& allocator, uint32_t capacity);
						Vector(const Vector<T>& other);
						~Vector();

	/// Random access by index
	T&					operator[](uint32_t index);

	/// Random access by index
	const T&			operator[](uint32_t index) const;

	/// Returns whether the vector is empty
	bool				empty() const;

	/// Returns the number of items in the vector
	uint32_t			size() const;

	/// Returns the maximum number of items the array can hold
	uint32_t			capacity() const;

	/// Resizes the vector to the given @a size.
	/// @note
	/// Old items will be copied to the newly created vector.
	/// If the new capacity is smaller than the previous one, the
	/// vector will be truncated.
	void				resize(uint32_t size);

	/// Reserves space in the vector for at least @a capacity items.
	void				reserve(uint32_t capacity);

	/// Sets the vector capacity
	void				set_capacity(uint32_t capacity);

	/// Grows the vector to contain at least @a min_capacity items
	void				grow(uint32_t min_capacity);

	/// Condenses the array so that the capacity matches the actual number
	/// of items in the vector.
	void				condense();

	/// Appends an item to the vector and returns its index.
	uint32_t			push_back(const T& item);

	/// Removes the last item from the vector.
	void				pop_back();

	/// Appends @a count @a items to the vector and returns the number
	/// of items in the vector after the append operation.
	uint32_t			push(const T* items, uint32_t count);

	/// Clears the content of the vector.
	/// @note
	/// Does not free memory nor call destructors, it only zeroes
	/// the number of items in the vector for efficiency.
	void				clear();

	/// Copies the content of the @a other vector into this one.
	const Vector<T>&		operator=(const Vector<T>& other);

	T*					begin();
	const T*			begin() const;
	T*					end();
	const T*			end() const;

	T&					front();
	const T&			front() const;
	T&					back();
	const T&			back() const;

private:

	Allocator*			m_allocator;
	uint32_t			m_capacity;
	uint32_t			m_size;
	T*					m_array;
};

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::Vector(Allocator& allocator)
	: m_allocator(&allocator), m_capacity(0), m_size(0), m_array(NULL)
{
}

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::Vector(Allocator& allocator, uint32_t capacity)
	: m_allocator(&allocator), m_capacity(0), m_size(0), m_array(NULL)
{
	resize(capacity);
}

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::Vector(const Vector<T>& other)
	: m_allocator(other.m_allocator), m_capacity(0), m_size(0), m_array(NULL)
{
	*this = other;
}

//-----------------------------------------------------------------------------
template <typename T>
inline Vector<T>::~Vector()
{
	if (m_array)
	{
		for (uint32_t i = 0; i < m_size; i++)
		{
			m_array[i].~T();
		}
		m_allocator->deallocate(m_array);
	}
}
{'fraction_non_alphanumeric': 0.16358293426208098, 'fraction_numerical': 0.01023073574227253, 'mean_word_length': 2.7007652033830043, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '794801', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2661, 'n_words': 1097}