<commit_before>﻿using System;
using System.Runtime.CompilerServices;
using Ruzzie.Common.Hashing;

namespace Ruzzie.Mtg.Core
{
    /// <summary>
    /// Helper methods for key generation.
    /// </summary>
    public static class KeyHelpers
    {
        private static readonly FNV1AHashAlgorithm64 HashAlgo64 = new FNV1AHashAlgorithm64();

        /// <summary>
        /// Creates a valid string based row key. The input value will be upper cased and // will be replaced by underscores
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="forwardSlashesReplaceValue"></param>
        /// <returns></returns>
        public static string CreateValidUpperCaseKeyForString(this string value, string forwardSlashesReplaceValue = "_")
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(value));
            }
            if (string.IsNullOrWhiteSpace(forwardSlashesReplaceValue))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(forwardSlashesReplaceValue));
            }

            return value.Replace("/", "_").ToUpperInvariant();
        }

        /// <summary>
        /// Generates the bidirectional key for two card name comparisons. the strings are first put through the <see cref="CreateValidUpperCaseKeyForString"/> function.
        /// </summary>
        /// <param name="firstString">The first string.</param>
        /// <param name="secondString">The second string.</param>
        /// <returns></returns>
        public static ulong GenerateBidirectonalKeyForTwoCardNameComparisons(this string firstString, string secondString)
        {
            return GenerateBidirectonalKeyForTwoStringComparisons(firstString.CreateValidUpperCaseKeyForString(),
                secondString.CreateValidUpperCaseKeyForString());
        }

        /// <summary>
        /// Generates the bidirectional key for two string comparisons.
        /// </summary>
        /// <param name="firstString">The first string.</param>
        /// <param name="secondString">The second string.</param>
        /// <returns></returns>
        public static ulong GenerateBidirectonalKeyForTwoStringComparisons(this string firstString, string secondString)
        {
            ulong firstStringHash = firstString.GenerateHash64ForStringCaseInsensitive();
            ulong secondStringHash = secondString.GenerateHash64ForStringCaseInsensitive();
            return firstStringHash.GenerateBidirectonalKeyForTwoULongs(secondStringHash);
        }

        /// <summary>
        /// Generates the bidirectional key for two u longs.
        /// </summary>
        /// <param name="firstUlong">The first ulong.</param>
        /// <param name="secondUlong">The second ulong.</param>
        /// <returns></returns>
#if !PORTABLE
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
        public static ulong GenerateBidirectonalKeyForTwoULongs(this ulong firstUlong, ulong secondUlong)
        {
            unchecked
            {
                return ((firstUlong * secondUlong) ^ secondUlong) ^ firstUlong;
            }
        }

        /// <summary>
        /// Generates the hash64 for string case insensitive.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
#if !PORTABLE
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
        public static ulong GenerateHash64ForStringCaseInsensitive(this string value )
        {
            return (ulong) HashAlgo64.HashStringCaseInsensitive(value);
        }
    }
}
<commit_msg>- fixed possible bug forwardSlashesReplaceValue parameter wasn't used<commit_after>﻿using System;
using System.Runtime.CompilerServices;
using Ruzzie.Common.Hashing;

namespace Ruzzie.Mtg.Core
{
    /// <summary>
    /// Helper methods for key generation.
    /// </summary>
    public static class KeyHelpers
    {
        private static readonly FNV1AHashAlgorithm64 HashAlgo64 = new FNV1AHashAlgorithm64();

        /// <summary>
        /// Creates a valid string based row key. The input value will be upper cased and // will be replaced by underscores
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="forwardSlashesReplaceValue"></param>
        /// <returns></returns>
        public static string CreateValidUpperCaseKeyForString(this string value, string forwardSlashesReplaceValue = "_")
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(value));
            }
            if (string.IsNullOrWhiteSpace(forwardSlashesReplaceValue))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(forwardSlashesReplaceValue));
            }

            return value.Replace("/", forwardSlashesReplaceValue).ToUpperInvariant();
        }

        /// <summary>
        /// Generates the bidirectional key for two card name comparisons. the strings are first put through the <see cref="CreateValidUpperCaseKeyForString"/> function.
        /// </summary>
        /// <param name="firstString">The first string.</param>
        /// <param name="secondString">The second string.</param>
        /// <returns></returns>
        public static ulong GenerateBidirectonalKeyForTwoCardNameComparisons(this string firstString, string secondString)
        {
            return GenerateBidirectonalKeyForTwoStringComparisons(firstString.CreateValidUpperCaseKeyForString(),
                secondString.CreateValidUpperCaseKeyForString());
        }

        /// <summary>
        /// Generates the bidirectional key for two string comparisons.
        /// </summary>
        /// <param name="firstString">The first string.</param>
        /// <param name="secondString">The second string.</param>
        /// <returns></returns>
        public static ulong GenerateBidirectonalKeyForTwoStringComparisons(this string firstString, string secondString)
        {
            ulong firstStringHash = firstString.GenerateHash64ForStringCaseInsensitive();
            ulong secondStringHash = secondString.GenerateHash64ForStringCaseInsensitive();
            return firstStringHash.GenerateBidirectonalKeyForTwoULongs(secondStringHash);
        }

        /// <summary>
        /// Generates the bidirectional key for two u longs.
        /// </summary>
        /// <param name="firstUlong">The first ulong.</param>
        /// <param name="secondUlong">The second ulong.</param>
        /// <returns></returns>
#if !PORTABLE
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
        public static ulong GenerateBidirectonalKeyForTwoULongs(this ulong firstUlong, ulong secondUlong)
        {
            unchecked
            {
                return ((firstUlong * secondUlong) ^ secondUlong) ^ firstUlong;
            }
        }

        /// <summary>
        /// Generates the hash64 for string case insensitive.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
#if !PORTABLE
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
        public static ulong GenerateHash64ForStringCaseInsensitive(this string value )
        {
            return (ulong) HashAlgo64.HashStringCaseInsensitive(value);
        }
    }
}

{'fraction_non_alphanumeric': 0.10492761322884846, 'fraction_numerical': 0.00478151148890955, 'mean_word_length': 2.4274010013654985, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 85, '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': '7312979', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1869, 'n_words': 463}