[linqbridge] 2 new revisions pushed by azizatif on 2012-04-17 16:10 GMT

0 views
Skip to first unread message

linqb...@googlecode.com

unread,
Apr 17, 2012, 12:10:36 PM4/17/12
to linqbridg...@googlegroups.com
2 new revisions:

Revision: c08984d432b1
Author: azizatif
Date: Tue Apr 17 09:05:19 2012
Log: Consolidating null key handling overlap between Intersect, Except
and ...
http://code.google.com/p/linqbridge/source/detail?r=c08984d432b1

Revision: 1567e00f1a20
Author: azizatif
Date: Tue Apr 17 09:09:51 2012
Log: Rolling DelegatingComparer under internals namespace
http://code.google.com/p/linqbridge/source/detail?r=1567e00f1a20

==============================================================================
Revision: c08984d432b1
Author: azizatif
Date: Tue Apr 17 09:05:19 2012
Log: Consolidating null key handling overlap between Intersect, Except
and Lookup
http://code.google.com/p/linqbridge/source/detail?r=c08984d432b1

Added:
/src/Internal.cs
Modified:
/src/Enumerable.cs
/src/LINQBridge.csproj
/src/Lookup.cs

=======================================
--- /dev/null
+++ /src/Internal.cs Tue Apr 17 09:05:19 2012
@@ -0,0 +1,69 @@
+#region License, Terms and Author(s)
+//
+// LINQBridge
+// Copyright (c) 2007 Atif Aziz, Joseph Albahari. All rights reserved.
+//
+// Author(s):
+//
+// Atif Aziz, http://www.raboof.com
+//
+// This library is free software; you can redistribute it and/or modify it
+// under the terms of the New BSD License, a copy of which should have
+// been delivered along with this distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+#endregion
+
+// $Id$
+
+namespace LinqBridge
+{
+ using System.Collections.Generic;
+
+ /// <remarks>
+ /// This type is not intended to be used directly from user code.
+ /// It may be removed or changed in a future version without notice.
+ /// </remarks>
+
+ struct Key<T>
+ {
+ public Key(T value) : this() { Value = value; }
+ public T Value { get; private set; }
+ }
+
+ /// <remarks>
+ /// This type is not intended to be used directly from user code.
+ /// It may be removed or changed in a future version without notice.
+ /// </remarks>
+
+ sealed class KeyComparer<T> : IEqualityComparer<Key<T>>
+ {
+ private readonly IEqualityComparer<T> _innerComparer;
+
+ public KeyComparer(IEqualityComparer<T> innerComparer)
+ {
+ _innerComparer = innerComparer ?? EqualityComparer<T>.Default;
+ }
+
+ public bool Equals(Key<T> x, Key<T> y)
+ {
+ return _innerComparer.Equals(x.Value, y.Value);
+ }
+
+ public int GetHashCode(Key<T> obj)
+ {
+ return obj.Value == null ? 0 :
_innerComparer.GetHashCode(obj.Value);
+ }
+ }
+}
=======================================
--- /src/Enumerable.cs Mon Apr 16 13:01:27 2012
+++ /src/Enumerable.cs Tue Apr 17 09:05:19 2012
@@ -1516,25 +1516,24 @@
if (first == null) throw new ArgumentNullException("first");
if (second == null) throw new ArgumentNullException("second");

- var keys = new List<TSource>();
- var nullFlag = false;
- var flags = new Dictionary<TSource, bool>(comparer);
-
- foreach (var item in first.Where(k => k ==
null ? !nullFlag : !flags.ContainsKey(k)))
- {
- if (item == null)
- nullFlag = !flag;
- else
- flags.Add(item, !flag);
+ var keys = new List<Key<TSource>>();
+ var flags = new Dictionary<Key<TSource>, bool>(new
KeyComparer<TSource>(comparer));
+
+ foreach (var item in from item in first
+ select new Key<TSource>(item) into item
+ where !flags.ContainsKey(item)
+ select item)
+ {
+ flags.Add(item, !flag);
keys.Add(item);
}

- foreach (var item in second.Where(k => k == null ? nullFlag :
flags.ContainsKey(k)))
- {
- if (item == null)
- nullFlag = flag;
- else
- flags[item] = flag;
+ foreach (var item in from item in second
+ select new Key<TSource>(item) into item
+ where flags.ContainsKey(item)
+ select item)
+ {
+ flags[item] = flag;
}

//
@@ -1542,7 +1541,7 @@
// which they were collected.
//

- return keys.Where(item => item == null ? nullFlag :
flags[item]);
+ return from item in keys where flags[item] select item.Value;
}

/// <summary>
=======================================
--- /src/LINQBridge.csproj Mon Apr 16 12:32:37 2012
+++ /src/LINQBridge.csproj Tue Apr 17 09:05:19 2012
@@ -48,6 +48,7 @@
<Compile Include="Func.cs" />
<Compile Include="IGrouping.cs" />
<Compile Include="ILookup.cs" />
+ <Compile Include="Internal.cs" />
<Compile Include="IOrderedEnumerable.cs" />
<Compile Include="Lookup.cs" />
<Compile Include="OrderedEnumerable.cs" />
=======================================
--- /src/Lookup.cs Mon Apr 16 13:01:27 2012
+++ /src/Lookup.cs Tue Apr 17 09:05:19 2012
@@ -35,7 +35,6 @@
using System.Collections;
using System.Collections.Generic;
using IEnumerable=System.Collections.IEnumerable;
-
using LinqBridge;

#endregion
@@ -46,18 +45,18 @@

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
+ private readonly Dictionary<Key<TKey>, IGrouping<TKey, TElement>>
_map;
+ private readonly List<Key<TKey>> _orderedKeys; // remember order
of insertion

internal Lookup(IEqualityComparer<TKey> comparer)
{
- _map = new Dictionary<Key, IGrouping<TKey, TElement>>(new
KeyComparer(comparer));
- _orderedKeys = new List<Key>();
+ _map = new Dictionary<Key<TKey>, IGrouping<TKey,
TElement>>(new KeyComparer<TKey>(comparer));
+ _orderedKeys = new List<Key<TKey>>();
}

internal void Add(IGrouping<TKey, TElement> item)
{
- var key = new Key(item.Key);
+ var key = new Key<TKey>(item.Key);
_map.Add(key, item);
_orderedKeys.Add(key);
}
@@ -65,7 +64,7 @@
internal IEnumerable<TElement> Find(TKey key)
{
IGrouping<TKey, TElement> grouping;
- return _map.TryGetValue(new Key(key), out grouping) ?
grouping : null;
+ return _map.TryGetValue(new Key<TKey>(key), out grouping) ?
grouping : null;
}

/// <summary>
@@ -86,7 +85,7 @@
get
{
IGrouping<TKey, TElement> result;
- return _map.TryGetValue(new Key(key), out result) ?
result : Enumerable.Empty<TElement>();
+ return _map.TryGetValue(new Key<TKey>(key), out result) ?
result : Enumerable.Empty<TElement>();
}
}

@@ -96,7 +95,7 @@

public bool Contains(TKey key)
{
- return _map.ContainsKey(new Key(key));
+ return _map.ContainsKey(new Key<TKey>(key));
}

/// <summary>
@@ -128,31 +127,5 @@
{
return GetEnumerator();
}
-
- struct Key
- {
- public Key(TKey value) : this() { Value = value; }
- public TKey Value { get; private set; }
- }
-
- 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 _innerComparer.Equals(x.Value, y.Value);
- }
-
- public int GetHashCode(Key obj)
- {
- return obj.Value == null ? 0 :
_innerComparer.GetHashCode(obj.Value);
- }
- }
}
}

==============================================================================
Revision: 1567e00f1a20
Author: azizatif
Date: Tue Apr 17 09:09:51 2012
Log: Rolling DelegatingComparer under internals namespace
http://code.google.com/p/linqbridge/source/detail?r=1567e00f1a20

Deleted:
/src/DelegatingComparer.cs
Modified:
/hgkwinit.cmd
/src/Internal.cs
/src/LINQBridge.csproj

=======================================
--- /src/DelegatingComparer.cs Mon Apr 16 12:45:45 2012
+++ /dev/null
@@ -1,51 +0,0 @@
-#region License, Terms and Author(s)
-//
-// LINQBridge
-// Copyright (c) 2007 Atif Aziz, Joseph Albahari. All rights reserved.
-//
-// Author(s):
-//
-// Atif Aziz, http://www.raboof.com
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the New BSD License, a copy of which should have
-// been delivered along with this distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-#endregion
-
-// $Id$
-
-namespace LinqBridge
-{
- #region Imports
-
- using System;
- using System.Collections.Generic;
-
- #endregion
-
- internal sealed class DelegatingComparer<T> : IComparer<T>
- {
- private readonly Func<T, T, int> _comparer;
-
- public DelegatingComparer(Func<T, T, int> comparer)
- {
- if (comparer == null) throw new
ArgumentNullException("comparer");
- _comparer = comparer;
- }
-
- public int Compare(T x, T y) { return _comparer(x, y); }
- }
-}
=======================================
--- /hgkwinit.cmd Mon Apr 16 13:09:55 2012
+++ /hgkwinit.cmd Tue Apr 17 09:09:51 2012
@@ -36,13 +36,13 @@
echo.
echo [keyword]
echo src/Action.cs=
-echo src/DelegatingComparer.cs=
echo src/Enumerable.cs=
echo src/Enumerable.g.tt=
echo src/ExtensionAttribute.cs=
echo src/Func.cs=
echo src/IGrouping.cs=
echo src/ILookup.cs=
+echo src/Internal.cs=
echo src/IOrderedEnumerable.cs=
echo src/Lookup.cs=
echo src/OrderedEnumerable.cs=
=======================================
--- /src/Internal.cs Tue Apr 17 09:05:19 2012
+++ /src/Internal.cs Tue Apr 17 09:09:51 2012
@@ -29,7 +29,30 @@

namespace LinqBridge
{
+ #region Imports
+
+ using System;
using System.Collections.Generic;
+
+ #endregion
+
+ /// <remarks>
+ /// This type is not intended to be used directly from user code.
+ /// It may be removed or changed in a future version without notice.
+ /// </remarks>
+
+ sealed class DelegatingComparer<T> : IComparer<T>
+ {
+ private readonly Func<T, T, int> _comparer;
+
+ public DelegatingComparer(Func<T, T, int> comparer)
+ {
+ if (comparer == null) throw new
ArgumentNullException("comparer");
+ _comparer = comparer;
+ }
+
+ public int Compare(T x, T y) { return _comparer(x, y); }
+ }

/// <remarks>
/// This type is not intended to be used directly from user code.
=======================================
--- /src/LINQBridge.csproj Tue Apr 17 09:05:19 2012
+++ /src/LINQBridge.csproj Tue Apr 17 09:09:51 2012
@@ -37,7 +37,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Action.cs" />
- <Compile Include="DelegatingComparer.cs" />
<Compile Include="Enumerable.cs" />
<Compile Include="Enumerable.g.cs">
<AutoGen>True</AutoGen>
Reply all
Reply to author
Forward
0 new messages