Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,12 @@ public static SearchValues<string> Create(ReadOnlySpan<string> values, StringCom
}

private static bool TryGetSingleRange<T>(ReadOnlySpan<T> values, out T minInclusive, out T maxInclusive)
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, INumber<T>
{
T min = T.MaxValue;
T max = T.MinValue;
minInclusive = values.Min();
maxInclusive = values.Max();
Comment thread
MihaZupan marked this conversation as resolved.

foreach (T value in values)
{
min = T.Min(min, value);
max = T.Max(max, value);
}

minInclusive = min;
maxInclusive = max;

uint range = uint.CreateChecked(max - min) + 1;
uint range = uint.CreateChecked(maxInclusive - minInclusive) + 1;
Comment thread
MihaZupan marked this conversation as resolved.
if (range > values.Length)
{
return false;
Expand All @@ -268,7 +259,7 @@ private static bool TryGetSingleRange<T>(ReadOnlySpan<T> values, out T minInclus

foreach (T value in values)
{
int offset = int.CreateChecked(value - min);
int offset = int.CreateChecked(value - minInclusive);
seenValues[offset] = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,11 @@ public byte[] SerializeToBytes()
// in other cases make use of the general serializer to long[]
long[] serialized = Serialize();

// make sure this serialization is not applied to MTBDDs
Debug.Assert(serialized.AsSpan().Min() > 0);

// get the maximal element from the array
long m = 0;
for (int i = 0; i < serialized.Length; i++)
{
// make sure this serialization is not applied to MTBDDs
Debug.Assert(serialized[i] > 0);
m = Math.Max(serialized[i], m);
}
long m = serialized.AsSpan().Max();
Comment thread
MihaZupan marked this conversation as resolved.
Comment thread
MihaZupan marked this conversation as resolved.

// k is the number of bytes needed to represent the maximal element
int k = m <= 0xFFFF ? 2 : (m <= 0xFF_FFFF ? 3 : (m <= 0xFFFF_FFFF ? 4 : (m <= 0xFF_FFFF_FFFF ? 5 : (m <= 0xFFFF_FFFF_FFFF ? 6 : (m <= 0xFF_FFFF_FFFF_FFFF ? 7 : 8)))));
Expand Down
Loading