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


ADVERTISEMENT

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++ :: Create Matrix Of Data That Add Values Based On Reading Get From DVM

Apr 22, 2012

Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.

The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.

What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?

Here is what I got

Code:
#include <vector>
typedef std::vector<double> Double1D;
typedef std::vector<Double1D> Double2D;
typedef std::vector<Double2D> Double3D;
#define HEIGHT 5
#define WIDTH 3

[Code]....

View 7 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++ :: 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++ :: 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++ :: 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/C++ :: Modifying Row Of Matrix Based On Zero Entry?

Nov 19, 2014

Here is the problem:

Write an algorithm such that if an element in an M * M matrix is 0, its entire row and column is set to 0.

Your function prototype may look like the following:

void setZeros ( int size, int arr[][size] );

Heres what I have:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 3
void scan_matrix(int arr[][SIZE]);
void print_matrix(int arr[][SIZE]);
void initiailize_matrix(int arr[][SIZE]);
void set_zeros(int matrix[][SIZE]);

[code]....

I'm not sure on how to scan zero for this code and I have bolded some comments that I am having trouble with as well.

View 1 Replies View Related

C++ :: Sparse 2 Dimensional Array?

Feb 26, 2012

i created a program which uses Sparse 2 dimensional array, but i am not sure if i did it in the right way .

this is the instruction i have:

Create a constructor and a destructor. The constructor should take as input the size of the array (consider only square NxN arrays, so only one dimension is needed) and the thickness of the ribbon. To make this precise, if supplied with a thickness parameter t, you may assume that the element [0,t] (i.e. the (t+1)-th element of the first row) is where the useless area begins on the right. Similarly, the element [t,0] is where the useless area begins on the left. The border of the useless areas moves diagonally down and to the right, i.e. it consists of [1,t+1],[2,t+2],... and [t+1,1],[t+2,2],... The above example has thickness 3.

The space for the 2-d array should be dynamically allocated and must be large enough to fit the useful data only.Create methods for random read and write access to the array as in the case of 1-d arrays.Overload the [] and << operators, as in the case of 1-d arrays. Think carefully about what the [] operator should return and how it should work. Ideally we would like this to behave in a manner similar to standard 2-d arrays (i.e. accessing elements in the normal way, like x[5][6]).

View 3 Replies View Related

C :: Create A Proper Table That Accepts Value In Each Box It Contains

Sep 29, 2013

I want to create a proper visible table with boundaries that contains boxes and each box receives a value .I don't know where to start from.i have an idea of using matrix for entering values in each box of table,but how to create lines and boundaries ?

View 1 Replies View Related

C++ :: Create A Binary File Based On HEX Data

Apr 24, 2013

I want to create a binary file based on some hex data :

Ex Input Hex :54313032202020303030

Out put like :6      

View 2 Replies View Related

C/C++ :: How To Create A Table With Variables From Multiple Structs

Aug 1, 2012

I would like to create an array of struct variables inside a table to avoid using many if/else and/or switch/case statements. I have attached a simple example of what I am trying to do, it doesn't work. For the table "sTablePtr" I see different values than what I set, when I dereference it with a "&" it just shows me the addresses of the variables. However at the end, when I do print out the values, by just using the structs themselves, they print out the values correctly.

My structure declarations must remain a pointer. To be clear, what I am trying to do is have sTablePtr[i] show me the correct values I set, in this case I want the for loop to print out 1, 2 and 3. If there is a different way of doing this, I am open to it as long as I can use a table of my struct variables to avoid many if statements.

#define MAX_CNT 3  
typedef struct {
   int nNum;
   int nCnt;   
}sDummy1;  

[Code] ....

View 4 Replies View Related

C++ :: Create Symbol Table For Assembly Language?

Jan 21, 2013

how to create a symbol table for an assembly language and high level language program in c++

View 1 Replies View Related







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