c++


What would be a good hash function for this list of English words?


Here's my code on Github if anyone would like to see it :
https://github.com/daicain/Hashing-Project
Currently, I am using a tablesize of 80, since I have about 73 words in the file.
My current method of hashing is pretty basic and generic. I add up the ASCII value of the letters after I make them all lowercase, then I mod (%) by the tablesize (80 currently). I am getting a lot of collisions, and a lot of unused bucket/indexes. Since I know exactly which words I need to hash and how many, are there better methods to use, for the least possible collisions? My goal is to get 6 or less.
Also, side question. Once the words are in the hashtable, if I want to look up a certain word, but type that word incorrectly, or scrambled up, how would I find it in the hashtable?
For example, if I have "apple" in the hashtable, and for my search, I use "leppa", which is apple spells backward, whats a good way to unscramble "leppa" in such a way that, apple would come out?
Please ask me if you're unsure about what I just ask, sorry if I'm not clear!
Murmur hash is considered fast and will probably give good distribution
http://en.wikipedia.org/wiki/MurmurHash
In order to look for a "scrambled" text in a hash, you need to use hash-function that is agnostic to the letters order - pretty bad idea since all permutations will be in the same hash bucket
Try md5, you won't have collisions in your dictionary.
You may simply use std::hash:
#include <string>
#include <iostream>
#include <functional>
int main()
{
std::string str = "air conditioner";
size_t h = std::hash<std::string>()(str);
std::cout << "hash of \"" << str << "\" is " << h << std::endl;
}
commonly it might be implemented as fnv1 hash. Another good hash function is murmur. Check related question on stackexchange for other common hash functions.

Related Links

How to exclude isolated nodes from generated Doxygen Class Hierarchy
Why might compiling with -march=native cause “pointer being freed was not allocated”?
Cant access correct number of vertices for a 3d model (.OBJ) using Assimp
In using-declaration, can dependent names render to constructors after template substitution?
How to add C++ files to the Objective-C/C++ OpenGL ES project
Using Eigen in custom tensorflow op
Create JSON structure based on input variables
C++ range for loop different than regular for loop [closed]
C++ boost thread causes segmentation fault when instantiated twice
c++ - 3 bears in a vector of a struct, how can I change this code so the specific bear at the exit is removed?
Reading from excel/text file without skipping whitespaces unless made by a tab
How to initialize const size array in constructor without explicitly stating the size in class declaration?
Reading txt file into 2d array C++
How can I mark a function with an attribute conditionally on the value of a parameter?
Read a text file and store into two different arrays: a string array and float array
converting constructor: How do you explain a function given different arguments in c++

Categories

HOME
menu
logic
inno-setup
reverse-geocoding
asynchronous
ignite
text
google-speech-api
g2o
animate.css
instagram-api
pstricks
vaadin-grid
javacard
uinavigationcontroller
css-modules
fontforge
navbar
affinity
category
postgresql-9.0
serenity-bdd
selenium-rc
flip-flop
phylogeny
indexof
formsets
nodemon
dsolve
angular-openlayers
android-sensors
week-number
radius
modeling
multiple-domains
transitions
r6
redhat-bpm
actor
oclazyload
binary-image
qnx
rethinkdb-python
cakephp-2.x
jquery-ui-widget-factory
bandwidth
lpc
tivoli-identity-manager
oltp
powerview
htsql
mds
client-side
giflib
numerical-analysis
throttle
timedelta
oslo
ng-template
idiorm
adobe-flash-cs3
stompjs
bullseye
steroids
ssas-2008
angularjs-ng-options
window-position
wave
scrollviewer
cakedc
allocation
image-manipulation
navigationbar
sql-job
filefield
unassigned-variable
appcompat-v7-r22.1
typescript1.4
xcode6.1
syntactic-sugar
httpwatch
phpmotion
node-http-proxy
hiding
pull-to-refresh
file-association
backbone-forms
happstack
python-sockets
glow
eda
openflashchart2
xml-comments
multiple-versions
zend-navigation
white-box-testing
html-rendering
nice

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile