DIRECTORY CD, CDCells, GList, HashTable; CDHacks: CEDAR PROGRAM IMPORTS CDCells, GList, HashTable SHARES CDCells = BEGIN RefIntList: TYPE = LIST OF REF INT; CountInstances: PROC [object: CD.Object] RETURNS [instanceCounts: RefIntList] = { RecurseCountInstances: PROC [object: CD.Object, oldInstanceCount: RefIntList] RETURNS [instanceCounts: RefIntList] = { instanceCounts _ oldInstanceCount; IF HashTable.Fetch[objectVisitTable, object].found THEN RETURN; IF NOT HashTable.Insert[objectVisitTable, object, $Visited] THEN ERROR; IF object.class=CDCells.pCellClass THEN { EachSubObject: CDCells.InstEnumerator = { instanceCounts _ RecurseCountInstances[inst.ob, instanceCounts]; }; ic: INT _ CDCells.CountInstances[object]; FOR icl: RefIntList _ instanceCounts, icl.rest UNTIL icl=NIL DO IF icl.first^=ic THEN EXIT; REPEAT FINISHED => instanceCounts _ CONS[NEW[INT _ ic], instanceCounts]; ENDLOOP; [] _ CDCells.EnumerateInstances[object, EachSubObject]; }; }; ReverseIntCompare: GList.CompareProc = { int1: REF INT _ NARROW[ref1]; int2: REF INT _ NARROW[ref2]; RETURN[SELECT TRUE FROM int1^ greater, int1^>int2^ => less, ENDCASE => equal]; }; objectVisitTable: HashTable.Table _ HashTable.Create[]; instanceCounts _ RecurseCountInstances[object, NIL]; instanceCounts _ NARROW[GList.Sort[instanceCounts, ReverseIntCompare]]; }; END. ͺCDHacks.mesa Copyright c 1986 by Xerox Corporation. All rights reserved. Barth, December 5, 1986 4:22:13 pm PST Bertrand Serlet February 20, 1987 0:55:30 am PST Κ*˜– "Cedar" stylešœ ™ Icode– "Cedar" stylešœ Οmœ1™