#ifndef QUADRATIC_PROBING_H #define QUADRATIC_PROBING_H #include #include #include #include using namespace std; int nextPrime( int n ); // QuadraticProbing Hash table class // // CONSTRUCTION: an approximate initial size or default of 101 // // ******************PUBLIC OPERATIONS********************* // bool insert( x ) --> Insert x // bool remove( x ) --> Remove x // bool contains( x ) --> Return true if x is present // void makeEmpty( ) --> Remove all items // int hashCode( string str ) --> Global method to hash strings template class HashTable { public: explicit HashTable( int size = 101 ); bool contains( const HashedObj & x ) const; void makeEmpty( ); bool insert( const HashedObj & x ); bool remove( const HashedObj & x ); enum EntryType { ACTIVE, EMPTY, DELETED }; private: struct HashEntry { HashedObj element; EntryType info; HashEntry( const HashedObj & e = HashedObj{ }, EntryType i = EMPTY ) : element{ e }, info{ i } { } HashEntry( HashedObj && e, EntryType i = EMPTY ) : element{ std::move( e ) }, info{ i } { } }; vector array; int currentSize; bool isActive( int currentPos ) const; int findPos( const HashedObj & x ) const; void rehash( ); size_t myhash( const HashedObj & x ) const; }; #endif