<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

namespace Hapil
{
	internal class UniqueNameSet
	{
		private readonly HashSet<string> m_NamesInUse;
		private int m_UniqueNumericSuffix;

		//-----------------------------------------------------------------------------------------------------------------------------------------------------

		public UniqueNameSet()
		{
			m_NamesInUse = new HashSet<string>();
			m_UniqueNumericSuffix = 0;
		}

		//-----------------------------------------------------------------------------------------------------------------------------------------------------

		public string TakeUniqueName(string proposedName, bool mustUseThisName = false)
		{
			string uniqueName;

			if ( m_NamesInUse.Add(proposedName) || mustUseThisName )
			{
				uniqueName = proposedName;
			}
			else
			{
				uniqueName = proposedName + Interlocked.Increment(ref m_UniqueNumericSuffix);
				m_NamesInUse.Add(uniqueName);
			}

			return uniqueName;
		}
	}
}<commit_msg>Bugfix: missed concurrent access synchronization in UniqueNameSet.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

namespace Hapil
{
	internal class UniqueNameSet
	{
        private readonly object m_SyncRoot;
        private readonly HashSet<string> m_NamesInUse;
		private int m_UniqueNumericSuffix;

		//-----------------------------------------------------------------------------------------------------------------------------------------------------

		public UniqueNameSet()
		{
            m_SyncRoot = new object();
			m_NamesInUse = new HashSet<string>();
			m_UniqueNumericSuffix = 0;
		}

		//-----------------------------------------------------------------------------------------------------------------------------------------------------

		public string TakeUniqueName(string proposedName, bool mustUseThisName = false)
		{
			string uniqueName;

		    lock ( m_SyncRoot )
		    {
		        if ( m_NamesInUse.Add(proposedName) || mustUseThisName )
		        {
		            uniqueName = proposedName;
		        }
		        else
		        {
		            uniqueName = proposedName + Interlocked.Increment(ref m_UniqueNumericSuffix);
		            m_NamesInUse.Add(uniqueName);
		        }
		    }

		    return uniqueName;
		}
	}
}
{'fraction_non_alphanumeric': 0.30659025787965616, 'fraction_numerical': 0.0008186655751125665, 'mean_word_length': 1.3122043519394513, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5368957', 'n_tokens_mistral': 668, 'n_tokens_neox': 568, 'n_words': 121}