blob: 47cbf575bb3b3015a97dd24ba5e19a579dc1aea5 [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PERIDOT_BIN_LEDGER_TESTING_DATA_GENERATOR_H_
#define PERIDOT_BIN_LEDGER_TESTING_DATA_GENERATOR_H_
#include <climits>
#include <random>
#include <vector>
#include <lib/fidl/cpp/vector.h>
#include "peridot/bin/ledger/fidl/include/types.h"
#include "peridot/lib/rng/random.h"
namespace ledger {
class DataGenerator {
public:
explicit DataGenerator(rng::Random* random);
~DataGenerator();
// Builds a key of the given length as "<the given int>-<random data>", so
// that deterministic ordering of entries can be ensured by using a different
// |i| value each time, but the resulting B-tree nodes are always distinct.
std::vector<uint8_t> MakeKey(int i, size_t size);
// Builds a random value that can be used as a page id.
PageId MakePageId();
// Builds a random value of the given length.
fidl::VectorPtr<uint8_t> MakeValue(size_t size);
// Builds a vector of length |key_count| containing keys of size |key_size|,
// |unique_key_count| of which are unique.
std::vector<std::vector<uint8_t>> MakeKeys(size_t key_count,
size_t key_size,
size_t unique_key_count);
private:
std::independent_bits_engine<rng::Random::BitGenerator<uint64_t>, CHAR_BIT,
uint8_t>
generator_;
};
} // namespace ledger
#endif // PERIDOT_BIN_LEDGER_TESTING_DATA_GENERATOR_H_