Example #1
0
        private Row GetRow(int forIndex)
        {
            // If there are no rows available in the cache, create one from scratch
            if (_rowCache.Count == 0)
            {
                var newRow = CreateRow();
                PopulateRow(forIndex, newRow);
                return(newRow);
            }

            var data = _itemList[forIndex];

            Row row    = null;
            Row altRow = null;

            // Determine if the row we're looking for is an alt row
            var target = forIndex % 2;

            // Try and find a row which previously had this data, so we can reuse it
            for (var i = 0; i < _rowCache.Count; i++)
            {
                row = _rowCache[i];

                // If this row previously represented this data, just use that one.
                if (row.Data == data)
                {
                    _rowCache.RemoveAt(i);
                    PopulateRow(forIndex, row);
                    break;
                }

                // Cache a row which is was the same alt state as the row we're looking for, in case
                // we don't find an exact match.
                if (row.Index % 2 == target)
                {
                    altRow = row;
                }

                // Didn't match, reset to null
                row = null;
            }

            // If an exact match wasn't found, but a row with the same alt-status was found, use that one.
            if (row == null && altRow != null)
            {
                _rowCache.Remove(altRow);
                row = altRow;
                PopulateRow(forIndex, row);
            }
            else if (row == null)
            {
                // No match found, use the last added item in the cache
                row = _rowCache.PopLast();
                PopulateRow(forIndex, row);
            }

            return(row);
        }
Example #2
0
        protected static Bandit GetBandit()
        {
            if (BanditCache.Count == 0)
            {
                return(new Bandit());
            }

            return(BanditCache.PopLast());
        }
Example #3
0
        private void InternalPerformScan()
        {
            while (_nearUnits.Count > 0)
            {
                RecycleBandit((Bandit)_nearUnits.PopLast());
            }

            PerformScan();

            _nearUnits.Sort((p, q) => p.Distance.CompareTo(q.Distance));

            if (Time.realtimeSinceStartup > NextCacheCheck)
            {
                CleanCache();
            }
        }