public static Validator Spawn()
            {
                Id id = LightPool <Id> .Spawn();

                id.value = _nextId++;

                return(new Validator()
                {
                    _idRef = id,
                    _idValue = id.value
                });
            }
Exemple #2
0
        /// <summary>
        /// Returns a Query containing integers that range from one value to another.  You can
        /// optionally specify the step to used when moving along the range, as well as specifying
        /// whether or not the final value of the range should be included or not.
        ///
        /// For Example:
        ///  Range(0, 10)           = 0,1,2,3,4,5,6,7,8,9
        ///  Range(0, 10, 2)        = 0,2,4,6,8
        ///  Range(0, 10, 2, false) = 0,2,4,6,8,10
        ///  Range(10, 0)           = 10,9,8,7,6,5,4,3,2,1
        ///  Range(-1,1,false)      = -1,0,1
        /// </summary>
        public static Query <int> Range(int from, int to, int step = 1, bool endIsExclusive = true)
        {
            if (step <= 0)
            {
                throw new ArgumentException("Step must be positive and non-zero.");
            }

            List <int> values = LightPool <List <int> > .Spawn();

            try
            {
                int value = from;
                int sign  = KhalreonUtility.Sign(to - from);

                if (sign != 0)
                {
                    while (KhalreonUtility.Sign(to - value) == sign)
                    {
                        values.Add(value);
                        value += step * sign;
                    }
                }

                if (!endIsExclusive && value == to)
                {
                    values.Add(to);
                }

                return(new Query <int>(values));
            }
            finally
            {
                values.Clear();
                LightPool <List <int> > .Recycle(values);
            }
        }