<commit_before>/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 * <EMAIL>. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Apache License, Version 2.0.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace Microsoft.Scripting.Utils {
    public static class ArrayUtils {
        internal sealed class FunctorComparer<T> : IComparer<T> {
            private readonly Comparison<T> _comparison;

            public FunctorComparer(Comparison<T> comparison) {
                Assert.NotNull(comparison);
                _comparison = comparison;
            }

            public int Compare(T x, T y) {
                return _comparison(x, y);
            }
        }

        // Emitted:
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")]
        public static readonly string[] EmptyStrings = new string[0];

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")]
        public static readonly object[] EmptyObjects = new object[0];

        public static IComparer<T> ToComparer<T>(Comparison<T> comparison) {
            return new FunctorComparer<T>(comparison);
        }

        public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] input, Func<TInput, TOutput> conv) {
            ContractUtils.RequiresNotNull(input, "input");
            ContractUtils.RequiresNotNull(conv, "conv");

            TOutput[] res = new TOutput[input.Length];
            for (int i = 0; i < input.Length; i++) {
                res[i] = conv(input[i]);
            }

            return res;
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1814:PreferJaggedArraysOverMultidimensional", MessageId = "1#")] // TODO: fix
        public static void PrintTable(StringBuilder output, string[,] table) {
            ContractUtils.RequiresNotNull(output, "output");
            ContractUtils.RequiresNotNull(table, "table");

            int max_width = 0;
            for (int i = 0; i < table.GetLength(0); i++) {
                if (table[i, 0].Length > max_width) {
                    max_width = table[i, 0].Length;
                }
            }

            for (int i = 0; i < table.GetLength(0); i++) {
                output.Append(" ");
                output.Append(table[i, 0]);<commit_msg>Revert to using System.Converter for ArrayUtils.ConvertAll.<commit_after>/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 * <EMAIL>. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Apache License, Version 2.0.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace Microsoft.Scripting.Utils {
    public static class ArrayUtils {
        internal sealed class FunctorComparer<T> : IComparer<T> {
            private readonly Comparison<T> _comparison;

            public FunctorComparer(Comparison<T> comparison) {
                Assert.NotNull(comparison);
                _comparison = comparison;
            }

            public int Compare(T x, T y) {
                return _comparison(x, y);
            }
        }

        // Emitted:
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")]
        public static readonly string[] EmptyStrings = new string[0];

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")]
        public static readonly object[] EmptyObjects = new object[0];

        public static IComparer<T> ToComparer<T>(Comparison<T> comparison) {
            return new FunctorComparer<T>(comparison);
        }

        public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] input, Converter<TInput, TOutput> conv) {
            ContractUtils.RequiresNotNull(input, "input");
            ContractUtils.RequiresNotNull(conv, "conv");

            TOutput[] res = new TOutput[input.Length];
            for (int i = 0; i < input.Length; i++) {
                res[i] = conv(input[i]);
            }

            return res;
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1814:PreferJaggedArraysOverMultidimensional", MessageId = "1#")] // TODO: fix
        public static void PrintTable(StringBuilder output, string[,] table) {
            ContractUtils.RequiresNotNull(output, "output");
            ContractUtils.RequiresNotNull(table, "table");

            int max_width = 0;
            for (int i = 0; i < table.GetLength(0); i++) {
                if (table[i, 0].Length > max_width) {
                    max_width = table[i, 0].Length;
                }
            }

            for (int i = 0; i < table.GetLength(0); i++) {
                output.Append(" ");
                output.Append(table[i, 0]);
{'fraction_non_alphanumeric': 0.1484984237597478, 'fraction_numerical': 0.009955201592832254, 'mean_word_length': 2.6160767846430715, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, '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': '5821712', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1509, 'n_words': 456}