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


ADVERTISEMENT

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++ :: 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++ :: 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++ :: Separate Chaining Hash Table?

Nov 28, 2014

my insert() function

template <class T>
class Node
{
public:

[Code]....

View 6 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

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 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 :: 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++ :: 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++ :: Hash Function Implementation

Aug 26, 2013

I was trying to implement a hash function in c++. This is just for learning purposes and not for a class project or assignment question. I had some questions before I started programming it:

1) Is it meaningful to have a hash function which maps string to string, string to int, int to int, float to int?
2) Can we have a template implementation which does element to element hashing?

I looked at several sources for a clear understanding of concepts and implementation technique but could not find a good source for reading about hashing.

View 3 Replies View Related

C++ :: Construct Simple Hash Function?

Jun 3, 2013

How to construct a simple hash function ? When the program executes, it will ask for your name. Type your name and it will print out a "hash code" (a number) from that name.

View 2 Replies View Related

C++ :: Multiplication Table In A Void Function?

Jan 20, 2015

I wanted to make a multiplication table.

Here's the code:

#include<iostream>
#include<conio.h>
using namespace std;
void initArray(int arg1[50][50], int r, int c) {
int val=1;
for(int row=0; row<r; row++) {

[code]....

I want the output to be like this:

1 2 3
2 4 6
3 6 9

If the user inputs 3 rows and 3 columns.

View 5 Replies View Related

C++ :: Truth Table Generator - If User Enters String Of Boolean Algebra It Will Output Table

Jan 25, 2013

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.

View 2 Replies View Related

C# :: Lookup Non-existent Rows In MySQL Table And Then Update Another Table

Dec 15, 2014

I have written an SQL statement that would:

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?

View 6 Replies View Related

C Sharp :: Copy Data Table To MySQL Table

Mar 25, 2013

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";

[Code] ....

View 2 Replies View Related

C++ :: Virtual Function Table Pointer Misplaced In Object Memory

Jul 29, 2014

I have found that when I dump a C++ object from memory to a file - it seems that there is a misplacement of the last Virtual-Function-Table pointer - in that appears at the beginning. The result is that the gdump information based on this object dump (using green hills) is incorrect. I copied the contents of the gdump information below. The executable is compiled in linux.

Basically MEIO::CameraStatus contains an item that relates to its parent class (line 188). Then it has 18 items that are all Diagnostics::EventsCounter items. Now for each Diagnostics::EventsCounter item there is a Virtual-Function-Table Info Pointer as its last item. All is fine and good except that the last item of MEIO::CameraStatus which is _selfReset is missing its last item of 4 bytes (which is the Virtual-Function-Table Info Pointer ). On the other hand - right before the first Diagnostics::EventsCounter item ("_vidErrors") - there is an extra 4 bytes which happens to be the Virtual-Function-Table Info Pointer. As I said the gdump information file does not see this.

Why the object memory "moves" the last Virtual-Function-Table Info Pointer to the beginning (right before _vidErrors) and is there a way to "fix" this?

///////////////////////////////////////////////////////////////////////////
"MEIO::CameraStatus" val:0x000002f0 ind208,-1) Struct-Begin Info
188: "" offset 0, Parent-Class Private Info C++ Struct ref = 114
189: "_vidErrors" offset 160, Member Info C++ Struct ref = 128
190: "_vdiErrors" offset 480, Member Info C++ Struct ref = 128

[Code] .....

View 4 Replies View Related







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