/*
 *	Frequency Table Class
 *	By Jeremy Lennert
 *	January 17, 2001
 *	v. 1.2.1
 *
 *	FreqTable.h
 *
 *	Class definition for frequency table class, used to store data
 *	on frequencies of letters, digrams, and trigrams for the
 *	Frequency Plotter and Decrypter programs.
 */

#include <fstream.h>

#ifndef FreqTable_h
#define FreqTable_h

typedef struct _chain{	// Linked list used to store data in case of collisions
	unsigned long unhashed;
	int value;
	_chain *next;
} Chain;

class FreqTable
{
public:
	FreqTable();

	void hash(unsigned long x, int value);	// Single-coordinate hash
	void hash(unsigned long x, unsigned long y, int value);	// Double-coordinate hash
	void hash(unsigned char x, unsigned char y, unsigned char z, int value);
				// Triple-coordinate hash
	int find(unsigned long x);	// Single-coordinate data retrieval
	int find(unsigned long x, unsigned long y);	// Double-coordinate retrieval
	int find(unsigned char x, unsigned char y, unsigned char z);
				// Triple-coordinate retrieval
	Chain* dump();	// Returns a value stored in hash table each time it is called,
					// starting with first value and iterating through all data
	void resetDump();	// Resets pointer used in dump to top of hash table

	~FreqTable();
protected:
	Chain *table[701];	// 701 hash values possible
	Chain *current;		// Used to keep track of position for a complete listing
	int currenth;		// Position in table where current is

	int doHash(unsigned long unhashed);
};

#endif