<commit_before>﻿using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace LinqStatistics
{
    static class BinFactory
    {
        public static IEnumerable<Bin> CreateBins(double min, double max, int binCount, BinningMode mode)
        {
            if (binCount <= 0)
                throw new InvalidOperationException("binCount must be greater than 0");
            
            if (mode == BinningMode.Unbounded)
            {
                return CreateBinsUnbounded(min, max, binCount);
            }

            if (mode == BinningMode.ExpandRange)
            {
                return CreateBinsExpandRange(min, max, binCount);
            }

            Debug.Assert(mode == BinningMode.MaxValueInclusive);
            return CreateBinsMaxInclusive(min, max, binCount);
        }

        private static IEnumerable<Bin> CreateBinsMaxInclusive(double min, double max, int binCount)
        {            
            double binSize = (max - min) / (double)binCount;
            double halfBin = binSize / 2.0;
            double rangeMin = min;
            double rangeMax = rangeMin + binSize;

            // first create a list of all the bins so even empty bins are accounted for
            List<Bin> bins = new List<Bin>(binCount);
            for (int i = 0; i < binCount; i++)
            {
                if (i == binCount - 1)
                {
                    // we can get some floating point noise as the ranges are calculated to ensure that the last bin encompasses the max value
                    bins.Add(new Bin(rangeMin + halfBin, rangeMin, max, true)); // set the last bin to be maxInclusive
                }
                else
                {
                    bins.Add(new Bin(rangeMin + halfBin, rangeMin, rangeMax)); 
                }
                rangeMin += binSize;
                rangeMax += binSize;
            }

            return bins;
        }

        private static IEnumerable<Bin> CreateBinsUnbounded(double min, double max, int binCount)
        {
            double binSize = (max - min) / (double)binCount;
            double halfBin = binSize / 2.0;
            double rangeMin = min;
            double rangeMax = rangeMin + binSize;

            // first create a list of all the bins so even empty bins are accounted for
            List<Bin> bins = new List<Bin>(binCount);
            for (int i = 0; i < binCount; i++)<commit_msg>remove unnnecessary casts<commit_after>﻿using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace LinqStatistics
{
    static class BinFactory
    {
        public static IEnumerable<Bin> CreateBins(double min, double max, int binCount, BinningMode mode)
        {
            if (binCount <= 0)
                throw new InvalidOperationException("binCount must be greater than 0");
            
            if (mode == BinningMode.Unbounded)
            {
                return CreateBinsUnbounded(min, max, binCount);
            }

            if (mode == BinningMode.ExpandRange)
            {
                return CreateBinsExpandRange(min, max, binCount);
            }

            Debug.Assert(mode == BinningMode.MaxValueInclusive);
            return CreateBinsMaxInclusive(min, max, binCount);
        }

        private static IEnumerable<Bin> CreateBinsMaxInclusive(double min, double max, int binCount)
        {            
            double binSize = (max - min) / binCount;
            double halfBin = binSize / 2.0;
            double rangeMin = min;
            double rangeMax = rangeMin + binSize;

            // first create a list of all the bins so even empty bins are accounted for
            List<Bin> bins = new List<Bin>(binCount);
            for (int i = 0; i < binCount; i++)
            {
                if (i == binCount - 1)
                {
                    // we can get some floating point noise as the ranges are calculated to ensure that the last bin encompasses the max value
                    bins.Add(new Bin(rangeMin + halfBin, rangeMin, max, true)); // set the last bin to be maxInclusive
                }
                else
                {
                    bins.Add(new Bin(rangeMin + halfBin, rangeMin, rangeMax)); 
                }
                rangeMin += binSize;
                rangeMax += binSize;
            }

            return bins;
        }

        private static IEnumerable<Bin> CreateBinsUnbounded(double min, double max, int binCount)
        {
            double binSize = (max - min) / binCount;
            double halfBin = binSize / 2.0;
            double rangeMin = min;
            double rangeMax = rangeMin + binSize;

            // first create a list of all the bins so even empty bins are accounted for
            List<Bin> bins = new List<Bin>(binCount);
            for (int i = 0; i < binCount; i++)
{'fraction_non_alphanumeric': 0.07799671592775041, 'fraction_numerical': 0.003694581280788177, 'mean_word_length': 1.5934007450771688, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, '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': '7298484', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1204, 'n_words': 413}