Ejemplo n.º 1
0
        public CachedStorage(IStorage baseStorage, int blockSize, int cacheSize, bool leaveOpen)
        {
            BaseStorage = baseStorage;
            BlockSize   = blockSize;
            LeaveOpen   = leaveOpen;

            BaseStorage.GetSize(out long baseSize).ThrowIfFailure();
            Length = baseSize;

            for (int i = 0; i < cacheSize; i++)
            {
                var block = new CacheBlock {
                    Buffer = new byte[blockSize], Index = -1
                };
                Blocks.AddLast(block);
            }
        }
Ejemplo n.º 2
0
        public CachedStorage(IStorage baseStorage, int blockSize, int cacheSize, bool leaveOpen)
        {
            BaseStorage = baseStorage;
            BlockSize   = blockSize;
            _length     = BaseStorage.GetSize();

            if (!leaveOpen)
            {
                ToDispose.Add(BaseStorage);
            }

            for (int i = 0; i < cacheSize; i++)
            {
                var block = new CacheBlock {
                    Buffer = new byte[blockSize], Index = -1
                };
                Blocks.AddLast(block);
            }
        }
Ejemplo n.º 3
0
        public CachedStorage(IStorage baseStorage, int blockSize, int cacheSize, bool leaveOpen)
        {
            BaseStorage = baseStorage;
            BlockSize   = blockSize;
            Length      = BaseStorage.Length;

            if (!leaveOpen)
            {
                ToDispose.Add(BaseStorage);
            }

            for (int i = 0; i < cacheSize; i++)
            {
                var block = new CacheBlock {
                    Buffer = ArrayPool <byte> .Shared.Rent(blockSize)
                };
                Blocks.AddLast(block);
            }
        }
        private void RecursiveBcc(int u)
        {
            // Initialize discovery time and low value
            _discovery[u] = _low[u] = time++;

            //near nodes to check
            List <int> childrens = new List <int>();

            if ((u + 1) % World.Width != 0 && !IsBlockedLinear(u + 1))
            {
                childrens.Add(u + 1);                                                        //right location
            }
            if (u % World.Width != 0 && !IsBlockedLinear(u - 1))
            {
                childrens.Add(u - 1);                                                  //left location
            }
            if (!IsBlockedLinear(u + World.Width))
            {
                childrens.Add(u + World.Width);                                    //down location
            }
            if (!IsBlockedLinear(u - World.Width))
            {
                childrens.Add(u - World.Width);                                    //up location
            }
            foreach (var v in childrens)
            {
                if (_discovery[v] == -1) //child not visited, continue recursion
                {
                    _parent[v] = u;
                    _edgeStack.Push(new Edge(u, v));
                    RecursiveBcc(v);

                    // Case 1 (Strongly Connected Components Article)
                    // Check if the subtree rooted with 'v' has a connection to one of the ancestors of 'u'
                    if (_low[u] > _low[v])
                    {
                        _low[u] = _low[v];
                    }
                    // If u is an articulation point,
                    // pop all edges from stack till u -- v
                    if ((_discovery[u] == 1 && childrens.Count > 1) || (_discovery[u] > 1 && _low[v] >= _discovery[u]))
                    {
                        Edge          edgeInBlock;
                        HashSet <int> blk = new HashSet <int>();
                        while (_edgeStack.Peek().U != u || _edgeStack.Peek().V != v)
                        {
                            edgeInBlock = _edgeStack.Pop();
                            blk.Add(edgeInBlock.U);
                            blk.Add(edgeInBlock.V);
                        }
                        edgeInBlock = _edgeStack.Pop();
                        blk.Add(edgeInBlock.U);
                        blk.Add(edgeInBlock.V);
                        Blocks.AddLast(blk);
                    }
                }

                // Case 2 (Strongly Connected Components Article)
                // Update low value of 'u' only of 'v' is still in stack (i.e. it's a back edge, not cross edge).
                else if (v != _parent[u] && _discovery[v] < _low[u])
                {
                    if (_low[u] > _discovery[v])
                    {
                        _low[u] = _discovery[v];
                    }
                    _edgeStack.Push(new Edge(u, v));
                }
            } //foreach childrens
        }