ImmutableNetSchem(Snapshot snapshot, CellId cellId) {
    assert cellId.isIcon() || cellId.isSchematic();
    this.snapshot = snapshot;
    this.cellId = cellId;
    //        System.out.println("begin ImmutableNetSchem " + cellId);
    techPool = snapshot.techPool;
    schem = techPool.getSchematics();
    busPinPortId = schem != null ? schem.busPinNode.getPort(0).getId() : null;
    busArc = schem != null ? schem.bus_arc : null;
    cellTree = snapshot.getCellTree(cellId);
    cellBackup = cellTree.top;
    m = cellBackup.getMemoization();
    cellRevision = cellBackup.cellRevision;
    exports = cellRevision.exports;
    nodes = cellRevision.nodes;
    arcs = cellRevision.arcs;
    numExports = cellRevision.exports.size();
    numNodes = cellRevision.nodes.size();
    numArcs = cellRevision.arcs.size();

    CellId implementationCellId = cellId;
    if (cellId.isIcon()) {
      CellId mainSchemId = snapshot.getMainSchematics(cellId);
      if (mainSchemId != null) {
        getEquivExports(mainSchemId);
        implementationCellId = mainSchemId;
      }
    }
    this.implementationCellId = implementationCellId;

    // init connections
    ni_pi = new int[numNodes];
    int offset = numExports;
    for (int i = 0; i < numNodes; i++) {
      ImmutableNodeInst n = nodes.get(i);
      ni_pi[i] = offset;
      offset += getNumPorts(n.protoId);
    }
    arcsOffset = offset;
    offset += numArcs;

    headConn = new int[offset];
    tailConn = new int[offset];
    drawns = new int[offset];
    for (int i = numExports; i < arcsOffset; i++) {
      headConn[i] = i;
      tailConn[i] = i;
    }
    for (int i = 0; i < numExports; i++) {
      int portOffset = i;
      ImmutableExport export = exports.get(i);
      int orig = getPortInstOffset(export.originalNodeId, export.originalPortId);
      headConn[portOffset] = headConn[orig];
      headConn[orig] = portOffset;
      tailConn[portOffset] = -1;
    }
    for (int arcIndex = 0; arcIndex < numArcs; arcIndex++) {
      ImmutableArcInst a = arcs.get(arcIndex);
      int arcOffset = arcsOffset + arcIndex;
      int head = getPortInstOffset(a.headNodeId, a.headPortId);
      headConn[arcOffset] = headConn[head];
      headConn[head] = arcOffset;
      int tail = getPortInstOffset(a.tailNodeId, a.tailPortId);
      tailConn[arcOffset] = tailConn[tail];
      tailConn[tail] = arcOffset;
    }

    makeDrawns();

    initNetnames();

    portOffsets = new int[numExports + 1];
    drawnNames = new Name[numDrawns];
    drawnWidths = new int[numDrawns];
    drawnOffsets = new int[numDrawns];

    calcDrawnWidths();

    initNodables();

    int mapSize = netNamesOffset + netNames.size();
    int[] netMapN = ImmutableNetLayout.initMap(mapSize);
    localConnections(netMapN);

    int[] netMapP = netMapN.clone();
    int[] netMapA = netMapN.clone();
    internalConnections(netMapN, netMapP, netMapA);

    ImmutableNetLayout.closureMap(netMapN);
    ImmutableNetLayout.closureMap(netMapP);
    ImmutableNetLayout.closureMap(netMapA);

    //        updatePortImplementation();

    updateInterface(netMapN, netMapP, netMapA);
    //        System.out.println("end ImmutableNetSchem " + cellId);
  }