private static int _BinarySearchPosition(BaseFastCollection <T> collection, T currentValue) { var isFindPosition = false; var searchIndex = -1; if (collection != null) { var collectionCount = collection.Count > int.MaxValue ? int.MaxValue : (int)collection.Count; var arrayCount = collectionCount - 1; if (arrayCount >= 0) { var leftValue = 0; var rightValue = arrayCount; do { searchIndex = leftValue + (rightValue - leftValue) / 2; if (currentValue.CompareTo(collection[(ulong)searchIndex]) < 0) { rightValue = searchIndex - 1; } else if (currentValue.CompareTo(collection[(ulong)searchIndex]) > 0) { leftValue = searchIndex + 1; } else { isFindPosition = true; } if (leftValue > rightValue) { searchIndex = leftValue; isFindPosition = true; } }while (!isFindPosition); } } return(searchIndex); }
public void AddCollection(BaseFastCollection <T> collection, T currentValue) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } CheckThrowObjectDisposedException(); _addMode = AddMode.FastCollection; _availableFastCollection = collection; _currentValue = currentValue; _comboBoxClearDatas(); if (Equals(currentValue, default(T))) { if (_availableFastCollection.Count != 0) { _currentValue = _availableFastCollection[0]; _comboBox.Text = _createDataByFormatText(_currentValue); } else { _comboBoxTextEmptyValue(); } } else { _comboBox.Text = _createDataByFormatText(currentValue); } if (_availableFastCollection.Count != 0) { _subscribeComboBoxGotFocusEvents(true); } }