public override IDecorationOf <IStore> ApplyThisDecorationTo(IStore store) { var returnValue = new IndexingDecoration(store); return(returnValue); }
public override IDecorationOf<IStore> ApplyThisDecorationTo(IStore store) { var returnValue = new IndexingDecoration(store); return returnValue; }
public Test() : base(LogicOf <IStore> .New((x) => { x.Clear(); //add a bunch of decorations and then search for them IndexingDecoration store = x.WithIndex(); //bit 0- IHasContext //since we're not supplying an index, it assumes it's the next one store.StoreOfIndices.IndexFactory.SetBitLogic("hascontext", (o) => { return(o is IHasContext); }); //bit 1 - IHasNameValue store.StoreOfIndices.IndexFactory.SetBitLogic("hasnamevalue", (o) => { return(o is IHasNameValue); }); //bit 2 - IHasName store.StoreOfIndices.IndexFactory.SetBitLogic("hasname", (o) => { return(o is IHasName); }); for (int i = 0; i < 20; i++) { //bit 3 + i - IHasNameValue - name of i store.StoreOfIndices.IndexFactory.SetBitLogic("hasnamevalue" + i, (o) => { return(o is IHasNameValue && (o as IHasNameValue).Name == i.ToString()); }); } //this gives us a few decorations to search thru. now generate mock data int numRecords = 1; Random rnd = new Random(); Parallel.For(0, numRecords, (i) => { IHasId obj = i.BuildAsId(); //using a suddendeath iteration for each record, flip a coin and add a random namevalue //try to get lucky 10 times. //this will create discernable groupings in the distribution and predictability //eg. probability of an item to have N NameValue pair decorations is = .5 ^ (n -1). //because we're randomizing which namevalue pair decoration should also give us //a flat bias at each quanta of grouping for (int j = 0; j < 10; j++) { //coin flip //if (rnd.Next(2) == 0) // continue; //pick a decoration from 0 to 22 var decNum = rnd.Next(20); obj = obj.HasNameValue(decNum.ToString(), decNum);//decorate } //then add name on a coin flip if (rnd.Next(2) == 0) obj = obj.HasName(i.ToString()); store.SaveItem(obj); }); //add a needle to look for var needleObj = int.MaxValue.BuildAsId().HasName("root").HasNameValue("0", 0).HasNameValue("1", 1).HasNameValue("2", 2).HasNameValue("3", 3).HasNameValue("4", 4).HasNameValue("5", 5); store.SaveItem(needleObj); //use this as a mask var mask = store.StoreOfIndices.IndexFactory.GenerateIndex(needleObj); var maskFunc = mask.BuildANDLogic(); //now search for stuff var equalsFunc = mask.BuildIsEquivalentToLogic(); var findNeedleMatches = store.SearchIndex(equalsFunc); var matches = store.SearchIndex(maskFunc); store.Dispose(); })) { }