- public static void compactify(OldTransferableGraph1 tg,
- TIntHashSet removed) {
- // Filter removed set
- for(Identity id : tg.identities) {
- IdentityDefinition def = id.definition;
- if(def instanceof Root)
- removed.remove(id.resource);
- else if(def instanceof External)
- removed.remove(((External)def).parent);
- else if(def instanceof Internal)
- removed.remove(((Internal)def).parent);
- else if(def instanceof Optional)
- removed.remove(((Optional)def).parent);
- }
- for(int r : tg.statements)
- removed.remove(r);
- for(OldValue1 value : tg.values)
- removed.remove(value.resource);
-
- // Compactify
- if(!removed.isEmpty()) {
- // create map
- int resourceCount = tg.resourceCount;
- int[] map = new int[resourceCount];
- for(int i=0;i<resourceCount;++i)
- map[i] = i;
- for(int r : removed.toArray()) {
- map[--resourceCount] = map[r];
- }
-
- // map
- ArrayList<Identity> newIdentities = new ArrayList<Identity>(tg.identities.length);
- for(Identity id : tg.identities) {
- if(removed.contains(id.resource))
- continue;
- else
- newIdentities.add(id);
- id.resource = map[id.resource];
- IdentityDefinition def = id.definition;
- if(def instanceof External) {
- External d = (External)def;
- d.parent = map[d.parent];
- }
- else if(def instanceof Internal) {
- External d = (External)def;
- d.parent = map[d.parent];
- }
- else if(def instanceof Optional) {
- External d = (External)def;
- d.parent = map[d.parent];
- }
- }
- tg.identities = newIdentities.toArray(new Identity[newIdentities.size()]);
- int[] statements = tg.statements;
- for(int i=0;i<statements.length;++i) {
- int r = statements[i];
- if(r >= 0)
- statements[i] = map[r];
- }
- for(OldValue1 value : tg.values)
- value.resource = map[value.resource];
- tg.resourceCount = resourceCount;
- }
- }
-