Skip to content

Instantly share code, notes, and snippets.

@bklooste
Last active July 16, 2017 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bklooste/b0130b1eaaae1cb563f0be8dc10b846c to your computer and use it in GitHub Desktop.
Save bklooste/b0130b1eaaae1cb563f0be8dc10b846c to your computer and use it in GitHub Desktop.
IMemoryIndex
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);
}
@bklooste
Copy link
Author

bklooste commented Jul 5, 2017

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.

@bklooste
Copy link
Author

bklooste commented Jul 6, 2017

The biggest issue with the original is the calls are synch but the provider is asynch..

@bklooste
Copy link
Author

bklooste commented Jul 13, 2017

  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 ...

@bklooste
Copy link
Author

bklooste commented Jul 13, 2017

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