Skip to content

Commit

Permalink
Add NonStructuralComparison ops
Browse files Browse the repository at this point in the history
commit 3d64e6c4a6f9b9760e7e77e3031dff7d437169f6
Author: latkin <[email protected]>
Date:   Tue Dec 16 14:07:12 2014 -0800

    Adding conditional compilation where required

commit 8a5a33c99fcc82718adcd78146b59fe8f93321c9
Author: latkin <[email protected]>
Date:   Tue Dec 16 13:29:48 2014 -0800

    Updating surface area tests

commit 6c6925633d5c95bb0d34e16377651f6d62913ee1
Author: latkin <[email protected]>
Date:   Tue Dec 16 12:00:45 2014 -0800

    Small test changes

commit 3b4f1355ca0b5a022e18811a84d1fc6cda04b96e
Author: latkin <[email protected]>
Date:   Tue Dec 16 11:59:03 2014 -0800

    Fix doc comment

commit 321c1abfe00bea20316daccc41bd33a873b50fe5
Merge: ecfa21c 979c99d
Author: latkin <[email protected]>
Date:   Tue Dec 16 11:03:26 2014 -0800

    Merge branch 'non-structural-eq-compare' of https://git01.codeplex.com/forks/dsyme/cleanup into comparison

commit 979c99d6605a7b5b7540d94d0446d734728743c6
Author: Don Syme <[email protected]>
Date:   Tue Dec 2 18:20:07 2014 +0000

    fix string comparison and add tests for decimal

commit dc46cc5c9b2871711c22c9f364604361d8a14fef
Author: Don Syme <[email protected]>
Date:   Tue Nov 11 12:33:49 2014 +0000

    Add HashIdentity.NonStructural and ComparisonIdentity.NonStructural

commit 5d84b340bd94579388a5394c8138e1cb99433cbc
Author: Don Syme <[email protected]>
Date:   Tue Nov 11 11:38:03 2014 +0000

    rename to NonStructuralComparison

commit 768dfb521bf7bd25135e8e1a4603a15b86360903
Author: Don Syme <[email protected]>
Date:   Tue Nov 11 11:35:20 2014 +0000

    rename to NonStructuralOperators

commit 9f919071cd22d8ec994cfad6d7eb0cb209d6e164
Author: Don Syme <[email protected]>
Date:   Tue Nov 11 11:29:21 2014 +0000

    add StaticCOmparisonOperators to LeafExpressionConvert for symmetry

commit 9c59edcc43275a7060547df012e97b52c7d08e89
Author: Don Syme <[email protected]>
Date:   Tue Nov 11 11:09:26 2014 +0000

    add testing and small fixes for StaticComparisonOperators

commit 982da7b725a3cd8c25591f40e9a0e3d36d26bc00
Author: Don Syme <[email protected]>
Date:   Mon Nov 10 21:27:29 2014 +0000

    fast structural comparison operators
  • Loading branch information
dsyme authored and latkin committed Dec 16, 2014
1 parent ecfa21c commit f11c636
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 104 deletions.
17 changes: 17 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Microsoft.FSharp.Collections.ArrayModule: Void SortInPlace[T](T[])
Microsoft.FSharp.Collections.ComparisonIdentity: Boolean Equals(System.Object)
Microsoft.FSharp.Collections.ComparisonIdentity: Int32 GetHashCode()
Microsoft.FSharp.Collections.ComparisonIdentity: System.Collections.Generic.IComparer`1[T] FromFunction[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]])
Microsoft.FSharp.Collections.ComparisonIdentity: System.Collections.Generic.IComparer`1[T] NonStructural[T]()
Microsoft.FSharp.Collections.ComparisonIdentity: System.Collections.Generic.IComparer`1[T] Structural[T]()
Microsoft.FSharp.Collections.ComparisonIdentity: System.String ToString()
Microsoft.FSharp.Collections.ComparisonIdentity: System.Type GetType()
Expand Down Expand Up @@ -289,6 +290,7 @@ Microsoft.FSharp.Collections.HashIdentity: Boolean Equals(System.Object)
Microsoft.FSharp.Collections.HashIdentity: Int32 GetHashCode()
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] FromFunctions[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32], Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]])
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] LimitedStructural[T](Int32)
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] NonStructural[T]()
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] Reference[T]()
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] Structural[T]()
Microsoft.FSharp.Collections.HashIdentity: System.String ToString()
Expand Down Expand Up @@ -2443,6 +2445,20 @@ Microsoft.FSharp.Core.Operators+Checked: UInt16 ToUInt16[T](T)
Microsoft.FSharp.Core.Operators+Checked: UInt32 ToUInt32[T](T)
Microsoft.FSharp.Core.Operators+Checked: UInt64 ToUInt64[T](T)
Microsoft.FSharp.Core.Operators+Checked: UIntPtr ToUIntPtr[T](T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_Equality[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_GreaterThanOrEqual[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_GreaterThan[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_Inequality[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_LessThanOrEqual[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_LessThan[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Int32 Compare[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Int32 GetHashCode()
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Int32 Hash[T](T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: System.String ToString()
Microsoft.FSharp.Core.Operators+NonStructuralComparison: System.Type GetType()
Microsoft.FSharp.Core.Operators+NonStructuralComparison: T Max[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: T Min[T](T, T)
Microsoft.FSharp.Core.Operators+OperatorIntrinsics: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators+OperatorIntrinsics: Byte PowByte(Byte, Int32)
Microsoft.FSharp.Core.Operators+OperatorIntrinsics: Double PowDouble(Double, Int32)
Expand Down Expand Up @@ -2553,6 +2569,7 @@ Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.FSharpOption`1[System.Str
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.FSharpOption`1[T] TryUnbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.FSharpRef`1[T] Ref[T](T)
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+Checked
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+NonStructuralComparison
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+OperatorIntrinsics
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+Unchecked
Microsoft.FSharp.Core.Operators: SByte ToSByte[T](T)
Expand Down
17 changes: 17 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Microsoft.FSharp.Collections.ArrayModule: Void SortInPlace[T](T[])
Microsoft.FSharp.Collections.ComparisonIdentity: Boolean Equals(System.Object)
Microsoft.FSharp.Collections.ComparisonIdentity: Int32 GetHashCode()
Microsoft.FSharp.Collections.ComparisonIdentity: System.Collections.Generic.IComparer`1[T] FromFunction[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]])
Microsoft.FSharp.Collections.ComparisonIdentity: System.Collections.Generic.IComparer`1[T] NonStructural[T]()
Microsoft.FSharp.Collections.ComparisonIdentity: System.Collections.Generic.IComparer`1[T] Structural[T]()
Microsoft.FSharp.Collections.ComparisonIdentity: System.String ToString()
Microsoft.FSharp.Collections.ComparisonIdentity: System.Type GetType()
Expand Down Expand Up @@ -283,6 +284,7 @@ Microsoft.FSharp.Collections.HashIdentity: Boolean Equals(System.Object)
Microsoft.FSharp.Collections.HashIdentity: Int32 GetHashCode()
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] FromFunctions[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32], Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]])
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] LimitedStructural[T](Int32)
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] NonStructural[T]()
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] Reference[T]()
Microsoft.FSharp.Collections.HashIdentity: System.Collections.Generic.IEqualityComparer`1[T] Structural[T]()
Microsoft.FSharp.Collections.HashIdentity: System.String ToString()
Expand Down Expand Up @@ -2430,6 +2432,20 @@ Microsoft.FSharp.Core.Operators+Checked: UInt16 ToUInt16[T](T)
Microsoft.FSharp.Core.Operators+Checked: UInt32 ToUInt32[T](T)
Microsoft.FSharp.Core.Operators+Checked: UInt64 ToUInt64[T](T)
Microsoft.FSharp.Core.Operators+Checked: UIntPtr ToUIntPtr[T](T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_Equality[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_GreaterThanOrEqual[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_GreaterThan[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_Inequality[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_LessThanOrEqual[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Boolean op_LessThan[T,TResult](T, TResult)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Int32 Compare[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Int32 GetHashCode()
Microsoft.FSharp.Core.Operators+NonStructuralComparison: Int32 Hash[T](T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: System.String ToString()
Microsoft.FSharp.Core.Operators+NonStructuralComparison: System.Type GetType()
Microsoft.FSharp.Core.Operators+NonStructuralComparison: T Max[T](T, T)
Microsoft.FSharp.Core.Operators+NonStructuralComparison: T Min[T](T, T)
Microsoft.FSharp.Core.Operators+OperatorIntrinsics: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators+OperatorIntrinsics: Byte PowByte(Byte, Int32)
Microsoft.FSharp.Core.Operators+OperatorIntrinsics: Double PowDouble(Double, Int32)
Expand Down Expand Up @@ -2540,6 +2556,7 @@ Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.FSharpOption`1[System.Str
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.FSharpOption`1[T] TryUnbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.FSharpRef`1[T] Ref[T](T)
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+Checked
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+NonStructuralComparison
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+OperatorIntrinsics
Microsoft.FSharp.Core.Operators: Microsoft.FSharp.Core.Operators+Unchecked
Microsoft.FSharp.Core.Operators: SByte ToSByte[T](T)
Expand Down
14 changes: 14 additions & 0 deletions src/fsharp/FSharp.Core/Linq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ module LeafExpressionConverter =
let (|LessEqQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x,y) -> x <= y))
let (|NotEqQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x,y) -> x <> y))

let (|StaticEqualsQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x:int,y:int) -> NonStructuralComparison.(=) x y))
let (|StaticGreaterQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x:int,y:int) -> NonStructuralComparison.(>) x y))
let (|StaticGreaterEqQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x:int,y:int) -> NonStructuralComparison.(>=) x y))
let (|StaticLessQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x:int,y:int) -> NonStructuralComparison.(<) x y))
let (|StaticLessEqQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x:int,y:int) -> NonStructuralComparison.(<=) x y))
let (|StaticNotEqQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x:int,y:int) -> NonStructuralComparison.(<>) x y))

let (|NullableEqualsQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x,y) -> NullableOperators.( ?= ) x y))
let (|NullableNotEqQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x,y) -> NullableOperators.( ?<> ) x y))
let (|NullableGreaterQ|_|) = (|SpecificCallToMethod|_|) (methodhandleof (fun (x,y) -> NullableOperators.( ?> ) x y))
Expand Down Expand Up @@ -487,6 +494,13 @@ module LeafExpressionConverter =
| LessEqQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 false Expression.LessThanOrEqual
| NotQ (_, _, [x1]) -> Expression.Not(ConvExprToLinqInContext env x1) |> asExpr

| StaticEqualsQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 false Expression.Equal
| StaticNotEqQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 false Expression.NotEqual
| StaticGreaterQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 false Expression.GreaterThan
| StaticGreaterEqQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 false Expression.GreaterThanOrEqual
| StaticLessQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 false Expression.LessThan
| StaticLessEqQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 false Expression.LessThanOrEqual

| NullableEqualsQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 true Expression.Equal
| NullableNotEqQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 true Expression.NotEqual
| NullableGreaterQ (_, _,[x1;x2]) -> transBinOp env false x1 x2 true Expression.GreaterThan
Expand Down
15 changes: 13 additions & 2 deletions src/fsharp/FSharp.Core/collections.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ namespace Microsoft.FSharp.Collections
member self.GetHashCode(x) = LanguagePrimitives.PhysicalHash(x)
member self.Equals(x,y) = LanguagePrimitives.PhysicalEquality x y }

let inline NonStructural< 'T when 'T : equality and 'T : (static member ( = ) : 'T * 'T -> bool) > =
{ new IEqualityComparer< 'T > with
member self.GetHashCode(x) = NonStructuralComparison.hash x
member self.Equals(x, y) = NonStructuralComparison.(=) x y }

let inline FromFunctions hash eq : IEqualityComparer<'T> =
let eq = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(eq)
{ new IEqualityComparer<'T> with
Expand All @@ -37,10 +42,16 @@ namespace Microsoft.FSharp.Collections

module ComparisonIdentity =


let inline Structural<'T when 'T : comparison > : IComparer<'T> =
LanguagePrimitives.FastGenericComparer<'T>


#if BUILDING_WITH_LKG
#else
let inline NonStructural< 'T when 'T : (static member ( < ) : 'T * 'T -> bool) and 'T : (static member ( > ) : 'T * 'T -> bool) > : IComparer< 'T > =
{ new IComparer<'T> with
member self.Compare(x,y) = NonStructuralComparison.compare x y }
#endif

let FromFunction comparer =
let comparer = OptimizedClosures.FSharpFunc<'T,'T,int>.Adapt(comparer)
{ new IComparer<'T> with
Expand Down
13 changes: 10 additions & 3 deletions src/fsharp/FSharp.Core/collections.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ namespace Microsoft.FSharp.Collections

/// <summary>Structural comparison. Compare using Operators.compare.</summary>
val inline Structural<'T> : IComparer<'T> when 'T : comparison


#if BUILDING_WITH_LKG
#else
/// <summary>Non-structural comparison. Compare using NonStructuralComparison.compare.</summary>
val inline NonStructural< ^T > : IComparer< ^T > when ^T : (static member ( < ) : ^T * ^T -> bool) and ^T : (static member ( > ) : ^T * ^T -> bool)
#endif

/// <summary>Compare using the given comparer function.</summary>
/// <param name="comparer">A function to compare two values.</param>
/// <returns>An object implementing IComparer using the supplied comparer.</returns>
Expand All @@ -24,10 +30,11 @@ namespace Microsoft.FSharp.Collections
module HashIdentity =

/// <summary>Structural hashing. Hash using Operators.(=) and Operators.hash.</summary>
// inline justification: allows specialization of structural hash functions based on type
val inline Structural<'T> : IEqualityComparer<'T> when 'T : equality

/// <summary>Non-structural hashing. Equality using NonStructuralComparison.(=) and NonStructuralComparison.hash.</summary>
val inline NonStructural<'T> : IEqualityComparer< ^T > when ^T : equality and ^T : (static member ( = ) : ^T * ^T -> bool)

val inline LimitedStructural<'T> : limit: int -> IEqualityComparer<'T> when 'T : equality

/// <summary>Physical hashing (hash on reference identity of objects, and the contents of value types).
Expand Down
Loading

0 comments on commit f11c636

Please sign in to comment.