base32 refactoring
.NET Test / .NET tests (push) Failing after 1m54s

This commit is contained in:
2026-07-10 21:53:37 +04:00
parent d11c74e5d6
commit 566c813e8d
18 changed files with 375 additions and 88 deletions
+6 -3
View File
@@ -51,7 +51,7 @@ public sealed class SeqId(DateTime epoch)
/// Thrown if more than 255 IDs generated in 1ms
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long NextId(RngEntropy entropy = RngEntropy.Strong) => Default.Next(DateTime.UtcNow, entropy);
public static long NextId(RngEntropy entropy = RngEntropy.Strong) => Default.Next(entropy);
#if NET9_0_OR_GREATER
private readonly Lock _lock = new();
@@ -62,6 +62,7 @@ public sealed class SeqId(DateTime epoch)
private readonly DateTime _epoch = epoch;
private int _seqId = 0;
private long _lastTimestamp = -1L;
private Func<DateTime> _defaultTimeFactory = static () => DateTime.UtcNow;
/// <summary>
/// Generates next ID using current UTC time
@@ -72,7 +73,7 @@ public sealed class SeqId(DateTime epoch)
/// Thrown if more than 255 IDs generated in 1ms
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Next(RngEntropy entropy = RngEntropy.Strong) => Next(DateTime.UtcNow, entropy);
public long Next(RngEntropy entropy = RngEntropy.Strong) => Next(_defaultTimeFactory(), entropy);
/// <summary>
/// Generates next ID with explicit timestamp
@@ -104,7 +105,7 @@ public sealed class SeqId(DateTime epoch)
throw new InvalidOperationException("Refused to create new SeqId. Last timestamp is in the future.");
}
if (_seqId == SeqMask)
if (_seqId > SeqMask)
{
throw new IndexOutOfRangeException("Refused to create new SeqId. Sequence exhausted.");
}
@@ -118,4 +119,6 @@ public sealed class SeqId(DateTime epoch)
return timestamp | currentSeq | currentRand;
}
internal void UnsafeReplaceDefaultTimeFactory(Func<DateTime> timeFactory) => _defaultTimeFactory = timeFactory;
}