Search/binarySearchFileInteger.c File Reference

Task to perform number of binary search operations on a disk file with integers. Receive integers one by one (must be in sorted order!) to be written to disk where a file "input.dat" is first created and then it is used as the source for a disk-based binary search of integers. More...

#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include "report.h"

Functions

void construct (int n)
 Method to construct the initial search structure to contain 'sz' elements.
void insert (int value)
 Method to insert an integer element into the search structure.
int search (int target, int(*cmp)(const int, const int))
 Method to search for an integer element in the search structure.

Variables

static int idx = 0
 Current integer to be added to the generated input file.
static int num = 0
 The number of elements to be generated/found in the input file.
static int reported = 0
 Record whether the input file has been created or not.
static FILE * fp
 handle to the file being generated/read.
static char * input = "input.dat"
 Location of file that is created during 'construction' phase and which is loaded during the 'search' phase.


Detailed Description

Task to perform number of binary search operations on a disk file with integers. Receive integers one by one (must be in sorted order!) to be written to disk where a file "input.dat" is first created and then it is used as the source for a disk-based binary search of integers.

Author:
George Heineman
Date:
6/15/08

Function Documentation

void construct ( int  n  ) 

Method to construct the initial search structure to contain 'sz' elements.

Creates a file on disk into which binary integer values are to be written.

void insert ( int  value  ) 

Method to insert an integer element into the search structure.

In our case, we are receiving the values ALREADY IN SORTED ORDER in which case we simply write into the FileHandle associated with the generated file.

Parameters:
value Value to be inserted.

int search ( int  target,
int(*)(const int, const int)  cmp 
)

Method to search for an integer element in the search structure.

Parameters:
target the desired target
cmp the comparison function between two string elements.


Variable Documentation

FILE* fp [static]

handle to the file being generated/read.

int idx = 0 [static]

Current integer to be added to the generated input file.

char* input = "input.dat" [static]

Location of file that is created during 'construction' phase and which is loaded during the 'search' phase.

int num = 0 [static]

The number of elements to be generated/found in the input file.

int reported = 0 [static]

Record whether the input file has been created or not.

Algorithm Development Kit 1.0