generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Nexus-Mods/excision
Excision
- Loading branch information
Showing
10 changed files
with
255 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/NexusMods.MnemonicDB.Abstractions/Attributes/ULongAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using NexusMods.MnemonicDB.Abstractions.ElementComparers; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// UInt64 attribute (ulong) | ||
/// </summary> | ||
public class ULongAttribute(string ns, string name) : ScalarAttribute<ulong, ulong>(ValueTags.UInt64, ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override ulong ToLowLevel(ulong value) | ||
{ | ||
return value; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override ulong FromLowLevel(ulong value, ValueTags tags, AttributeResolver resolver) | ||
{ | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.MnemonicDB.Abstractions.IndexSegments; | ||
using NexusMods.MnemonicDB.Abstractions.Query; | ||
|
||
namespace NexusMods.MnemonicDB; | ||
|
||
/// <summary> | ||
/// This is a wrapper around snapshots that allows you to query the snapshot as of a specific transaction | ||
/// id, this requires merging two indexes together, and then the deduplication of the merged index (retractions | ||
/// removing assertions). | ||
/// </summary> | ||
internal class HistorySnapshot(ISnapshot inner, TxId asOfTxId, AttributeCache attributeCache) : ISnapshot | ||
{ | ||
public IndexSegment Datoms(SliceDescriptor descriptor) | ||
{ | ||
// TODO: stop using IEnumerable and use IndexSegment directly | ||
var current = inner.Datoms(descriptor with {Index = descriptor.Index.CurrentVariant()}); | ||
var history = inner.Datoms(descriptor with {Index = descriptor.Index.HistoryVariant()}); | ||
var comparatorFn = descriptor.Index.GetComparator(); | ||
|
||
using var builder = new IndexSegmentBuilder(attributeCache); | ||
|
||
var merged = current.Merge(history, | ||
(dCurrent, dHistory) => comparatorFn.CompareInstance(dCurrent, dHistory)); | ||
|
||
foreach (var datom in merged) | ||
{ | ||
builder.Add(datom); | ||
} | ||
|
||
return builder.Build(); | ||
} | ||
|
||
public IEnumerable<IndexSegment> DatomsChunked(SliceDescriptor descriptor, int chunkSize) | ||
{ | ||
// TODO: stop using IEnumerable and use IndexSegment directly | ||
var current = inner.DatomsChunked(descriptor with {Index = descriptor.Index.CurrentVariant()}, chunkSize).SelectMany(c => c); | ||
var history = inner.DatomsChunked(descriptor with {Index = descriptor.Index.HistoryVariant()}, chunkSize).SelectMany(c => c); | ||
var comparatorFn = descriptor.Index.GetComparator(); | ||
|
||
using var builder = new IndexSegmentBuilder(attributeCache); | ||
|
||
var merged = current.Merge(history, | ||
(dCurrent, dHistory) => comparatorFn.CompareInstance(dCurrent, dHistory)); | ||
|
||
foreach (var datom in merged) | ||
{ | ||
builder.Add(datom); | ||
if (builder.Count % chunkSize == 0) | ||
{ | ||
yield return builder.Build(); | ||
builder.Reset(); | ||
} | ||
} | ||
|
||
yield return builder.Build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters