示例#1
0
        /// <summary>
        ///     Swap two items, across all divisions.
        /// </summary>
        /// <param name="dataDivisionList">The division list.</param>
        /// <param name="a">The index of the first item to swap.</param>
        /// <param name="b">The index of the second item to swap.</param>
        private void VirtualSwap(IEnumerable <DataDivision> dataDivisionList, int a, int b)
        {
            DataDivision divA    = null;
            DataDivision divB    = null;
            int          offsetA = 0;
            int          offsetB = 0;

            // Find points a and b in the collections.
            int baseIndex = 0;

            foreach (DataDivision division in dataDivisionList)
            {
                baseIndex += division.Count;

                if (divA == null && a < baseIndex)
                {
                    divA    = division;
                    offsetA = a - (baseIndex - division.Count);
                }
                if (divB == null && b < baseIndex)
                {
                    divB    = division;
                    offsetB = b - (baseIndex - division.Count);
                }
            }

            // Swap a and b.
            int temp = divA.Mask[offsetA];

            divA.Mask[offsetA] = divB.Mask[offsetB];
            divB.Mask[offsetB] = temp;
        }
示例#2
0
        /// <summary>
        ///     Generate the counts for all divisions, give remaining items to final division.
        /// </summary>
        /// <param name="dataDivisionList">The division list.</param>
        /// <param name="totalCount">The total count.</param>
        private void GenerateCounts(IList <DataDivision> dataDivisionList,
                                    int totalCount)
        {
            // First pass at division.
            int countSofar = 0;

            foreach (DataDivision division in dataDivisionList)
            {
                var count = (int)(division.Percent * totalCount);
                division.Count = count;
                countSofar    += count;
            }
            // Adjust any remaining count
            int remaining = totalCount - countSofar;

            while (remaining-- > 0)
            {
                int          idx = _rnd.NextInt(dataDivisionList.Count);
                DataDivision div = dataDivisionList[idx];
                div.Count = div.Count + 1;
            }
        }