Implementation Manual


BACK | INDEX | NEXT

Frequency Analysis


The object of frequency analysis is to analyze the frequencies of characters or multiple-characters in the cipher text. Both storage classes and working classes are needed for this.

QuickSort Small class used soley for quicksorting types of h_table_entry
struct h_table_entry ( string d_name; float d_num_occurences)

A structure labeled as h_table_entry that has two elements, a string and a float. These two elements are respectively the "name" and the "frequency." This structure is the most basic storage piece of the character or multi-character frequency data.
swap(h_table_entry &x, h_table_entry &y) return void

Procedure taking two references of h_table_entry's and swaps each with the other.
swap3(h_table_entry &x, h_table_entry &y, h_table_entry &z) return void

Procedure taking three references of h_table_entry's and swaps them such that the first is the third, the second is the first, and the third is the second.
alphasort3(h_table_entry &x, h_table_entry &y, h_table_entry &z) return void

Procedure taking three references of h_table_entry's and sorts them in increasing order.
AlphaQuickSort(h_table_entry *&a, int n) return void

AlphaQuickSortAux(h_table_entry *a, int n) return void

sort3(h_table_entry &x, h_table_entry &y, h_table_entry &z) return void

Procedure taking three references of h_table_entry's and sorts them in increasing order.
QuickSort(h_table_entry *a, int n) return void

Procedure taking an array of h_table_entry's and an integer representing the size of the array. QuickSort then sorts the array in increasing order.
QuickSort_reverse(h_table_entry *a, int n) return void

Procedure taking an array of h_table_entry's and an integer representing the size of the array. It then uses QuickSort to sort the array in increasing order, but then reorders them in decreasing.

H_table Hash Table class for quick access and growability
H_table (int num_buckets) constructor

Constructor constructing a hash table of h_table_entry with the specified number of buckets given by the integer parameter num_buckets.
hash ( const string & name) return int

Function taking a reference to a string and hashing that string to an integer.
insert (string h_input) return void

Procedure taking a string and inputting into the H_table, the hash table. If the string is not in the H_table, then it is inputted in and its frequency set to one. Else if the string is in the H_table, then the entry already there is increased in its frequency by one.
print_Table() return void

Procedure taking nothing, and outputting the contents of H_table to the command line.
array_implement() return void

Procedure taking nothing, but takes the private member "d_table," representing the actual hash table, and converts it into an array and points the private member "d_array_head" to it. All this is done with out erasing the "d_table."
get_top_entries(int num_top_entries) return h_table_entry

Function takes the an integer that is the number of top entries you would like out of the hash table, and it then returns an array with those entries.
table_analysis(char key_name)

Returns table analysis data.
Private Members

int d_num_buckets; number of buckets in hash table
vector * d_table; the actual hash table as an array of arrays
int increment; the amount between or in each bucket
int distinct_entries; the number of distinct entries in the hash table
h_table_entry * d_array_head; the hash table in array form

Statistics Analyze text for statistics on occurrence of letters.
Statistics(const char* input_file)

Constructor constructing an Statistics object on an array of characters, the input file. Allocates memory for "data_3char," the hash table, and analyzes the input file.
initialize() return void

Initialize data_1char values to 0
Initialize data_2char values to 0
Initialize data_3char H_table
~Statistics() destructor

Destructor freeing up the memory used by the Statistics object at the time it is killed. Deletes "data_3char," and sets the pointer to NULL.
single_analysis( bool alphasort ) return void

Function returning single character frequencies.
double_analysis() return void

Function returning double character frequencies.
triple_analysis() return void

Function returning triple character frequencies.
return_size ( int which_freq ) return int

Returns size of statistical data ( 1, 2, 3 )
return_data ( int which_data, int index )

returns data ( 1, 2, 3 ) / index #
analyze( const char * input, const bool ignore_nonalpha ) return void

Tallies single, digram, and trigram frequencies and total counts in text input and stores results in sample_space[] and data_1char[], data_2char[], and data_3char.