Allow random stores and accesses to MapBuffer values

Summary:
Removes the need to store keys in incremental order by sorting them after before inserting into MapBuffer.
Updates MapBuffer to support random access on C++ side, actually retrieving values by keys and not bucket index.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33611758

fbshipit-source-id: c81e970613c8ecc688bfacb29ba038bf081a0c0f
This commit is contained in:
Andrei Shikov
2022-01-20 12:57:22 -08:00
committed by Facebook GitHub Bot
parent 1ec399781d
commit d287598d23
6 changed files with 98 additions and 71 deletions
@@ -166,3 +166,20 @@ TEST(MapBufferTest, testMapEntries) {
EXPECT_EQ(readMap2.getString(0), "This is a test");
EXPECT_EQ(readMap2.getInt(1), 1234);
}
TEST(MapBufferTest, testMapRandomAccess) {
auto builder = MapBufferBuilder();
builder.putInt(1234, 4321);
builder.putString(0, "This is a test");
builder.putDouble(8, 908.1);
builder.putNull(2);
builder.putString(65535, "Let's count: 的, 一, 是");
auto map = builder.build();
EXPECT_EQ(map.count(), 5);
EXPECT_EQ(map.getString(0), "This is a test");
EXPECT_EQ(map.getDouble(8), 908.1);
EXPECT_EQ(map.isNull(2), true);
EXPECT_EQ(map.getInt(1234), 4321);
EXPECT_EQ(map.getString(65535), "Let's count: 的, 一, 是");
}