Esempio n. 1
0
        public SymbolGraph(T[,] inputs)
        {
            indexes = new LinearProbingHashSymbolTable <T, int>();

            // 构建顶点到索引的映射
            for (int i = 0; i < inputs.GetLength(0); i++)
            {
                for (int j = 0; j < inputs.GetLength(1); j++)
                {
                    if (!indexes.Contains(inputs[i, j]))
                    {
                        indexes.Put(inputs[i, j], indexes.Size);
                    }
                }
            }

            // 构建索引到顶点的映射
            keys = new T[indexes.Size];
            foreach (var item in indexes)
            {
                keys[indexes.Get(item.Key)] = item.Key;
            }

            // 构建图
            graph = new UndirectedGraph(indexes.Size);
            for (int i = 0; i < inputs.GetLength(0); i++)
            {
                int v = indexes.Get(inputs[i, 0]);

                for (int j = 1; j < inputs.GetLength(1); j++)
                {
                    graph.AddEdge(v, Index(inputs[i, j]));
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 获取顶点对应的索引
 /// </summary>
 /// <param name="vertex">顶点</param>
 /// <returns>顶点的索引</returns>
 public int Index(T vertex)
 {
     return(indexes.Get(vertex));
 }