HashIdentity Module
Common notions of value identity implementing the IEqualityComparer interface, for constructing Dictionary objects and other collections
Functions and values
Function or value |
Description
|
Full Usage:
FromFunctions hasher equality
Parameters:
'T -> int
-
A function to generate a hash code from a value.
equality : 'T -> 'T -> bool
-
A function to test equality of two values.
Returns: IEqualityComparer<'T>
An object implementing IEqualityComparer using the given functions.
Modifiers: inline Type parameters: 'T |
Get an implementation of equality semantics using the given functions.
ExampleCreate a dictionary which uses the given functions for equality and hashing:
namespace System
namespace System.Collections
namespace System.Collections.Generic
val modIdentity: ((obj -> obj -> bool) -> IEqualityComparer<obj>)
module HashIdentity
from Microsoft.FSharp.Collections
val FromFunctions: hasher: ('T -> int) -> equality: ('T -> 'T -> bool) -> IEqualityComparer<'T>
val i: 'a (requires member (%))
val i1: 'a (requires member (%) and equality and member (%))
val i2: 'a (requires member (%) and equality and member (%))
val dict: Dictionary<int,int>
Multiple items
type Dictionary<'TKey,'TValue> = interface ICollection<KeyValuePair<'TKey,'TValue>> interface IEnumerable<KeyValuePair<'TKey,'TValue>> interface IEnumerable interface IDictionary<'TKey,'TValue> interface IReadOnlyCollection<KeyValuePair<'TKey,'TValue>> interface IReadOnlyDictionary<'TKey,'TValue> interface ICollection interface IDictionary interface IDeserializationCallback interface ISerializable ... <summary>Represents a collection of keys and values.</summary> <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> <typeparam name="TValue">The type of the values in the dictionary.</typeparam> -------------------- Dictionary() : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>) : Dictionary<'TKey,'TValue> Dictionary(comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int) : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Multiple items
In this example, only one entry is added, as the keys val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int 2 and 7 have the same hash and are equal according to the provided functions.
|
Full Usage:
LimitedStructural limit
Parameters:
int
-
The limit on the number of hashing operations used.
Returns: IEqualityComparer<'T>
An object implementing IEqualityComparer.
Modifiers: inline Type parameters: 'T |
Get an implementation of equality semantics using limited structural equality and structural hashing.
ExampleCreate a dictionary which uses limited structural equality and structural hashing on the key, allowing trees as efficient keys:
namespace System
namespace System.Collections
namespace System.Collections.Generic
Multiple items
union case Tree.Tree: int * Tree list -> Tree -------------------- type Tree = | Tree of int * Tree list type Tree = | Tree of int * Tree list
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T list = List<'T>
val dict: Dictionary<Tree,int>
Multiple items
type Dictionary<'TKey,'TValue> = interface ICollection<KeyValuePair<'TKey,'TValue>> interface IEnumerable<KeyValuePair<'TKey,'TValue>> interface IEnumerable interface IDictionary<'TKey,'TValue> interface IReadOnlyCollection<KeyValuePair<'TKey,'TValue>> interface IReadOnlyDictionary<'TKey,'TValue> interface ICollection interface IDictionary interface IDeserializationCallback interface ISerializable ... <summary>Represents a collection of keys and values.</summary> <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> <typeparam name="TValue">The type of the values in the dictionary.</typeparam> -------------------- Dictionary() : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>) : Dictionary<'TKey,'TValue> Dictionary(comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int) : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> module HashIdentity
from Microsoft.FSharp.Collections
val LimitedStructural: limit: int -> IEqualityComparer<'T> (requires equality)
val tree1: Tree
val tree2: Tree
Dictionary.Add(key: Tree, value: int) : unit
|
Full Usage:
NonStructural
Returns: IEqualityComparer<^T>
An object implementing IEqualityComparer using NonStructuralComparison.op_Equality
and NonStructuralComparison.hash.
Modifiers: inline Type parameters: ^T |
Get an implementation of equality semantics using non-structural equality and non-structural hashing.
ExampleCreate a dictionary which uses non-structural equality and hashing on the key:
namespace System
namespace System.Collections
namespace System.Collections.Generic
val dict: Dictionary<System.DateTime,int>
Multiple items
type Dictionary<'TKey,'TValue> = interface ICollection<KeyValuePair<'TKey,'TValue>> interface IEnumerable<KeyValuePair<'TKey,'TValue>> interface IEnumerable interface IDictionary<'TKey,'TValue> interface IReadOnlyCollection<KeyValuePair<'TKey,'TValue>> interface IReadOnlyDictionary<'TKey,'TValue> interface ICollection interface IDictionary interface IDeserializationCallback interface ISerializable ... <summary>Represents a collection of keys and values.</summary> <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> <typeparam name="TValue">The type of the values in the dictionary.</typeparam> -------------------- Dictionary() : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>) : Dictionary<'TKey,'TValue> Dictionary(comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int) : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Multiple items
[<Struct>] type DateTime = new: date: DateOnly * time: TimeOnly -> unit + 16 overloads member Add: value: TimeSpan -> DateTime member AddDays: value: float -> DateTime member AddHours: value: float -> DateTime member AddMicroseconds: value: float -> DateTime member AddMilliseconds: value: float -> DateTime member AddMinutes: value: float -> DateTime member AddMonths: months: int -> DateTime member AddSeconds: value: float -> DateTime member AddTicks: value: int64 -> DateTime ... <summary>Represents an instant in time, typically expressed as a date and time of day.</summary> -------------------- System.DateTime () (+0 other overloads) System.DateTime(ticks: int64) : System.DateTime (+0 other overloads) System.DateTime(date: System.DateOnly, time: System.TimeOnly) : System.DateTime (+0 other overloads) System.DateTime(ticks: int64, kind: System.DateTimeKind) : System.DateTime (+0 other overloads) System.DateTime(date: System.DateOnly, time: System.TimeOnly, kind: System.DateTimeKind) : System.DateTime (+0 other overloads) System.DateTime(year: int, month: int, day: int) : System.DateTime (+0 other overloads) System.DateTime(year: int, month: int, day: int, calendar: System.Globalization.Calendar) : System.DateTime (+0 other overloads) System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : System.DateTime (+0 other overloads) System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: System.DateTimeKind) : System.DateTime (+0 other overloads) System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: System.Globalization.Calendar) : System.DateTime (+0 other overloads) Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module HashIdentity
from Microsoft.FSharp.Collections
val NonStructural<'T (requires equality and member (=))> : IEqualityComparer<'T> (requires equality and member (=))
Dictionary.Add(key: System.DateTime, value: int) : unit
property System.DateTime.Now: System.DateTime with get
<summary>Gets a <see cref="T:System.DateTime" /> object that is set to the current date and time on this computer, expressed as the local time.</summary> <returns>An object whose value is the current local date and time.</returns> |
Full Usage:
Reference
Returns: IEqualityComparer<'T>
An object implementing IEqualityComparer using LanguagePrimitives.PhysicalEquality
and LanguagePrimitives.PhysicalHash.
|
Get an implementation of equality semantics using reference equality and reference hashing.
ExampleCreate a dictionary which uses reference equality and hashing on the key, giving each key reference identity:
namespace System
namespace System.Collections
namespace System.Collections.Generic
val dict: Dictionary<int array,int>
Multiple items
type Dictionary<'TKey,'TValue> = interface ICollection<KeyValuePair<'TKey,'TValue>> interface IEnumerable<KeyValuePair<'TKey,'TValue>> interface IEnumerable interface IDictionary<'TKey,'TValue> interface IReadOnlyCollection<KeyValuePair<'TKey,'TValue>> interface IReadOnlyDictionary<'TKey,'TValue> interface ICollection interface IDictionary interface IDeserializationCallback interface ISerializable ... <summary>Represents a collection of keys and values.</summary> <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> <typeparam name="TValue">The type of the values in the dictionary.</typeparam> -------------------- Dictionary() : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>) : Dictionary<'TKey,'TValue> Dictionary(comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int) : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module HashIdentity
from Microsoft.FSharp.Collections
val Structural<'T (requires equality)> : IEqualityComparer<'T> (requires equality)
val arr1: int array
val arr2: int array
Dictionary.Add(key: int array, value: int) : unit
In this example, two entries are added to the dictionary, as the arrays have different object reference identity.
|
Full Usage:
Structural
Returns: IEqualityComparer<'T>
An object implementing IEqualityComparer using Operators.op_Equality and Operators.hash.
Modifiers: inline Type parameters: 'T |
Get an implementation of equality semantics using structural equality and structural hashing.
ExampleCreate a dictionary which uses structural equality and structural hashing on the key, allowing an array as a key:
namespace System
namespace System.Collections
namespace System.Collections.Generic
val dict: Dictionary<int array,int>
Multiple items
type Dictionary<'TKey,'TValue> = interface ICollection<KeyValuePair<'TKey,'TValue>> interface IEnumerable<KeyValuePair<'TKey,'TValue>> interface IEnumerable interface IDictionary<'TKey,'TValue> interface IReadOnlyCollection<KeyValuePair<'TKey,'TValue>> interface IReadOnlyDictionary<'TKey,'TValue> interface ICollection interface IDictionary interface IDeserializationCallback interface ISerializable ... <summary>Represents a collection of keys and values.</summary> <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> <typeparam name="TValue">The type of the values in the dictionary.</typeparam> -------------------- Dictionary() : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>) : Dictionary<'TKey,'TValue> Dictionary(comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int) : Dictionary<'TKey,'TValue> Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(collection: IEnumerable<KeyValuePair<'TKey,'TValue>>, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : Dictionary<'TKey,'TValue> Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module HashIdentity
from Microsoft.FSharp.Collections
val Structural<'T (requires equality)> : IEqualityComparer<'T> (requires equality)
val arr1: int array
val arr2: int array
In this example, only one entry is added to the dictionary, as the arrays identical by structural equality.
|