ln.objects/index/IndexLeaf.cs

56 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace ln.objects.index
{
public class IndexLeaf
{
public Type LeafType { get; set; }
public string LeafName { get; set; }
public Index Index { get; set; }
Dictionary<string, IndexLeaf> leafs = new Dictionary<string, IndexLeaf>();
Func<object, object> leafGetter;
public IndexLeaf()
{
}
public IndexLeaf(Type valueType, string leafName, Func<object, object> getter)
{
LeafType = valueType;
LeafName = leafName;
leafGetter = getter;
}
public IndexLeaf GetLeaf(string path) => leafs[path];
public void AddLeaf(IndexLeaf indexLeaf) => leafs.Add(indexLeaf.LeafName, indexLeaf);
public void RemoveLeaf(string leafName) => leafs.Remove(leafName);
public void Reindex(Guid uid, object value)
{
Index?.Reindex(uid, value);
foreach (IndexLeaf indexLeaf in leafs.Values)
indexLeaf.Reindex(uid, indexLeaf.leafGetter(value));
}
public void Remove(Guid uid)
{
Index?.Remove(uid);
foreach (IndexLeaf indexLeaf in leafs.Values)
indexLeaf.Remove(uid);
}
public void Clear()
{
Index?.Clear();
foreach (IndexLeaf indexLeaf in leafs.Values)
indexLeaf.Clear();
}
public void Match(Func<object, bool> criterion, ISet<Guid> matches) => Index?.Match(criterion, matches);
}
}