コード例 #1
0
        public int Add(AutoWrap obj)
        {
            var element = new StorageElem(obj);
            var gotLock = false;

            try
            {
                _lockObject.Enter(ref gotLock);

                if (FirstDeleted == -1)
                {
                    return(AddInArray(element));
                }
                else
                {
                    int newPos = FirstDeleted;
                    FirstDeleted      = _elements[newPos].Next;
                    _elements[newPos] = element;
                    return(newPos);
                }
            }
            finally
            {
                if (gotLock)
                {
                    _lockObject.Exit();
                }
            }
        }
コード例 #2
0
        private int AddInArray(StorageElem element)
        {
            if (ElementsCount == _arraySize)
            {
                var temp = new StorageElem[_arraySize * 2];
                Array.Copy(_elements, 0, temp, 0, _elements.Length);
                _elements  = temp;
                _arraySize = _elements.Length;
            }

            _elements[ElementsCount] = element;
            var res = ElementsCount;

            ElementsCount++;
            return(res);
        }
コード例 #3
0
        public void RemoveKey(int position)
        {
            if (position > 0 && position < _elements.Length && _elements[position].Wrap != null)
            {
                var gotLock = false;
                try
                {
                    _lockObject.Enter(ref gotLock);

                    var element = new StorageElem(null, FirstDeleted);
                    _elements[position] = element;
                    FirstDeleted        = position;
                }
                finally
                {
                    if (gotLock)
                    {
                        _lockObject.Exit();
                    }
                }
            }
        }