Beispiel #1
0
        private int GetCurrentPosition(ChangeAwareList <T> target, T item)
        {
            var index = _sortOptions == SortOptions.UseBinarySearch ? target.BinarySearch(item, _comparer) : target.IndexOf(item);

            if (index < 0)
            {
                throw new SortException($"Cannot find item: {typeof(T).Name} -> {item}");
            }

            return(index);
        }
Beispiel #2
0
        private int GetInsertPositionBinary(ChangeAwareList <T> target, T item)
        {
            int index       = target.BinarySearch(item, _comparer);
            int insertIndex = ~index;

            //sort is not returning uniqueness
            if (insertIndex < 0)
            {
                throw new SortException("Binary search has been specified, yet the sort does not yeild uniqueness");
            }
            return(insertIndex);
        }
Beispiel #3
0
        private int GetCurrentPosition(ChangeAwareList <T> target, T item)
        {
            int index = _sortOptions == SortOptions.UseBinarySearch
                ? target.BinarySearch(item, _comparer)
                : target.IndexOf(item);

            if (index < 0)
            {
                throw new SortException("Current item cannot be found");
            }

            return(index);
        }
Beispiel #4
0
        private int GetCurrentPosition(ChangeAwareList <T> target, T item)
        {
            int index;

            if (_sortOptions == SortOptions.UseBinarySearch)
            {
                index = target.BinarySearch(item, _comparer);
            }
            else
            {
                var index1 = target.IndexOf(item);
                index = target.IndexOf(item, _referencEqualityComparer);

                Debug.Assert(index == index1);
            }

            if (index < 0)
            {
                throw new SortException("Current item cannot be found");
            }

            return(index);
        }