8 new revisions:
Revision: 00f4036bafdf
Author:
il...@industry-soft.ru
Date: Sat Apr 30 12:35:00 2011
Log: issue #21: GroupBy fails on null keys....
http://code.google.com/p/linqbridge/source/detail?r=00f4036bafdf
Revision: 82d4f150892d
Author: azizatif
Date: Sun May 1 02:58:38 2011
Log: Automated merge with
https://ilyaindustry-linqbridge-issue21.googlecod...
http://code.google.com/p/linqbridge/source/detail?r=82d4f150892d
Revision: 3274da2546e8
Author: azizatif
Date: Sun May 1 03:14:48 2011
Log: Nested Wrapped & WrappedEqualityComparer under Lookup
http://code.google.com/p/linqbridge/source/detail?r=3274da2546e8
Revision: d40cfb26ce59
Author: azizatif
Date: Sun May 1 03:16:49 2011
Log: Addressed warning CS0693: Type parameter 'TKey' has the same name
as t...
http://code.google.com/p/linqbridge/source/detail?r=d40cfb26ce59
Revision: 69447b300c11
Author: azizatif
Date: Sun May 1 03:17:42 2011
Log: Renamed Lookup.Wrapped* to simply Key*
http://code.google.com/p/linqbridge/source/detail?r=69447b300c11
Revision: 53ae02117157
Author: azizatif
Date: Sun May 1 03:19:06 2011
Log: Reduced accessibility of Lookup.Key*; internal detail
http://code.google.com/p/linqbridge/source/detail?r=53ae02117157
Revision: 49dafe875ab2
Author: azizatif
Date: Sun May 1 03:24:16 2011
Log: Reviewed Lookup.Key* for terseness
http://code.google.com/p/linqbridge/source/detail?r=49dafe875ab2
Revision: f775a15d4148
Author: azizatif
Date: Sun May 1 03:29:19 2011
Log: Added back yielding of groupings by insertion order of keys for
GroupB...
http://code.google.com/p/linqbridge/source/detail?r=f775a15d4148
==============================================================================
Revision: 00f4036bafdf
Author:
il...@industry-soft.ru
Date: Sat Apr 30 12:35:00 2011
Log: issue #21: GroupBy fails on null keys.
Wrapping Lookup key in the non-nullable structure to use generic Dictionary
as backing store of the Lookup.
http://code.google.com/p/linqbridge/source/detail?r=00f4036bafdf
Added:
/src/Wrapped.cs
/src/WrappedEqualityComparer.cs
Modified:
/src/LINQBridge.csproj
/src/Lookup.cs
=======================================
--- /dev/null
+++ /src/Wrapped.cs Sat Apr 30 12:35:00 2011
@@ -0,0 +1,21 @@
+namespace LinqBridge
+{
+
+ internal struct Wrapped<TKey>
+ {
+ public Wrapped(TKey value)
+ {
+ m_Value = value;
+ }
+
+ private readonly TKey m_Value;
+
+ public TKey Value
+ {
+ get
+ {
+ return m_Value;
+ }
+ }
+ }
+}
=======================================
--- /dev/null
+++ /src/WrappedEqualityComparer.cs Sat Apr 30 12:35:00 2011
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+
+namespace LinqBridge
+{
+ internal class WrappedEqualityComparer<TKey> :
IEqualityComparer<Wrapped<TKey>>
+ {
+ private readonly IEqualityComparer<TKey> m_InnerComparer;
+
+ public WrappedEqualityComparer() : this(null) {}
+
+ public WrappedEqualityComparer(IEqualityComparer<TKey>
innerComparer)
+ {
+ m_InnerComparer = innerComparer ??
EqualityComparer<TKey>.Default;
+ }
+
+ #region IEqualityComparer<Wrapped<TKey>> Members
+
+ public bool Equals(Wrapped<TKey> x, Wrapped<TKey> y)
+ {
+ return m_InnerComparer.Equals(x.Value, y.Value);
+ }
+
+ public int GetHashCode(Wrapped<TKey> obj)
+ {
+ if ((default(TKey) == null) && (obj.Value as object == null))
+ return 0;
+
+ return m_InnerComparer.GetHashCode(obj.Value);
+ }
+
+ #endregion
+ }
+}
=======================================
--- /src/LINQBridge.csproj Sat Apr 30 05:48:09 2011
+++ /src/LINQBridge.csproj Sat Apr 30 12:35:00 2011
@@ -53,6 +53,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Public.cs" />
<Compile Include="Tuple.cs" />
+ <Compile Include="Wrapped.cs" />
+ <Compile Include="WrappedEqualityComparer.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
=======================================
--- /src/Lookup.cs Sat Apr 30 07:13:04 2011
+++ /src/Lookup.cs Sat Apr 30 12:35:00 2011
@@ -36,6 +36,8 @@
using System.Collections.Generic;
using IEnumerable=System.Collections.IEnumerable;
+ using LinqBridge;
+
#endregion
/// <summary>
@@ -44,38 +46,22 @@
internal sealed class Lookup<TKey, TElement> : ILookup<TKey, TElement>
{
- private readonly Dictionary<TKey, IGrouping<TKey, TElement>> _map;
- private readonly List<TKey> _orderedKeys; // in order of insertion
- private IGrouping<TKey, TElement> _nullGrouping;
+ private readonly Dictionary<Wrapped<TKey>, IGrouping<TKey,
TElement>> _map;
internal Lookup(IEqualityComparer<TKey> comparer)
{
- _map = new Dictionary<TKey, IGrouping<TKey,
TElement>>(comparer);
- _orderedKeys = new List<TKey>();
+ _map = new Dictionary<Wrapped<TKey>, IGrouping<TKey,
TElement>>(new WrappedEqualityComparer<TKey>(comparer));
}
internal void Add(IGrouping<TKey, TElement> item)
{
- var key = item.Key;
- if (key == null)
- {
- if (_nullGrouping != null)
- throw new ArgumentException("An item with the same key
has already been added.");
- _nullGrouping = item;
- }
- else
- {
- _map.Add(key, item);
- }
- _orderedKeys.Add(key);
+ _map.Add(new Wrapped<TKey>(item.Key), item);
}
internal IEnumerable<TElement> Find(TKey key)
{
- if (key == null)
- return _nullGrouping;
IGrouping<TKey, TElement> grouping;
- return _map.TryGetValue(key, out grouping) ? grouping : null;
+ return _map.TryGetValue(new Wrapped<TKey>(key), out
grouping) ? grouping : null;
}
/// <summary>
@@ -95,10 +81,8 @@
{
get
{
- if (key == null)
- return _nullGrouping ?? Enumerable.Empty<TElement>();
IGrouping<TKey, TElement> result;
- return _map.TryGetValue(key, out result) ? result :
Enumerable.Empty<TElement>();
+ return _map.TryGetValue(new Wrapped<TKey>(key), out
result) ? result : Enumerable.Empty<TElement>();
}
}
@@ -108,7 +92,7 @@
public bool Contains(TKey key)
{
- return key == null ? _nullGrouping != null :
_map.ContainsKey(key);
+ return _map.ContainsKey(new Wrapped<TKey>(key));
}
/// <summary>
@@ -121,9 +105,9 @@
{
if (resultSelector == null)
throw new ArgumentNullException("resultSelector");
-
- foreach (var grouping in this)
- yield return resultSelector(grouping.Key, grouping);
+
+ foreach (var pair in _map)
+ yield return resultSelector(pair.Key.Value, pair.Value);
}
/// <summary>
@@ -132,8 +116,7 @@
public IEnumerator<IGrouping<TKey, TElement>> GetEnumerator()
{
- foreach (var key in _orderedKeys)
- yield return key == null ? _nullGrouping : _map[key];
+ return _map.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
==============================================================================
Revision: 82d4f150892d
Author: azizatif
Date: Sun May 1 02:58:38 2011
Log: Automated merge with
https://ilyaindustry-linqbridge-issue21.googlecode.com/hg/
http://code.google.com/p/linqbridge/source/detail?r=82d4f150892d
Modified:
/src/Lookup.cs
=======================================
--- /src/Lookup.cs Sat Apr 30 12:58:58 2011
+++ /src/Lookup.cs Sun May 1 02:58:38 2011
@@ -36,6 +36,8 @@
using System.Collections.Generic;
using IEnumerable=System.Collections.IEnumerable;
+ using LinqBridge;
+
#endregion
/// <summary>
@@ -44,38 +46,22 @@
internal sealed class Lookup<TKey, TElement> : ILookup<TKey, TElement>
{
- private readonly Dictionary<TKey, IGrouping<TKey, TElement>> _map;
- private readonly List<TKey> _orderedKeys; // in order of insertion
- private IGrouping<TKey, TElement> _nullGrouping;
+ private readonly Dictionary<Wrapped<TKey>, IGrouping<TKey,
TElement>> _map;
internal Lookup(IEqualityComparer<TKey> comparer)
{
- _map = new Dictionary<TKey, IGrouping<TKey,
TElement>>(comparer);
- _orderedKeys = new List<TKey>();
+ _map = new Dictionary<Wrapped<TKey>, IGrouping<TKey,
TElement>>(new WrappedEqualityComparer<TKey>(comparer));
}
internal void Add(IGrouping<TKey, TElement> item)
{
- var key = item.Key;
- if (key == null)
- {
- if (_nullGrouping != null)
- throw new ArgumentException("An item with the same key
has already been added.");
- _nullGrouping = item;
- }
- else
- {
- _map.Add(key, item);
- }
- _orderedKeys.Add(key);
+ _map.Add(new Wrapped<TKey>(item.Key), item);
}
internal IEnumerable<TElement> Find(TKey key)
{
- if (key == null)
- return _nullGrouping;
IGrouping<TKey, TElement> grouping;
- return _map.TryGetValue(key, out grouping) ? grouping : null;
+ return _map.TryGetValue(new Wrapped<TKey>(key), out
grouping) ? grouping : null;
}
/// <summary>
@@ -95,10 +81,8 @@
{
get
{
- if (key == null)
- return _nullGrouping ?? Enumerable.Empty<TElement>();
IGrouping<TKey, TElement> result;
- return _map.TryGetValue(key, out result) ? result :
Enumerable.Empty<TElement>();
+ return _map.TryGetValue(new Wrapped<TKey>(key), out
result) ? result : Enumerable.Empty<TElement>();
}
}
@@ -108,7 +92,7 @@
public bool Contains(TKey key)
{
- return key == null ? _nullGrouping != null :
_map.ContainsKey(key);
+ return _map.ContainsKey(new Wrapped<TKey>(key));
}
/// <summary>
@@ -121,9 +105,9 @@
{
if (resultSelector == null)
throw new ArgumentNullException("resultSelector");
-
- foreach (var grouping in this)
- yield return resultSelector(grouping.Key, grouping);
+
+ foreach (var pair in _map)
+ yield return resultSelector(pair.Key.Value, pair.Value);
}
/// <summary>
@@ -132,8 +116,7 @@
public IEnumerator<IGrouping<TKey, TElement>> GetEnumerator()
{
- foreach (var key in _orderedKeys)
- yield return key == null ? _nullGrouping : _map[key];
+ return _map.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
==============================================================================
Revision: 3274da2546e8
Author: azizatif
Date: Sun May 1 03:14:48 2011
Log: Nested Wrapped & WrappedEqualityComparer under Lookup
http://code.google.com/p/linqbridge/source/detail?r=3274da2546e8
Deleted:
/src/Wrapped.cs
/src/WrappedEqualityComparer.cs
Modified:
/src/LINQBridge.csproj
/src/Lookup.cs
=======================================
--- /src/Wrapped.cs Sat Apr 30 12:35:00 2011
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace LinqBridge
-{
-
- internal struct Wrapped<TKey>
- {
- public Wrapped(TKey value)
- {
- m_Value = value;
- }
-
- private readonly TKey m_Value;
-
- public TKey Value
- {
- get
- {
- return m_Value;
- }
- }
- }
-}
=======================================
--- /src/WrappedEqualityComparer.cs Sat Apr 30 12:35:00 2011
+++ /dev/null
@@ -1,34 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace LinqBridge
-{
- internal class WrappedEqualityComparer<TKey> :
IEqualityComparer<Wrapped<TKey>>
- {
- private readonly IEqualityComparer<TKey> m_InnerComparer;
-
- public WrappedEqualityComparer() : this(null) {}
-
- public WrappedEqualityComparer(IEqualityComparer<TKey>
innerComparer)
- {
- m_InnerComparer = innerComparer ??
EqualityComparer<TKey>.Default;
- }
-
- #region IEqualityComparer<Wrapped<TKey>> Members
-
- public bool Equals(Wrapped<TKey> x, Wrapped<TKey> y)
- {
- return m_InnerComparer.Equals(x.Value, y.Value);
- }
-
- public int GetHashCode(Wrapped<TKey> obj)
- {
- if ((default(TKey) == null) && (obj.Value as object == null))
- return 0;
-
- return m_InnerComparer.GetHashCode(obj.Value);
- }
-
- #endregion
- }
-}
=======================================
--- /src/LINQBridge.csproj Sat Apr 30 12:35:00 2011
+++ /src/LINQBridge.csproj Sun May 1 03:14:48 2011
@@ -53,8 +53,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Public.cs" />
<Compile Include="Tuple.cs" />
- <Compile Include="Wrapped.cs" />
- <Compile Include="WrappedEqualityComparer.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
=======================================
--- /src/Lookup.cs Sun May 1 02:58:38 2011
+++ /src/Lookup.cs Sun May 1 03:14:48 2011
@@ -123,5 +123,52 @@
{
return GetEnumerator();
}
+
+ internal struct Wrapped<TKey>
+ {
+ public Wrapped(TKey value)
+ {
+ m_Value = value;
+ }
+
+ private readonly TKey m_Value;
+
+ public TKey Value
+ {
+ get
+ {
+ return m_Value;
+ }
+ }
+ }
+
+ internal class WrappedEqualityComparer<TKey> :
IEqualityComparer<Wrapped<TKey>>
+ {
+ private readonly IEqualityComparer<TKey> m_InnerComparer;
+
+ public WrappedEqualityComparer() : this(null) { }
+
+ public WrappedEqualityComparer(IEqualityComparer<TKey>
innerComparer)
+ {
+ m_InnerComparer = innerComparer ??
EqualityComparer<TKey>.Default;
+ }
+
+ #region IEqualityComparer<Wrapped<TKey>> Members
+
+ public bool Equals(Wrapped<TKey> x, Wrapped<TKey> y)
+ {
+ return m_InnerComparer.Equals(x.Value, y.Value);
+ }
+
+ public int GetHashCode(Wrapped<TKey> obj)
+ {
+ if ((default(TKey) == null) && (obj.Value as object ==
null))
+ return 0;
+
+ return m_InnerComparer.GetHashCode(obj.Value);
+ }
+
+ #endregion
+ }
}
}
==============================================================================
Revision: d40cfb26ce59
Author: azizatif
Date: Sun May 1 03:16:49 2011
Log: Addressed warning CS0693: Type parameter 'TKey' has the same name
as the type parameter from outer type 'System.Linq.Lookup<TKey,TElement>'
http://code.google.com/p/linqbridge/source/detail?r=d40cfb26ce59
Modified:
/src/Lookup.cs
=======================================
--- /src/Lookup.cs Sun May 1 03:14:48 2011
+++ /src/Lookup.cs Sun May 1 03:16:49 2011
@@ -46,22 +46,22 @@
internal sealed class Lookup<TKey, TElement> : ILookup<TKey, TElement>
{
- private readonly Dictionary<Wrapped<TKey>, IGrouping<TKey,
TElement>> _map;
+ private readonly Dictionary<Wrapped, IGrouping<TKey, TElement>>
_map;
internal Lookup(IEqualityComparer<TKey> comparer)
{
- _map = new Dictionary<Wrapped<TKey>, IGrouping<TKey,
TElement>>(new WrappedEqualityComparer<TKey>(comparer));
+ _map = new Dictionary<Wrapped, IGrouping<TKey, TElement>>(new
WrappedEqualityComparer(comparer));
}
internal void Add(IGrouping<TKey, TElement> item)
{
- _map.Add(new Wrapped<TKey>(item.Key), item);
+ _map.Add(new Wrapped(item.Key), item);
}
internal IEnumerable<TElement> Find(TKey key)
{
IGrouping<TKey, TElement> grouping;
- return _map.TryGetValue(new Wrapped<TKey>(key), out
grouping) ? grouping : null;
+ return _map.TryGetValue(new Wrapped(key), out grouping) ?
grouping : null;
}
/// <summary>
@@ -82,7 +82,7 @@
get
{
IGrouping<TKey, TElement> result;
- return _map.TryGetValue(new Wrapped<TKey>(key), out
result) ? result : Enumerable.Empty<TElement>();
+ return _map.TryGetValue(new Wrapped(key), out result) ?
result : Enumerable.Empty<TElement>();
}
}
@@ -92,7 +92,7 @@
public bool Contains(TKey key)
{
- return _map.ContainsKey(new Wrapped<TKey>(key));
+ return _map.ContainsKey(new Wrapped(key));
}
/// <summary>
@@ -124,7 +124,7 @@
return GetEnumerator();
}
- internal struct Wrapped<TKey>
+ internal struct Wrapped
{
public Wrapped(TKey value)
{
@@ -142,7 +142,7 @@
}
}
- internal class WrappedEqualityComparer<TKey> :
IEqualityComparer<Wrapped<TKey>>
+ internal class WrappedEqualityComparer : IEqualityComparer<Wrapped>
{
private readonly IEqualityComparer<TKey> m_InnerComparer;
@@ -153,22 +153,18 @@
m_InnerComparer = innerComparer ??
EqualityComparer<TKey>.Default;
}
- #region IEqualityComparer<Wrapped<TKey>> Members
-
- public bool Equals(Wrapped<TKey> x, Wrapped<TKey> y)
+ public bool Equals(Wrapped x, Wrapped y)
{
return m_InnerComparer.Equals(x.Value, y.Value);
}
- public int GetHashCode(Wrapped<TKey> obj)
+ public int GetHashCode(Wrapped obj)
{
if ((default(TKey) == null) && (obj.Value as object ==
null))
return 0;
return m_InnerComparer.GetHashCode(obj.Value);
}
-
- #endregion
}
}
}
==============================================================================
Revision: 69447b300c11
Author: azizatif
Date: Sun May 1 03:17:42 2011
Log: Renamed Lookup.Wrapped* to simply Key*
http://code.google.com/p/linqbridge/source/detail?r=69447b300c11
Modified:
/src/Lookup.cs
=======================================
--- /src/Lookup.cs Sun May 1 03:16:49 2011
+++ /src/Lookup.cs Sun May 1 03:17:42 2011
@@ -46,22 +46,22 @@
internal sealed class Lookup<TKey, TElement> : ILookup<TKey, TElement>
{
- private readonly Dictionary<Wrapped, IGrouping<TKey, TElement>>
_map;
+ private readonly Dictionary<Key, IGrouping<TKey, TElement>> _map;
internal Lookup(IEqualityComparer<TKey> comparer)
{
- _map = new Dictionary<Wrapped, IGrouping<TKey, TElement>>(new
WrappedEqualityComparer(comparer));
+ _map = new Dictionary<Key, IGrouping<TKey, TElement>>(new
KeyEqualityComparer(comparer));
}
internal void Add(IGrouping<TKey, TElement> item)
{
- _map.Add(new Wrapped(item.Key), item);
+ _map.Add(new Key(item.Key), item);
}
internal IEnumerable<TElement> Find(TKey key)
{
IGrouping<TKey, TElement> grouping;
- return _map.TryGetValue(new Wrapped(key), out grouping) ?
grouping : null;
+ return _map.TryGetValue(new Key(key), out grouping) ?
grouping : null;
}
/// <summary>
@@ -82,7 +82,7 @@
get
{
IGrouping<TKey, TElement> result;
- return _map.TryGetValue(new Wrapped(key), out result) ?
result : Enumerable.Empty<TElement>();
+ return _map.TryGetValue(new Key(key), out result) ?
result : Enumerable.Empty<TElement>();
}
}
@@ -92,7 +92,7 @@
public bool Contains(TKey key)
{
- return _map.ContainsKey(new Wrapped(key));
+ return _map.ContainsKey(new Key(key));
}
/// <summary>
@@ -124,9 +124,9 @@
return GetEnumerator();
}
- internal struct Wrapped
- {
- public Wrapped(TKey value)
+ internal struct Key
+ {
+ public Key(TKey value)
{
m_Value = value;
}
@@ -142,23 +142,23 @@
}
}
- internal class WrappedEqualityComparer : IEqualityComparer<Wrapped>
+ internal class KeyEqualityComparer : IEqualityComparer<Key>
{
private readonly IEqualityComparer<TKey> m_InnerComparer;
- public WrappedEqualityComparer() : this(null) { }
-
- public WrappedEqualityComparer(IEqualityComparer<TKey>
innerComparer)
+ public KeyEqualityComparer() : this(null) { }
+
+ public KeyEqualityComparer(IEqualityComparer<TKey>
innerComparer)
{
m_InnerComparer = innerComparer ??
EqualityComparer<TKey>.Default;
}
- public bool Equals(Wrapped x, Wrapped y)
+ public bool Equals(Key x, Key y)
{
return m_InnerComparer.Equals(x.Value, y.Value);
}
- public int GetHashCode(Wrapped obj)
+ public int GetHashCode(Key obj)
{
if ((default(TKey) == null) && (obj.Value as object ==
null))
return 0;
==============================================================================
Revision: 53ae02117157
Author: azizatif
Date: Sun May 1 03:19:06 2011
Log: Reduced accessibility of Lookup.Key*; internal detail
http://code.google.com/p/linqbridge/source/detail?r=53ae02117157
Modified:
/src/Lookup.cs
=======================================
--- /src/Lookup.cs Sun May 1 03:17:42 2011
+++ /src/Lookup.cs Sun May 1 03:19:06 2011
@@ -124,7 +124,7 @@
return GetEnumerator();
}
- internal struct Key
+ struct Key
{
public Key(TKey value)
{
@@ -142,11 +142,9 @@
}
}
- internal class KeyEqualityComparer : IEqualityComparer<Key>
+ sealed class KeyEqualityComparer : IEqualityComparer<Key>
{
private readonly IEqualityComparer<TKey> m_InnerComparer;
-
- public KeyEqualityComparer() : this(null) { }
public KeyEqualityComparer(IEqualityComparer<TKey>
innerComparer)
{
==============================================================================
Revision: 49dafe875ab2
Author: azizatif
Date: Sun May 1 03:24:16 2011
Log: Reviewed Lookup.Key* for terseness
http://code.google.com/p/linqbridge/source/detail?r=49dafe875ab2
Modified:
/src/Lookup.cs
=======================================
--- /src/Lookup.cs Sun May 1 03:19:06 2011
+++ /src/Lookup.cs Sun May 1 03:24:16 2011
@@ -50,7 +50,7 @@
internal Lookup(IEqualityComparer<TKey> comparer)
{
- _map = new Dictionary<Key, IGrouping<TKey, TElement>>(new
KeyEqualityComparer(comparer));
+ _map = new Dictionary<Key, IGrouping<TKey, TElement>>(new
KeyComparer(comparer));
}
internal void Add(IGrouping<TKey, TElement> item)
@@ -126,42 +126,27 @@
struct Key
{
- public Key(TKey value)
- {
- m_Value = value;
- }
-
- private readonly TKey m_Value;
-
- public TKey Value
- {
- get
- {
- return m_Value;
- }
- }
+ public Key(TKey value) : this() { Value = value; }
+ public TKey Value { get; private set; }
}
- sealed class KeyEqualityComparer : IEqualityComparer<Key>
- {
- private readonly IEqualityComparer<TKey> m_InnerComparer;
-
- public KeyEqualityComparer(IEqualityComparer<TKey>
innerComparer)
- {
- m_InnerComparer = innerComparer ??
EqualityComparer<TKey>.Default;
+ sealed class KeyComparer : IEqualityComparer<Key>
+ {
+ private readonly IEqualityComparer<TKey> _innerComparer;
+
+ public KeyComparer(IEqualityComparer<TKey> innerComparer)
+ {
+ _innerComparer = innerComparer ??
EqualityComparer<TKey>.Default;
}
public bool Equals(Key x, Key y)
{
- return m_InnerComparer.Equals(x.Value, y.Value);
+ return _innerComparer.Equals(x.Value, y.Value);
}
public int GetHashCode(Key obj)
{
- if ((default(TKey) == null) && (obj.Value as object ==
null))
- return 0;
-
- return m_InnerComparer.GetHashCode(obj.Value);
+ return obj.Value == null ? 0 :
_innerComparer.GetHashCode(obj.Value);
}
}
}
==============================================================================
Revision: f775a15d4148
Author: azizatif
Date: Sun May 1 03:29:19 2011
Log: Added back yielding of groupings by insertion order of keys for
GroupBy
http://code.google.com/p/linqbridge/source/detail?r=f775a15d4148
Modified:
/src/Lookup.cs
=======================================
--- /src/Lookup.cs Sun May 1 03:24:16 2011
+++ /src/Lookup.cs Sun May 1 03:29:19 2011
@@ -47,15 +47,19 @@
internal sealed class Lookup<TKey, TElement> : ILookup<TKey, TElement>
{
private readonly Dictionary<Key, IGrouping<TKey, TElement>> _map;
+ private readonly List<Key> _orderedKeys; // remember order of
insertion
internal Lookup(IEqualityComparer<TKey> comparer)
{
_map = new Dictionary<Key, IGrouping<TKey, TElement>>(new
KeyComparer(comparer));
+ _orderedKeys = new List<Key>();
}
internal void Add(IGrouping<TKey, TElement> item)
{
- _map.Add(new Key(item.Key), item);
+ var key = new Key(item.Key);
+ _map.Add(key, item);
+ _orderedKeys.Add(key);
}
internal IEnumerable<TElement> Find(TKey key)
@@ -116,7 +120,8 @@
public IEnumerator<IGrouping<TKey, TElement>> GetEnumerator()
{
- return _map.Values.GetEnumerator();
+ foreach (var key in _orderedKeys)
+ yield return _map[key];
}
IEnumerator IEnumerable.GetEnumerator()