<commit_before>/** @file
	
	@ingroup jamoma2
	
	@brief Read and write items within a circular container.
	
	@author <NAME>, <NAME>
	
	@copyright Copyright © 2015 by Jamoma authors and contributors @n
	This code is licensed under the terms of the "BSD 3-Clause License" @n
	https://github.com/jamoma/jamoma2/blob/master/LICENSE.md @n
 */

#pragma once

#include <thread>
#include <cassert>

namespace Jamoma {

	
	/**	A generic circular buffer designed specifically for access from a single thread.
	 
		Allows items of a single datatype to be written into a vector that wraps around to the beginning whenever the end is exceeded.
		Reading items from the vector can then return chunks of the N most recent items.
		The initial design of this class was for use as an audio sample delay buffer, 
		however it's functionality has been generalized to allow for other datatypes and applications.
	 */
	template <class T>
	class CircularStorage {
		friend class CircularStorageTest;
		
		std::vector<T>		mItems;										///< storage for the circular buffer's data
		std::size_t			mIndex = { 0 };								///< location of the record head
		std::size_t			mSize;										///< the size of the circular buffer (may be different from the amount of allocated storage)
		std::thread::id		mThread = { std::this_thread::get_id() };	///< used to ensure we don't access unsafely from multiple threads
	
	public:
		/** Constructor specifies a fixed amount of storage for the container.
			If you want a different amount of storage, create a new container and dispose of the one you don't want.
		 */
		CircularStorage(std::size_t itemCount)
		: mItems(itemCount)
		, mSize(itemCount)
		{}
		
		<commit_msg>CircularStorage: new ctor overload so that size can be specified in addition to capacity. Implemented using a std::pair so that this can be passed as a single arg from e.g. a std::vector resize() call.<commit_after>/** @file
	
	@ingroup jamoma2
	
	@brief Read and write items within a circular container.
	
	@author <NAME>, <NAME>
	
	@copyright Copyright © 2015 by Jamoma authors and contributors @n
	This code is licensed under the terms of the "BSD 3-Clause License" @n
	https://github.com/jamoma/jamoma2/blob/master/LICENSE.md @n
 */

#pragma once

#include <thread>
#include <cassert>

namespace Jamoma {

	
	/**	A generic circular buffer designed specifically for access from a single thread.
	 
		Allows items of a single datatype to be written into a vector that wraps around to the beginning whenever the end is exceeded.
		Reading items from the vector can then return chunks of the N most recent items.
		The initial design of this class was for use as an audio sample delay buffer, 
		however it's functionality has been generalized to allow for other datatypes and applications.
	 */
	template <class T>
	class CircularStorage {
		friend class CircularStorageTest;
		
		std::vector<T>		mItems;										///< storage for the circular buffer's data
		std::size_t			mIndex = { 0 };								///< location of the record head
		std::size_t			mSize;										///< the size of the circular buffer (may be different from the amount of allocated storage)
		std::thread::id		mThread = { std::this_thread::get_id() };	///< used to ensure we don't access unsafely from multiple threads
	
	public:
		/** Constructor specifies a fixed amount of storage for the container.
			If you want a different amount of storage, create a new container and dispose of the one you don't want.
		 */
		CircularStorage(std::size_t itemCount)
		: mItems(itemCount)
		, mSize(itemCount)
		{}


		CircularStorage(std::pair<size_t, size_t> capacityAndSize)
		: mItems(capacityAndSize.first)
		, mSize(capacityAndSize.second)
		{}

		
{'fraction_non_alphanumeric': 0.07733910221741482, 'fraction_numerical': 0.004326663061114116, 'mean_word_length': 3.566666666666667, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 16, 'https://': 2, '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': '3815622', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1024, 'n_words': 470}