<commit_before>﻿namespace Georadix.Core
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Enumerates the different types of interval endpoints.
    /// </summary>
    public enum EndpointType
    {
        /// <summary>
        /// Open endpoint.
        /// </summary>
        Open,

        /// <summary>
        /// Closed endpoint.
        /// </summary>
        Closed,

        /// <summary>
        /// Unbounded endpoint.
        /// </summary>
        Unbounded
    }

    /// <summary>
    /// Represents a set of values.
    /// </summary>
    /// <typeparam name="T">The type of value in the interval.</typeparam>
    public class Interval<T>
        : IComparable, IComparable<Interval<T>>, IEquatable<Interval<T>> where T : struct, IComparable<T>
    {
        private int endpoints;
        private T? left;
        private T? right;

        /// <summary>
        /// Initializes a new instance of the <see cref="Interval{T}"/> class.
        /// </summary>
        /// <param name="left">The left endpoint.</param>
        /// <param name="leftType">The left endpoint type.</param>
        /// <param name="right">The right endpoint.</param>
        /// <param name="rightType">The right endpoint type.</param>
        /// <exception cref="ArgumentException">The interval is empty.</exception>
        private Interval(T? left, EndpointType leftType, T? right, EndpointType rightType)
        {
            CloseEndpoint(ref left, ref leftType, 1);
            CloseEndpoint(ref right, ref rightType, -1);

            if ((left.HasValue && right.HasValue) &&
                IsEmpty(left.Value, leftType == EndpointType.Closed, right.Value, rightType == EndpointType.Closed))
            {
                throw new ArgumentException("The interval cannot be empty.");
            }

            this.left = left;
            this.right = right;
            this.endpoints =
                (leftType == EndpointType.Closed ? 0x1 : 0) | (rightType == EndpointType.Closed ? 0x2 : 0);
        }

        /// <summary>
        /// Gets the left endpoint.
        /// </summary>
        /// <value>
        /// The left endpoint.
        /// </value>
        public T? Left
        {
            get { return this.left; }
        }

        /// <summary>
        /// Gets the left endpoint type.
        /// </summary>
        /// <value>
        /// The left endpoint type.
        /// </value>
        public EndpointType LeftType
        {
            get
            {
                return this.Left.HasValue ?
                    ((this.endpoints & 0x1) != 0 ? EndpointType.Closed : EndpointType.Open) : EndpointType.Unbounded;
            }
        }

        /// <summary>
        /// Gets the right endpoint.
        /// </summary>
        /// <value>
        /// The right endpoint.
        /// </value>
        public T? Right
        {
            get { return this.right; }
        }

        /// <summary>
        /// Gets the right endpoint type.
        /// </summary>
        /// <value>
        /// The right endpoint type.
        /// </value>
        public EndpointType RightType
        {
            get
            {
                return this.Right.HasValue ?
                    ((this.endpoints & 0x2) != 0 ? EndpointType.Closed : EndpointType.Open) : EndpointType.Unbounded;
            }
        }

        /// <summary>
        /// Initializes a new bounded instance of the <see cref="Interval{T}"/> class.
        /// </summary>
        /// <param name="left">The left endpoint.</param>
        /// <param name="isLeftClosed">A value indicating whether the left endpoint is closed.</param>
        /// <param name="right">The right.</param>
        /// <param name="isRightClosed">A value indicating whether the right endpoint is closed.</param>
        /// <returns>An <see cref="Interval{T}"/> instance.</returns>
        public static Interval<T> Bounded(T left, bool isLeftClosed, T right, bool isRightClosed)
        {
            return new Interval<T>(
                left,
                isLeftClosed ? EndpointType.Closed : EndpointType.Open,
                right,
                isRightClosed ? EndpointType.Closed : EndpointType.Open);
        }

        /// <summary>
        /// Combines a set of intervals into one.<commit_msg>Removed value doc tags.<commit_after>﻿namespace Georadix.Core
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Enumerates the different types of interval endpoints.
    /// </summary>
    public enum EndpointType
    {
        /// <summary>
        /// Open endpoint.
        /// </summary>
        Open,

        /// <summary>
        /// Closed endpoint.
        /// </summary>
        Closed,

        /// <summary>
        /// Unbounded endpoint.
        /// </summary>
        Unbounded
    }

    /// <summary>
    /// Represents a set of values.
    /// </summary>
    /// <typeparam name="T">The type of value in the interval.</typeparam>
    public class Interval<T>
        : IComparable, IComparable<Interval<T>>, IEquatable<Interval<T>> where T : struct, IComparable<T>
    {
        private int endpoints;
        private T? left;
        private T? right;

        /// <summary>
        /// Initializes a new instance of the <see cref="Interval{T}"/> class.
        /// </summary>
        /// <param name="left">The left endpoint.</param>
        /// <param name="leftType">The left endpoint type.</param>
        /// <param name="right">The right endpoint.</param>
        /// <param name="rightType">The right endpoint type.</param>
        /// <exception cref="ArgumentException">The interval is empty.</exception>
        private Interval(T? left, EndpointType leftType, T? right, EndpointType rightType)
        {
            CloseEndpoint(ref left, ref leftType, 1);
            CloseEndpoint(ref right, ref rightType, -1);

            if ((left.HasValue && right.HasValue) &&
                IsEmpty(left.Value, leftType == EndpointType.Closed, right.Value, rightType == EndpointType.Closed))
            {
                throw new ArgumentException("The interval cannot be empty.");
            }

            this.left = left;
            this.right = right;
            this.endpoints =
                (leftType == EndpointType.Closed ? 0x1 : 0) | (rightType == EndpointType.Closed ? 0x2 : 0);
        }

        /// <summary>
        /// Gets the left endpoint.
        /// </summary>
        public T? Left
        {
            get { return this.left; }
        }

        /// <summary>
        /// Gets the left endpoint type.
        /// </summary>
        public EndpointType LeftType
        {
            get
            {
                return this.Left.HasValue ?
                    ((this.endpoints & 0x1) != 0 ? EndpointType.Closed : EndpointType.Open) : EndpointType.Unbounded;
            }
        }

        /// <summary>
        /// Gets the right endpoint.
        /// </summary>
        public T? Right
        {
            get { return this.right; }
        }

        /// <summary>
        /// Gets the right endpoint type.
        /// </summary>
        public EndpointType RightType
        {
            get
            {
                return this.Right.HasValue ?
                    ((this.endpoints & 0x2) != 0 ? EndpointType.Closed : EndpointType.Open) : EndpointType.Unbounded;
            }
        }

        /// <summary>
        /// Initializes a new bounded instance of the <see cref="Interval{T}"/> class.
        /// </summary>
        /// <param name="left">The left endpoint.</param>
        /// <param name="isLeftClosed">A value indicating whether the left endpoint is closed.</param>
        /// <param name="right">The right.</param>
        /// <param name="isRightClosed">A value indicating whether the right endpoint is closed.</param>
        /// <returns>An <see cref="Interval{T}"/> instance.</returns>
        public static Interval<T> Bounded(T left, bool isLeftClosed, T right, bool isRightClosed)
        {
            return new Interval<T>(
                left,
                isLeftClosed ? EndpointType.Closed : EndpointType.Open,
                right,
                isRightClosed ? EndpointType.Closed : EndpointType.Open);
        }

        /// <summary>
        /// Combines a set of intervals into one.
{'fraction_non_alphanumeric': 0.13165365507452093, 'fraction_numerical': 0.0033120416370948664, 'mean_word_length': 1.5171181899374815, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 123, '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': '2949373', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2193, 'n_words': 602}