zoukankan      html  css  js  c++  java
  • Prefuse 3 prefuse.data

    Prefuse的data包中,定义了集中常用的结构,除了两个异常处理类,其他的类如下:

    class Schema implements Cloneable
    
    interface Tuple 
    interface Edge extends Tuple
    interface Node extends Tuple
    
    class Table extends AbstractTupleSet implements ColumnListener
    class CascadedTable extends Table
    
    class Graph extends CompositeTupleSet
    class Tree extends Graph
    class SpanningTree extends Tree 

     1.  Schema:

    对于table列的描述,Schema的数据结构如下:

        private String[] m_names;   
        private Class[]  m_types;
        private Object[] m_dflts;
        private HashMap  m_lookup;
        private int      m_size;
        private boolean  m_locked;

    Schema比较好理解,其中lookup是一个用来检索元素的索引表, m_dflts是值,其他的从字面就可以理解变量的含义:需要注意的是,prefuse的table可以动态地添加一个列,其中定义了一个函数:

    public void addColumn(String name, Class type, Object defaultValue) {
            // check lock status
            if ( m_locked ) {
                throw new IllegalStateException(
                    "Can not add column to a locked Schema.");
            }
            // check for validity
            if ( name == null ) {
                throw new IllegalArgumentException(
                    "Null column names are not allowed.");
            }
            if ( type == null ) {
                throw new IllegalArgumentException(
                    "Null column types are not allowed.");
            }
            for ( int i=0; i<m_size; ++i ) {
                if ( m_names[i].equals(name) ) {
                    throw new IllegalArgumentException(
                        "Duplicate column names are not allowed: "+m_names[i]);
                }
            }
            
            // resize if necessary
            // TODO put resizing functionality into library routines?
            if ( m_names.length == m_size ) {
                int capacity = (3*m_names.length)/2 + 1;
                String[] names = new String[capacity];
                Class[]  types = new Class[capacity];
                Object[] dflts = new Object[capacity];
                System.arraycopy(m_names, 0, names, 0, m_size);
                System.arraycopy(m_types, 0, types, 0, m_size);
                System.arraycopy(m_dflts, 0, dflts, 0, m_size);
                m_names = names;
                m_types = types;
                m_dflts = dflts;
            }
            
            m_names[m_size] = name;
            m_types[m_size] = type;
            m_dflts[m_size] = defaultValue;
            
            if ( m_lookup != null )
                m_lookup.put(name, new Integer(m_size));
            
            ++m_size;
        }
    View Code

    2.  Tuple类:

    Tuple是一个接口,定义了一组操作。每个Tupe对应prefuse 的table中非的一个元素,即一组tuple可以用来表示table中的一行。

    3.  Edge类:

    仍然是一个接口,继承了Tupe类,定义了一些新的接口。

    4.  Node类:

    仍然是一个接口,继承了Node类,定义了一些新的接口。

    5.  Table类:

    Table通过行和列来组织一个数据集合,这个表支持动态添加列。

     /** Listeners for changes to this table */
        protected CopyOnWriteArrayList m_listeners;
        
        /** Locally stored data columns */
        protected ArrayList m_columns;
        /** Column names for locally store data columns */
        protected ArrayList m_names;
        
        /** Mapping between column names and column entries
         * containing column, metadata, and index references */ 
        protected HashMap m_entries;
        
        /** Manager for valid row indices */
        protected RowManager m_rows;
        
        /** manager for tuples, which are object representations for rows */
        protected TupleManager m_tuples;
        
        /** Tracks the number of edits of this table */
        protected int m_modCount = 0;
        
        /** Memoize the index of the last column operated on,
         * used to expedite handling of column updates. */
        protected int m_lastCol = -1;
        
        /** A cached schema instance, loaded lazily */
        protected Schema m_schema;

    其他剩下的是一些常规的Table操作函数

    5.  Graph:

    Graph 继承了CompositeTupleSet,他的数据主要是保存在CompositeTupleSet中定义的数据结构中,Graph通过使用两个表:Node 表和Edge表(都是在CompositeTupleSet中的m_map中保存的)来构建一个图。它的一些重要的变量如下:

        /** Table containing the adjacency lists for the graph */
        protected Table m_links;
        /** TupleManager for managing Node tuple instances */
        protected TupleManager m_nodeTuples;
        /** TupleManager for managing Edge tuple instances */
        protected TupleManager m_edgeTuples;
        
        /** Indicates if this graph is directed or undirected */
        protected boolean      m_directed = false;
        /** The spanning tree over this graph */
        protected SpanningTree m_spanning = null;
        
        /** The node key field (for the Node table) */
        protected String m_nkey;
        /** The source node key field (for the Edge table) */
        protected String m_skey;
        /** The target node key field (for the Edge table) */
        protected String m_tkey;
        /** Reference to an index over the node key field */
        protected Index m_nidx;
        /** Indicates if the key values are of type long */
        protected boolean m_longKey = false;
        /** Update listener */
        private Listener m_listener;

    m_links是一个邻接表,m_nkey是Node表的列名,m_skey和m_tkey是edge表源节点和目标节点的列名。这种结构的一个好处就是可以根据自己的需求定义灵活的结构,比如:Graph继承了大多数的操作,而只针对图的专有特性进行定义,可以极大地减少代码量。而 CompositeTupleSet,只需要对可能用到的提供接口提供相应的函数即可。CompositeTupleSet类:

    public class CompositeTupleSet extends AbstractTupleSet {
    
        private static final Logger s_logger
            = Logger.getLogger(CompositeTupleSet.class.getName());
        
        private Map m_map;   // map names to tuple sets
        private Set m_sets;  // support quick reverse lookup
        private int m_count; // count of total tuples
        private Listener m_lstnr;
        ......
    
    }

    m_map:中存放各中表,如Node表,Edge表等等

    m_sets:存放的所有的表,它的作用是可以快速地用表的的实例来检索这个表是后在CompositeTupleSet实例中。m_count表示所有的元组个数

    6.  Tree:

    Tree继承了Graph类,相对较为简单,定义了root等自己需要的一系列操作。

    Prefuse.data包的内容就介绍到这里,整体上来说内容加多,但都不太难

  • 相关阅读:
    9.17 HTML CSS
    9.16
    9.15
    9.14
    9.13
    9.12
    9.11
    9.10
    9.9
    9.8
  • 原文地址:https://www.cnblogs.com/Joy06/p/3372979.html
Copyright © 2011-2022 走看看