Professional Documents
Culture Documents
HashKuadratik.h
#ifndef HASHKUADRATIK_H
#define HASHKUADRATIK_H
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
void makeEmpty( )
{
currentSize = 0;
for( auto & entry : array )
entry.info = EMPTY;
}
// Rehash
if( ++currentSize > array.size( ) / 2 )
rehash( );
return true;
}
1
ADT Hash i Mbyllur Kuadratik
{
// Insert x as active
int currentPos = findPos( x );
if( isActive( currentPos ) )
return false;
// Rehash;
if( ++currentSize > array.size( ) / 2 )
rehash( );
return true;
}
private:
struct HashEntry
{
HashedObj element;
EntryType info;
vector<HashEntry> array;
int currentSize;
2
ADT Hash i Mbyllur Kuadratik
currentPos += offset; // Compute ith probe
offset += 2;
if( currentPos >= array.size( ) )
currentPos -= array.size( );
}
return currentPos;
}
void rehash( )
{
vector<HashEntry> oldArray = array;
#endif // HASHKUADRATIK_H
3
ADT Hash i Mbyllur Kuadratik
HashKuadratik.cpp
#include "HashKuadratik.h"
#include <iostream>
using namespace std;
/**
Nuk eshte metode eficente
*/
bool isPrime( int n )
{
if( n == 2 || n == 3 )
return true;
if( n == 1 || n % 2 == 0 )
return false;
return true;
}
for( ; !isPrime( n ); n += 2 )
;
return n;
}
4
ADT Hash i Mbyllur Kuadratik
Main.cpp
#include <iostream>
#include <iostream>
#include "HashKuadratik.h"
using namespace std;
int main( )
{
HashKuadratik<int> h1;
HashKuadratik<int> h2;
h2 = h1;
return 0;
}