Author: mes
Date: 2012-01-20 10:20:24 -0800 (Fri, 20 Jan 2012)
New Revision: 28065

Modified:
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/EdgePointer.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NodePointer.java
Log:
This change improves memory consumption for subnetworks by about 20%.

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
      2012-01-20 01:26:36 UTC (rev 28064)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
      2012-01-20 18:20:24 UTC (rev 28065)
@@ -76,8 +76,6 @@
        private int internalNodeCount;
        private int internalEdgeCount;
        private NodePointer inFirstNode;
-       private Set<CyNode> nodeSet;
-       private Set<CyEdge> edgeSet;
        private boolean fireAddedNodesAndEdgesEvents;
 
        private final Map<String,CyTable> netTables;
@@ -103,9 +101,6 @@
                this.edgeTables = edgeTables;
                this.tableMgr = tableMgr;
                
-               nodeSet = new HashSet<CyNode>(20000);
-               edgeSet = new HashSet<CyEdge>(20000);
-
                internalNodeCount = 0;
                internalEdgeCount = 0;
                fireAddedNodesAndEdgesEvents = false;
@@ -181,7 +176,6 @@
                        ret = parent.nodeAdd();
                        updateNode(ret);
                        internalNodeCount++;
-                       nodeSet.add(ret);
                }
 
                if (fireAddedNodesAndEdgesEvents)
@@ -201,7 +195,6 @@
                        ret = parent.edgeAdd(source, target, isDirected, this);
                        updateEdge(ret);
                        internalEdgeCount++;
-                       edgeSet.add(ret);
                }
 
                if (fireAddedNodesAndEdgesEvents)
@@ -243,14 +236,24 @@
         * {@inheritDoc}
         */
        public boolean containsNode(final CyNode node) {
-               return parent.containsNode(node) && nodeSet.contains(node);
+               if ( parent.containsNode(node) ) {
+                       final NodePointer np = parent.getNodePointer(node);
+                       return np.isSet(internalId);
+               } else {
+                       return false;
+               }
        }
 
        /**
         * {@inheritDoc}
         */
        public boolean containsEdge(final CyEdge edge) {
-               return parent.containsEdge(edge) && edgeSet.contains(edge);
+               if ( parent.containsEdge(edge) ) {
+                       final EdgePointer np = parent.getEdgePointer(edge);
+                       return np.isSet(internalId);
+               } else {
+                       return false;
+               }
        }
 
        /**
@@ -270,7 +273,8 @@
                        return null;
 
                // make sure the subnetwork still contains the node
-               if ( nodeSet.contains(n) )
+               final NodePointer np = parent.getNodePointer(n);
+               if ( np.isSet(internalId) )
                        return n;
                else
                        return null;
@@ -286,7 +290,8 @@
                        return null;
 
                // make sure the subnetwork still contains the edge
-               if ( edgeSet.contains(e) )
+               final EdgePointer ep = parent.getEdgePointer(e);
+               if ( ep.isSet(internalId) )
                        return e;
                else
                        return null;
@@ -337,7 +342,6 @@
 
                        // add node
                        internalNodeCount++;
-                       nodeSet.add(node);
                        updateNode(node);
                        copyDefaultAttrs(parent.getRow(node), 
this.getRow(node));
                }
@@ -375,7 +379,6 @@
 
                        // add edge
                        internalEdgeCount++;
-                       edgeSet.add(edge);
                        updateEdge(edge);
                        copyDefaultAttrs(parent.getRow(edge), 
this.getRow(edge));
                        copyDefaultEdgeAttrs(parent.getRow(edge), 
this.getRow(edge));
@@ -410,7 +413,6 @@
                                inFirstNode = 
node.remove(inFirstNode,internalId);
 
                                internalNodeCount--;
-                               nodeSet.remove(n);
                        }
                }
 
@@ -452,7 +454,6 @@
                        e.remove(internalId);
 
                        internalEdgeCount--;
-                       edgeSet.remove(edge);
                }
                return true;
        }

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/EdgePointer.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/EdgePointer.java
        2012-01-20 01:26:36 UTC (rev 28064)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/EdgePointer.java
        2012-01-20 18:20:24 UTC (rev 28065)
@@ -29,6 +29,7 @@
 
 
 import org.cytoscape.model.CyEdge;
+import java.util.Arrays; 
 
 
 /**
@@ -48,6 +49,8 @@
        EdgePointer[] nextInEdge = new 
EdgePointer[NodePointer.INITIAL_ALLOCATION];
        EdgePointer[] prevInEdge = new 
EdgePointer[NodePointer.INITIAL_ALLOCATION];
 
+       boolean[] includes = new boolean[NodePointer.INITIAL_ALLOCATION];
+
        EdgePointer(final NodePointer s, final NodePointer t, final boolean 
dir, final int ind, final CyEdge edge) {
                index = ind;
                source = s;
@@ -60,6 +63,8 @@
 
                nextInEdge[0] = null;
                prevInEdge[0] = null;
+
+               Arrays.fill(includes,false);
        }
 
        void expandTo(final int z) {
@@ -72,6 +77,7 @@
                prevOutEdge = expandEdgePointerArray(prevOutEdge, x);
                nextInEdge = expandEdgePointerArray(nextInEdge, x);
                prevInEdge = expandEdgePointerArray(prevInEdge, x);
+               includes = NodePointer.expandBooleanArray(includes,x);
        }
 
        static EdgePointer[] expandEdgePointerArray(final EdgePointer[] np, 
final int n) {
@@ -81,6 +87,8 @@
        }
 
        void insert(final int inId) {
+               includes[inId] = true;
+
                nextOutEdge[inId] = source.firstOutEdge[inId];
 
                if (source.firstOutEdge[inId] != null)
@@ -114,6 +122,8 @@
        }
 
        void remove(final int inId) {
+               includes[inId] = false;
+
                if (prevOutEdge[inId] != null)
                        prevOutEdge[inId].nextOutEdge[inId] = nextOutEdge[inId];
                else
@@ -152,4 +162,10 @@
                nextInEdge[inId] = null;
                prevInEdge[inId] = null;
        }
+
+    boolean isSet(final int inId) {
+               return ( inId >= 0 &&
+                        inId < includes.length && 
+                        includes[inId] );
+    }
 }

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NodePointer.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NodePointer.java
        2012-01-20 01:26:36 UTC (rev 28064)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NodePointer.java
        2012-01-20 18:20:24 UTC (rev 28065)
@@ -29,6 +29,7 @@
 
 
 import org.cytoscape.model.CyNode;
+import java.util.Arrays; 
 
 
 /**
@@ -60,6 +61,10 @@
        // The number of directed self-edges on this node.
        int[] selfEdges = new int[INITIAL_ALLOCATION];
 
+       // Whether the node pointer is included in the subnetwork 
+       // specified by the index of the array.
+       boolean[] includes = new boolean[INITIAL_ALLOCATION];
+
        NodePointer(final int nodeIndex, final CyNode cyn) {
                index = nodeIndex;
                cyNode = cyn;
@@ -71,6 +76,8 @@
 
                firstOutEdge[0] = null;
                firstInEdge[0] = null;
+
+               Arrays.fill(includes,false);
        }
 
        void expandTo(final int z) {
@@ -87,6 +94,7 @@
                inDegree = expandIntArray(inDegree, x);
                undDegree = expandIntArray(undDegree, x);
                selfEdges = expandIntArray(selfEdges, x);
+               includes = expandBooleanArray(includes, x);
        }
 
        static NodePointer[] expandNodePointerArray(final NodePointer[] np, 
final int n) {
@@ -101,7 +109,15 @@
                return nnp;
        }
 
+       static boolean[] expandBooleanArray(final boolean[] np, final int n) {
+               final boolean[] nnp = new boolean[n+1];
+               System.arraycopy(np,0,nnp,0,np.length);
+               return nnp;
+       }
+
        NodePointer insert(final NodePointer next, final int inId) {
+               includes[inId] = true;
+
                nextNode[inId] = next;
                if (next != null)
                        next.prevNode[inId] = this;
@@ -111,6 +127,8 @@
        }
 
        NodePointer remove(final NodePointer first, final int inId) {
+               includes[inId] = false;
+
                NodePointer ret = first;
                if (prevNode[inId] != null)
                        prevNode[inId].nextNode[inId] = nextNode[inId];
@@ -127,4 +145,10 @@
 
                return ret;
        }
+
+       boolean isSet(final int inId) {
+               return ( inId >= 0 &&
+                        inId < includes.length && 
+                        includes[inId] );
+       }
 }

-- 
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