// © Copyright 1997. Joseph Bergin. All rights reserved.#ifndef Database_H#define Database_H#include "algo_jb.h"template <class Key, class Value>class DataRecord{	private:		Key key;		Value value;		DataRecord(){} // Needed to create arrays of DataRecords.	friend class Database<Key, Value>;	public:		DataRecord(Key k, Value v):key(k), value(v){}		Value getValue() const { return value; }		Key getKey() const{ return key; }				bool match(const Key k) const		{	return k == key;		}		bool operator< (const DataRecord<Key, Value> d) const		{	return key < d.key;		}		bool operator== (const DataRecord<Key, Value> d) const		{	return key == d.key;		}friend ostream& operator<< (ostream & o, const Database<Key, Value>& db);};template <class Key, class Value>class Database{public:	typedef DataRecord<Key, Value> value_type;	Database(int size)	:	currentSize(0), 		storage(new DataRecord<Key, Value> [size] )	{	};		void store (const Key  k, const Value v)	{	storage[currentSize++] = DataRecord<Key, Value> (k, v);		DataRecord<Key, Value> * after = &storage[currentSize];//		selectionSortIT(storage, after);	}	const Value retrieve(const Key k)const 	{	for(int i = 0; i < currentSize; i++)			if(storage[i].key == k) return storage[i].value;		return Value(); // The default value of type Value;	}	bool retrieve(const Key k, Value &v)const 	{	for(int i = 0; i < currentSize; i++)			if(storage[i].key == k)			{ 	v = storage[i].value;				return true;			}		return false; 	}		//unsigned int find(Key k)	//{	return BinarySearch(storage, DataRecord<Key,Value>(k,Value()), 0, currentSize-1);	//}		Value get(Key k)	{	return (*binarySearchIT( DataRecord<Key,Value>(k,Value()), storage, storage + currentSize)).getValue();	}		value_type* begin(){return storage;}	value_type* end(){return &storage[currentSize];}	void dump()	{	for(int i = 0; i < currentSize; i++)			cout << storage[i].key<<' '<<storage[i].value<<endl;	}	 private:	DataRecord<Key, Value> * storage;	// Save the data in an array.	int	currentSize;friend ostream& operator<< (ostream & o, const Database<Key, Value>& db);};template <class Key, class Info>ostream& operator<< (ostream & o, const Database<Key, Info>& db){	for(int i = 0; i < db.currentSize; i++)		o << db.storage[i].key<<' '<<db.storage[i].value<<endl;	return o;}#endif