Skip to content

Commit

Permalink
remove cache
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-4 committed Jan 17, 2025
1 parent 2e5ff74 commit e58113a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonIntVectorTopicReader extends TopicReader<Integer> {
private final Map<Integer, float[]> vectorCache = new HashMap<>();

public JsonIntVectorTopicReader(Path topicFile) throws IOException {
super(topicFile);
}

public float[] getVector(Integer qid) {
return vectorCache.get(qid);
}

@Override
public SortedMap<Integer, Map<String, String>> read(BufferedReader reader) throws IOException {
SortedMap<Integer, Map<String, String>> map = new TreeMap<>();
Expand All @@ -53,15 +48,6 @@ public SortedMap<Integer, Map<String, String>> read(BufferedReader reader) throw
Map<String, String> fields = new HashMap<>();
fields.put("vector", vectorNode.toString());
map.put(topicID, fields);

// Cache parsed vector
if (vectorNode.isArray()) {
float[] vector = new float[vectorNode.size()];
for (int i = 0; i < vectorNode.size(); i++) {
vector[i] = (float) vectorNode.get(i).asDouble();
}
vectorCache.put(topicID, vector);
}
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonStringVectorTopicReader extends TopicReader<String> {
private final Map<String, float[]> vectorCache = new HashMap<>();

public JsonStringVectorTopicReader(Path topicFile) throws IOException {
super(topicFile);
}

public float[] getVector(String qid) {
return vectorCache.get(qid);
}

@Override
public SortedMap<String, Map<String, String>> read(BufferedReader reader) throws IOException {
SortedMap<String, Map<String, String>> map = new TreeMap<>();
Expand All @@ -54,15 +49,6 @@ public SortedMap<String, Map<String, String>> read(BufferedReader reader) throws
Map<String, String> fields = new HashMap<>();
fields.put("vector", vectorNode.toString());
map.put(topicID, fields);

// Cache parsed vector
if (vectorNode.isArray()) {
float[] vector = new float[vectorNode.size()];
for (int i = 0; i < vectorNode.size(); i++) {
vector[i] = (float) vectorNode.get(i).asDouble();
}
vectorCache.put(topicID, vector);
}
}
return map;
}
Expand Down

0 comments on commit e58113a

Please sign in to comment.