Skip to content

Commit

Permalink
Merge pull request #112 from Nexus-Mods/tame-the-warnings
Browse files Browse the repository at this point in the history
tame-the-warnings
  • Loading branch information
halgari authored Nov 12, 2024
2 parents 87522de + ec65bf3 commit 00ddc0c
Show file tree
Hide file tree
Showing 66 changed files with 539 additions and 225 deletions.
1 change: 1 addition & 0 deletions NexusMods.MnemonicDB.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EAVT/@EntryIndexedValue">EAVT</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=datom/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=datoms/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ABenchmark : IAsyncLifetime

public async Task InitializeAsync()
{
await Task.Yield();
var builder = Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,4 @@ public int FindBinarySearchRework()
var find = EntityId.From((ulong)ToFind);
return _index.FindFirst(find); // Return the first occurrence found, or -1 if not found
}

[Benchmark]
public int FindBinarySearchReworkAVX2()
{
var find = EntityId.From((ulong)ToFind);
return _index.FindFirstAVX2(find.Value); // Return the first occurrence found, or -1 if not found
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12"/>
<PackageReference Include="JetBrains.Profiler.Api" Version="1.4.6" />
<PackageReference Update="JetBrains.Annotations" Version="2023.3.0"/>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="JetBrains.Profiler.Api" Version="1.4.8" />
<PackageReference Update="JetBrains.Annotations" Version="2024.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Update="JetBrains.Annotations" Version="2023.3.0"/>
<PackageReference Update="JetBrains.Annotations" Version="2024.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/NexusMods.MnemonicDB.Abstractions/Attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public abstract class Attribute<TValueType, TLowLevelType, TSerializer> :
IReadableAttribute<TValueType>
where TSerializer : IValueSerializer<TLowLevelType>
{

/// <summary>
/// Constructor used when subclassing, provides a few of the important flags
/// and the name of the attribute
/// </summary>
protected Attribute(
string ns,
string name,
Expand Down
3 changes: 3 additions & 0 deletions src/NexusMods.MnemonicDB.Abstractions/AttributeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public sealed class AttributeCache
private ValueTag[] _valueTags;
private BitArray _isNoHistory;

/// <summary>
/// Constructs a new cache, populated with the hardcoded attribute definitions
/// </summary>
public AttributeCache()
{
var maxId = AttributeDefinition.HardcodedIds.Values.Max() + 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NexusMods.MnemonicDB.Abstractions.Models;
// ReSharper disable UnusedTypeParameter
#pragma warning disable CS9113 // Parameter is unread.

namespace NexusMods.MnemonicDB.Abstractions.Attributes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace NexusMods.MnemonicDB.Abstractions.DatomComparators;
/// <summary>
/// The AEVT Comparator.
/// </summary>
/// <typeparam name="TRegistry"></typeparam>
public sealed class AEVTComparator : ADatomComparator<
AComparer,
EComparer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using NexusMods.MnemonicDB.Abstractions.ElementComparers;
using NexusMods.MnemonicDB.Abstractions.Internals;
using NexusMods.MnemonicDB.Storage.Abstractions.ElementComparers;

namespace NexusMods.MnemonicDB.Abstractions.DatomComparators;

/// <summary>
/// The EAVT Comparator.
/// </summary>
/// <typeparam name="TRegistry"></typeparam>
public sealed class EAVTComparator : ADatomComparator<
EComparer,
AComparer,
Expand Down
1 change: 1 addition & 0 deletions src/NexusMods.MnemonicDB.Abstractions/DatomKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public int GetHashCode(DatomKey obj)
return hash.ToHashCode();
}

/// <inheritdoc />
public override string ToString()
{
if (_valueMemory.IsEmpty)
Expand Down
3 changes: 3 additions & 0 deletions src/NexusMods.MnemonicDB.Abstractions/DatomStoreSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ namespace NexusMods.MnemonicDB.Abstractions;
/// </summary>
public class DatomStoreSettings
{
/// <summary>
/// The path to the datom store's storage
/// </summary>
public AbsolutePath Path { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public static IServiceCollection AddAttribute<TAttribute>(this IServiceCollectio
/// Assumes that the specified type is a static class with nested attribute classes, it registers all the nested
/// classes with the service collection.
/// </summary>
/// <param name="services"></param>
/// <typeparam name="TAttributeCollection"></typeparam>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static IServiceCollection AddAttributeCollection(this IServiceCollection services,
Type type)
{
Expand Down
3 changes: 3 additions & 0 deletions src/NexusMods.MnemonicDB.Abstractions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace NexusMods.MnemonicDB.Abstractions;

/// <summary>
/// Extensions for IEnumerable
/// </summary>
public static class EnumerableExtensions
{
/// <summary>
Expand Down

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions src/NexusMods.MnemonicDB.Abstractions/GlobalComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public static unsafe int Compare(byte* aPtr, int aLen, byte* bPtr, int bLen)
};
}

/// <summary>
/// Compare two datoms
/// </summary>
public static int Compare(in Datom a, in Datom b)
{
var cmp = ((byte)a.Prefix.Index).CompareTo((byte)b.Prefix.Index);
Expand Down
3 changes: 3 additions & 0 deletions src/NexusMods.MnemonicDB.Abstractions/ITransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public interface ITransaction : IDisposable
void Add<TVal, TAttribute>(EntityId entityId, TAttribute attribute, TVal val, bool isRetract = false)
where TAttribute : IWritableAttribute<TVal>;

/// <summary>
/// Adds a new datom to the transaction
/// </summary>
void Add<TVal, TLowLevel, TSerializer>(EntityId entityId, Attribute<TVal, TLowLevel, TSerializer> attribute, TVal val, bool isRetract = false)
where TSerializer : IValueSerializer<TLowLevel>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void Dispose() { }
/// <summary>
/// A wrapper around EntityIds that auto-creates the given ReadModel on-the-fly
/// </summary>
/// <typeparam name="TModel"></typeparam>
public Entities(EntityIds ids, IDb db)
{
_ids = ids;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
namespace NexusMods.MnemonicDB.Abstractions.IndexSegments;

public interface IIndexSegment<TValue>
/// <summary>
/// An index segment that reutrns values of a specific type
/// </summary>
/// <typeparam name="TValue"></typeparam>
public interface IIndexSegment<out TValue>
{
/// <summary>
/// Gets the value at the given index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,46 +227,7 @@ public int FindFirst(EntityId find)
}
return result; // Return the first occurrence found, or -1 if not found
}

public int FindFirstAVX2(ulong find)
{
var targetVector = Vector256<ulong>.Zero.WithElement(0, find)
.WithElement(1, find)
.WithElement(2, find)
.WithElement(3, find);

var casted = MemoryMarshal.Cast<ulong, Vector256<ulong>>(Lowers);

for (var idx = 0; idx < casted.Length; idx += 1)
{
var lowers = casted[idx];

var maskHigh = Avx2.And(lowers, Vector256.Create(0x7F00000000000000UL));
var maskLow = Avx2.And(Avx2.ShiftRightLogical(lowers, 8), Vector256.Create(0x0000FFFFFFFFFFFFUL));
var ored = Avx2.Or(maskHigh, maskLow);

var comparison = Avx2.CompareEqual(ored, targetVector);

var mask = Avx2.MoveMask(comparison.As<ulong, byte>());
if (mask != 0)
{
var index = BitOperations.TrailingZeroCount(mask) / 8;
return idx * Vector256<ulong>.Count + index;
}
}

// Handle remaining elements
for (int i = (casted.Length * Vector256<ulong>.Count); i < Lowers.Length; i++)
{
if (Lowers[i] >= find)
{
return i;
}
}

return -1; // No value found that is greater than or equal to the target
}


/// <summary>
/// Enumerator.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace NexusMods.MnemonicDB.Abstractions.IndexSegments;
private readonly PooledMemoryBufferWriter _data;
private readonly AttributeCache _attributeCache;

/// <summary>
/// Not supported, use the other constructor
/// </summary>
/// <exception cref="NotSupportedException"></exception>
public IndexSegmentBuilder()
{
throw new NotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace NexusMods.MnemonicDB.Abstractions.IndexSegments;

/// <summary>
/// Extensions for working with index segments
/// </summary>
public static class IndexSegmentExtensions
{
/// <summary>
Expand Down Expand Up @@ -88,7 +91,10 @@ public static List<EntityId> MergeByEntityId(this IndexSegment setA, IndexSegmen
return result;
}


/// <summary>
/// Merges four index segments by entity id, returning a list of the entity ids found in all four segments. This is a
/// union operation, and assumes that the four segments ar ordered by entity id.
/// </summary>
public static List<EntityId> MergeByEntityId(this IndexSegment setA, IndexSegment setB, IndexSegment setC, IndexSegment setD)
{
var lowerA = setA.Lowers;
Expand Down
52 changes: 44 additions & 8 deletions src/NexusMods.MnemonicDB.Abstractions/IndexType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,74 @@
using NexusMods.MnemonicDB.Abstractions.DatomComparators;
using NexusMods.MnemonicDB.Abstractions.DatomIterators;
using NexusMods.MnemonicDB.Abstractions.Internals;
// ReSharper disable InconsistentNaming

namespace NexusMods.MnemonicDB.Abstractions;

/// <summary>
/// The type of indexes in the database
/// </summary>
public enum IndexType : byte
{
// No specified index, default for datoms
/// <summary>
/// Default for datoms that are not part of an index
/// </summary>
None = 0,

// Transaction log, the final source of truth, used
// for replaying the database
/// <summary>
/// Transaction log index
/// </summary>
TxLog = 1,

// Primary index for looking up values on an entity
/// <summary>
/// Current row-level index
/// </summary>
EAVTCurrent = 2,

/// <summary>
/// History row-level index
/// </summary>
EAVTHistory,

// Indexes for asking what entities have this attribute?
/// <summary>
/// Current column-level index
/// </summary>
AEVTCurrent,

/// <summary>
/// History column-level index
/// </summary>
AEVTHistory,

// Backref index for asking "who references this entity?"
/// <summary>
/// Current reverse reference index
/// </summary>
VAETCurrent,

/// <summary>
/// History reverse reference index
/// </summary>
VAETHistory,

// Secondary index for asking "who has this value on this attribute?"
/// <summary>
/// Current indexed value index
/// </summary>
AVETCurrent,

/// <summary>
/// History indexed value index
/// </summary>
AVETHistory
}


/// <summary>
/// Extension methods for the IndexType enum
/// </summary>
public static class IndexTypeExtensions
{
/// <summary>
/// Get a comparator for the given index type
/// </summary>
public static IDatomComparator GetComparator(this IndexType type)
{
return type switch
Expand Down
Loading

0 comments on commit 00ddc0c

Please sign in to comment.