Exemplo n.º 1
0
        public DGraph2()
        {
            vertices          = new DVector <double>();
            vertex_edges      = new DVector <List <int> >();
            vertices_refcount = new RefCountVector();

            edges          = new DVector <int>();
            edges_refcount = new RefCountVector();
            max_group_id   = 0;
        }
Exemplo n.º 2
0
 public RefCountVector(RefCountVector copy)
 {
     ref_counts   = new DVector <short>(copy.ref_counts);
     free_indices = new DVector <int>(copy.free_indices);
     used_count   = copy.used_count;
 }
Exemplo n.º 3
0
        public static void test_rcvector()
        {
            for (int ROUND = 0; ROUND < 2; ++ROUND)
            {
                RefCountVector vec = new RefCountVector();

                int N = 10 + ROUND;

                for (int k = 0; k < N; ++k)
                {
                    int i = vec.allocate();
                    Debug.Assert(i == k);
                }
                Debug.Assert(vec.count == N);
                Debug.Assert(vec.is_dense == true);

                int counter = 0;
                foreach (int i in vec)
                {
                    Debug.Assert(i == counter++);
                }

                int removed = 0;
                for (int k = 0; k < N; ++k)
                {
                    if (k % 2 == 0)
                    {
                        vec.decrement(k);
                        ++removed;
                    }
                }
                Debug.Assert(vec.count == N - removed);
                Debug.Assert(vec.is_dense == false);

                System.Console.WriteLine("After remove:");
                System.Console.WriteLine(vec.debug_print());

                for (int k = 0; k < N; ++k)
                {
                    if (k % 2 == 0)
                    {
                        Debug.Assert(vec.refCount(k) == 0);
                    }
                    else
                    {
                        Debug.Assert(vec.refCount(k) == 1);
                    }
                }

                System.Console.WriteLine("\niteration:");
                int iter_count = 0;
                foreach (int i in vec)
                {
                    System.Console.Write(i.ToString() + ":" + vec.refCount(i) + " ");
                    iter_count++;
                }
                System.Console.WriteLine(" (done)");

                Debug.Assert(iter_count == N - removed);

                // re-allocate
                for (int k = 0; k < removed; ++k)
                {
                    int j = vec.allocate();
                    vec.increment(j);
                }

                System.Console.WriteLine("\nAfter adding back:");
                System.Console.WriteLine(vec.debug_print());
            }
        }