Beispiel #1
0
        public void Hang(AtomNodeProto head)
        {
            this.head = head;

            processed.Clear();
            queue.Clear();

            queue.Enqueue(head);
            processed.Add(head);
            layers = 0;

            while (queue.Count > 0)
            {
                for (int i = queue.Count; i > 0; i--)
                {
                    var a = queue.Dequeue();
                    nodeLayers[a.originalIndx] = layers;
                    var bonds = a.bonds;
                    for (int bi = bonds.Count - 1; bi >= 0; bi--)
                    {
                        var b     = bonds[bi];
                        var other = b.Other(a);
                        if (!processed.Contains(other))
                        {
                            queue.Enqueue(other);
                            processed.Add(other);
                        }
                    }
                }
                layers++;
            }
        }
Beispiel #2
0
 public NodeBondProto(AtomNodeProto a1, AtomNodeProto a2, BondInfo.BondType type, int indx)
 {
     originalIndx = indx;
     this.type    = 128 + (int)type;
     node1        = a1;
     node2        = a2;
 }
Beispiel #3
0
        public bool AllNodesConnected(AtomNodeProto head)
        {
            processed.Clear();
            queue.Clear();

            queue.Enqueue(head);
            processed.Add(head);

            while (queue.Count > 0)
            {
                for (int i = queue.Count; i > 0; i--)
                {
                    var a     = queue.Dequeue();
                    var bonds = a.bonds;
                    for (int bi = bonds.Count - 1; bi >= 0; bi--)
                    {
                        var b     = bonds[bi];
                        var other = b.Other(a);
                        if (!processed.Contains(other))
                        {
                            queue.Enqueue(other);
                            processed.Add(other);
                        }
                    }
                }
            }
            return(proto.atoms.Count == processed.Count);
        }
Beispiel #4
0
 public AtomNodeProto Other(AtomNodeProto node)
 {
     return(node1 == node ? node2 : node1);
 }