source: branches/stable/GDE/MUSCLE/src/edgelist.cpp

Last change on this file was 10390, checked in by aboeckma, 11 years ago

added muscle sourcles amd makefile

File size: 1.7 KB
Line 
1#include "muscle.h"
2#include "edgelist.h"
3
4EdgeList::EdgeList()
5        {
6        m_uNode1 = 0;
7        m_uNode2 = 0;
8        m_uCount = 0;
9        m_uCacheSize = 0;
10        }
11
12EdgeList::~EdgeList()
13        {
14        Clear();
15        }
16
17void EdgeList::Clear()
18        {
19        delete[] m_uNode1;
20        delete[] m_uNode2;
21        m_uNode1 = 0;
22        m_uNode2 = 0;
23        m_uCount = 0;
24        m_uCacheSize = 0;
25        }
26
27void EdgeList::Add(unsigned uNode1, unsigned uNode2)
28        {
29        if (m_uCount <= m_uCacheSize)
30                Expand();
31        m_uNode1[m_uCount] = uNode1;
32        m_uNode2[m_uCount] = uNode2;
33        ++m_uCount;
34        }
35
36unsigned EdgeList::GetCount() const
37        {
38        return m_uCount;
39        }
40
41void EdgeList::GetEdge(unsigned uIndex, unsigned *ptruNode1, unsigned *ptruNode2) const
42        {
43        if (uIndex > m_uCount)
44                Quit("EdgeList::GetEdge(%u) count=%u", uIndex, m_uCount);
45        *ptruNode1 = m_uNode1[uIndex];
46        *ptruNode2 = m_uNode2[uIndex];
47        }
48
49void EdgeList::Copy(const EdgeList &rhs)
50        {
51        Clear();
52        const unsigned uCount = rhs.GetCount();
53        for (unsigned n = 0; n < uCount; ++n)
54                {
55                unsigned uNode1;
56                unsigned uNode2;
57                rhs.GetEdge(n, &uNode1, &uNode2);
58                Add(uNode1, uNode2);
59                }
60        }
61
62void EdgeList::Expand()
63        {
64        unsigned uNewCacheSize = m_uCacheSize + 512;
65        unsigned *NewNode1 = new unsigned[uNewCacheSize];
66        unsigned *NewNode2 = new unsigned[uNewCacheSize];
67        if (m_uCount > 0)
68                {
69                memcpy(NewNode1, m_uNode1, m_uCount*sizeof(unsigned));
70                memcpy(NewNode2, m_uNode2, m_uCount*sizeof(unsigned));
71                }
72        delete[] m_uNode1;
73        delete[] m_uNode2;
74        m_uNode1 = NewNode1;
75        m_uNode2 = NewNode2;
76        m_uCacheSize = uNewCacheSize;
77        }
78
79void EdgeList::LogMe() const
80        {
81        for (unsigned n = 0; n < m_uCount; ++n)
82                {
83                if (n > 0)
84                        Log(" ");
85                Log("%u->%u", m_uNode1[n], m_uNode2[n]);
86                }
87        Log("\n");
88        }
Note: See TracBrowser for help on using the repository browser.