📄 snapshot.java
字号:
CellBackup newBackup = CellBackup.read(reader, techPool); cellBackupsArray[cellIndex] = newBackup; } else { cellIndex = ~cellIndex; assert cellBackupsArray[cellIndex] != null; cellBackupsArray[cellIndex] = null; assert boundsChanged; assert cellBoundsArray[cellIndex] != null; cellBoundsArray[cellIndex] = null; } } ImmutableArrayList<CellBackup> cellBackups = new ImmutableArrayList<CellBackup>(cellBackupsArray); if (boundsChanged) { for (;;) { int cellIndex = reader.readInt(); if (cellIndex == Integer.MAX_VALUE) break; ERectangle newBounds = reader.readRectangle(); cellBoundsArray[cellIndex] = newBounds; } } int[] cellGroups = oldSnapshot.cellGroups; CellId[] groupMainSchematics = oldSnapshot.groupMainSchematics; boolean cellGroupsChanged = reader.readBoolean(); if (cellGroupsChanged) { cellGroups = new int[cellBackups.size()]; int maxGroup = -1; for (int cellIndex = 0; cellIndex < cellGroups.length; cellIndex++) { int groupIndex = reader.readInt(); maxGroup = Math.max(maxGroup, groupIndex); cellGroups[cellIndex] = groupIndex; } groupMainSchematics = new CellId[maxGroup + 1]; for (int groupIndex = 0; groupIndex < groupMainSchematics.length; groupIndex++) { CellId mainSchematics = null; int cellIndex = reader.readInt(); if (cellIndex >= 0) mainSchematics = reader.idManager.getCellId(cellIndex); groupMainSchematics[groupIndex] = mainSchematics; } } for (int i = 0; i < cellBackups.size(); i++) { assert (cellBackups.get(i) != null) == (cellBoundsArray[i] != null); assert (cellBackups.get(i) != null) == (cellGroups[i] >= 0); } return new Snapshot(oldSnapshot.idManager, snapshotId, tool, cellBackups, cellGroups, groupMainSchematics, libBackups, techPool, cellBoundsArray); } /** * Checks if all cell bounds are defined. * @return true if all cell bounds are defined. */ public boolean cellBoundsDefined() { assert cellBackups.size() == cellBounds.length; for (int cellIndex = 0; cellIndex < cellBackups.size(); cellIndex++) { if (cellBackups.get(cellIndex) == null) continue; if (cellBounds[cellIndex] == null) return false; } return true; } /** * Checks invariant of this Snapshot. * @throws IllegalArgumentException on invariant violation. * @throws ArrayOutOfBoundsException on some invariant violations. * @throws AssertionError if invariant is broken. * @throws AssertionError if invariant is broken. */ public void check() {// long startTime = System.currentTimeMillis(); techPool.check(); for (LibraryBackup libBackup: libBackups) { if (libBackup == null) continue; libBackup.check(); } for (CellBackup cellBackup: cellBackups) { if (cellBackup != null) cellBackup.check(); } if (libBackups.size() > 0) assert libBackups.get(libBackups.size() - 1) != null; if (cellBackups.size() > 0) assert cellBackups.get(cellBackups.size() - 1) != null; checkRecursion(cellBackups); int[] cellGroups = new int[cellBackups.size()]; checkNames(idManager, cellBackups, cellGroups, libBackups); assert Arrays.equals(this.cellGroups, cellGroups); int maxGroup = -1; for (int groupIndex: cellGroups) maxGroup = Math.max(maxGroup, groupIndex); assert groupMainSchematics.length == maxGroup + 1; BitSet foundMainSchematics = new BitSet(); for (CellBackup cellBackup: cellBackups) { if (cellBackup == null) continue; CellId cellId = cellBackup.cellRevision.d.cellId; if (!cellId.isSchematic()) continue; int groupIndex = cellGroups[cellId.cellIndex]; int cmp = cellId.cellName.compareTo(groupMainSchematics[groupIndex].cellName); assert cmp >= 0; if (cmp == 0) { assert groupMainSchematics[groupIndex] == cellId; foundMainSchematics.set(groupIndex); } } for (int groupIndex = 0; groupIndex < groupMainSchematics.length; groupIndex++) { assert foundMainSchematics.get(groupIndex) == (groupMainSchematics[groupIndex] != null); } assert cellBackups.size() == cellBounds.length; BitSet checkUsedTechs = new BitSet(); for (int cellIndex = 0; cellIndex < cellBackups.size(); cellIndex++) { CellBackup cellBackup = cellBackups.get(cellIndex); if (cellBackup == null) { assert cellBounds[cellIndex] == null; continue; } CellRevision cellRevision = cellBackup.cellRevision;// assert cellBounds.get(cellIndex) != null; checkUsedTechs.or(cellRevision.techUsages); CellId cellId = cellBackup.cellRevision.d.cellId; for (int i = 0; i < cellRevision.cellUsages.length; i++) { CellRevision.CellUsageInfo cui = cellRevision.cellUsages[i]; if (cui == null) continue; CellUsage u = cellId.getUsageIn(i); int subCellIndex = u.protoId.cellIndex; cui.checkUsage(cellBackups.get(subCellIndex).cellRevision); } assert cellBackup.techPool == techPool.restrict(cellRevision.techUsages, cellBackup.techPool); } assert techPool.idManager == idManager; for (int techIndex = 0; techIndex < checkUsedTechs.length(); techIndex++) { if (!checkUsedTechs.get(techIndex)) continue; TechId techId = idManager.getTechId(techIndex); assert techId != null; assert techPool.getTech(techId) != null; }// long endTime = System.currentTimeMillis();// System.out.println("Checking snapshot invariants took: " + (endTime - startTime) + " msec"); } /* * Checks name consistency of arrays intended for Sbapshot construction. * @throws IllegalArgumentException on invariant violation. * @throws ArrayOutOfBoundsException on some invariant violations. */ private static void checkNames(IdManager idManager, ImmutableArrayList<CellBackup> cellBackups, int[] cellGroups, ImmutableArrayList<LibraryBackup> libBackups) { HashSet<String> libNames = new HashSet<String>(); ArrayList<HashMap<String,CellName>> protoNameToGroupName = new ArrayList<HashMap<String,CellName>>(); ArrayList<HashSet<CellName>> cellNames = new ArrayList<HashSet<CellName>>(); ArrayList<HashMap<CellName,Integer>> groupNameToGroupIndex = new ArrayList<HashMap<CellName,Integer>>(); for (int libIndex = 0; libIndex < libBackups.size(); libIndex++) { LibraryBackup libBackup = libBackups.get(libIndex); if (libBackup == null) { protoNameToGroupName.add(null); cellNames.add(null); groupNameToGroupIndex.add(null); continue; } protoNameToGroupName.add(new HashMap<String,CellName>()); cellNames.add(new HashSet<CellName>()); groupNameToGroupIndex.add(new HashMap<CellName,Integer>()); if (libBackup.d.libId != idManager.getLibId(libIndex)) throw new IllegalArgumentException("LibId"); String libName = libBackup.d.libId.libName; if (!libNames.add(libName)) throw new IllegalArgumentException("duplicate libName"); for (LibId libId: libBackup.referencedLibs) { if (libId != libBackups.get(libId.libIndex).d.libId) throw new IllegalArgumentException("LibId in referencedLibs"); } } assert protoNameToGroupName.size() == libBackups.size() && cellNames.size() == libBackups.size() && groupNameToGroupIndex.size() == libBackups.size(); assert cellBackups.size() == cellGroups.length; Arrays.fill(cellGroups, -1); ArrayList<ImmutableCell> groupParamOwners = new ArrayList<ImmutableCell>(); for (int cellIndex = 0; cellIndex < cellBackups.size(); cellIndex++) { CellBackup cellBackup = cellBackups.get(cellIndex); if (cellBackup == null) continue; ImmutableCell d = cellBackup.cellRevision.d; CellId cellId = d.cellId; if (cellId != idManager.getCellId(cellIndex)) throw new IllegalArgumentException("CellId"); LibId libId = d.getLibId(); int libIndex = libId.libIndex; if (libId != libBackups.get(libIndex).d.libId) throw new IllegalArgumentException("LibId in ImmutableCell"); HashMap<String,CellName> cellNameToGroupNameInLibrary = protoNameToGroupName.get(libId.libIndex); HashSet<CellName> cellNamesInLibrary = cellNames.get(libId.libIndex); HashMap<CellName,Integer> groupNameToGroupIndexInLibrary = groupNameToGroupIndex.get(libId.libIndex); String protoName = cellId.cellName.getName(); CellName groupName = cellNameToGroupNameInLibrary.get(protoName); if (groupName == null) { groupName = d.groupName; cellNameToGroupNameInLibrary.put(protoName, groupName); } else if (!d.groupName.equals(groupName)) throw new IllegalArgumentException("cells with same proto name in different groups"); Integer gn = groupNameToGroupIndexInLibrary.get(groupName); if (gn == null) { gn = Integer.valueOf(groupParamOwners.size()); groupParamOwners.add(null); groupNameToGroupIndexInLibrary.put(groupName, gn); } cellGroups[cellIndex] = gn.intValue(); if (!cellNamesInLibrary.add(cellId.cellName)) throw new IllegalArgumentException("duplicate CellName in library"); if (d.paramsAllowed()) { ImmutableCell paramOwner = groupParamOwners.get(gn.intValue()); if (paramOwner != null) d.checkSimilarParams(paramOwner); else groupParamOwners.set(gn.intValue(), paramOwner); } } } private static void checkRecursion(ImmutableArrayList<CellBackup> cellBackups) { BitSet visited = new BitSet(); BitSet checked = new BitSet(); for (CellBackup cellBackup: cellBackups) { if (cellBackup == null) continue; checkRecursion(cellBackup.cellRevision.d.cellId, cellBackups, visited, checked); } assert visited.equals(checked); } private static void checkRecursion(CellId cellId, ImmutableArrayList<CellBackup> cellBackups, BitSet visited, BitSet checked) { int cellIndex = cellId.cellIndex; if (checked.get(cellIndex)) return; assert !visited.get(cellIndex); visited.set(cellIndex); CellBackup cellBackup = cellBackups.get(cellIndex); CellRevision cellRevision = cellBackup.cellRevision; for (int i = 0; i < cellRevision.cellUsages.length; i++) { CellRevision.CellUsageInfo cui = cellRevision.cellUsages[i]; if (cui == null) continue; CellUsage u = cellId.getUsageIn(i); int subCellIndex = u.protoId.cellIndex; if (checked.get(subCellIndex)) continue; if (visited.get(subCellIndex)) throw new IllegalArgumentException("Recursive instance of " + u.protoId + " in " + u.parentId); checkRecursion(u.protoId, cellBackups, visited, checked); } checked.set(cellIndex); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -