2 * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
3 * Copyright (C) 2006-2009 Brian Aker
6 * Use and distribution licensed under the BSD license. See
7 * the COPYING file in the parent directory for full text.
13 #include <mem_config.h>
23 #include "clients/generator.h"
27 /* Use this for string generation */
28 static const char ALPHANUMERICS
[]=
29 "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
31 #define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
33 static size_t get_alpha_num(void)
35 return (size_t)random() % ALPHANUMERICS_SIZE
;
38 void get_random_string(char *buffer
, size_t size
)
40 char *buffer_ptr
= buffer
;
44 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
46 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
49 void pairs_free(pairs_st
*pairs
)
56 /* We free until we hit the null pair we stores during creation */
57 for (uint32_t x
= 0; pairs
[x
].key
; x
++)
69 pairs_st
*pairs_generate(uint64_t number_of
, size_t value_length
)
71 pairs_st
*pairs
= (pairs_st
*)calloc((size_t)number_of
+ 1, sizeof(pairs_st
));
78 for (uint64_t x
= 0; x
< number_of
; x
++)
80 pairs
[x
].key
= (char *)calloc(KEY_BYTES
, sizeof(char));
82 if (pairs
[x
].key
== NULL
)
85 get_random_string(pairs
[x
].key
, KEY_BYTES
);
86 pairs
[x
].key_length
= KEY_BYTES
;
90 pairs
[x
].value
= (char *)calloc(value_length
, sizeof(char));
92 if (pairs
[x
].value
== NULL
)
95 get_random_string(pairs
[x
].value
, value_length
);
96 pairs
[x
].value_length
= value_length
;
100 pairs
[x
].value
= NULL
;
101 pairs
[x
].value_length
= 0;
107 std::cerr
<< "Memory Allocation failure in pairs_generate." << std::endl
;