Skip to content

Commit

Permalink
change cache key type to be fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Oct 8, 2024
1 parent 6de3d0e commit d4f0854
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
import com.google.common.collect.ImmutableSet;
import edu.ucr.cs.riple.core.registries.index.Error;
import edu.ucr.cs.riple.core.registries.index.Fix;
import edu.ucr.cs.riple.injector.location.Location;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nullable;

/**
Expand All @@ -40,8 +38,7 @@
* @param <T> type of impacts saved in this model.
* @param <S> type of the map used to store impacts.
*/
public abstract class BaseCache<T extends Impact, S extends Map<Set<Location>, T>>
implements ImpactCache<T> {
public abstract class BaseCache<T extends Impact, S extends Map<Fix, T>> implements ImpactCache<T> {

/** Container holding cache entries. */
protected final S store;
Expand All @@ -52,19 +49,19 @@ public BaseCache(S store) {

@Override
public boolean isUnknown(Fix fix) {
return !this.store.containsKey(fix.toLocations());
return !this.store.containsKey(fix);
}

@Nullable
@Override
public T fetchImpact(Fix fix) {
return store.get(fix.toLocations());
return store.get(fix);
}

@Override
public ImmutableSet<Error> getTriggeredErrorsForCollection(Collection<Fix> fixes) {
return fixes.stream()
.map(fix -> store.get(fix.toLocations()))
.map(store::get)
.filter(Objects::nonNull)
.flatMap(impact -> impact.triggeredErrors.stream())
// filter errors that will be resolved with the existing collection of fixes.
Expand All @@ -75,7 +72,7 @@ public ImmutableSet<Error> getTriggeredErrorsForCollection(Collection<Fix> fixes
@Override
public ImmutableSet<Fix> getTriggeredFixesFromDownstreamForCollection(Collection<Fix> fixTree) {
return fixTree.stream()
.map(fix -> store.get(fix.toLocations()))
.map(store::get)
.filter(Objects::nonNull)
.flatMap(impact -> impact.getTriggeredFixesFromDownstreamErrors().stream())
// filter fixes that are already inside tree.
Expand All @@ -96,6 +93,6 @@ public void updateImpactsAfterInjection(Collection<Fix> fixes) {

@Override
public int size() {
return this.store.values().size();
return this.store.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.common.collect.ImmutableSet;
import edu.ucr.cs.riple.core.registries.index.Error;
import edu.ucr.cs.riple.core.registries.index.Fix;
import edu.ucr.cs.riple.injector.location.Location;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -90,15 +89,6 @@ public ImmutableSet<Fix> getTriggeredFixesFromDownstreamErrors() {
return triggeredFixesFromDownstreamErrors;
}

/**
* Gets the containing locations.
*
* @return Containing fix locations.
*/
public Set<Location> toLocations() {
return fix.toLocations();
}

@Override
public int hashCode() {
return fix.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

package edu.ucr.cs.riple.core.cache;

import edu.ucr.cs.riple.injector.location.Location;
import edu.ucr.cs.riple.core.registries.index.Fix;
import java.util.HashMap;
import java.util.Set;

/**
* Cache for storing impacts of fixes on target module. This cache's state is not immutable and can
* be updated.
*/
public class TargetModuleCache extends BaseCache<Impact, HashMap<Set<Location>, Impact>> {
public class TargetModuleCache extends BaseCache<Impact, HashMap<Fix, Impact>> {

public TargetModuleCache() {
super(new HashMap<>());
Expand All @@ -44,6 +44,6 @@ public TargetModuleCache() {
* @param newData New given impacts.
*/
public void updateCacheState(Set<Impact> newData) {
newData.forEach(t -> store.put(t.toLocations(), t));
newData.forEach(t -> store.put(t.fix, t));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* once created, cannot be updated.
*/
public class DownstreamImpactCacheImpl
extends BaseCache<DownstreamImpact, Map<Set<Location>, DownstreamImpact>>
extends BaseCache<DownstreamImpact, Map<Fix, DownstreamImpact>>
implements DownstreamImpactCache {

/** Annotator context instance. */
Expand Down Expand Up @@ -130,7 +130,7 @@ public void analyzeDownstreamDependencies() {
reports.forEach(
report -> {
DownstreamImpact impact = new DownstreamImpact(report);
store.put(report.root.toLocations(), impact);
store.put(report.root, impact);
});
System.out.println("Analyzing downstream dependencies completed!");
}
Expand Down

0 comments on commit d4f0854

Please sign in to comment.