Skip to content

Commit

Permalink
back to working linux ci
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Dec 11, 2023
1 parent b6969d5 commit 2bb43c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ skip_commits:
message: /noci .*/

build_script:
- dotnet test -f net7.0 -c Release test/ImTools.UnitTests/ImTools.UnitTests.csproj
- dotnet test -f net8.0 -c Release test/ImTools.UnitTests/ImTools.UnitTests.csproj
- dotnet test -f net7.0 -c Release -p:DevMode=false test/ImTools.UnitTests/ImTools.UnitTests.csproj

for:
- matrix:
Expand Down
24 changes: 12 additions & 12 deletions src/ImTools/ImTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6505,7 +6505,7 @@ public static DebugHashItem<K, V>[] Explain<K, V, TEq, TEntries>(this SmallMap<K
where TEntries : struct, IEntries<K, V, TEq>
{
var hashes = map.PackedHashesAndIndexes;
var capacity = (1 << map.CapacityBitShift);
var capacity = map.Capacity;
var indexMask = capacity - 1;

var items = new DebugHashItem<K, V>[hashes.Length];
Expand Down Expand Up @@ -6955,7 +6955,7 @@ public struct SmallMap<K, V, TEq, TEntries> : IReadOnlyCollection<Entry<K, V>>
#if DEBUG
ProbesTracker _dbg;
#endif
private byte _capacityBitShift;
private int _indexMask;

// The _packedHashesAndIndexes elements are of `Int32` with the bits split as following:
// 00010|000...110|01101
Expand All @@ -6969,8 +6969,8 @@ public struct SmallMap<K, V, TEq, TEntries> : IReadOnlyCollection<Entry<K, V>>
private TEntries _entries;
#pragma warning restore IDE0044

/// <summary>Capacity bits</summary>
public int CapacityBitShift => _capacityBitShift;
/// <summary>The capacity</summary>
public int Capacity => _indexMask + 1;

/// <summary>Access to the hashes and indexes</summary>
public int[] PackedHashesAndIndexes => _packedHashesAndIndexes;
Expand All @@ -6984,7 +6984,7 @@ public struct SmallMap<K, V, TEq, TEntries> : IReadOnlyCollection<Entry<K, V>>
/// <summary>Capacity calculates as `1 leftShift capacityBitShift`</summary>
public SmallMap(byte capacityBitShift)
{
_capacityBitShift = capacityBitShift;
_indexMask = (1 << capacityBitShift) - 1;

// the overflow tail to the hashes is the size of log2N where N==capacityBitShift,
// it is probably fine to have the check for the overlow of capacity because it will be mispredicted only once at the end of loop (it even rarely for the lookup)
Expand All @@ -7001,13 +7001,13 @@ public bool TryGetValue(K key, out V value)
{
var hash = default(TEq).GetHashCode(key);

var indexMask = (1 << _capacityBitShift) - 1;
var indexMask = _indexMask;
var hashMiddleMask = HashAndIndexMask & ~indexMask;
var hashMiddle = hash & hashMiddleMask;
var hashIndex = hash & indexMask;

#if NET7_0_OR_GREATER
ref var hashesAndIndexes = ref MemoryMarshal.GetArrayDataReference(_packedHashesAndIndexes);
ref var hashesAndIndexes = ref MemoryMarshal.GetArrayDataReference(_packedHashesAndIndexes);
#else
var hashesAndIndexes = _packedHashesAndIndexes;
#endif
Expand Down Expand Up @@ -7053,7 +7053,7 @@ public int GetEntryIndex(K key)
{
var hash = default(TEq).GetHashCode(key);

var indexMask = (1 << _capacityBitShift) - 1;
var indexMask = _indexMask;
var hashMiddleMask = HashAndIndexMask & ~indexMask;
var hashMiddle = hash & hashMiddleMask;
var hashIndex = hash & indexMask;
Expand Down Expand Up @@ -7100,7 +7100,7 @@ public ref V GetOrAddValueRef(K key)
{
var hash = default(TEq).GetHashCode(key);

var indexMask = (1 << _capacityBitShift) - 1;
var indexMask = _indexMask;
var entryCount = _entries.GetCount();

// if the free space is less than 1/8 of capacity (12.5%) then Resize
Expand Down Expand Up @@ -7175,7 +7175,7 @@ public bool TryRemove(K key)
{
var hash = default(TEq).GetHashCode(key);

var indexMask = (1 << _capacityBitShift) - 1;
var indexMask = _indexMask;
var hashMiddleMask = ~indexMask & HashAndIndexMask;
var hashMiddle = hash & hashMiddleMask;
var hashIndex = hash & indexMask;
Expand Down Expand Up @@ -7234,7 +7234,7 @@ internal int ResizeHashes(int indexMask)
{
if (indexMask == 0)
{
_capacityBitShift = MinCapacityBits;
_indexMask = (1 << MinCapacityBits) - 1;
_packedHashesAndIndexes = new int[1 << MinCapacityBits];
#if DEBUG
Debug.WriteLine($"[ResizeHashes] new empty hashes {1} -> {_packedHashesAndIndexes.Length}");
Expand Down Expand Up @@ -7289,7 +7289,7 @@ internal int ResizeHashes(int indexMask)
Debug.WriteLine($"[ResizeHashes] {oldCapacity} -> {newHashesAndIndexes.Length}");
_dbg.DebugReCollectAndOutputProbes(newHashesAndIndexes);
#endif
++_capacityBitShift;
_indexMask = _indexMask << 1 | 1;
_packedHashesAndIndexes = newHashesAndIndexes;
return newIndexMask;
}
Expand Down
4 changes: 2 additions & 2 deletions test/ImTools.UnitTests/SmallMapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public static void VerifyNoDuplicateKeys<K, V, TEq, TEntries>(this SmallMap<K, V
// Verify the indexes do no contains duplicate keys
var uniq = new Dictionary<K, int>(map.Count);
var hashes = map.PackedHashesAndIndexes;
var capacity = 1 << map.CapacityBitShift;
var capacity = map.Capacity;
var indexMask = capacity - 1;
for (var i = 0; i < hashes.Length; i++)
{
Expand All @@ -523,7 +523,7 @@ public static void VerifyProbesAreFitRobinHood<K, V, TEq, TEntries>(this SmallMa
where TEntries : struct, IEntries<K, V, TEq>
{
var hashes = map.PackedHashesAndIndexes;
var capacity = 1 << map.CapacityBitShift;
var capacity = map.Capacity;
var indexMask = capacity - 1;
var prevProbes = -1;
const int ProbeCountShift = 32 - MaxProbeBits;
Expand Down

0 comments on commit 2bb43c3

Please sign in to comment.