Simplify inverted indexes
This commit is contained in:
parent
8a9712cfd8
commit
455b8e2c6c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
bin/
|
||||
obj/
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# Ignore pre compiled web interface
|
||||
docker/dist
|
||||
|
@ -68,14 +68,14 @@ public class TestAudioFingerprinting
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7
|
||||
var fpr = new List<uint>(new uint[] { 1, 2, 3, 1, 5, 77, 42, 2 }).AsReadOnly();
|
||||
var expected = new Dictionary<uint, Collection<uint>>()
|
||||
var expected = new Dictionary<uint, int>()
|
||||
{
|
||||
{1, new Collection<uint>{ 0, 3 } },
|
||||
{2, new Collection<uint>{ 1, 7 } },
|
||||
{3, new Collection<uint>{ 2 } },
|
||||
{5, new Collection<uint>{ 4 } },
|
||||
{42, new Collection<uint>{ 6 } },
|
||||
{77, new Collection<uint>{ 5 } },
|
||||
{1, 3},
|
||||
{2, 7},
|
||||
{3, 2},
|
||||
{5, 4},
|
||||
{42, 6},
|
||||
{77, 5},
|
||||
};
|
||||
|
||||
var actual = Chromaprint.CreateInvertedIndex(fpr);
|
||||
|
@ -110,24 +110,21 @@ public static class Chromaprint
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a Chromaprint into an inverted index of fingerprint points to the indexes they appeared at.
|
||||
/// Transforms a Chromaprint into an inverted index of fingerprint points to the last index it appeared at.
|
||||
/// </summary>
|
||||
/// <param name="fingerprint">Chromaprint fingerprint.</param>
|
||||
/// <returns>Inverted index.</returns>
|
||||
public static Dictionary<uint, Collection<uint>> CreateInvertedIndex(ReadOnlyCollection<uint> fingerprint)
|
||||
public static Dictionary<uint, int> CreateInvertedIndex(ReadOnlyCollection<uint> fingerprint)
|
||||
{
|
||||
var invIndex = new Dictionary<uint, Collection<uint>>();
|
||||
var invIndex = new Dictionary<uint, int>();
|
||||
|
||||
for (int i = 0; i < fingerprint.Count; i++)
|
||||
{
|
||||
// Get the current point.
|
||||
var point = fingerprint[i];
|
||||
|
||||
// Create a new collection for points of this value if it doesn't exist already.
|
||||
invIndex.TryAdd(point, new Collection<uint>());
|
||||
|
||||
// Append the current sample's timecode to the collection for this point.
|
||||
invIndex[point].Add((uint)i);
|
||||
invIndex[point] = i;
|
||||
}
|
||||
|
||||
return invIndex;
|
||||
|
@ -530,9 +530,8 @@ public class FingerprinterTask : IScheduledTask
|
||||
|
||||
if (rhsIndex.ContainsKey(point))
|
||||
{
|
||||
// TODO: consider all timecodes before falling back
|
||||
var lhsFirst = (int)lhsIndex[point][0];
|
||||
var rhsFirst = (int)rhsIndex[point][0];
|
||||
var lhsFirst = (int)lhsIndex[point];
|
||||
var rhsFirst = (int)rhsIndex[point];
|
||||
indexShifts.Add(rhsFirst - lhsFirst);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user