object-introspection/test/integration/folly_f14_fast_set.toml
Jake Hillion 71e734b120 tbv2: calculate total memory footprint
Add the option to calculate total size (inclusive size) by wrapping the
existing iterator. This change provides a new iterator, `SizedIterator`, which
wraps an existing iterator and adds a new field `size` to the output element.

This is achieved with a two pass algorithm on the existing iterator:
1. Gather metadata for each element. This includes the total size up until that
   element and the range of elements that should be included in the size.
2. Return the result from the underlying iterator with the additional
   field.

This algorithm is `O(N)` time on the number of elements in the iterator and
`O(N)` time, storing 16 bytes per element. This isn't super expensive but is a
lot more than the current algorithm which requires close to constant space.
Because of this I've implemented it as a wrapper on the iterator rather than on
by default, though it is now on in every one of our integration test cases.

Test plan:
- Added to the integration tests for full coverage.
2024-01-04 09:21:35 +00:00

85 lines
2.5 KiB
TOML

includes = ["folly/container/F14Set.h"]
definitions = '''
struct Bar {
float a, b;
};
inline bool operator==(const Bar &lhs, const Bar &rhs) noexcept {
return lhs.a == rhs.a && lhs.b == rhs.b;
}
struct BarHasher {
inline size_t operator()(const Bar &bar) const {
return folly::hash::hash_combine(bar.a, bar.b);
}
};
struct Foo {
folly::F14FastSet<int> m1;
folly::F14FastSet<Bar, BarHasher> m2;
folly::F14FastSet<int> m3;
folly::F14FastSet<int> m4;
};
'''
[cases]
[cases.a]
param_types = ["const Foo&"]
setup = '''
Foo foo;
foo.m1.reserve(3);
for (int i = 0; i < 3; i++) {
foo.m1.emplace(i);
}
foo.m2.reserve(5);
for (int i = 0; i < 5; i++) {
foo.m2.emplace(Bar{(float)i, 0.0f});
}
foo.m3.reserve(7);
for (int i = 0; i < 7; i++) {
foo.m3.emplace(i);
}
foo.m4.reserve(9);
for (int i = 0; i < 9; i++) {
foo.m4.emplace(i);
}
return {foo};
'''
expect_json = '''[{
"staticSize":96,
"dynamicSize":208,
"members":[
{"name":"m1", "staticSize":24, "dynamicSize":32, "length":3, "capacity":3, "elementStaticSize":4},
{
"name":"m2",
"staticSize":24,
"dynamicSize":64,
"length":5,
"capacity":5,
"elementStaticSize":8,
"members":[
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]}
]},
{"name":"m3", "staticSize":24, "dynamicSize":48, "length":7, "capacity":7, "elementStaticSize":4},
{"name":"m4", "staticSize":24, "dynamicSize":64, "length":9, "capacity":9, "elementStaticSize":4}
]}]'''
expect_json_v2 = '''[{
"staticSize":96,
"exclusiveSize": 0,
"size":304,
"members":[
{"name":"m1", "staticSize":24, "exclusiveSize": 44, "size":56, "length": 3, "capacity": 3},
{"name":"m2", "staticSize":24, "exclusiveSize": 48, "size":88, "length": 5, "capacity": 5},
{"name":"m3", "staticSize":24, "exclusiveSize": 44, "size":72, "length": 7, "capacity": 7},
{"name":"m4", "staticSize":24, "exclusiveSize": 52, "size":88, "length": 9, "capacity": 9}
]}]'''