Skip to content

Commit

Permalink
CountMap now optimizes integers and longs (#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
apmoriarty authored Dec 11, 2024
1 parent b83c9ef commit 8fb39f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ public boolean containsKey(String key) {
@Override
public void read(Kryo kryo, Input input) {
counts.clear();
int size = input.readInt();
int size = input.readInt(true);
for (int i = 0; i < size; i++) {
String key = input.readString();
Long value = input.readLong();
Long value = input.readLong(true);
put(key, value);
}
}

@Override
public void write(Kryo kryo, Output output) {
output.writeInt(keySet().size());
output.writeInt(keySet().size(), true);
for (Entry<String,Long> entry : entrySet()) {
output.writeString(entry.getKey());
output.writeLong(entry.getValue());
output.writeLong(entry.getValue(), true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void testSerDeBytes() {
map.put("FIELD_B", 23L);

byte[] data = serDe.serialize(map);
assertEquals(18, data.length); // 35 without optimizing integers/longs
CountMap deserialized = serDe.deserialize(data);

assertMap(map, deserialized);
Expand All @@ -29,6 +30,7 @@ void testSerDeString() {
map.put("FIELD_B", 23L);

String s = serDe.serializeToString(map);
assertEquals(18, s.length()); // 35 without optimizing integers/longs
CountMap deserialized = serDe.deserializeFromString(s);

assertMap(map, deserialized);
Expand Down

0 comments on commit 8fb39f3

Please sign in to comment.