Ejemplo n.º 1
0
        private EdgePair LocateEdge(int u, int v)
        {
            VertexPair pair = HelpSearchEdge(u, v);

            if (pair == null)
            {
                return(null);
            }
            Vertex v1 = pair.V1;
            Vertex v2 = pair.V2;

            if (v1.marked || v2.marked)
            {
                return(null);
            }

            while (true)
            {
                Edge e1 = v1.outgoingHead;
                Edge e2 = e1.next;
                while (e2.key < v)
                {
                    e1 = e2;
                    e2 = e2.next;
                }
                Lock(e1, e2);
                if (ValidateEdge(e1, e2))
                {
                    return(new EdgePair(e1, e2));
                }
                Unlock(e1, e2);
            }
        }
Ejemplo n.º 2
0
        public void AddVertex(int key)
        {
            VertexPair pair = LocateVertex(key); // v1,v2 still locked at this point
            Vertex     v1   = pair.V1;
            Vertex     v2   = pair.V2;

            if (v2.key != key || v2.marked) // if does not exist, or marked
            {
                Vertex v3 = new Vertex(key, version);
                v3.next = v2; // same key might appear twice, but marked nodes are always last
                v1.next = v3;
            }
            Unlock(v1, v2);
        }
Ejemplo n.º 3
0
        public void AddVertex(int key)
        {
            VertexPair pair = LocateVertex(key); // v1,v2 still locked at this point
            Vertex     v1   = pair.V1;
            Vertex     v2   = pair.V2;

            if (v2.key != key) // if does not exist
            {
                Vertex v3 = new Vertex(key);
                v3.next = v2;
                v1.next = v3;
            }
            Unlock(v1, v2);
        }
Ejemplo n.º 4
0
        public bool ContainsEdge(int u, int v)
        {
            VertexPair pair = HelpSearchEdge(u, v);

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

            Edge e = pair.V1.outgoingHead;

            while (e.key < v)
            {
                e = e.next;
            }

            return(e.key == v && !e.marked);
        }
Ejemplo n.º 5
0
        public void RemoveVertex(int key)
        {
            VertexPair pair = LocateVertex(key); // v1,v2 still locked at this point
            Vertex     v1   = pair.V1;
            Vertex     v2   = pair.V2;

            if (v2.key == key)
            {
                v2.marked = true;    // logically remove
                v1.next   = v2.next; // physically remove

                Unlock(v1, v2);

                RemoveIncomingEdge(key);
            }
            else
            {
                Unlock(v1, v2);
            }
        }