<commit_before>﻿using System;
using System.Collections.Generic;
using MasDev.Utils;

namespace MasDev.Common
{
	public abstract class ExclusiveAccessDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IExclusiveAccessProvider
	{
		readonly object _lock = new object ();

		public IDisposable StartExclusiveAccess (IIdentifier identifier)
		{
			lock (_lock) {
				return new LockByIdMutex (identifier.Identify);
			}
		}

		public abstract IIdentifier GetIdentifier (TKey key);
	}

	class Identifier<TKey, TValue> : IIdentifier
	{
		const string IdentifierFormat = "{0}_{1}_{2}s";
		readonly string _keyTypeName = typeof(TKey).Name;
		readonly string _valueTypeName = typeof(TValue).Name;
		readonly TKey _keyInstance;

		public Identifier (TKey keyInstance)
		{
			_keyInstance = keyInstance;
		}

		public string Identify {
			get { return string.Format (IdentifierFormat, _keyTypeName, _keyInstance, _valueTypeName); }
		}
	}
}

<commit_msg>odino<commit_after>﻿using System;
using System.Collections.Generic;
using MasDev.Utils;

namespace MasDev.Common
{
	public abstract class ExclusiveAccessDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IExclusiveAccessProvider
	{
		readonly object _lock = new object ();

		public virtual IDisposable StartExclusiveAccess (IIdentifier identifier)
		{
			lock (_lock) {
				return new LockByIdMutex (identifier.Identify);
			}
		}

		public abstract IIdentifier GetIdentifier (TKey key);
	}

	class Identifier<TKey, TValue> : IIdentifier
	{
		const string IdentifierFormat = "{0}_{1}_{2}s";
		readonly string _keyTypeName = typeof(TKey).Name;
		readonly string _valueTypeName = typeof(TValue).Name;
		readonly TKey _keyInstance;

		public Identifier (TKey keyInstance)
		{
			_keyInstance = keyInstance;
		}

		public string Identify {
			get { return string.Format (IdentifierFormat, _keyTypeName, _keyInstance, _valueTypeName); }
		}
	}
}


{'fraction_non_alphanumeric': 0.091005291005291, 'fraction_numerical': 0.0031746031746031746, 'mean_word_length': 4.800613496932515, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6748276', 'n_tokens_mistral': 643, 'n_tokens_neox': 575, 'n_words': 147}