make CacheKey comparable

The CacheKey is used as a key in a HashMap. Lookup can
be faster if the CacheKey is comparable when there are
hash collisions.
In this case I was not able to measure any effect. I am
keeping the comparables nonetheless, because the can
only have a positive effect.
This commit is contained in:
2019-01-01 08:47:48 +01:00
parent 4cde10a9f2
commit f2d16b6758
3 changed files with 37 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ public class TagsToFile implements AutoCloseable {
private final static Logger METRICS_LOGGER_NEW_WRITER = LoggerFactory
.getLogger("org.lucares.metrics.ingestion.tagsToFile.newPdbWriter");
private static final class CacheKey {
private static final class CacheKey implements Comparable<CacheKey> {
private final Tags tags;
public CacheKey(final Tags tags) {
@@ -30,6 +30,11 @@ public class TagsToFile implements AutoCloseable {
this.tags = tags;
}
@Override
public int compareTo(final CacheKey o) {
return tags.compareTo(o.tags);
}
@Override
public int hashCode() {
final int prime = 31;
@@ -54,7 +59,6 @@ public class TagsToFile implements AutoCloseable {
return false;
return true;
}
}
private final static class RemovalListener implements EventListener<CacheKey, PdbWriter> {