C++ :: Implementing Hash Table - STL List Compiler Error

Jun 5, 2013

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)

Here's the Delete function:

template <typename T, typename X>
void HashTable<T,X>::Delete(T key) {
HashNode<T,X> Node;
HashNode<T,X> NodeTemp;
list<HashNode<T,X>> temp;
list<HashNode<T,X>>::iterator it;
vector<list<HashNode<T,X>>>::iterator iter;

[Code] ....

Why it's not letting me do the .Remove() function?

View 3 Replies


ADVERTISEMENT

C++ :: Runtime Error In Hash Table

Apr 25, 2013

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.

View 1 Replies View Related

C :: Linked List Or Hash Table For Matrix Operations And Representation

Jul 21, 2014

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?

View 5 Replies View Related

C++ :: Hash Table Program - Sorting Pointer Table After All Of Values Entered

Nov 19, 2013

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?

#include "/home/onyuksel/courses/340/progs/13f/p9/util9.h"
#include "/home/onyuksel/courses/340/progs/13f/p9/hTable.h"

#ifndef H_TABLE1
#define H_TABLE1
void ptr_sort ( );

[Code] ....

View 1 Replies View Related

C :: How To Add New Value To Hash Table

Apr 18, 2013

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:

Code:

typedef struct {
char key[25];
char value[100];
} object;

[code]....

View 2 Replies View Related

C :: How To Generate Hash Table

Jul 29, 2013

Code: I have these two columns.

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.

View 5 Replies View Related

C++ :: Duplicates In Hash Table

Feb 24, 2013

I am having problems with this function:

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.

View 1 Replies View Related

C/C++ :: PJW Algorithm Of Hash Table

Jul 28, 2012

I have a doubt in the PJW algorithm of the Hash Table.

What is the logic in shifting the bytes by this specified number as specified in the pjw algorithm.

View 1 Replies View Related

C++ :: Retrieve Object From Hash Table

Feb 25, 2013

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.

View 3 Replies View Related

C++ :: Hash Table Remove Function

Apr 11, 2013

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.

class HTable
{
public:
HTable(int size);

[Code]....

View 5 Replies View Related

C++ :: Separate Chaining Hash Table?

Nov 28, 2014

my insert() function

template <class T>
class Node
{
public:

[Code]....

View 6 Replies View Related

C++ :: Hash Table Of Function Pointers?

Dec 15, 2014

Is it possible to create a hash table of function pointers so that functions can be referenced by their name (using a string?)

View 2 Replies View Related

C :: Setting Hash-table Entries To NULL?

Apr 21, 2013

Here is my code so far:

Code:
//LINEAR CHAINING OR SEPERATE CHAINING...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_USERNAME_LEN 15
#define MAX_PASSWORD_LEN 20

[Code] ....

When I compile I get this error:

Code:
simpleauth.c: In function ‘initialize_table’:
simpleauth.c:179:30: error: incompatible types when assigning to type ‘DBEntry’ from type ‘void *’

I am sure its a simple error but I cannot seem to figure out how to set all the entries in the database to NULL. My plan is this:

1. Set all entries to NULL.
2. Check if entry is empty, if empty insert into hash-location, if not increment until empty...

Part 2 seems easy to me, but I cannot set them to empty....

View 3 Replies View Related

C/C++ :: Hash Table - Interpreting Valgrind Output

Nov 22, 2014

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.

View 4 Replies View Related

C++ :: Dynamically Allocating Hash Table Using Data From File

Nov 5, 2013

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();

[Code] .....

View 3 Replies View Related

C++ :: Create A Map Based Hash Table For A Sparse Matrix?

Jul 24, 2014

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:

typedef unordered_map<Object,Tuple,TupleHash> HashTable;

The next typedef was given to me like so:

typedef typename HashTable::value_type valueType;

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> >'|

View 1 Replies View Related

Visual C++ :: Hash Table - How To Setup Static Variable

Apr 22, 2014

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

[Code] ....

View 10 Replies View Related

C++ :: Insert Numbers Into A Hash Table Of Size 10 - Using Linear Probing And Chaining

May 28, 2014

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.

75, 98, 43,1,-56,93,101,34,23

View 2 Replies View Related

C :: Make A Hash Table Array Of Linked Lists / Separate Chaining Technique

Jul 5, 2013

how to create a hash table array and use linked lists inside the elements.

View 5 Replies View Related

C++ :: Implementing Adjacency List?

Mar 1, 2014

Today I am refining my skills on graph theory and data structures. I decided to do a small project in C++ because it's been a while since I've worked in C++. I want to make an adjacency list for a directed graph. In other words, something which looks like: 0-->1-->3 1-->2 2-->4 3--> 4-->This would be a directed graph with V0 (vertex 0) having an edge to V1 and V3, V1 having an edge to V2, and V2 having an edge to V4, like this:

V0----->V1---->V2---->V4
|
|
v
V3

I know that in order to do this, I will need to create an adjacency list in C++. An adjacency list is basically an array of linked lists. Okay, let's see some pseudo C++ code:

Code:
#include <stdio>
#include <iostream>
using namespace std;
struct graph{

[Code] ....

This pseudocode is currently far from the mark. And that is what -- pointers and structs in C++ have never been my strong suit. First of all, this takes care of the vertices that a vertex points to -- but what about the vertex itself? How can I keep track of that vertex? When I loop over the array, it will do me no good to only know what vertices are being pointed to, rather than also knowing what points to them. The first element in each list should probably be that vertex, and then the elements after that are the vertices it points to.

But then, how can I access this first element of the list in my main program?. I would like to be able to loop over this adjacency list to do some cool things with graphs. For example, to implement some graph theory algorithms (sorts, shortest paths, etc) using the adjacency list representation. (Also, I had a question about the adjacency list. What is different than just using a list of arrays? Why can't I just have a list with an array at each element in the list?)

View 2 Replies View Related

C :: Implementing And Manipulating Polynomial ADT Using Linked List

Sep 23, 2014

Implementing and manipulating a Polynomial ADT using a linked list.

So far I have:

poly_ADT.h
Code: typedef struct nodeT{
int coef;
int powr;
struct nodeT *next;
} node;

[Code]...

I need to create a function that creates the polynomial using input first.

poly *poly_create (num,...) ;return a new polynomial with num terms terms are listed in order of lowest ordered-term to highest. i.e., to initialize poly 15x^6 + -9x^4 + 3x^2 call poly_create(3, 3,2, -9,4, 15,6 );

Once I do that I need to implement various functions that can manipulate the polynomial itself but I'm having trouble just with creating the polynomial itself, how to do that using a linked list and nodes?

View 3 Replies View Related

C/C++ :: Implementing Stack Using A Double Linked List

May 12, 2014

So im trying to write a code that will take data in from a user and when that user enters specific character then i want to pop the top of the stack and place that node on a new stack. Then if the user enters a different specific character then i want to place what was just popped off the stack back on to the original stack. Anyways i'm just testing what i have without all the complicated stuff with the specific characters, but i get an error and i'm not not well versed in exception handling. So this is what i have so far. the push seems to work well but the pop seems to be giving me problems.

Stack::Stack(){
top = NULL;
bottom = NULL;
}
//method to push a line of text onto the stack
void Stack::push(string data)

[Code] .....

View 4 Replies View Related

C++ :: Compiler Error C2664 And C2228

Nov 9, 2013

Working on a basic class program and I'm generating two compiler errors that I'm not sure how to fix. Header file, implementation cpp and main cpp are shown below. The specific errors are shown after the code.

Header file Code:

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;

[Code].......

The file generates the second error, C2228, at lines 37-41 and 43. Basically where I tried using the second created object. Error message is "left of '.setFirstName' must have class/struct/union"

View 8 Replies View Related

C++ :: Compiler Error C2370 And C2011

Nov 29, 2013

Working on a solution involving inheritance. The whole solution is pretty massive at this point so I'll just focus on the problem areas. I'm getting a lot of "redefinition" and "undefined class type" compiler errors, including C2370, 2011, 2504, and 2027, in Benefit.h, Employee.h (the constant members are a big occurance) I'm also getting 2027 and 2079 in EmployeeMain.cpp. with my Benefit and Employee object calls.

Clearly I missed something in about how to code this correctly. Sadly the course textbook focuses on general OOP theory instead on the accompanying C++ syntax.

Benefit.h
Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;

[Code] .....

View 4 Replies View Related

C++ :: Unexpected Expression Compiler Error

Jul 30, 2013

My compiler (GCC) keeps expecting an expression where it shouldn't in 1 specific piece of my code:

int zxcNewWindow( HWND parent, TCHAR *text, zxWINDOW *kid,
UINT style, int x, int y, int w, int h, int type )
// right here
{
*kid = zxDefWINDOW;

The project contains only 2 files right now and the settings are just the default for an empty Code::Blocks 12.11 project. Both files are in UTF-8 format (tried in ASCII too), I just cannot see why this is not compiling correctly. I'll post the files in the next two posts.

Edit: For those of you who didn't get what the error was from the above here's the full log:

mingw32-gcc.exe -Wall -g -DzxDEBUG -c C:MePrjscppzxGUImain.c -o objmain.o
C:MePrjscppzxGUImain.c: In function 'zxcNewWindow':
C:MePrjscppzxGUImain.c:39:10: error: expected expression before '{' token
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings (0 minutes, 0 seconds)

View 8 Replies View Related

C++ :: Compiler Error - Expression Must Have A Constant Value

May 20, 2014

I am trying to run this source code but i am getting the compiler error Expression Must Have a Constant Value. I tried making both the variables x and y constants and assigned them to a significantly big number but then i am getting the error expression must be a modifiable lvalue.I have made comments in the code in front where Visual Studio is giving me the syntax error (red squiggly line).

#include<iostream>
#include <string>
#include<cmath>
using namespace std;
int main(){
int x;
int y;

[Code] ......

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved