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've been working on this program and am finished with what I want it to accomplish. But the last step I'd like to take is to delete the linked list and free all the memory. When I free the memory the way I am right now, the program breaks. I'm not sure how I should go about freeing and setting things to NULL.
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 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 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.
I am looking at one of the functions of an exercise:
void escape(char * s, char * t) { int i, j; i = j = 0; while ( t[i] ) { /* Translate the special character, if we have one */ switch( t[i] ) {
[code]...
Notice the while loop evaluates the current value in t to true or false. When we hit the null terminator, does that get evaluated as 0 and hence evaluates as a falsy value so the while loop exits?
When you login to my site my loginservice which is done by ajax and json make a session called context.Session["Name"]. With BreakPoints it shows that everything is good and the variables are in place. However when I use Session["Name"] it comes out as null.
I will add my code at the bottem not
using System; using System.Collections.Generic; using System.Linq;
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.
1) Count the number of rows in the table booking that are open and where the booking.postcode is "MK",
2) Take a note of the plot (in booking.plot_id), and then update the table plot.jobs with the value count.
For example running the SQL query when booking table has the following rows:
Would see the following highlighted values in plot.jobs being updated to 1:
I managed to resolve it with this code so far (note I am using Connector/Net):
public void RefreshPlot(){ string query = "SELECT Count(*) AS count, plot_id FROM booking WHERE postcode='MK' AND status='open' GROUP BY plot_id"; var cmd = new MySqlCommand(query, _connection); var da = new MySqlDataAdapter(cmd); var dtCounts = new DataTable(); da.Fill(dtCounts);
[code]....
Currently, my code only checks for existing rows in the booking table and updates the plot table. However if the row gets deleted in the booking, then the changes are not reflected in the plot table.
Example: If we delete the row with plot.id=1 and plot.plot_id=4, then booking.plot_id should go back to being 0, if it was initially 1. At the moment, it doesn't. How would I update my SQL statement to better reflect this? In a sense, it should check for "non-existent" rows, i.e. the impact that the row plot.plot_id=4 & plot.id=1 has on booking.plot_id when deleted?
I have a C# .NET Application which get data from QuickBooks via the ODBC Driver and save the result to C# data table. So, I want to transfer this data table to a mysql table on my own server. That's the code I use:
using System.IO; using MySql.Data.MySqlClient; //Add mysql dll on the .NET Tab in Project's references string connStr = "DSN=QBTest;"; string myServerAddress = "192.168.0.243"; string myDataBase = "CostTest";