Example #1
0
        internal ConcurrentDependencyNode(ConcurrentDependencyGraph graph, int index, IDictionary <int, string> labels, int headIndex)
        {
            if (index < 0)
            {
                throw new ConcurrentGraphException("Not allowed to have negative node index");
            }

            if (headIndex < -1)
            {
                throw new ConcurrentGraphException("Not allowed to have head index less than -1.");
            }

            if (index == 0 && headIndex != -1)
            {
                throw new ConcurrentGraphException("Not allowed to add head to a root node.");
            }

            if (index == headIndex)
            {
                throw new ConcurrentGraphException("Not allowed to add head to itself");
            }

            this.graph = graph ?? throw new ConcurrentGraphException("The graph node must belong to a dependency graph.");

            Index = index;

            this.labels = new SortedDictionary <int, string>(labels);

            HeadIndex = headIndex;
        }
Example #2
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            if (obj == null)
            {
                return(false);
            }

            if (GetType() != obj.GetType())
            {
                return(false);
            }

            ConcurrentDependencyGraph other = (ConcurrentDependencyGraph)obj;

            if (DataFormat == null)
            {
                if (other.DataFormat != null)
                {
                    return(false);
                }
            }
            else if (!DataFormat.Equals(other.DataFormat))
            {
                return(false);
            }

            return(Arrays.Equals(nodes, other.nodes));
        }
Example #3
0
        internal ConcurrentDependencyNode(ConcurrentDependencyGraph graph, ConcurrentDependencyNode node)
        {
            this.graph = graph ?? throw new ConcurrentGraphException("The graph node must belong to a dependency graph.");

            Index = node.Index;

            labels = new SortedDictionary <int, string>(node.labels);

            HeadIndex = node.HeadIndex;
        }
Example #4
0
        /// <summary>
        /// Creates a copy of a dependency graph
        /// </summary>
        /// <param name="graph"> a dependency graph </param>
        /// <exception cref="ConcurrentGraphException"> </exception>
        public ConcurrentDependencyGraph(ConcurrentDependencyGraph graph)
        {
            DataFormat = graph.DataFormat;

            nodes = new ConcurrentDependencyNode[graph.nodes.Length + 1];

            for (int i = 0; i < graph.nodes.Length; i++)
            {
                nodes[i] = new ConcurrentDependencyNode(this, graph.nodes[i]);
            }
        }
Example #5
0
        internal ConcurrentDependencyNode(ConcurrentDependencyGraph graph, int index, IReadOnlyList <string> labels)
        {
            if (index < 0)
            {
                throw new ConcurrentGraphException("Not allowed to have negative node index");
            }

            this.graph = graph ?? throw new ConcurrentGraphException("The graph node must belong to a dependency graph.");

            Index = index;

            this.labels = new SortedDictionary <int, string>();

            int tmpHeadIndex = -1;

            if (labels != null)
            {
                for (int i = 0; i < labels.Count; i++)
                {
                    int columnCategory = this.graph.DataFormat.GetColumnDescription(i).Category;

                    if (columnCategory == ColumnDescription.Head)
                    {
                        tmpHeadIndex = int.Parse(labels[i]);
                    }
                    else if (columnCategory == ColumnDescription.Input || columnCategory == ColumnDescription.DependencyEdgeLabel)
                    {
                        this.labels[i] = labels[i];
                    }
                }
            }

            HeadIndex = tmpHeadIndex;

            if (HeadIndex < -1)
            {
                throw new ConcurrentGraphException("Not allowed to have head index less than -1.");
            }

            if (Index == 0 && HeadIndex != -1)
            {
                throw new ConcurrentGraphException("Not allowed to add head to a root node.");
            }

            if (Index == HeadIndex)
            {
                throw new ConcurrentGraphException("Not allowed to add head to itself");
            }
        }