コード例 #1
0
        /// <summary>
        /// Generates new Sorted Map of data. Generation is made in a copy, not to interfere with readings. Usually used after new data additions.
        /// </summary>
        private void SortMapOfArrays()
        {
            if (_itemsAllCount > _sortedMap.Length && !_isDisposed)
            {
                lock (_lockMap)
                {
                    if (_itemsAllCount > _sortedMap.Length && !_isDisposed)
                    {
                        int _containersCount = _containersData.Count;
                        int _lastIndex       = _sortedMap.Length;

                        IntInt[] arrayNewMap = new IntInt[_itemsAllCount];
                        Array.Copy(_sortedMap, arrayNewMap, _sortedMap.Length);

                        // initialize new items in Sort Map with initial unsorted positions of new items
                        for (int containerNum = _lastSortedContainer + 1; containerNum < _containersCount; containerNum++)
                        {
                            for (int arrayPos = 0; arrayPos < _containersLengths[containerNum]; arrayPos++)
                            {
                                arrayNewMap[_lastIndex] = new IntInt(containerNum, arrayPos);
                                _lastIndex++;
                            }
                        }

                        this.InsertionSortMap(arrayNewMap, _sortedMap.Length);

                        // Apply sorting as current Map
                        _sortedMap           = arrayNewMap;
                        _lastSortedContainer = _containersCount - 1;
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Allow unsorted access to data to all containers as usual array, by IntInt index, e.g. concurentArr[currentIndex]
 /// </summary>
 /// <param name="index">IntInt index of item to retrieve </param>
 /// <returns>Returns string item for index position </returns>
 public string this[IntInt index]
 {
     get
     {
         return(_containersData[index.ContainerIndex][index.ArrayIndex]);
     }
 }
コード例 #3
0
        /// <summary>
        /// Comapre the content in unordered string array, based on index parameters.
        /// </summary>
        /// <param name="item1">First Item to be compared </param>
        /// <param name="item2">Second Item, to be compared</param>
        /// <returns></returns>
        private int CompareContent(IntInt item1, IntInt item2)
        {
            string a1 = _containersData[item1.ContainerIndex][item1.ArrayIndex];
            string a2 = _containersData[item2.ContainerIndex][item2.ArrayIndex];

            return(a1.CompareTo(a2));
        }
コード例 #4
0
 /// <summary>
 /// Duplicate current sorted map. Purpose is not to work with original one, to avoid locking/ access violations on sortings.
 /// </summary>
 /// <returns></returns>
 private IntInt[] GetCurrentMapCopy()
 {
     IntInt[] currentMap = new IntInt[_sortedMap.Length];
     lock (_lockMap)
     {
         Array.Copy(_sortedMap, currentMap, _sortedMap.Length);
     }
     return(currentMap);
 }
コード例 #5
0
        /// <summary>
        /// Same as <see cref="BinarySearch{T}"/>, but allows compare to be done on another array of data
        /// </summary>
        /// <param name="arrayMap">Array with input data</param>
        /// <param name="item">Item to find position </param>
        /// <param name="low">low range to search</param>
        /// <param name="high">high range to search</param>
        /// <returns>Position, to which item should be instert</returns>
        private int BinarySearchMap(IntInt[] arrayMap, IntInt item, int low, int high)
        {
            if (high <= low)
            {
                return((CompareContent(item, arrayMap[low]) > 0) ? (low + 1) : low);
            }

            int mid = (low + high) / 2;

            if (CompareContent(item, arrayMap[mid]) == 0)
            {
                return(mid + 1);
            }

            if (CompareContent(item, arrayMap[mid]) > 0)
            {
                return(BinarySearchMap(arrayMap, item, mid + 1, high));
            }

            return(BinarySearchMap(arrayMap, item, low, mid - 1));
        }