<commit_before>﻿#region License
/*********************************************************************************
 * PMap.cs
 *
 * Copyright (c) 2004-2019 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
**********************************************************************************/
#endregion

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Eutherion.Win.Storage
{
    /// <summary>
    /// Represents a read-only map of string keys onto <see cref="PValue"/>s.
    /// </summary>
    public class PMap : IReadOnlyDictionary<string, PValue>, PValue
    {
        // Prevent repeated allocations of empty dictionaries.
        private static readonly Dictionary<string, PValue> emptyMap = new Dictionary<string, PValue>();

        private readonly Dictionary<string, PValue> map;

        /// <summary>
        /// Initializes a new instance of <see cref="PMap"/>.
        /// </summary>
        /// <param name="map">
        /// The map which contains the key-value pairs to construct this <see cref="PMap"/> with.
        /// </param>
        /// <exception cref="ArgumentException">
        /// <paramref name="map"/> contains one or more duplicate keys.
        /// </exception>
        public PMap(IDictionary<string, PValue> map)
        {
            this.map = map != null && map.Count > 0
                ? new Dictionary<string, PValue>(map)
                : emptyMap;
        }

        /// <summary>
        /// Gets the <see cref="PValue"/> associated with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to locate.
        /// </param>
        /// <returns>
        /// The value associated with the specified key.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="key"/> is null.
        /// </exception>
        /// <exception cref="KeyNotFoundException">
        /// The key does not exist.
        /// </exception>
        public PValue this[string key] => map[key];

        /// <summary>
        /// Gets the number of key-value pairs in this <see cref="PMap"/>.<commit_msg>Disallow null map parameter in PMap constructor.<commit_after>﻿#region License
/*********************************************************************************
 * PMap.cs
 *
 * Copyright (c) 2004-2019 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
**********************************************************************************/
#endregion

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Eutherion.Win.Storage
{
    /// <summary>
    /// Represents a read-only map of string keys onto <see cref="PValue"/>s.
    /// </summary>
    public class PMap : IReadOnlyDictionary<string, PValue>, PValue
    {
        // Prevent repeated allocations of empty dictionaries.
        private static readonly Dictionary<string, PValue> emptyMap = new Dictionary<string, PValue>();

        private readonly Dictionary<string, PValue> map;

        /// <summary>
        /// Initializes a new instance of <see cref="PMap"/>.
        /// </summary>
        /// <param name="map">
        /// The map which contains the key-value pairs to construct this <see cref="PMap"/> with.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="map"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="map"/> contains one or more duplicate keys.
        /// </exception>
        public PMap(IDictionary<string, PValue> map)
        {
            if (map == null) throw new ArgumentNullException(nameof(map));

            this.map = map.Count > 0
                ? new Dictionary<string, PValue>(map)
                : emptyMap;
        }

        /// <summary>
        /// Gets the <see cref="PValue"/> associated with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to locate.
        /// </param>
        /// <returns>
        /// The value associated with the specified key.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="key"/> is null.
        /// </exception>
        /// <exception cref="KeyNotFoundException">
        /// The key does not exist.
        /// </exception>
        public PValue this[string key] => map[key];

        /// <summary>
        /// Gets the number of key-value pairs in this <see cref="PMap"/>.
{'fraction_non_alphanumeric': 0.17774617845716317, 'fraction_numerical': 0.004621400639886242, 'mean_word_length': 2.271511627906977, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6484986', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1378, 'n_words': 498}