Esempio n. 1
0
 public void Select(object item, bool ctrlKey, bool shiftKey)
 {
     if ((!(shiftKey || ctrlKey)) || (shiftKey && _selectionBase == null))
     {
         Selection = new SortedSet(Source.Compare, (Array)Script.Literal("[item]"), true);
         _selectionBase = item;
         _selectionFocus = item;
     }
     else if (shiftKey)
     {
         int first = Source.IndexOf(_selectionBase);
         int last = Source.IndexOf(item);
         if (first > last)
         {
             int x = first;
             first = last;
             last = x;
         }
         Selection = new SortedSet(Source.Compare, Source.GetItems(first, last - first + 1), true);
         _selectionFocus = item;
     }
     else
     {
         Array newSel = Selection.GetAllItems();
         int ins = Util.BinarySearchForInsert(newSel, item, Selection.Compare);
         ((ArrayList)(object)newSel).Insert(ins, item);
         Selection = new SortedSet(Selection.Compare, newSel, true);
         _selectionBase = item;
         _selectionFocus = item;
     }
     // TODO this.triggerItemFocused();
 }
Esempio n. 2
0
        public override async Task <bool> TryAddAsync(TKey key, ISortedSet <TItem> value, bool overwrite = false, CancellationToken cancelationToken = default)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var internalSet = value as InternalSortedSetList;

            if (internalSet != null)
            {
                return(internalSet.Key.Equals(key) && overwrite);
            }

            var database = GetDatabase() as IDatabase;

            if (database == null)
            {
                throw new NotSupportedException("The database instance type is not supported");
            }

            var redisKey = GetRedisKey(key);

            if (await database.KeyExistsAsync(redisKey, ReadFlags) && !overwrite)
            {
                return(false);
            }

            var transaction  = database.CreateTransaction();
            var commandTasks = new List <Task>();

            if (overwrite)
            {
                commandTasks.Add(transaction.KeyDeleteAsync(redisKey, WriteFlags));
            }

            internalSet = CreateList(key, transaction);

            var enumerable = await value.AsEnumerableWithScoreAsync().ConfigureAwait(false);

            foreach (var item in enumerable)
            {
                commandTasks.Add(internalSet.AddAsync(item.Value, item.Key));
            }

            var success = await transaction.ExecuteAsync(WriteFlags).ConfigureAwait(false);

            await Task.WhenAll(commandTasks).ConfigureAwait(false);

            return(success);
        }
Esempio n. 3
0
 public static TreeSet <E> NewTreeSet <E>(ISortedSet <E> s)
 {
     return(new TreeSet <E>(s));
 }
Esempio n. 4
0
 public override ISortedSet <T> GetResult(ISortedSet <T> set) => set.GetViewBetween(LowerValue, UpperValue);
Esempio n. 5
0
 public override IEnumerable <T> GetResult(ISortedSet <T> set) => set.Reverse();
Esempio n. 6
0
 public override T GetResult(ISortedSet <T> set) => set.Max;
Esempio n. 7
0
 public abstract R GetResult(ISortedSet <T> set);
Esempio n. 8
0
 public sealed override void Accept(ISortedSet <T> set) => _ = GetResult(set);
Esempio n. 9
0
 public abstract void Accept(ISortedSet <T> set);
Esempio n. 10
0
 public void SelectAll()
 {
     Selection = new SortedSet(Source.Compare, Source.GetAllItems(), true);
 }