Spinach.SwarmMemory.splitIndex C# (CSharp) Method

splitIndex() public method

public splitIndex ( int start, int end, int number, List &lhs, List &rhs ) : int
start int
end int
number int
lhs List
rhs List
return int
        public int splitIndex(int start, int end, int number, out List<int> lhs, out List<int> rhs)
        {
            if (start < end)
            {
                Console.WriteLine("Incorrect start and end.");
            }
            int range = end - start + 1;
            int quotient = range / number;
            int residue = range % number;
            lhs = new List<int>();
            rhs = new List<int>();
            if (number == 1)
            {
                lhs.Add(start);
                rhs.Add(end);
                return lhs.Count;
            }

            if (residue == 0)
            {
                for (int i = 0; i < number; ++i)
                {
                    lhs.Add(start + quotient * i);
                    rhs.Add(start + quotient * (i + 1) - 1);
                }
            }
            else
            {
                int local_start = 0;
                int local_end = 0;
                for (int i = 0; i < residue; ++i)
                {
                    lhs.Add(local_start);
                    local_end = local_start + quotient;
                    rhs.Add(local_end);
                    local_start = local_end + 1;
                }
                for (int i = residue; i < number; i++)
                {
                    lhs.Add(local_start);
                    local_end = local_start + quotient - 1;
                    rhs.Add(local_end);
                    local_start = local_end + 1;
                }
            }

            return lhs.Count;
        }