<commit_before>﻿using ObjectPool.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ObjectPool
{
    /// <summary>
    /// An object pool instance.
    /// </summary>
    /// <typeparam name="T">The type of object to store in this pool</typeparam>
    public sealed class Pool<T> : IDisposable where T : class
    {
        readonly IObjectStore<T> store_;
        readonly LoadingMode loadingMode_;
        readonly Func<T> instanceFactory_;
        readonly Semaphore sync_;

        int size_;
        int count_;

        /// <summary>
        /// Creates a new instance of <see cref="Pool{T}"/>
        /// </summary>
        /// <param name="size">The size of the pool</param>
        /// <param name="loadingMode">The loading mode the pool should use</param>
        /// <param name="accessMode">The access mode the pool should use</param>
        /// <param name="instanceFactory">An delegate that builds instances of <see cref="T"/> </param>
        public Pool(int size, LoadingMode loadingMode, AccessMode accessMode, Func<T> instanceFactory)
        {
            if (size <= 0) throw new ArgumentOutOfRangeException("size must be greater than 0!");
            if (instanceFactory == null) throw new ArgumentNullException("instanceFactory");

            size_ = size;
            loadingMode_ = loadingMode;
            instanceFactory_ = instanceFactory;
            sync_ = new Semaphore(size_, size_);
            store_ = CreateStore(accessMode, size_);

            if (loadingMode == LoadingMode.Eager)
            {
                PreLoad();
            }
        }

        #region private static members
        /// <summary>
        /// Creates an underlying store instance
        /// </summary>
        /// <param name="mode">The access mode that the store should use</param>
        /// <param name="capacity">The capacity of the store</param>
        /// <returns></returns>
        private static IObjectStore<T> CreateStore(AccessMode mode, int capacity)
        {
            switch (mode)
            {
                case AccessMode.Fifo:
                    return new QueueStore<T>(capacity);
                case AccessMode.Lifo:
                    return new StackStore<T>(capacity);
                default:
                    return new CircularStore<T>(capacity);
            }
        } 
        #endregion

        #region private instance members

        /// <summary>
        /// Eagrely acquires an instance of T
        /// </summary>
        /// <returns></returns>
        private T AcquireEagre()<commit_msg>added a missing 'case' statement<commit_after>﻿using ObjectPool.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ObjectPool
{
    /// <summary>
    /// An object pool instance.
    /// </summary>
    /// <typeparam name="T">The type of object to store in this pool</typeparam>
    public sealed class Pool<T> : IDisposable where T : class
    {
        readonly IObjectStore<T> store_;
        readonly LoadingMode loadingMode_;
        readonly Func<T> instanceFactory_;
        readonly Semaphore sync_;

        int size_;
        int count_;

        /// <summary>
        /// Creates a new instance of <see cref="Pool{T}"/>
        /// </summary>
        /// <param name="size">The size of the pool</param>
        /// <param name="loadingMode">The loading mode the pool should use</param>
        /// <param name="accessMode">The access mode the pool should use</param>
        /// <param name="instanceFactory">An delegate that builds instances of <see cref="T"/> </param>
        public Pool(int size, LoadingMode loadingMode, AccessMode accessMode, Func<T> instanceFactory)
        {
            if (size <= 0) throw new ArgumentOutOfRangeException("size must be greater than 0!");
            if (instanceFactory == null) throw new ArgumentNullException("instanceFactory");

            size_ = size;
            loadingMode_ = loadingMode;
            instanceFactory_ = instanceFactory;
            sync_ = new Semaphore(size_, size_);
            store_ = CreateStore(accessMode, size_);

            if (loadingMode == LoadingMode.Eager)
            {
                PreLoad();
            }
        }

        #region private static members
        /// <summary>
        /// Creates an underlying store instance
        /// </summary>
        /// <param name="mode">The access mode that the store should use</param>
        /// <param name="capacity">The capacity of the store</param>
        /// <returns></returns>
        private static IObjectStore<T> CreateStore(AccessMode mode, int capacity)
        {
            switch (mode)
            {
                case AccessMode.Fifo:
                    return new QueueStore<T>(capacity);
                case AccessMode.Lifo:
                    return new StackStore<T>(capacity);
                case AccessMode.Circular:
                default:
                    return new CircularStore<T>(capacity);
            }
        } 
        #endregion

        #region private instance members

        /// <summary>
        /// Eagrely acquires an instance of T
        /// </summary>
        /// <returns></returns>
        private T AcquireEagre()
{'fraction_non_alphanumeric': 0.10775782262543973, 'fraction_numerical': 0.0007406035919274209, 'mean_word_length': 1.9168466522678185, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 75, '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': '7423183', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1327, 'n_words': 419}