I have a large hash table, where each index has a container that has a doubly linked list. Things work up until releasing the memory. Each record is created with malloc, and each record->data is also created with malloc and the associated string is copied in using strcpy(). The table itself is released in another part of the program and doesn't produce and error.
/**
* valgrind --track-origins=yes
*/
==16898== Conditional jump or move depends on uninitialised value(s)
==16898== at 0x8049685: shFree (SpellHash.c:110)
==16898== by 0x8049352: unload (dictionary.c:115)
==16898== by 0x8048E64: main (speller.c:158)
==16898== Uninitialised value was created by a heap allocation
[Code] .....
How to interpret valgrind. Error resolved on a small problem. Now running into issues on large (>10000 words to check) problems. It appears the virtual machine just can't keep up for some reason. Running the code on my local computer produces no errors, memory usage is minuscule, and profile tools don't report any issues.
I am having an issue with my sort function. This is one part of the Hash table program. The main issue is that I am trying to sort the pointer table after all of the values have been entered. The ptr_sort function is not a class function and so I am therefore unable to use the class variables psize and pTable. Is there another way I should be trying this? it is a Vector should I use the sort() function from the vector class in STL?
I have a problem with this function that adds a new value to the hash table or updates its data if the value already exists:
Code:
int tab_add(tab_disp *td, const object *value) the function should return: TABDISP_OK if the value is correctly added, or TABDISP_ERROR if memory error, or TABDISP_INVALID if pointer td = NULL
The type of structure I am using is the following:
ID Group 0 2 1 2 2 3 3 4 4 4 5 4 6 4 7 4 Code: I want to store ID values on the bases of same Group, like we do in Hash table (key, value) .
Group ID 2 0,1 3 2 4 3,4,5,6,7
so when i said key 2 it will give me 0,1. how can i do it. As first i thought that i can use array of array but then how i can store the value of key. Now I am thinking of hash but i don't know how I will store and retrieve these values.
bool HashTable::insert(char const * const key, const Player& aPlayer) { //calculate the insertion position (the index of the array) size_t index = calculateIndex(key); for(int i=0; i < capacity; i++) {
[Code] ....
The inserting part works just fine, but the checking for duplicates where I compare the two values is crashing my program.
I'm trying to retrieve the Player object from my hash table so I can edit the content of that object. Here is what I have.
Player* HashTable::retrieve(char * key, Player& aPlayer) { //calculate the retrieval position (the index of the array) size_t index = calculateIndex(key); //search for the data in the chain (linked list) node * curr = table[index]; char id[100];
[Code] .....
Here I'm calling the retrieve and I need to return a pointer of that object.
Player* PlayerDB::FetchPlayer(char* name) { Player* info = new Player(); out << "Fetching player " << """ << name << "" -- "; if(h.retrieve(name, *info)) { out << "Success!" << endl;
[Code] .....
And here is my call in main. Player* outPlayer = NULL; outPlayer = pdb.FetchPlayer("Sappho"); if (outPlayer != NULL) { outPlayer->LevelUp(); }
I'm just trying to change the actual level of the player using the LevelUp function, but right now it is not making that change. I've been told I need to return a reference of the object in my retrieve function, but I thought that was what I was doing already.
I am getting a strange runtime error when trying to run my hash table program. I have it separated in 3 separate files. I believe I have narrowed down where the error is occurring. It is either happening in insert(const &string s) or in the implementation of vector<list<string>> ht. I would appreciate some input. This is the implementation of insert():
void HTable::insert(const string &s) { int h = hash(s); cout<<h<<endl; list<string> &tempList = ht[h];
[Code] .....
And it is giving me some sort of compilation error saying I cannot convert a type string to type list.
I am working on creating a program using HashTables. This is for homework. This is the first time I am using and creating HashTables, so forgive me in advance as to I don't know entirely what I am doing. The main problem I am having right now is incorporating my remove() function. I can get the code to compile, but when I run test the program out, it crashes. The error that I am receiving is list iterator is not decrementable Here is my hashtable class as well as my remove() function. Also need to incorporate a print method.
I have an abstract based class and three derived classes. I also have a templated hash table class(using chaining as my collision resolution method, an array of stl lists), and a class to parse commands from a file, this also holds the instantiation of the hash table. My question is that since my command parsing class's constructor instantiates the hash table in the main driver(unable to modify) how can I make this dynamically allocated using data from the file?
template<class T> class hashTable{ public: hashTable(int size); ~hashTable();
I have this assignment where I have to create a map based hash table for a sparse matrix. The professor has provided some code and I'm supposed to fill in parts of it to make it work.
He has given us a class sparseMatrix which we need to provide a hash function for. This hash function is to be defined in a Class TupleHash which is inside sparseMatrix. I think I got that part down. What is really confusing me is what he has done with some typedefs.
For one of them I had to declare an unorderd_map that maps a struct Tuple on to the class template argument Object. I did that like so:
This is giving me a world of unintelligible error messages. This is how it starts.
In instantiation of 'struct std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash>':| recursively required from 'struct std::__and_<std::is_default_constructible<sparseMatrix<int>::TupleHash>, std::is_copy_assignable<sparseMatrix<int>::TupleHash>, std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash> >'|
I have been implementing a Hash Table class made, and ran into a bit of a problem in my Delete function. I have the hash table made up as
vector<list<HashNode<T,X>>> m_Table
My problem is when I iterate through the vector, and then the list in that current element to try and find the Node I want to delete, the STL list class gives me the error:
Error1error C2678: binary '==' : no operator found which takes a left-hand operand of type 'HashNode<T,X>' (or there is no acceptable conversion)
I am having trouble getting the cout statements that I commented out to work properly. And I can't figure out why the first movie in the movies.txt file displays at the end of the list in my output screen when it should only display once as the first item. I am also having trouble figuring out where and how to set up the static variable.
Purpose : This assignment requires that you to develop a program using the classes listed above. Specifically you will build a hash table containing movie data. The collision strategy will be to build linked lists as the array elements.
Program Specifications : Your program will read the data from the file named Movies.txt located in the StudentFiles1.zip file on the Connections Portal. Each record contains 2 fields separated by a space. They are:
FieldsData Type Motion Picture Association Code (MPAC)Integer Movie NameString
Your application program will read each record, create a Movie structure instance and place that structure instance into the hash table.
You will need to modify the appropriate code to provide for an audit trail of the hash table construction. To accomplish this, you will use cout statements in the above class member functions. You will need to modify them to include couts, but the modifications will be relatively small. If not, you are doing it wrong. The hashing algorithm to use is:
Index = int ( 0.618033 * MPAC) % size
Make the array size a constant and set it to 10.
Include a counter for the number of collisions that occurred in building the hash table. Including a static variable in the LinkedList or List class is the best method for doing that.
See the sample audit trail below for the first 5 records on Movies.txt and the size of the hash table set to 3. This is shown for illustration only. The full file will have different locations calculated.
1101-Casablanca is being added The hashed location is 2 There was no collision loading 1101-Casablanca ------------------------------------------------ 1200-Duck Soup is being added The hashed location is 0 There was no collision loading 1200-Duck Soup ------------------------------------------------
[Code] ....
After the above is displayed, prompt the user to enter the MPAC of a movie to locate. Produce an audit trail when locating the requested movie as shown below: Make sure you list all movies that have collided at the hashed location. That may also cause you to modify one of the existing ADTs a little.
Will search for 6601 at the hashed location is 2 There was a collision here with 6601-Wizard of Oz There was a collision here with 1101-Casablanca retrieved from hash table: 6601-Wizard of Oz
I have matrix in C with size m x n. Size n isn't known. I want to have operations on matrix such as : delete first element and find i-th element. (where size m woudn't be too big , from 10 to 50 columns).
What is more efficient to use, linked list or hash table? How can I map each column of matrix to different element of linked list or hash table; depends what I choose to use?
How to approach this? Not very clear on how hashing works..
Insert the following numbers into a hash table of size 10 (ie an array with 0…9 index position) using a hash function h(k)=(k*71+94)%10 and using Linear Probing.
75, 98, 43,1,-56,93,101,34,23
Insert the following numbers into a hash table of size 10 (ie an array with 0…9 index position) using a hash function h(k)=(k*71+94)%10 and using Chaining.
If a user enters a string of boolean algebra it will ouput the table.
I have input parsing, cycling through the combinations, and outputing working. However once i parse the input I am not sure what to do with it. I have thought of having it write the parsed input to a new file as a function and then use that function, but that seems bad.
How to dynamically create the function, how to implement it.
BTW This is a console function, if that changes anything.
I am nearing completion of my first real app.. but I noticed a nasty catch in that it consumes 10-20% CPU at idle. I went around commenting features that I suspected may be causing it but it had 0 impact and my CPU usage at idle is still 10-20%.
The program has two threads, one of which is used very little and the second one consume needless CPU.. The only clues a profiler gives me is
So when you enter the number 99 its supposed to quit the program and it wasnt so i fixed that then i noticed that if you don't hit the green its supposed to loop back to a certain point but it was going to far back so i put a goto statement in and now it wont output my data table.
Have everything working fine as far as input and functions.. I am supposed to output the information as a table. I started to write a void function in order to complete this task. I know how to output the information if i were to have an array for the months, but how to display the months when I am using a switch statement.
#include <iostream> #include <cstring> #include <iomanip> /* author: John Pierce Description: program reads in averages, then prompts user for current month. The program then continues to prompt the user for the rain fall amounts for the previous year. */ using namespace std; void printMonth(int month);
So the latest challenge from jumping into c++ is as following.
Code: Write a function that builds the multiplication table of arbitrary dimensions This chapter also talks a ton about 2d arrays.
So I've built my program thus far as this.
Code: #include <iostream> using namespace std; int drawTable(int,int); int main()
[Code] .....
So basically, the idea is that I can use the arrays dimensions as a placeholder, and just multiple them to get that specific spot, so table[0][0] = 0, [0][1] = 0 and so on. However the output actually seems to be randomly generated numbers so I'd like to ask, what am I doing wrong? Am I on the right track? Or have I missed the bus stop completely.