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