Skip to content

Commit c07112c

Browse files
committed
Improved docs for ReadOnlySpanExtensions.GetDjb2HashCode<T>
1 parent c9a5c4c commit c07112c

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

Microsoft.Toolkit.HighPerformance/Extensions/ArrayExtensions.2D.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ public static int Count<T>(this T[,] array, T value)
287287

288288
/// <summary>
289289
/// Gets a content hash from the input 2D <typeparamref name="T"/> array instance using the Djb2 algorithm.
290+
/// For more info, see the documentation for <see cref="ReadOnlySpanExtensions.GetDjb2HashCode{T}"/>.
290291
/// </summary>
291292
/// <typeparam name="T">The type of items in the input 2D <typeparamref name="T"/> array instance.</typeparam>
292293
/// <param name="array">The input 2D <typeparamref name="T"/> array instance.</param>

Microsoft.Toolkit.HighPerformance/Extensions/ArrayExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public static SpanTokenizer<T> Tokenize<T>(this T[] array, T separator)
179179

180180
/// <summary>
181181
/// Gets a content hash from the input <typeparamref name="T"/> array instance using the Djb2 algorithm.
182+
/// For more info, see the documentation for <see cref="ReadOnlySpanExtensions.GetDjb2HashCode{T}"/>.
182183
/// </summary>
183184
/// <typeparam name="T">The type of items in the input <typeparamref name="T"/> array instance.</typeparam>
184185
/// <param name="array">The input <typeparamref name="T"/> array instance.</param>

Microsoft.Toolkit.HighPerformance/Extensions/ReadOnlySpanExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ public static ReadOnlySpanTokenizer<T> Tokenize<T>(this ReadOnlySpan<T> span, T
234234

235235
/// <summary>
236236
/// Gets a content hash from the input <see cref="ReadOnlySpan{T}"/> instance using the Djb2 algorithm.
237+
/// It was designed by <see href="https://en.wikipedia.org/wiki/Daniel_J._Bernstein">Daniel J. Bernstein</see> and is a
238+
/// <see href="https://en.wikipedia.org/wiki/List_of_hash_functions#Non-cryptographic_hash_functions">non-cryptographic has function</see>.
239+
/// The main advantages of this algorithm are a good distribution of the resulting hash codes, which results in a relatively low
240+
/// number of collisions, while at the same time being particularly fast to process, making it suitable for quickly hashing
241+
/// even long sequences of values. For the reference implementation, see: <see href="http://www.cse.yorku.ca/~oz/hash.html"/>.
242+
/// For details on the used constants, see the details provided in this StackOverflow answer (as well as the accepted one):
243+
/// <see href="https://stackoverflow.com/questions/10696223/reason-for-5381-number-in-djb-hash-function/13809282#13809282"/>.
244+
/// Additionally, a comparison between some common hashing algoriths can be found in the reply to this StackExchange question:
245+
/// <see href="https://softwareengineering.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed"/>.
246+
/// Note that the exact implementation is slightly different in this method when it is not called on a sequence of <see cref="byte"/>
247+
/// values: in this case the <see cref="object.GetHashCode"/> method will be invoked for each <typeparamref name="T"/> value in
248+
/// the provided <see cref="ReadOnlySpan{T}"/> instance, and then those values will be combined using the Djb2 algorithm.
237249
/// </summary>
238250
/// <typeparam name="T">The type of items in the input <see cref="ReadOnlySpan{T}"/> instance.</typeparam>
239251
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> instance.</param>

Microsoft.Toolkit.HighPerformance/Extensions/SpanExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public static SpanTokenizer<T> Tokenize<T>(this Span<T> span, T separator)
164164

165165
/// <summary>
166166
/// Gets a content hash from the input <see cref="Span{T}"/> instance using the Djb2 algorithm.
167+
/// For more info, see the documentation for <see cref="ReadOnlySpanExtensions.GetDjb2HashCode{T}"/>.
167168
/// </summary>
168169
/// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
169170
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>

Microsoft.Toolkit.HighPerformance/Extensions/StringExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public static ReadOnlySpanTokenizer<char> Tokenize(this string text, char separa
148148

149149
/// <summary>
150150
/// Gets a content hash from the input <see cref="string"/> instance using the Djb2 algorithm.
151+
/// For more info, see the documentation for <see cref="ReadOnlySpanExtensions.GetDjb2HashCode{T}"/>.
151152
/// </summary>
152153
/// <param name="text">The source <see cref="string"/> to enumerate.</param>
153154
/// <returns>The Djb2 value for the input <see cref="string"/> instance.</returns>

0 commit comments

Comments
 (0)