Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41ddc16

Browse files
dsymelatkin
authored andcommitted
document primitive hash-compare implementation and improve hash/comparison/distinctBy/groupBy performance
1 parent959cbdc commit41ddc16

File tree

9 files changed

+502
-278
lines changed

9 files changed

+502
-278
lines changed

‎src/fsharp/FSharp.Core/collections.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.FSharp.Collections
2020
let inlineStructural<'Twhen'T:equality>:IEqualityComparer<'T>=
2121
LanguagePrimitives.FastGenericEqualityComparer<'T>
2222

23-
letLimitedStructural<'Twhen'T:equality>(limit):IEqualityComparer<'T>=
23+
letinlineLimitedStructural<'Twhen'T:equality>(limit):IEqualityComparer<'T>=
2424
LanguagePrimitives.FastLimitedGenericEqualityComparer<'T>(limit)
2525

2626
letReference<'Twhen'T:notstruct>:IEqualityComparer<'T>=
@@ -38,7 +38,7 @@ namespace Microsoft.FSharp.Collections
3838
moduleComparisonIdentity=
3939

4040

41-
letStructural<'Twhen'T:comparison>:IComparer<'T>=
41+
letinlineStructural<'Twhen'T:comparison>:IComparer<'T>=
4242
LanguagePrimitives.FastGenericComparer<'T>
4343

4444
letFromFunction comparer=

‎src/fsharp/FSharp.Core/collections.fsi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.FSharp.Collections
1313
moduleComparisonIdentity=
1414

1515
/// <summary>Structural comparison. Compare using Operators.compare.</summary>
16-
valStructural<'T>:IComparer<'T>when 'T:comparison
16+
valinlineStructural<'T>:IComparer<'T>when 'T:comparison
1717

1818
/// <summary>Compare using the given comparer function.</summary>
1919
/// <param name="comparer">A function to compare two values.</param>
@@ -28,7 +28,7 @@ namespace Microsoft.FSharp.Collections
2828
// inline justification: allows specialization of structural hash functions based on type
2929
val inlineStructural<'T>:IEqualityComparer<'T>when 'T:equality
3030

31-
valLimitedStructural<'T>:limit:int->IEqualityComparer<'T>when 'T:equality
31+
valinlineLimitedStructural<'T>:limit:int->IEqualityComparer<'T>when 'T:equality
3232

3333
/// <summary>Physical hashing (hash on reference identity of objects, and the contents of value types).
3434
/// Hash using LanguagePrimitives.PhysicalEquality and LanguagePrimitives.PhysicalHash,

‎src/fsharp/FSharp.Core/list.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ namespace Microsoft.FSharp.Collections
5959
letiter f list= Microsoft.FSharp.Primitives.Basics.List.iter f list
6060

6161
[<CompiledName("Distinct")>]
62-
letdistinct(list:'T list)= Microsoft.FSharp.Primitives.Basics.List.distinct HashIdentity.Structural<'T> list
62+
letdistinct(list:'T list)= Microsoft.FSharp.Primitives.Basics.List.distinctWithComparer HashIdentity.Structural<'T> list
6363

6464
[<CompiledName("DistinctBy")>]
65-
letdistinctBy keyf(list:'T list)= Microsoft.FSharp.Primitives.Basics.List.distinctBy HashIdentity.Structural<_> keyf list
65+
letdistinctBy keyf(list:'T list)= Microsoft.FSharp.Primitives.Basics.List.distinctByWithComparer HashIdentity.Structural<_> keyf list
6666

6767
[<CompiledName("OfArray")>]
6868
letofArray(array:'T array)= Microsoft.FSharp.Primitives.Basics.List.ofArray array

‎src/fsharp/FSharp.Core/local.fs‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module internal List =
4141
else
4242
distinctToFreshConsTail cons hashSet rest
4343

44-
letdistinct(comparer:System.Collections.Generic.IEqualityComparer<'T>)(list:'T list)=
44+
letdistinctWithComparer(comparer:System.Collections.Generic.IEqualityComparer<'T>)(list:'T list)=
4545
match listwith
4646
|[]->[]
4747
|[h]->[h]
@@ -63,7 +63,7 @@ module internal List =
6363
else
6464
distinctByToFreshConsTail cons hashSet keyf rest
6565

66-
letdistinctBy(comparer:System.Collections.Generic.IEqualityComparer<'Key>)(keyf:'T->'Key)(list:'T list)=
66+
letdistinctByWithComparer(comparer:System.Collections.Generic.IEqualityComparer<'Key>)(keyf:'T->'Key)(list:'T list)=
6767
match listwith
6868
|[]->[]
6969
|[h]->[h]
@@ -627,6 +627,7 @@ module internal Array =
627627
|_,_->
628628
letcomparer=match comparerwithnull-> LanguagePrimitives.FastGenericComparer<'Key>|_-> comparer
629629
qsort(keys, values,0, keys.Length-1, comparer)
630+
630631
static memberSort<'Key,'Valuewhen'Key:comparison>(keys:'Key[],values:'Value[])=
631632
letvaluesExist=
632633
match valueswith
@@ -637,13 +638,7 @@ module internal Array =
637638
|_,_when valuesExist&&(keys.Length<> values.Length)-> raise(ArgumentException())
638639
|_,_->
639640
qsort(keys,values,0,keys.Length-1,LanguagePrimitives.FastGenericComparer<'Key>)
640-
(*
641-
static member Sort<'Key,'Value when 'Key : comparison>(keys : 'Key[], values : 'Value[], start : int, last : int) =
642-
match keys with
643-
| null -> raise (ArgumentNullException())
644-
| _ ->
645-
qsort(keys,values,start,last,LanguagePrimitives.FastGenericComparer<'Key>)
646-
*)
641+
647642
static memberSort<'Key,'Valuewhen'Key:comparison>(keys:'Key[],values:'Value[],start:int,length:int,comparer:IComparer<'Key>)=
648643
match keyswith
649644
|null-> raise(ArgumentNullException())

‎src/fsharp/FSharp.Core/local.fsi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ open Microsoft.FSharp.Core
77
openMicrosoft.FSharp.Collections
88

99
moduleinternalList=
10-
valdistinct:System.Collections.Generic.IEqualityComparer<'T>->'T list->'T list
11-
valdistinctBy:System.Collections.Generic.IEqualityComparer<'Key>->('T->'Key)->list:'T list->'T list when 'Key:equality
10+
valdistinctWithComparer:System.Collections.Generic.IEqualityComparer<'T>->'T list->'T list
11+
valdistinctByWithComparer:System.Collections.Generic.IEqualityComparer<'Key>->('T->'Key)->list:'T list->'T list when 'Key:equality
1212
valinit:int->(int->'T)->'T list
1313
valiter:('T-> unit)->'T list->unit
1414
valfilter:predicate:('T-> bool)->'T list->'T list

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp