58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
using ln.collections;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace ln.objects.index
|
|
{
|
|
class SimpleIndex<T> : Index
|
|
{
|
|
BTreeValueSet<T, Guid> index = new BTreeValueSet<T, Guid>();
|
|
BTree<Guid, T> reverseIndex = new BTree<Guid, T>();
|
|
|
|
public SimpleIndex()
|
|
{
|
|
}
|
|
|
|
public override void Clear()
|
|
{
|
|
index.Clear();
|
|
reverseIndex.Clear();
|
|
}
|
|
|
|
public override void Match(Func<object, bool> criterion, ISet<Guid> matches)
|
|
{
|
|
foreach (T ivalue in index.Keys)
|
|
{
|
|
if (criterion(ivalue))
|
|
matches.UnionWith(index[ivalue]);
|
|
}
|
|
}
|
|
|
|
public override void Reindex(Guid uid, object value)
|
|
{
|
|
Remove(uid);
|
|
index.Add((T)value, uid);
|
|
}
|
|
|
|
public override void Remove(Guid uid)
|
|
{
|
|
if (reverseIndex.ContainsKey(uid))
|
|
{
|
|
index.TryRemove(reverseIndex[uid], uid);
|
|
reverseIndex.TryRemove(uid);
|
|
}
|
|
}
|
|
|
|
public override bool TryDeserializeIndex(byte[] serializedIndex)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override bool TrySerializeIndex(out byte[] serializedIndex)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|