24 #include <unordered_set> 27 #include <glog/logging.h> 36 namespace compression {
40 CHECK_LT(n, 2 * maxId);
41 std::uniform_int_distribution<> uid(1, maxId);
42 std::unordered_set<uint32_t> dataset;
43 while (dataset.size() < n) {
45 if (dataset.count(value) == 0) {
46 dataset.insert(value);
50 std::vector<uint32_t> ids(dataset.begin(), dataset.end());
51 std::sort(ids.begin(), ids.end());
60 inline std::vector<uint32_t>
62 CHECK_LE(minId, maxId);
64 std::vector<uint32_t> ids;
65 ids.reserve((maxId - minId) / step + 1);
73 std::ifstream fin(filename);
74 std::vector<uint32_t> result;
83 template <
class...
Args>
89 template <
class Vector,
class Reader,
class Index>
91 -> decltype(reader.previousValue(), void()) {
98 template <
class...
Args>
104 template <
class Vector,
class Reader,
class Index>
106 -> decltype(reader.previous(), void()) {
107 auto r = reader.previous();
118 template <
class Reader,
class List>
123 for (
size_t i = 0;
i < data.size(); ++
i) {
133 EXPECT_EQ(reader.position(), reader.size());
136 template <
class Reader,
class List>
138 const std::vector<uint32_t>&
data,
141 CHECK_GT(skipStep, 0);
144 for (
size_t i = skipStep - 1;
i < data.size();
i += skipStep) {
154 EXPECT_EQ(reader.position(), reader.size());
158 template <
class Reader,
class List>
160 for (
size_t skipStep = 1; skipStep < 25; ++skipStep) {
161 testSkip<Reader, List>(
data,
list, skipStep);
163 for (
size_t skipStep = 25; skipStep <= 500; skipStep += 25) {
164 testSkip<Reader, List>(
data,
list, skipStep);
168 template <
class Reader,
class List>
170 const std::vector<uint32_t>&
data,
173 CHECK_GT(skipToStep, 0);
176 const uint32_t delta = std::max<uint32_t>(1, data.back() / skipToStep);
178 auto it = data.begin();
180 it = std::lower_bound(it, data.end(),
value);
181 if (it == data.end()) {
188 EXPECT_EQ(reader.position(), std::distance(data.begin(), it));
189 value = reader.value() + delta;
194 EXPECT_EQ(reader.position(), reader.size());
198 template <
class Reader,
class List>
219 EXPECT_EQ(reader.position(), reader.size());
225 using ValueType =
typename Reader::ValueType;
228 EXPECT_EQ(reader.position(), reader.size());
233 template <
class Reader,
class List>
236 std::vector<size_t> is(data.size());
237 for (
size_t i = 0;
i < data.size(); ++
i) {
240 std::shuffle(is.begin(), is.end(), gen);
241 if (Reader::EncoderType::forwardQuantum == 0) {
242 is.resize(std::min<size_t>(is.size(), 100));
255 EXPECT_EQ(reader.position(), reader.size());
258 template <
class Reader,
class List>
260 CHECK(!data.empty());
265 std::uniform_int_distribution<>
values(0, data.back());
266 const size_t iters = Reader::EncoderType::skipQuantum == 0 ? 100 : 10000;
267 for (
size_t i = 0;
i < iters; ++
i) {
269 auto it = std::lower_bound(data.begin(), data.end(),
value);
270 CHECK(it != data.end());
273 EXPECT_EQ(reader.position(), std::distance(data.begin(), it));
282 EXPECT_EQ(reader.position(), reader.size() - 1);
286 EXPECT_EQ(reader.position(), reader.size());
289 template <
class Reader,
class Encoder>
291 const typename Encoder::ValueType*
const data =
nullptr;
312 template <
class Reader,
class Encoder>
323 template <
class Reader,
class List>
330 for (
size_t i = 0;
i < iters; ++
i) {
331 if (
LIKELY(reader.next())) {
339 template <
class Reader,
class List>
342 const std::vector<uint32_t>& ,
345 size_t avg = (size_t(1) << logAvgSkip);
346 size_t base = avg - (avg >> 2);
347 size_t mask = (avg > 1) ? (avg >> 1) - 1 : 0;
350 for (
size_t i = 0;
i < iters; ++
i) {
351 size_t skip = base + (
i & mask);
352 if (
LIKELY(reader.skip(skip))) {
360 template <
class Reader,
class List>
363 const std::vector<uint32_t>&
data,
366 size_t avg = (size_t(1) << logAvgSkip);
367 size_t base = avg - (avg >> 2);
368 size_t mask = (avg > 1) ? (avg >> 1) - 1 : 0;
371 for (
size_t i = 0, j = -1;
i < iters; ++
i) {
372 size_t skip = base + (
i & mask);
374 if (j >= data.size()) {
379 reader.skipTo(data[j]);
384 template <
class Reader,
class List>
387 const std::vector<uint32_t>&
data,
388 const std::vector<size_t>&
order,
390 CHECK(!data.empty());
391 CHECK_EQ(data.size(), order.size());
394 for (
size_t i = 0, j = 0;
i < iters; ++
i, ++j) {
395 if (j == order.size()) {
398 reader.jump(order[j]);
403 template <
class Reader,
class List>
406 const std::vector<uint32_t>&
data,
407 const std::vector<size_t>&
order,
409 CHECK(!data.empty());
410 CHECK_EQ(data.size(), order.size());
413 for (
size_t i = 0, j = 0;
i < iters; ++
i, ++j) {
414 if (j == order.size()) {
417 reader.jumpTo(data[order[j]]);
426 -> decltype(
f(std::declval<instructions::Default>())) {
folly::Optional< instructions::Type > instructionsOverride()
void testNext(const std::vector< uint32_t > &data, const List &list)
auto dispatchInstructions(F &&f) -> decltype(f(std::declval< instructions::Default >()))
unique_ptr< IOBuf > encode(vector< HPACKHeader > &headers, HPACKEncoder &encoder)
void maybeTestPrevious(Args &&...)
void bmJumpTo(const List &list, const std::vector< uint32_t > &data, const std::vector< size_t > &order, size_t iters)
void bmSkip(const List &list, const std::vector< uint32_t > &, size_t logAvgSkip, size_t iters)
void testJumpTo(const std::vector< uint32_t > &data, const List &list)
#define EXPECT_EQ(val1, val2)
std::vector< uint32_t > generateRandomList(size_t n, uint32_t maxId, URNG &&g)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
void testSkipTo(const std::vector< uint32_t > &data, const List &list, size_t skipToStep)
detail::Skip skip(size_t count)
std::vector< uint32_t > loadList(const std::string &filename)
void testSkip(const std::vector< uint32_t > &data, const List &list, size_t skipStep)
void maybeTestPreviousValue(Args &&...)
void testAll(const std::vector< uint32_t > &data)
void bmNext(const List &list, const std::vector< uint32_t > &data, size_t iters)
std::vector< uint32_t > generateSeqList(uint32_t minId, uint32_t maxId, uint32_t step=1)
constexpr auto data(C &c) -> decltype(c.data())
Encoder::MutableCompressedList list
void bmSkipTo(const List &list, const std::vector< uint32_t > &data, size_t logAvgSkip, size_t iters)
#define EXPECT_TRUE(condition)
void testJump(const std::vector< uint32_t > &data, const List &list)
auto dispatch(Type type, F &&f) -> decltype(f(std::declval< Default >()))
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
#define EXPECT_FALSE(condition)
void bmJump(const List &list, const std::vector< uint32_t > &data, const std::vector< size_t > &order, size_t iters)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
std::vector< int > values(1'000)