Sorting/buildFileBasedInput.c File Reference

Driver to construct array of Strings on disk

Build up a file on disk representing an array of strings to test the various sorting algorithms. More...

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include "buildFileBasedInput.h"
#include "problem.h"
#include "report.h"

Functions

int fileCompString (const long pos, const char *a2)
 comparator function, by offset into file and AGAINST string in memory.
int ascending (const long pos, const void *a2)
 comparator function for the ascending case.
int descending (const long pos, const void *a2)
 comparator function for the descending case.
void prepareInput (int size, int argc, char **argv)
 Construct a random string of size ssize and have 'str1' and 'str2' be allocated strings with the same contents.
void postInputProcessing ()
 Validate that sorting was successful.
void execute ()
 Execute by invoking malloc(numElements) a total of numT times.
void problemUsage ()
 No specific problem usage.

Variables

FILE * strings
 information is stored on disk accessed via FILE handle.


Detailed Description

Driver to construct array of Strings on disk

Build up a file on disk representing an array of strings to test the various sorting algorithms.

Required Input:

  1. int numElements
  2. int verbose

Input flags:

  1. -a Numbers are sorted in ascending order
  2. -d Numbers are sorted in descending order
  3. -f File into which data is written
  4. -u n,o When paired with [a/d] determines number of pairs out of order, and distance of entity with which to swap [if o=0 then random]
External API
  1. void problemUsage() shows what is expected
  2. void postInputProcessing() performs post-solution processing
  3. void prepareInput() prepare the input
  4. void execute() begin the problem

Author:
George Heineman
Date:
6/15/08

Function Documentation

int ascending ( const long  pos,
const void *  a2 
)

comparator function for the ascending case.

int descending ( const long  pos,
const void *  a2 
)

comparator function for the descending case.

void execute (  ) 

Execute by invoking malloc(numElements) a total of numT times.

.numElements

output sum to be sure is correct.

int fileCompString ( const long  pos,
const char *  a2 
)

comparator function, by offset into file and AGAINST string in memory.

void postInputProcessing (  ) 

Validate that sorting was successful.

void prepareInput ( int  size,
int  argc,
char **  argv 
)

Construct a random string of size ssize and have 'str1' and 'str2' be allocated strings with the same contents.

use character-swapping algorithm from strfry.c in glibc

http://www.koders.com/c/fidBD83E492934F9F671DE79B11E6AC0277F9887CF5.aspx

void problemUsage (  ) 

No specific problem usage.


Variable Documentation

FILE* strings

information is stored on disk accessed via FILE handle.

Algorithm Development Kit 1.0