I'm attempting to create a Hash Table using vectors for open hashing. The issue is the program runs just fine in NetBeans IDE, however when run on the older unix based test server, it seg faults. I've ran through GDB numerous times, and here's what I've found:
Here's the piece of the code that's acting up:Program received signal SIGSEGV, Segmentation fault.0x001c538b in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
(gdb) where
#0 0x001c538b in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#1 0x08049841 in __gnu_cxx::new_allocator<std::string>::construct (this=0x804fffc, __p=0x4, __val=...)
at /usr/include/c++/4.6/ext/new_allocator.h:108
#2 0x080493f8 in std::vector<std::string, std::allocator<std::string> >:ush_back (this=0x804fffc,
__x=...) at /usr/include/c++/4.6/bits/stl_vector.h:830
#3 0x08048e74 in main () at openhash.cpp:65
If anyone can offer some insight into the problem, I would be forever grateful!Code:int main() { vector< vector<string> > hashTable; //initialize hash table, 100 buckets, using vectors to chain strings. vector<string> buffer; hashTable.resize(100); for (int j = 0; j < 100; j++) hashTable[j].resize(15); string buff; int key; int collisions = 0; while (cin >> buff) { buffer.push_back(buff); } int placeholder =0; while(placeholder < buffer.size()) { key = hashKey(buff); if(hashTable[key].empty()) { (hashTable[key]).push_back(buffer[placeholder]); placeholder++; } else { (hashTable[key]).push_back(buffer[placeholder]); //line 65 in full program// collisions++; placeholder++; } }
Thank You very much.
~ALex~