void (Iterable<Node<?, ?>> deletedNodes, Iterable<Node<?, ?>> updatedNodes, BackDependencyIndex deltaIndex) { Map<ReferenceID, Set<ReferenceID>> depsToRemove = new HashMap<>(); for (var node : deletedNodes) { cleanupDependencies(node, depsToRemove); // corner case, relevant to situations when keys in this index are actually real node IDs // if a node gets deleted, corresponding index key gets deleted to: this allows to ensure there is no outdated information in the index // If later a new node with the same ID is added, the previous index data for this ID will not interfere with the new state. myMap.remove(node.getReferenceID()); } for (var node : updatedNodes) { cleanupDependencies(node, depsToRemove); } for (ReferenceID id : Iterators.unique(Iterators.flat(deltaIndex.getKeys(), depsToRemove.keySet()))) { Set<ReferenceID> toRemove = depsToRemove.get(id); if (!Iterators.isEmpty(toRemove)) { Set<ReferenceID> deps = Iterators.collect(getDependencies(id), new HashSet<>()); deps.removeAll(toRemove); myMap.put(id, Iterators.collect(deltaIndex.getDependencies(id), deps)); } else { Iterable<ReferenceID> toAdd = deltaIndex.getDependencies(id); if (!Iterators.isEmpty(toAdd)) { myMap.appendValues(id, toAdd); } } } }