Initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
QuadraticProbing.h - Header file for quadratic probing hash table
|
||||
|
||||
#ifndef QUADRATIC_PROBING_H_
|
||||
#define QUADRATIC_PROBING_H_
|
||||
|
||||
#include "vector.h"
|
||||
#include "mystring.h"
|
||||
|
||||
// QuadraticProbing Hash table class
|
||||
//
|
||||
// CONSTRUCTION: an initialization for ITEM_NOT_FOUND
|
||||
// and an approximate initial size or default of 101
|
||||
//
|
||||
// ******************PUBLIC OPERATIONS*********************
|
||||
// void insert( x ) --> Insert x
|
||||
// void remove( x ) --> Remove x
|
||||
// Hashable find( x ) --> Return item that matches x
|
||||
// void makeEmpty( ) --> Remove all items
|
||||
|
||||
template <class HashedObj>
|
||||
class HashTable
|
||||
{
|
||||
public:
|
||||
explicit HashTable( const HashedObj & notFound, int size = 101 );
|
||||
HashTable( const HashTable & rhs )
|
||||
: ITEM_NOT_FOUND( rhs.ITEM_NOT_FOUND ),
|
||||
array( rhs.array ), currentSize( rhs.currentSize ) { }
|
||||
|
||||
const HashedObj & find( const HashedObj & x ) const;
|
||||
|
||||
void makeEmpty( );
|
||||
void insert( const HashedObj & x );
|
||||
void remove( const HashedObj & x );
|
||||
|
||||
const HashTable & operator=( const HashTable & rhs );
|
||||
|
||||
enum EntryType { ACTIVE, EMPTY, DELETED };
|
||||
private:
|
||||
struct HashEntry
|
||||
{
|
||||
HashedObj element;
|
||||
EntryType info;
|
||||
|
||||
HashEntry( const HashedObj & e = HashedObj( ), EntryType i = EMPTY )
|
||||
: element( e ), info( i ) { }
|
||||
};
|
||||
|
||||
vector<HashEntry> array;
|
||||
int currentSize;
|
||||
const HashedObj ITEM_NOT_FOUND;
|
||||
|
||||
bool isActive( int currentPos ) const;
|
||||
int findPos( const HashedObj & x ) const;
|
||||
void rehash( );
|
||||
};
|
||||
|
||||
int hash( const string & key, int tableSize );
|
||||
int hash( int key, int tableSize );
|
||||
|
||||
#include "QuadraticProbing.cpp"
|
||||
#endif
|
||||
Reference in New Issue
Block a user