/// <inheritdoc />
        protected override void SetItem(int index, StackDependency <TContents> item)
        {
            AssertDependencyValidity(item);

            RemoveAt(index);
            Insert(index, item);
        }
 /// <summary>
 /// Creates a new instance of the <see cref="Enumerator"/> structure.
 /// </summary>
 /// <param name="collection">The collection to enumerate.</param>
 public Enumerator(StackDependencyCollection <TContents> collection)
     : this()
 {
     _collection = collection;
     _index      = -1;
     _current    = null;
 }
            /// <inheritdoc />
            public bool MoveNext()
            {
                _index++;
                if (_index < _collection.Count)
                {
                    _current = _collection[_index];
                    return(true);
                }

                _current = null;
                return(false);
            }
Example #4
0
        public void AddStackDependencyShouldSetDependant()
        {
            var dfg = new DataFlowGraph <int>(IntArchitecture.Instance);
            var n0  = dfg.Nodes.Add(0, 0);
            var n1  = dfg.Nodes.Add(1, 1);

            var dependency = new StackDependency <int>();

            n1.StackDependencies.Add(dependency);
            dependency.Add(n0);

            Assert.Same(n1, dependency.Dependent);
        }
Example #5
0
        public void RemoveStackDependencyShouldUnsetDependant()
        {
            var dfg = new DataFlowGraph <int>(IntArchitecture.Instance);
            var n0  = dfg.Nodes.Add(0, 0);
            var n1  = dfg.Nodes.Add(1, 1);

            var symbolicValue = new StackDependency <int>();

            n1.StackDependencies.Add(symbolicValue);
            symbolicValue.Add(n0);

            n1.StackDependencies.Remove(symbolicValue);
            Assert.Null(symbolicValue.Dependent);
        }
        private void AssertDependencyValidity(StackDependency <TContents> item)
        {
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (item.Dependent is not null)
            {
                throw new ArgumentException("Stack dependency was already added to another node.");
            }

            if (item.Any(n => n.Node.ParentGraph != _owner.ParentGraph))
            {
                throw new ArgumentException("Dependency contains data sources from another graph.");
            }
        }
Example #7
0
        public void AddStackDependencyWithMultipleSourcesShouldSetDegree()
        {
            var graph = new DataFlowGraph <int>(IntArchitecture.Instance);

            var n1 = graph.Nodes.Add(1, 1);
            var n2 = graph.Nodes.Add(2, 2);
            var n3 = graph.Nodes.Add(3, 3);

            Assert.Equal(0, n1.OutDegree);

            var dependency = new StackDependency <int>();

            n1.StackDependencies.Add(dependency);
            dependency.Add(n2);
            dependency.Add(n3);

            Assert.Equal(2, n1.OutDegree);
        }
Example #8
0
        public void AddStackDependencyShouldAddToDependants()
        {
            var dfg = new DataFlowGraph <int>(IntArchitecture.Instance);
            var n0  = dfg.Nodes.Add(0, 0);
            var n1  = dfg.Nodes.Add(1, 1);
            var n2  = dfg.Nodes.Add(2, 2);

            var dependency1 = new StackDependency <int>();

            n1.StackDependencies.Add(dependency1);
            dependency1.Add(n0);

            var dependency2 = new StackDependency <int>();

            n2.StackDependencies.Add(dependency2);
            dependency2.Add(n0);

            Assert.Equal(new HashSet <DataFlowNode <int> >
            {
                n1, n2
            }, new HashSet <DataFlowNode <int> >(n0.GetDependants()));
        }
 /// <inheritdoc />
 protected override void InsertItem(int index, StackDependency <TContents> item)
 {
     AssertDependencyValidity(item);
     base.InsertItem(index, item);
     item.Dependent = _owner;
 }
Example #10
0
 /// <inheritdoc />
 public void Reset()
 {
     _index   = -1;
     _current = null;
 }