Commit 4a896c51 authored by An Ionescu's avatar An Ionescu

Tidying BiMap. Adding class for tracing debug info, since NUnit and its...

Tidying BiMap. Adding class for tracing debug info, since NUnit and its adapter are very good at swallowing up any potential ways of printing debug info.
parent 5960059b
......@@ -26,9 +26,6 @@ namespace Anvoker.Collections.Maps
private Dictionary<TKey, TVal> dictFwd;
private Dictionary<TVal, HashSet<TKey>> dictRev;
private KeyCollection keyCollection;
private ValueCollection valueCollection;
/// <summary>
/// Holds all of the keys that are associated with null values. We need
/// it because dictRev cannot hold null as keys.
......@@ -112,8 +109,6 @@ namespace Anvoker.Collections.Maps
capacity,
comparerValue);
keysWithNullValue = new HashSet<TKey>(comparerKey);
keyCollection = new KeyCollection(this);
valueCollection = new ValueCollection(this);
}
/// <summary>
......@@ -239,7 +234,7 @@ namespace Anvoker.Collections.Maps
/// Gets a collection containing the keys in the
/// <see cref="BiMap{TKey, TVal}"/>.
/// </summary>
public KeyCollection Keys => keyCollection;
public IReadOnlyCollection<TKey> Keys => dictFwd.Keys;
/// <summary>
/// Gets the number of unique values contained in the
......@@ -251,7 +246,7 @@ namespace Anvoker.Collections.Maps
/// Gets a collection containing the values in the
/// <see cref="BiMap{TKey, TVal}"/>.
/// </summary>
public ValueCollection Values => valueCollection;
public IReadOnlyCollection<TVal> Values => dictFwd.Values;
#endregion Public Properties
......@@ -412,27 +407,6 @@ namespace Anvoker.Collections.Maps
}
}
/// <summary>
/// Returns an enumerator that iterates through the values-key elements
/// of the <see cref="BiMap{TKey, TVal}"/>. Since the same value can be
/// associated with multiple keys, keys are grouped in their own
/// collection in each element.
/// </summary>
/// <returns>A <see cref="Dictionary{TVal, IReadOnlyCollection{TKey}}
/// .Enumerator"/> structure for the
/// <see cref="BiMap{TKey, TVal}"/>.</returns>
public IEnumerator<KeyValuePair<TVal, TKey>>
GetReverseEnumerator()
{
foreach (var kvp in dictRev)
{
foreach (var value in kvp.Value)
{
yield return new KeyValuePair<TVal, TKey>(kvp.Key, value);
}
}
}
/// <summary>
/// Removes the element with the specified key from the
/// <see cref="BiMap{TKey, TVal}"/>.
......
......@@ -37,8 +37,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BiMap.cs" />
<Compile Include="BiMap.KeyCollection.cs" />
<Compile Include="BiMap.ValueCollection.cs" />
<Compile Include="Interfaces\IBiMap.cs" />
<Compile Include="Interfaces\IFixedKeysBiMap.cs" />
<Compile Include="Interfaces\IFixedKeysMultiBiMap.cs" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Reflection;
using System.IO;
namespace Anvoker.Collections.Tests.Common
{
public static class Tracing
{
static Tracing()
{
string path = Path.Combine(DllPath, "SetupTrace.log");
//streamLogFile = File.Create(path, 4096, FileOptions.Asynchronous);
streamLogFile = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Read);
Trace.AutoFlush = true;
}
public static TextWriterTraceListener SetupTracer
=> new TextWriterTraceListener(
streamLogFile,
"SetupTrace")
{
TraceOutputOptions = TraceOptions.LogicalOperationStack
| TraceOptions.DateTime
| TraceOptions.Timestamp
| TraceOptions.ProcessId
| TraceOptions.ThreadId
};
public static string DllPath { get; }
= Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
private static readonly Stream streamLogFile;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment