WebGraph使用小結

來源:互聯網
上載者:User

WebGraph是一個非常不錯的web圖工具,網站地址http://webgraph.dsi.unimi.it/,提供多種圖的格式,更可貴的是提供一種壓縮圖格式。

 

 ImmutableGraph用來遍曆,ASCIIGraph用來讀取ASCIIGraph格式,ArrayListMutableGraph用來構建自己的web圖,但是實現的不是很快捷,我自己實現了一個稍微改進的版本:

public class DictionaryMutableGraph:ImmutableGraph    {        protected List> graph = new List>();        protected int n;        protected long m;        public DictionaryMutableGraph(int numNodes, int[][] arc)        {            // scan            for (int i = arc.Length; i– != 0; )            {                if (arc[i].Length != 2) throw new ArgumentException(“The arc of index “ + i + “ has length “ + arc[i].Length);                if (arc[i][0] = numNodes || arc[i][1] >= numNodes) throw new ArgumentException(“The arc of index “ + i + “ (“ + arc[i][0] + “, “ + arc[i][1] + “) is illegal“);            }            this.n = numNodes;            this.m = arc.LongLength;            // add nodes            for (int i = 0; i ());            }            // add arcs            for (int i = 0; i = n)                throw new ArgumentException(“Node index “ + node + “ is larger than graph order (“ + n + “)“);        }        public void AddNodes(int numNodes)        {            for (int i = n - 1; i ();            n += numNodes;        }        public void RemoveNode(int node)        {            EnsureNode(node);            // remove node            graph.RemoveAt(node);            n–;            // remove arcs associate the node            for (int i = 0; i  resize = new List();                int remove = -1;                foreach (int j in graph[i])                {                    if (j == node)                    {                        remove = j;                    }                    else if(j > node)                    {                        resize.Add(j);                    }                }                if (remove != -1)                {                    graph[i].Remove(remove);                    m–;                }                foreach (int j in resize)                {                    graph[i].Remove(j);                    graph[i].Add(j - 1);                }            }        }        public void AddArc(int i, int j)        {            EnsureNode(i);            EnsureNode(j);            graph[i].Add(j);            m++;        }        public void RemoveArc(int i, int j)        {            EnsureNode(i);            EnsureNode(j);            graph[i].Remove(j);            n–;        }        public override int[] successorArray(int x)        {            return graph[x].ToArray();        }        public override LazyIntIterator successors(int x)        {            return new DMGrapLazyIntIterator(this, x);        }        public override NodeIterator nodeIterator()        {            return new DMGraphNodeIterator(this);        }        public override NodeIterator nodeIterator(int from)        {            return new DMGraphNodeIterator(this, from);        }        public override ImmutableGraph copy()        {            return this;        }        public override int numNodes()        {            return n;        }        public override long numArcs()        {            return m;        }        public override int outdegree(int i)        {            EnsureNode(i);            return graph[i].Count;        }        public override bool randomAccess()        {            return true;        }        private class DMGraphNodeIterator : NodeIterator        {            DictionaryMutableGraph dmgraph;            int from;            public DMGraphNodeIterator(DictionaryMutableGraph dmgraph, int from)            {                this.dmgraph = dmgraph;                this.from = from - 1;            }            public DMGraphNodeIterator(DictionaryMutableGraph dmgraph):this(dmgraph, 0)            {            }            public override int outdegree()            {                return dmgraph.outdegree(from);            }            public override java.lang.Integer next()            {                return new java.lang.Integer(++from);            }            public override int nextInt()            {                return ++from;            }            public override void remove()            {                dmgraph.RemoveNode(from);            }            public override int skip(int n)            {                from += n;                return from;            }            public override int[] successorArray()            {                return dmgraph.successorArray(from);            }            public override LazyIntIterator successors()            {                return new DMGrapLazyIntIterator(dmgraph, from);            }            public override bool hasNext()            {                if (from .Enumerator em;            public DMGrapLazyIntIterator(DictionaryMutableGraph dmgraph, int node)            {                em = dmgraph.graph[node].GetEnumerator();            }            public int nextInt()            {                if (em.MoveNext())                    return em.Current;                else                    return -1;            }            public int skip(int i)            {                bool next = false;                for (int j = 0; j 

另外那個壓縮的圖是BVGraph,一般用他store方法來儲存自己的web圖。本來這個webgrap是java實現的,但我把它用IKVM.NET弄成了.net版本的了。

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.