Esempio n. 1
0
        public SparseMatrix <EdgeT>[] GetComponentsUndirected(ref int[] seeds, bool seedsOnly)
        {
            Utils.ThrowException(!IsUndirected() ? new InvalidOperationException() : null);
            ArrayList <int> seedList = new ArrayList <int>();
            ArrayList <SparseMatrix <EdgeT> > components = new ArrayList <SparseMatrix <EdgeT> >();
            Set <int> unvisited = new Set <int>();

            for (int j = 0; j < mVtx.Count; j++)
            {
                unvisited.Add(j);
            }
            while (unvisited.Count > 0)
            {
                int seedIdx = unvisited.Any;
                SparseMatrix <EdgeT> component = new SparseMatrix <EdgeT>();
                seedList.Add(seedIdx);
                Queue <int> queue = new Queue <int>(new int[] { seedIdx });
                unvisited.Remove(seedIdx);
                while (queue.Count > 0)
                {
                    int vtxIdx = queue.Dequeue();
                    SparseVector <EdgeT> vtxInfo = mMtx[vtxIdx];
                    if (vtxInfo != null)
                    {
                        if (!seedsOnly)
                        {
                            component[vtxIdx] = vtxInfo.Clone();
                        }
                        foreach (IdxDat <EdgeT> otherVtx in vtxInfo)
                        {
                            if (unvisited.Contains(otherVtx.Idx))
                            {
                                unvisited.Remove(otherVtx.Idx);
                                queue.Enqueue(otherVtx.Idx);
                            }
                        }
                    }
                }
                if (!seedsOnly /*&& component.GetLastNonEmptyRowIdx() >= 0*/)
                {
                    components.Add(component);
                }
            }
            seeds = seedList.ToArray();
            return(components.ToArray());
        }
Esempio n. 2
0
            // *** IReadOnlyAdapter interface implementation ***

            public SparseVector <T> GetWritableCopy()
            {
                return(mVec.Clone());
            }