/*
simple rb test tool
Copyright (C) Ronnie Sahlberg 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see .
*/
#include "includes.h"
#include "lib/util/dlinklist.h"
#include "system/filesys.h"
#include "popt.h"
#include "cmdline.h"
#include
#include
#include "common/rb_tree.h"
static struct timeval tp1,tp2;
static void start_timer(void)
{
gettimeofday(&tp1,NULL);
}
static double end_timer(void)
{
gettimeofday(&tp2,NULL);
return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
(tp1.tv_sec + (tp1.tv_usec*1.0e-6));
}
int num_records=5;
static void *callback(void *p, void *d)
{
uint32_t *data = (uint32_t *)d;
if (d==NULL) {
data = (uint32_t *)p;
}
(*data)++;
return data;
}
static void *random_add(void *p, void *d)
{
return p;
}
static int traverse(void *p, void *d)
{
uint32_t *data = (uint32_t *)d;
printf("traverse data:%d\n",*data);
return 0;
}
static int random_traverse(void *p, void *d)
{
printf("%s ",(char *)d);
return 0;
}
static uint32_t calc_checksum = 0;
static int traverse_checksum(void *p, void *d)
{
int i,j,k;
sscanf(d, "%d.%d.%d", &i, &j, &k);
calc_checksum += i*100+j*10+k;
return 0;
}
static int count_traverse(void *p, void *d)
{
int *count = p;
(*count)++;
return 0;
}
static int count_traverse_abort(void *p, void *d)
{
int *count = p;
(*count)++;
return -1;
}
/*
main program
*/
int main(int argc, const char *argv[])
{
struct poptOption popt_options[] = {
POPT_AUTOHELP
POPT_CTDB_CMDLINE
{ "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
POPT_TABLEEND
};
int opt, traverse_count;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
int i,j,k;
trbt_tree_t *tree;
uint32_t *data;
uint32_t key[3];
uint32_t key1[3] = {0,10,20};
uint32_t key2[3] = {0,10,21};
uint32_t key3[3] = {0,11,20};
uint32_t key4[3] = {2,10,20};
TALLOC_CTX *memctx;
uint32_t **u32array;
uint32_t checksum;
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
default:
fprintf(stderr, "Invalid option %s: %s\n",
poptBadOption(pc, 0), poptStrerror(opt));
exit(1);
}
}
/* setup the remaining options for the main program to use */
extra_argv = poptGetArgs(pc);
if (extra_argv) {
extra_argv++;
while (extra_argv[extra_argc]) extra_argc++;
}
printf("testing trbt_insert32_callback for %d records\n", num_records);
memctx = talloc_new(NULL);
u32array = talloc_array(memctx, uint32_t *, num_records);
tree = trbt_create(memctx, 0);
for (i=0; i