public void RemoveOutEdge(ref DynamicArrayBlockAllocator <EdgeIdx> links, ref int start, EdgeIdx edge)
        {
            var oldCapacity = this.OutDegree + this.InDegree;
            var span        = links.AsSpan(start, oldCapacity);
            var i           = span.IndexOf(edge);

            Debug.Assert(i < this.OutDegree);

            if (this.InDegree > 0)
            {
                span[i] = span[this.OutDegree];
                span[this.OutDegree] = span[span.Length - 1];
            }
            else
            {
                span[i] = span[span.Length - 1];
            }

            if (oldCapacity == 1)
            {
                links.Deallocate(start, 1);
                start = -1;
            }
            else
            {
                start = links.Resize(start, oldCapacity, oldCapacity - 1);
            }

            this.OutDegree--;
        }
        public void AddInEdge(ref DynamicArrayBlockAllocator <EdgeIdx> links, ref int start, EdgeIdx edge)
        {
            if (start < 0)
            {
                start         = links.Allocate(1);
                this.InDegree = 1;
                links[start]  = edge;
                return;
            }

            var oldCapacity = this.OutDegree + this.InDegree;

            start = links.Resize(start, oldCapacity, oldCapacity + 1);
            links[start + oldCapacity] = edge;
            this.InDegree++;
        }
示例#3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="UndirectedGraph{TVertex,TEdge}"/> class that is empty.
 /// </summary>
 public UndirectedGraph()
 {
     this._vertices = new(0);
     this._edges    = new(0);
     this._links    = new(0, 31);
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="DirectedGraphWithoutInEdges{TVertex,TEdge}"/> class that is empty.
 /// </summary>
 public DirectedGraphWithoutInEdges()
 {
     this._vertices = new(0);
     this._edges    = new(0);
     this._links    = new(0, 31);
 }
 public void RemoveInEdge(ref DynamicArrayBlockAllocator <EdgeIdx> links, ref int start, EdgeIdx edge)
 {
     this.RemoveOutEdge(ref links, ref start, Reverse(edge));
 }