text
stringlengths
0
2.2M
void fill(char *data, size_t length, char repeatingElement)
// Load the specified 'repeatingElement' into each byte of the specified
// 'length' bytes long 'data'. The behaviour is undefined if 'data' does
// not point to at least 'length' bytes of writable memory.
{
for(size_t i = 0; i != length; ++i) {
data[i] = repeatingElement;
}
}
typedef bslh::SeedGenerator<MockRNG> Obj;
//=============================================================================
// USAGE EXAMPLE
//-----------------------------------------------------------------------------
///Usage
///-----
// This section illustrates intended usage of this component.
//
///Example: Seeding hashing algorithms requiring different seed sizes
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Suppose we have a number of hashing algorithms that all require different
// length seeds. Some require 32 bits, some require 64 bits, some even require
// 1024 bits. We want to generate all these seeds in the same way, but we do
// not want to keep manually generating seeds of different sizes for these
// algorithms. Moreover, we want to be able to use all these algorithms
// through a general purpose functor. To accomplish this, we give all our
// algorithm the same interface and supply a seed generator, which can create
// any size seed that the algorithms require.
//
// First, we write our first hashing algorithm, which accepts a 32-bit seed and
// returns a 32-bit unsigned int.
//..
class Seeded32BitHashingAlgorithm {
// This class is a functor that implements a hashing algorithm seeded
// with 32 bits.
public:
typedef unsigned result_type; // Type of the hash returned
enum { k_SEED_LENGTH = 4 }; // Seed length in bytes
private:
const char *d_seed; // Seed used in the generation of hashes
public:
explicit Seeded32BitHashingAlgorithm(const char *seed);
// Construct a 'Seeded32BitHashingAlgorithm' that will use the
// first 4 bytes of the specified 'seed' to seed the algorithm.
result_type operator()(const char *data, size_t length);
// Return a hash of the specified 'length' bytes of 'data'.
};
//..
// Then, we define another hashing algorithm, which accepts a 64-bit seed and
// returns a 32-bit unsigned int
//..
class Seeded64BitHashingAlgorithm {
// This class is a functor that implements a hashing algorithm seeded
// with 64 bits.
public:
typedef unsigned result_type; // Type of the hash returned
enum { k_SEED_LENGTH = 8 }; // Seed length in bytes
private:
const char *d_seed; // Seed used in the generation of hashes
public:
explicit Seeded64BitHashingAlgorithm(const char *seed);
// Construct a 'Seeded64BitHashingAlgorithm' that will use the
// first 8 bytes of the specified 'seed' to seed the algorithm.
result_type operator()(const char *data, size_t length);
// Return a hash of the specified 'length' bytes of 'data'.
};
//..
// Next, we define a final hashing algorithm, which accepts a 1024-bit seed and
// returns a 32-bit unsigned int
//..
class Seeded1024BitHashingAlgorithm {
// This class is a functor that implements a hashing algorithm seeded
// with 1024 bits.
public:
typedef unsigned result_type; // Type of the hash returned
enum { k_SEED_LENGTH = 128 }; // Seed length in bytes
private:
const char *d_seed; // Seed used in the generation of hashes
public:
explicit Seeded1024BitHashingAlgorithm(const char *seed);
// Construct a 'Seeded1024BitHashingAlgorithm' that will use the
// first 128 bytes of the specified 'seed' to seed the algorithm.