public override void Remove(IValuable <G> key, IValueProvider <G> valueProvider) { lock (this) { if (IsMap) { if (_valuesDictionary.TryGetValue(key, out EntryValuePointer <G> pointer)) { int index = pointer.Index; _valuesDictionary.Remove(key); _valuesList.RemoveAt(index); for (int i = index; i < _valuesList.Count; i++) { _valuesList[i].Index = i; } } } else { int index = AsArrayIndex(key).Value; if (index >= 0 && index < _valuesList.Count) { _valuesList.RemoveAt(index); for (int i = index; i < _valuesList.Count; i++) { _valuesList[i].Index = i; _valuesList[i].Key = valueProvider.GetInt(i); } } } } }
public override ValuePointer <G> Get(IValuable <G> key, bool createNonExistent, IValueProvider <G> valueProvider) { lock (this) { EntryValuePointer <G> pointer = null; if (!IsMap) { int?keyInt = AsArrayIndex(key); if (keyInt != null && keyInt.Value >= 0 && keyInt.Value <= _valuesList.Count) { if (keyInt.Value >= 0 && keyInt.Value < _valuesList.Count) { pointer = _valuesList[keyInt.Value]; } else if (createNonExistent) { pointer = new EntryValuePointer <G>(this, key, keyInt.Value, valueProvider); } } else if (createNonExistent) { IsMap = true; _valuesDictionary = new Dictionary <IValuable <G>, EntryValuePointer <G> >(); for (int i = 0; i < _valuesList.Count; i++) { _valuesDictionary[valueProvider.GetInt(i)] = _valuesList[i]; } } } if (IsMap && !_valuesDictionary.TryGetValue(key, out pointer)) { if (createNonExistent) { pointer = new EntryValuePointer <G>(this, key, _valuesList.Count, valueProvider); } } return(pointer); } }
public DefaultArrayMapValue(IEnumerable <ValuePointer <G> > values, IValueProvider <G> valueProvider) { IsMap = false; int index = 0; _valuesList = new List <EntryValuePointer <G> >(values.Select(pointer => new EntryValuePointer <G>(this, valueProvider.GetInt(index), index++, valueProvider, true) { Value = pointer.Value })); }
private IValuable <G> Remainder(int value, IValueProvider <G> valueProvider) { return(valueProvider.GetInt(Data % value)); }
private IValuable <G> Or(int value, IValueProvider <G> valueProvider) { return(valueProvider.GetInt(Data | value)); }