Example #1
0
        public RemoteChunksSeries(long mapId,
                                  IKeyComparer <K> comparer,
                                                                                // mapId, current map version => map with chunk keys and versions
                                  Func <long, long, Task <SortedMap <long, SeriesChunk> > > remoteKeysLoader,
                                                                                // mapId, chunkKey => deserialied chunk
                                  Func <long, long, Task <SeriesChunk> > remoteLoader,
                                                                                // mapId, chunkKey, deserialied chunk => whole map version
                                  Func <SeriesChunk, Task <long> > remoteSaver, // TODO corresponding updates
                                                                                // mapId, chunkKey, direction => whole map version
                                  Func <long, long, long, Lookup, Task <long> > remoteRemover,
                                  long version,
                                  bool readOnly = false)
        {
            _mapId            = mapId;
            _comparer         = comparer;
            _remoteKeysLoader = remoteKeysLoader;
            _remoteLoader     = remoteLoader;
            _remoteSaver      = remoteSaver;
            _remoteRemover    = remoteRemover;
            _readOnly         = readOnly;

            var renewedKeys = _remoteKeysLoader(_mapId, 0).Result;
            var sm          = renewedKeys.Map((k, ch) => new LazyValue(k, ch.Count, ch.Version, this)).ToSortedMap();

            sm.IsSynchronized = true;
            _chunksCache      = sm;
            var maxChunkVersion = _chunksCache.Values.Max(x => x.ChunkVersion);

            if (maxChunkVersion != version)
            {
                Trace.TraceWarning("Inconsistent series version in chunks and series definition.");
            }
            _chunksCache.Version = Math.Max(version, maxChunkVersion);
        }
Example #2
0
 private KeyComparer(IComparer <T> comparer)
 {
     if (comparer != null && !ReferenceEquals(comparer, Comparer <T> .Default))
     {
         //
         if (IsBuiltInNumericType)
         {
             ThrowHelper.ThrowNotSupportedException("Custom IComparer<T> for built-in type is not supported. Create a wrapper struct that implements IComparable<T> and use KeyComparer<T>.Default for it.");
         }
         if (IsIComparable)
         {
             ThrowHelper.ThrowNotSupportedException("Custom IComparer<T> for a type T that implements IComparable<T> is not supported. Create a wrapper struct that implements a different IComparable<T> logic and use KeyComparer<T>.Default for it.");
         }
         if (comparer is IKeyComparer <T> kc)
         {
             _keyComparer = kc;
         }
         else
         {
             _keyComparer = new DummyKeyComparer <T>(comparer);
         }
     }
     else
     {
         _keyComparer = null;
     }
 }
 public KeyDetails(KeyDetails key, IKeyComparer comparer)
 {
     Type     = key.Type;
     BaseType = key.BaseType;
     Fields.AddRange(key.Fields);
     KeyComparer = comparer;
 }
Example #4
0
 public TValue GetOrAdd <TKey, TValue>(
     TKey key,
     Func <TKey, TValue> valueFactory,
     IKeyComparer <TKey> keyComparer = null)
 {
     return(CreateScoped <TKey, TValue>(keyComparer).GetOrAdd(key, valueFactory));
 }
Example #5
0
 public IronLeveldbStub(IronLeveldbOptions options,
                        ISeekable <InternalKey, InternalIByteArrayKeyValuePair> dataProvider, Action onDispose = null)
 {
     _dataProvider = dataProvider;
     _onDispose    = onDispose;
     _comparer     = options?.Comparer ?? LeveldbDefaultKeyComparer.Comparer;
 }
Example #6
0
        public ICache <TKey, TValue> CreateScoped <TKey, TValue>(IKeyComparer <TKey> keyComparer = null)
        {
            var cache = _cachesByType.GetOrAdd(
                typeof(ICache <TKey, TValue>),
                t => CreateNew <TKey, TValue>(keyComparer));

            return((ICache <TKey, TValue>)cache);
        }
	// Constructors.
	protected KeyedCollectionBase(IKeyComparer comparer, int capacity)
			{
				if(comparer == null)
				{
					throw new ArgumentNullException("comparer");
				}
				this.comparer = comparer;
				this.values = new ArrayList(capacity);
				this.keys = new ArrayList(capacity);
			}
Example #8
0
 // Constructors.
 protected KeyedCollectionBase(IKeyComparer comparer, int capacity)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException("comparer");
     }
     this.comparer = comparer;
     this.values   = new ArrayList(capacity);
     this.keys     = new ArrayList(capacity);
 }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="comparer"></param>
 internal KeyComparer(IComparer <T> comparer)
 {
     if (comparer != null)
     {
         _comparer = comparer;
         if (comparer is IKeyComparer <T> kc)
         {
             _keyComparer = kc;
         }
     }
 }
Example #10
0
 private KeyComparer(IComparer <T> comparer)
 {
     if (comparer != null && !ReferenceEquals(comparer, Comparer <T> .Default))
     {
         _comparer = comparer;
         if (comparer is IKeyComparer <T> kc)
         {
             _keyComparer = kc;
         }
     }
 }
Example #11
0
 /// <summary>
 /// Get a new or default instance of KeyComparer.
 /// </summary>
 public static KeyComparer <T> Create(IKeyComparer <T> comparer)
 {
     if (comparer == null)
     {
         return(Default);
     }
     if (comparer is KeyComparer <T> kc)
     {
         return(kc);
     }
     return(new KeyComparer <T>(comparer));
 }
Example #12
0
        public ArrayCache(IKeyComparer <TKey> keyComparer)
        {
            _capacity    = DefaultCapacity;
            _length      = 0;
            _keyComparer = keyComparer ?? default(DefaultComparer <TKey>);
            _values      = new TValue[DefaultCapacity];

            if (UseHashCodes)
            {
                _hashCodes  = new int[DefaultCapacity];
                _keyIndexes = new int[DefaultCapacity];
            }
            else
            {
                _keys = new TKey[DefaultCapacity];
            }
        }
Example #13
0
 /// <summary>
 /// Get a new or default instance of KeyComparer.
 /// </summary>
 public static KeyComparer <T> Create(IKeyComparer <T> comparer)
 {
     return(comparer == null ? Default : new KeyComparer <T>(comparer));
 }
Example #14
0
 public InternalKeyComparer(IKeyComparer userComparer)
 {
     _userComparer = userComparer;
 }
Example #15
0
 public ICache <TKey, TValue> CreateNew <TKey, TValue>(IKeyComparer <TKey> keyComparer = null)
 => new ArrayCache <TKey, TValue>(keyComparer);
Example #16
0
 public KeyedCollection(IKeyComparer comparer) : base(comparer)
 {
 }
Example #17
0
 // Constructors.
 public KeyedCollection(IKeyComparer comparer, int capacity)
     : base(comparer, capacity)
 {
 }
	protected KeyedCollectionBase(IKeyComparer comparer) : this(comparer, 16) {}
	// Constructors.
	public KeyedCollection(IKeyComparer comparer, int capacity)
			: base(comparer, capacity) {}
Example #20
0
	public Dictionary(int capacity, IKeyComparer comparer)
			{
				// TODO
			}
Example #21
0
 protected KeyedCollectionBase(IKeyComparer comparer) : this(comparer, 16)
 {
 }
Example #22
0
	public Dictionary(IDictionary<K,V> dictionary, IKeyComparer comparer)
			{
				// TODO
			}
	public KeyedCollection(IKeyComparer comparer) : base(comparer) {}
Example #24
0
	public Dictionary(IKeyComparer comparer)
			{
				// TODO
			}