Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronous addition of the edge (asynchronous lock of edges list)
        /// </summary>
        /// <param name="edge"></param>
        /// <returns></returns>
        public async Task <Graph <T> > AddAsync(IEdge <T> edge)
        {
            _edges.ThrowIfContainsWithLock(edge, _rwEdgesLock);
            _edges.AddWithLock(edge, _rwEdgesLock);

            if (!await _nodes.ContainsWithLockAsync(edge.Nodes.Item1, _rwNodesLock))
            {
                await _nodes.AddWithLockAsync(edge.Nodes.Item1, _rwNodesLock);
            }
            if (!await _nodes.ContainsWithLockAsync(edge.Nodes.Item2, _rwNodesLock))
            {
                await _nodes.AddWithLockAsync(edge.Nodes.Item2, _rwNodesLock);
            }

            edge.Connect();

            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Synchronous addition of the edge (synchronous lock of edges list)
        /// </summary>
        /// <param name="edge"></param>
        /// <returns></returns>
        public Graph <T> Add(IEdge <T> edge)
        {
            _edges.ThrowIfContainsWithLock(edge, _rwEdgesLock);
            _edges.AddWithLock(edge, _rwEdgesLock);

            if (!_nodes.ContainsWithLock(edge.Nodes.Item1, _rwNodesLock))
            {
                _nodes.AddWithLock(edge.Nodes.Item1, _rwNodesLock);
            }
            if (!_nodes.ContainsWithLock(edge.Nodes.Item2, _rwNodesLock))
            {
                _nodes.AddWithLock(edge.Nodes.Item2, _rwNodesLock);
            }

            edge.Connect();

            return(this);
        }