@@ -142,6 +142,15 @@ private static void InitCharArrays(string alphabet, string seps, ReadOnlySpan<ch
142142 }
143143 }
144144
145+ #if NETCOREAPP3_1_OR_GREATER
146+ /// <summary>
147+ /// Encodes the provided number into a hashed string
148+ /// </summary>
149+ /// <param name="number">the number</param>
150+ /// <returns>the hashed string</returns>
151+ public string Encode ( int number ) => EncodeLong ( number ) ;
152+ #endif
153+
145154 /// <summary>
146155 /// Encodes the provided numbers into a hash string.
147156 /// </summary>
@@ -156,6 +165,20 @@ private static void InitCharArrays(string alphabet, string seps, ReadOnlySpan<ch
156165 /// <returns>Encoded hash string.</returns>
157166 public virtual string Encode ( IEnumerable < int > numbers ) => Encode ( numbers . ToArray ( ) ) ;
158167
168+ #if NETCOREAPP3_1_OR_GREATER
169+ /// <summary>
170+ /// Encodes the provided number into a hashed string
171+ /// </summary>
172+ /// <param name="number">the number</param>
173+ /// <returns>the hashed string</returns>
174+ public string EncodeLong ( long number )
175+ {
176+ ReadOnlySpan < long > span = stackalloc [ ] { number } ;
177+
178+ return GenerateHashFrom ( span ) ;
179+ }
180+ #endif
181+
159182 /// <summary>
160183 /// Encodes the provided numbers into a hash string.
161184 /// </summary>
@@ -268,7 +291,7 @@ private string GenerateHashFrom(ReadOnlySpan<long> numbers)
268291 {
269292 Array . Copy ( alphabet , 0 , shuffleBuffer , startIndex , length ) ;
270293 }
271-
294+
272295 ConsistentShuffle ( alphabet , _alphabet . Length , shuffleBuffer , _alphabet . Length ) ;
273296 var hashLength = BuildReversedHash ( number , alphabet , hashBuffer ) ;
274297
@@ -375,7 +398,7 @@ private long[] GetNumbersFrom(string hash)
375398
376399 if ( lottery == '\0 ' ) /* default(char) == '\0' */
377400 return Array . Empty < long > ( ) ;
378-
401+
379402 hashBreakdown = hashBreakdown . Substring ( 1 ) ;
380403
381404 hashArray = hashBreakdown . Split ( _seps , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -447,4 +470,4 @@ private static void ConsistentShuffle(char[] alphabet, int alphabetLength, ReadO
447470 }
448471 }
449472 }
450- }
473+ }
0 commit comments