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.
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.
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 am having trouble with the implementation section of my code. The trouble I am having is with the """"string Name::RevereUsingString()""" function/method. I keep getting an error saying that """"control reaches end of non-void function"""". The two void function below the ""string Name::RevereUsingString()"" fuction/method are ok and ready to be worked on.
How to implement the ""string Name::RevereUsingString()"" correctly in the implementation section?
#include <iostream> #include <string> using namespace std; //-------------Class Section------------------------------------ class Name {
I got a code of a BST and i need to create a function that will return the value of the parent that it's son/sons sum to the biggest sum - BST and not AVL.
I assume that the shortest code will be recursive but i didn't manage to get it right - i'll send the code without my function because it's wrong - l
#include <vector> #include <iostream> using namespace std; //----------------------------------------------------------------- // class Node // a single Node from a binary tree //----------------------------------------------------------------- template <class T> class Node
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 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.
My program had a requirement to ignore an input beginning with a # sign. The input is entered by user from keyboard. I wanted to know how to use cin.ignore to achieve this.
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'm trying to write a little C++ wrapper around the PolarSLL SHA-512 / 384 implementation, the source code of which you can view here: [URL] .....
The problem I'm having is that the length of the digest is not always 64 bytes (for sha512) or 49 bytes (for sha384) as it's supposed to be, it often is, but not always.
I have pretty much used the code as it is on PolarSSL's website, except for wrapping it in an "impl" namespace. I also ran the self_tests, which all passed.
Here's the code I'm using to wrap the PolarSSL implementation:
When I do a strchr() for '' on the original (non-hex) values, the pointer position returned is the same as the checksums length, so I'm wondering if perhaps the sha4 implementation would shift bits around and one of them happens to become a '', null terminating the hash early?
How difficult would it be to program a hash-map system where each "key" can have multiple values under indexes?
For example: "Word" -> 45(index 0) , 67(index 1) , 12(index 2). What could I start with to program this or where could I find a pre-made system that does this?