Last active
July 16, 2017 02:40
-
-
Save bklooste/b0130b1eaaae1cb563f0be8dc10b846c to your computer and use it in GitHub Desktop.
IMemoryIndex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FieldSelector<TValue>: Expression<Func<TValue, object>> {} | |
public interface IIndexedDictionary<TKey, TValue> : IEnumerable<TValue> | |
where TKey : IEquatable<TKey> | |
{ | |
// I dont see the value vs 2 steps , maybe accross multiple indexes... | |
// purposes is to apply a brute force predicate on an index eg ( x => return (x == myName); ) | |
IEnumerable<KeyValuePair<TKey,TIndexType>> GetSlice<TIndexType>(FieldSelector<TValue> field, TIndexType minValue = default(TIndexType), TIndexType maxValue = default(TIndexType) ); | |
// the following which returns the objects has not been included so consumers can interact with the store explicitly. | |
//Task<IEnumerable<TValue>> Where(Expression<Func<TValue, bool>> predicate);// concrete will need a convert, Func<IEnumerable<TKey>,Task<IEnumerable<TValue>>> converter); // if its crossprocess use the above and convert lists | |
IEnumerable<TKey> GetKeysInRange(FieldSelector<TValue> field , object minValue , object maxValue); | |
IEnumerable<TKey> GetKeysEqual(FieldSelector<TValue> field , object value); | |
// concrete type should have | |
// void AddIndex(FieldSelector<TValue> indexes , IComparer comparer = null); // need sort order should be part of concrete ? or do we need 2 interfaces | |
// void AddIndexes(FieldSelector<TValue> indexes); // need sort order should be part of concrete ? or do we need 2 interfaces | |
// can be not implimented , not sure if it is worth it. By the time you wait for quorum | |
//void WaitTillChanged(Tkey id , int timeout = 15); | |
// This should be on concrete class or another interface | |
//void AddRange(IEnumerable<KeyValuePair<TKey, TValue>> items); | |
} |
The biggest issue with the original is the calls are synch but the provider is asynch..
void AddIndexes(IEnumerable<Expression<Func<TValue, object>>> indexes); if we change the object to a TType you can make betetr judgements eg uncased string searches. Maybe be later ? Or pass in an IComparer on index creation ...
Can we replace object with TIndexType ? We could have a FieldSelector: Expression<Func<TValue, object>> , FieldSelector<TValue, TIndexType>: Expression<Func<TValue, , TIndexType>> maybe possible however we need to hold it in some non generic variable or introduce an interface which is getting expensive..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Big change here is this is opt in , supports ranges and is not a collection hiding the data store .. eg any keyvalue data store can have in memory indexes.. We could / should use a 3rd party lib behind the interface. Note it is also useful for non data related stuff when doing comparisons for large amount of objects.