main()
{
    unsigned int s = 0;
    int    num_op, r_key, r_data, i;
    int    range;
    char   r_op;
 //   int when_to_print;

    printf("Generating random operations\n");
    printf("Please enter the number of operations requested: ");
    scanf("%d", &num_op );
    printf("Please enter a range: ");
    scanf("%d", &range );
    printf("Please enter a starting seed: ");
    scanf("%d", &s );
    printf("\nGenerating %d operations with range %d and random seed %d \n", num_op, range, s);
    printf("----------------------------------------------------------------------\n");
    
    when_to_print = num_op/10;
	printf("when to print: %d",when_to_print);
    srand( s );
    printf("\nOperation\t     Key\t    Data\n\n");

    for( i = 1; i <= num_op; i++ )
    {
        Get_next_op( &r_op, &r_key, &r_data, range );

	if(r_op == 'I')
	{
		Insert_Sorted(r_key,r_data);		
	}   
	else if(r_op == 'D')
	{
		Delete(r_key);
	}
	else if(r_op == 'G')
	{
		Get(r_key);
	}
	if(i%when_to_print == 0 )
	{
		Print();
	}
     }
    printf("Num_G %d, Num_D %d, Num_I %d\n", num_G, num_D, num_I );

}
Exemplo n.º 2
0
int main( int argc, char *argv[] )
{ 

	Usage ( argc, argv );

    unsigned int s;
    int	rand_key; 
    char rand_op;
    int ret; 
    int ret_data;
    int i;

    unsigned long sum_data;
    int num_get, num_delete, num_insert;

    srand( s );

    sum_data   = 0;

    num_get    = 0;
    num_delete = 0;
    num_insert = 0;

    Repository_init( prob );

    for( i = 1; i <= num_op; i++ )
    {
        Get_next_op( &rand_op, &rand_key, Max_range );

	switch( rand_op )
	{
	    case 'G':
                num_get++;
		ret = Repository_get( rand_key, &ret_data );
		if( ret < 0 ) {
			printf("\nError in Get with return value %d \n", ret );
		}
		if( ret == 1 ) sum_data = sum_data + (ret_data%100);
		break;

	    case 'I':
                num_insert++;
		ret = Repository_insert( rand_key, i );
		if( ret < 0 ) {
			printf("\nError in Insert with return value %d \n", ret );
		}
		break;

	    case 'D':
                num_delete++;
		ret = Repository_delete( rand_key );
		if( ret < 0 ) {
			printf("\nError in Delete with return value %d \n", ret );
		}
		break;

	    default:
		printf("\nError!!!, Illegal operation %c\n", rand_op );
		exit(1);
	}

        if( (i % (num_op/10)) == 0 )
	{
		printf("Printing after %d operations of %d\n", i, num_op );
		if( Max_range > 100 ) Repository_print( 0 );
		else Repository_print( 2 );
	}
    }
    printf("Operation summary: get %d, delete %d, insert %d\n", num_get, num_delete, num_insert );
    printf("Sum of all Repository_get data modulo 100 is %d\n", sum_data );

  /*  
	int c;
	char op;
	int key;
	int val;
	char buf[1024];
	int pos = 0;
	while ((c=getchar()) != EOF)
	{
		if (c == '\n')
		{
			op = buf[0];
			key = val = strtol(buf + 2, NULL, 10);
			pos = 0;
			if (op == 'i')
				Repository_insert(key,val);
			else if (op == 'd')
				Repository_delete(key);
			else
				Repository_print(2);
		}
		else
		{
			buf[pos] = c;
			pos++;
		}
	}
*/			
	/*Repository_insert(1,400);
	Repository_insert(2,100);
	Repository_insert(3,100);
	Repository_insert(4,100);
	Repository_insert(5,100);
    	Repository_delete(3);
	Repository_print(2);*/
}
Exemplo n.º 3
0
main( int argc, char *argv[] )
{
    unsigned int s = 1;

    int    Max_range=100;
    int    num_op = 1000000; 
    int    rand_key; 
    char   rand_op;
    int    ret; 
    int    ret_data;
    int    i;
	unsigned int percent = 50;
    unsigned int sum_data;
    int num_get, num_delete, num_update;
	
	
	while( --argc >0 ){
		
		argv++;
		
		if( !strncmp(*argv,"-r",2))
		{
			sscanf(argv[1], "%d", &Max_range);
			argc--; argv++;
		}else if(!strncmp(*argv,"-o",2))
		{
			sscanf(argv[1],"%d", &num_op);
			argc--; argv++;
		}else if(!strncmp(*argv, "-s",2))
		{
			sscanf(argv[1],"%u",&s);
			argc--; argv++;
		}else if(!strncmp(*argv, "-p",2))
		{
			sscanf(argv[1],"%u", &percent);
			argc--; argv++;
		}
		
		
	}
	

    srand( s );

    sum_data   = 0;

    num_get    = 0;
    num_delete = 0;
    num_update = 0;
	

    Repository_init( percent );

    for( i = 1; i <= num_op; i++ )
    {
        Get_next_op( &rand_op, &rand_key, Max_range );


        switch( rand_op )
        {
            case 'G':
                num_get++;
                ret = Repository_get( rand_key, &ret_data );
                if( ret < 0 ) {
                    printf("\nError in Get with return value %d \n", ret );
                }
                if( ret == 1 ) sum_data = sum_data + (ret_data%100);
                break;

            case 'U':
                num_update++;
                ret = Repository_update( rand_key, i );
                if( ret < 0 ) {
                    printf("\nError in Update with return value %d \n", ret );
                }
                break;

            case 'D':
                num_delete++;
                ret = Repository_delete( rand_key );
				
                if( ret < 0 ) {
                    printf("\nError in Delete with return value %d \n", ret );
                }
                break;

            default:
                printf("\nError!!!, Illegal operation %c\n", rand_op );
                return 0;
        }

        if( (i % (num_op/10)) == 0 )
        {
            printf("\nPrinting after %d operations\n", i );
            if( Max_range > 100 ) Repository_print( 0 );
            else Repository_print( 1 );
        }
    }
    printf("\n\nOperation summary: get %d, delete %d, update %d\n", num_get, num_delete, num_update );
    printf("Sum of all Repository_get data modulo 100 is %d\n", sum_data );
}