|
From: vze3s3mw <vze...@ve...> - 2002-03-30 23:42:28
|
//Does anyone know what wrong with this program?
//THIS IS THE ERROR MESSAGE: syntax error before `('
//Thank you!!!!!!!!!!!!!!
#include <iostream.h>
#include <fstream.h>
#include <string>
//#include "chaining.h"
// we do not compute prime numbers but use a table instead
// this table is lifted from the STL, see hashtable.h
static const int num_primes =3D 25;
static const unsigned long prime_list[] =3D
{
53, 97, 193, 389, 769,
1543, 3079, 6151, 12289, 24593,
49157, 98317, 196613, 393241, 786433,
1572869, 3145739, 6291469, 12582917, 25165843,
50331653, 100663319, 201326611, 402653189, 805306457
};
class HashMap
{
public:
// provide flexibility
typedef string key_type;
typedef int value_type;
private:
// hashtable entries=20
struct Entry
{
key_type k;
value_type v; =20
bool b;
=20
Entry(): k(), v(), b(false) {}
};
=20
size_t sz; // number of entries
size_t nn; // index to size table
Entry *ht; // array of Entry's
=20
public:
HashMap(): sz(0), nn(0), ht( new Entry[prime_list[0]] ) {}
=20
=20
size_t size() const { return sz; }
size_t table_size() const { return prime_list[nn]; }
float load_factor() const { return float(size())/table_size(); }
size_t hash( const key_type& k );
pair<bool,size_t> search( const key_type& k );
size_t insert( const key_type& k, const value_type& v );
size_t resize();
value_type operator[]( size_t i ) { return ht[i].v; }
void print_table();
};
main( int argc, char **argv )
{
if( argc !=3D 3 )
{
cerr << "Usage: " << argv[0] << " <file> <number of words>" << =
endl;
exit(1);
}
HashMap Table;
ifstream inf( argv[1] );
if( !inf )
{
cerr << "cannot open " << argv[1] <<", exiting" << endl;
exit(0);
}
=20
int n =3D atoi( argv[2] );
int cnt =3D 0;
string word;
=20
while( inf >> word && cnt++ < n )=20
Table.insert( word, word.size() );
inf.close();
=20
Table.print_table();
exit(EXIT_SUCCESS);
}
|