Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/BranchOne_SuperPolicy' into Bran…
Browse files Browse the repository at this point in the history
…chOne_SuperPolicy
  • Loading branch information
EshedHere committed Feb 24, 2024
1 parent 3ef2925 commit e8df5a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
@Immutable
public class AccessEvent {
private final long key;
public final long key;

public AccessEvent(long key) {
this.key = key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.github.benmanes.caffeine.cache.simulator.policy;

import com.github.benmanes.caffeine.cache.simulator.policy.two_queue.TwoQueuePolicy;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;

import static com.google.common.base.Preconditions.checkState;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
Expand All @@ -32,14 +35,13 @@ public interface Policy {

/** Records that the entry was accessed. */
void record(AccessEvent event);
void evict(AccessEvent event);

/** Indicates that the recording has completed. */
default void finished() {}

/** Returns the cache efficiency statistics. */
PolicyStats stats();

Long2ObjectMap<Object> data();
/** The policy's name. */
default String name() {
PolicySpec policySpec = getClass().getAnnotation(PolicySpec.class);
Expand Down Expand Up @@ -68,15 +70,12 @@ enum Characteristic {
Characteristic[] characteristics() default {};
}


/** A policy that does not exploit external event metadata. */
interface KeyOnlyPolicy extends Policy {
@Override default void record(AccessEvent event) {
record(event.key());
}
@Override default void evict(AccessEvent event){
evict(event.key());
}
void record(long key);
void evict(long key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public void record(long key) {
int blockIndex = lookUptable.get(key);
if (pipelinePolicies.get(blockIndex) instanceof KeyOnlyPolicy) {
// Handle the event as a key-only event
((KeyOnlyPolicy) pipelinePolicies.get(blockIndex)).evict(key);
((KeyOnlyPolicy) pipelinePolicies.get(blockIndex)).data.remove(key);
} else {
// Handle the event for a generic policy
AccessEvent event = new AccessEvent(key/* Additional details here */);
pipelinePolicies.get(blockIndex).evict(event);
pipelinePolicies.get(blockIndex).data.remove(event.key);
}

//PROPAGATION
Expand Down Expand Up @@ -160,12 +160,6 @@ public void record(long key) {

}

@Override
public void evict(long key) {

}


@Override
public PolicyStats stats() {
// You can also access and use the statistics from the TwoQueuePolicy instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public SampledPolicy(Admission admission, EvictionPolicy policy, Config config)
this.maximumSize = Math.toIntExact(settings.PPmaximumSize()); //need to change
this.sampleStrategy = settings.sampleStrategy();
this.random = new Random(settings.randomSeed());

this.data = new Long2ObjectOpenHashMap<>();
this.sampleSize = settings.sampleSize();
this.table = new Node[maximumSize + 1];
Expand Down

0 comments on commit e8df5a0

Please sign in to comment.