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"
25 /* Use this for string generation */
26 static const char ALPHANUMERICS
[]=
27 "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
29 #define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
31 static size_t get_alpha_num(void)
33 return (size_t)random() % ALPHANUMERICS_SIZE
;
36 void get_random_string(char *buffer
, size_t size
)
38 char *buffer_ptr
= buffer
;
42 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
44 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
47 void pairs_free(pairs_st
*pairs
)
54 /* We free until we hit the null pair we stores during creation */
55 for (uint32_t x
= 0; pairs
[x
].key
; x
++)
67 pairs_st
*pairs_generate(uint64_t number_of
, size_t value_length
)
69 pairs_st
*pairs
= (pairs_st
*)calloc((size_t)number_of
+ 1, sizeof(pairs_st
));
76 for (uint64_t x
= 0; x
< number_of
; x
++)
78 pairs
[x
].key
= (char *)calloc(100, sizeof(char));
80 if (pairs
[x
].key
== NULL
)
83 get_random_string(pairs
[x
].key
, 100);
84 pairs
[x
].key_length
= 100;
88 pairs
[x
].value
= (char *)calloc(value_length
, sizeof(char));
90 if (pairs
[x
].value
== NULL
)
93 get_random_string(pairs
[x
].value
, value_length
);
94 pairs
[x
].value_length
= value_length
;
99 pairs
[x
].value_length
= 0;
105 std::cerr
<< "Memory Allocation failure in pairs_generate." << std::endl
;