Author: mes
Date: 2012-01-24 17:27:58 -0800 (Tue, 24 Jan 2012)
New Revision: 28098

Modified:
   
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTableFactory.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
   
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
   
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
Log:
fixes #591 we are now a bit smarter about the size of tables that we create by 
default, which was the root of the time and memory consumption problems here.

Modified: 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTableFactory.java
===================================================================
--- 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTableFactory.java 
    2012-01-25 00:53:06 UTC (rev 28097)
+++ 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTableFactory.java 
    2012-01-25 01:27:58 UTC (rev 28098)
@@ -35,6 +35,35 @@
  * @CyAPI.Api.Interface
  */
 public interface CyTableFactory {
+       /** 
+        * A description of the initial size of the table.
+        * Used only for the initial construction of the table
+        * and does not in any way limit the eventual size
+        * of the table!
+        */
+       enum InitialTableSize {
+               /** Small - about 100 entries. */
+               SMALL(100),
+               /** Medium - about 1000 entries. */
+               MEDIUM(1000),
+               /** Large - about 10,000 entries. */
+               LARGE(10000),
+               ;
+
+               private final int size; 
+               private InitialTableSize(int size) {
+                       this.size = size;
+               }
+
+               /**
+                * Returns the actual size value for the given enum.
+                * @return the actual size value for the given enum.
+                */
+               public int getSize() {
+                       return size;
+               }
+       }
+
        /**
         * Creates a CyTable object with the specified name, primary key, 
visibility, and mutability.
         * @param title The name of the CyTable.
@@ -42,9 +71,22 @@
         * @param primaryKeyType The type of the primaryKey column for this 
table. 
         * @param pub Whether or not the CyTable should be public.
         * @param isMutable if true, the table can be deleted later on, 
otherwise it can't
+        * @param initialSize a rough guess as to the expected size of the 
table 
         * @return A new {@link CyTable} with the specified name that is either 
public or not (see
         *         {@link CyTable#isPublic}.
         */
        CyTable createTable(String title, String primaryKey, Class<?> 
primaryKeyType, boolean pub,
+                           boolean isMutable, InitialTableSize initialSize);
+       /**
+        * Creates a CyTable object with the specified name, primary key, 
visibility, and mutability.
+        * @param title The name of the CyTable.
+        * @param primaryKey The name primaryKey column for this table. 
+        * @param primaryKeyType The type of the primaryKey column for this 
table. 
+        * @param pub Whether or not the CyTable should be public.
+        * @param isMutable if true, the table can be deleted later on, 
otherwise it can't
+        * @return A new {@link CyTable} with the specified name that is either 
public or not (see
+        *         {@link CyTable#isPublic}.
+        */
+       CyTable createTable(String title, String primaryKey, Class<?> 
primaryKeyType, boolean pub,
                            boolean isMutable);
 }

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
 2012-01-25 00:53:06 UTC (rev 28097)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
 2012-01-25 01:27:58 UTC (rev 28098)
@@ -52,6 +52,7 @@
 import org.cytoscape.model.events.NetworkAddedEvent;
 import org.cytoscape.model.subnetwork.CyRootNetwork;
 import org.cytoscape.model.subnetwork.CySubNetwork;
+import org.cytoscape.model.CyTableFactory.InitialTableSize;
 import org.cytoscape.service.util.CyServiceRegistrar;
 
 
@@ -153,13 +154,13 @@
 
        private Map<String,CyTable> createNetworkTables(long suidx) {
                Map<String,CyTable> netAttrMgr = new HashMap<String, CyTable>();
-        netAttrMgr.put(CyNetwork.DEFAULT_ATTRS, tableFactory.createTable(suidx 
+ " default network", CyTableEntry.SUID, Long.class, publicTables, false));
-        netAttrMgr.put(CyNetwork.HIDDEN_ATTRS, tableFactory.createTable(suidx 
+ " hidden network", CyTableEntry.SUID, Long.class, false, false));
+        netAttrMgr.put(CyNetwork.DEFAULT_ATTRS, tableFactory.createTable(suidx 
+ " default network", CyTableEntry.SUID, Long.class, publicTables, 
false,InitialTableSize.SMALL));
+        netAttrMgr.put(CyNetwork.HIDDEN_ATTRS, tableFactory.createTable(suidx 
+ " hidden network", CyTableEntry.SUID, Long.class, false, 
false,InitialTableSize.SMALL));
 
         
netAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyTableEntry.NAME, 
String.class, true);
 
                if ( suidx == suid ) { 
-               netAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared network", CyTableEntry.SUID, 
Long.class, publicTables, false));
+               netAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared network", CyTableEntry.SUID, 
Long.class, publicTables, false,InitialTableSize.SMALL));
                
netAttrMgr.get(CyRootNetwork.SHARED_ATTRS).createColumn(CyRootNetwork.SHARED_NAME,
 String.class, true);
                } else  
                        linkDefaultTables( 
netTables.get(CyRootNetwork.SHARED_ATTRS), 
@@ -170,14 +171,14 @@
 
        private Map<String,CyTable> createNodeTables(long suidx) {
         Map<String,CyTable> nodeAttrMgr = new HashMap<String, CyTable>();
-        nodeAttrMgr.put(CyNetwork.DEFAULT_ATTRS, 
tableFactory.createTable(suidx + " default node", CyTableEntry.SUID, 
Long.class, publicTables, false));
-        nodeAttrMgr.put(CyNetwork.HIDDEN_ATTRS, tableFactory.createTable(suidx 
+ " hidden node", CyTableEntry.SUID, Long.class, false, false));
+        nodeAttrMgr.put(CyNetwork.DEFAULT_ATTRS, 
tableFactory.createTable(suidx + " default node", CyTableEntry.SUID, 
Long.class, publicTables, false,getTableSize()));
+        nodeAttrMgr.put(CyNetwork.HIDDEN_ATTRS, tableFactory.createTable(suidx 
+ " hidden node", CyTableEntry.SUID, Long.class, false, false,getTableSize()));
 
         
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyTableEntry.NAME, 
String.class, true);
         
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyNetwork.SELECTED, 
Boolean.class, true, Boolean.FALSE);
 
                if ( suidx == suid ) {
-               nodeAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared node", CyTableEntry.SUID, Long.class, 
publicTables, false));
+               nodeAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared node", CyTableEntry.SUID, Long.class, 
publicTables, false,getTableSize()));
                
nodeAttrMgr.get(CyRootNetwork.SHARED_ATTRS).createColumn(CyRootNetwork.SHARED_NAME,
 String.class, true);
                } else
                        linkDefaultTables( 
nodeTables.get(CyRootNetwork.SHARED_ATTRS), 
@@ -188,15 +189,15 @@
 
        private Map<String,CyTable> createEdgeTables(long suidx) {
         Map<String,CyTable> edgeAttrMgr = new HashMap<String, CyTable>();
-        edgeAttrMgr.put(CyNetwork.DEFAULT_ATTRS, 
tableFactory.createTable(suidx + " default edge", CyTableEntry.SUID, 
Long.class, publicTables, false));
-        edgeAttrMgr.put(CyNetwork.HIDDEN_ATTRS, tableFactory.createTable(suidx 
+ " hidden edge", CyTableEntry.SUID, Long.class, false, false));
+        edgeAttrMgr.put(CyNetwork.DEFAULT_ATTRS, 
tableFactory.createTable(suidx + " default edge", CyTableEntry.SUID, 
Long.class, publicTables, false,getTableSize()));
+        edgeAttrMgr.put(CyNetwork.HIDDEN_ATTRS, tableFactory.createTable(suidx 
+ " hidden edge", CyTableEntry.SUID, Long.class, false, false,getTableSize()));
 
         
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyTableEntry.NAME, 
String.class, true);
         
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyNetwork.SELECTED, 
Boolean.class, true, Boolean.FALSE);
         
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyEdge.INTERACTION, 
String.class, true);
 
                if ( suidx == suid ) { 
-               edgeAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared edge", CyTableEntry.SUID, Long.class, 
publicTables, false));
+               edgeAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared edge", CyTableEntry.SUID, Long.class, 
publicTables, false,getTableSize()));
                
edgeAttrMgr.get(CyRootNetwork.SHARED_ATTRS).createColumn(CyRootNetwork.SHARED_NAME,
 String.class, true);
                } else  
                        linkDefaultTables( 
edgeTables.get(CyRootNetwork.SHARED_ATTRS), 
@@ -961,7 +962,16 @@
                return sub;
        }
 
+       private InitialTableSize getTableSize() {
+               if ( numSubNetworks < 5 )
+                       return InitialTableSize.LARGE;
+               else if ( numSubNetworks < 15 )
+                       return InitialTableSize.MEDIUM;
+               else 
+                       return InitialTableSize.SMALL;
+       }
 
+
        /**
         * {@inheritDoc}
         */

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
 2012-01-25 00:53:06 UTC (rev 28097)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
 2012-01-25 01:27:58 UTC (rev 28098)
@@ -67,10 +67,15 @@
        }
 
        public CyTable createTable(final String name, final String primaryKey, 
final Class<?> primaryKeyType,
-                                  final boolean pub, final boolean isMutable)
+                                  final boolean pub, final boolean isMutable) {
+               return 
createTable(name,primaryKey,primaryKeyType,pub,isMutable,CyTableFactory.InitialTableSize.MEDIUM);
+       }
+
+       public CyTable createTable(final String name, final String primaryKey, 
final Class<?> primaryKeyType,
+                                  final boolean pub, final boolean isMutable, 
final CyTableFactory.InitialTableSize size)
        {
                final CyTableImpl table = new CyTableImpl(name, primaryKey, 
primaryKeyType, pub, isMutable,
-                                                     SavePolicy.SESSION_FILE, 
help, interpreter);
+                                                     SavePolicy.SESSION_FILE, 
help, interpreter, size.getSize());
                eventDelegator.addListener(table);
                return table;
        }

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
        2012-01-25 00:53:06 UTC (rev 28097)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
        2012-01-25 01:27:58 UTC (rev 28098)
@@ -87,6 +87,7 @@
 
        private final CyEventHelper eventHelper;
        private final Interpreter interpreter;
+       private final int defaultInitSize;
 
        String lastInternalError = null;
 
@@ -101,7 +102,8 @@
         */
        public CyTableImpl(final String title, final String primaryKey, 
Class<?> primaryKeyType,
                           final boolean pub, final boolean isMutable, 
SavePolicy savePolicy,
-                          final CyEventHelper eventHelper, final Interpreter 
interpreter)
+                          final CyEventHelper eventHelper, final Interpreter 
interpreter,
+                                          final int defaultInitSize)
        {
                this.title = title;
                this.primaryKey = primaryKey;
@@ -112,11 +114,12 @@
                this.interpreter = interpreter;
                this.savePolicy = savePolicy;
                this.fireEvents = !pub;
+               this.defaultInitSize = defaultInitSize;
 
                currentlyActiveAttributes = new HashSet<String>();
                attributes = new HashMap<String, Map<Object, Object>>();
                reverse =  new HashMap<String, SetMultimap<Object,Object>>();
-               rows = new HashMap<Object, CyRow>(10000, 0.5f);
+               rows = new HashMap<Object, CyRow>(defaultInitSize, 0.5f);
                types = new HashMap<String, CyColumn>();
 
                VirtualColumnInfo virtualInfo = new 
VirtualColumnInfoImpl(false, null, null, null, null, true);
@@ -370,7 +373,7 @@
                                                               /* isPrimaryKey 
= */ false,
                                                               isImmutable,
                                                                   
defaultValue));
-                       attributes.put(columnName, new HashMap<Object, 
Object>(10000));
+                       attributes.put(columnName, new HashMap<Object, 
Object>(defaultInitSize));
                        reverse.put(columnName, HashMultimap.create());
                }
 
@@ -410,7 +413,7 @@
                                                               /* isPrimaryKey 
= */ false,
                                                               isImmutable,
                                                                   
defaultValue));
-                       attributes.put(columnName, new HashMap<Object, 
Object>(10000));
+                       attributes.put(columnName, new HashMap<Object, 
Object>(defaultInitSize));
                        reverse.put(columnName, HashMultimap.create());
                }
 

Modified: 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
  2012-01-25 00:53:06 UTC (rev 28097)
+++ 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
  2012-01-25 01:27:58 UTC (rev 28098)
@@ -91,9 +91,9 @@
                CyEventHelper eventHelper = new DummyCyEventHelper();
                final Interpreter interpreter = new InterpreterImpl();
                CyTable table = new CyTableImpl("homer", CyTableEntry.SUID, 
Long.class, true, true, SavePolicy.SESSION_FILE,
-                                               eventHelper, interpreter);
+                                               eventHelper, interpreter,1000);
                CyTable table2 = new CyTableImpl("marge", CyTableEntry.SUID, 
Long.class, true, true, SavePolicy.SESSION_FILE,
-                                                eventHelper, interpreter);
+                                                eventHelper, interpreter,1000);
 
                table.createColumn("x", Long.class, false);
                CyColumn column = table.getColumn("x");

Modified: 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
 2012-01-25 00:53:06 UTC (rev 28097)
+++ 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
 2012-01-25 01:27:58 UTC (rev 28098)
@@ -59,10 +59,10 @@
                eventHelper = new DummyCyEventHelper();
                final Interpreter interpreter = new InterpreterImpl();
                table = new CyTableImpl("homer", CyTableEntry.SUID, Long.class, 
false, true, SavePolicy.SESSION_FILE,
-                                       eventHelper, interpreter);
+                                       eventHelper, interpreter, 1000);
                attrs = table.getRow(1L);
                table2 = new CyTableImpl("marge", CyTableEntry.SUID, 
Long.class, false, true, SavePolicy.SESSION_FILE,
-                                        eventHelper, interpreter);
+                                        eventHelper, interpreter, 1000);
        }
 
        @After

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to