hash

shortest path in hash map

The following is a data set I have stored in a hash map, and I have to find the shortest path between two values. 9244, 4322, 4886, 5989, 8598, 9979, 1447, 9657 8598, 6752, 7146, 1951, 660, 1447, 7779 568, 1951, 4886, 2570, 9026, 9489, 7779 6752, 3424, 1977, 4746, 9657 77 The key value of the hash map is the first value of each line, ...

What is the best way to remap a Hash in Ruby?

Is there a simple way of remapping a hash in ruby the following way: from: {:name => "foo", :value => "bar"} to: {"foo" => "bar"} Preferably in a way that makes it simple to do this operation while iterating over an array of this type of hashes: from: [{:name => "foo", :value => "bar"}, {:name => "foo2", :value => "bar2"}] to:...

SQL Server PWDEncrypt value comparison

I think what I am about to ask is impossible, however, figured it was worth a shot here. We have an application that makes use of SQL Servers PWDEncrypt and PWDCompare functions. Part of the system creates duplicates of users (same logon and password). Due to a bug in the system, instead of copying the binary stored PWDEncrypt of a pas...

Adding values from file to a hash type structure in C++

I have a space separated file which contains some key->value pairs. These are to be loaded to a structure of the type given below: #define FV_PARAM1 "A" #define FV_PARAM2 "B" parameter_t & parameterFeatureVector ( parameter_t & param, int param1, int param2, ) { param.addParam(FV_PARAM1, par...

Built in python hash() function

Windows XP, Python 2.5: hash('http://stackoverflow.com') Result: 1934711907 Google App Engine (http://shell.appspot.com/): hash('http://stackoverflow.com') Result: -5768830964305142685 Why is that? How can I have a hash function which will give me same results across different platforms (Windows, Linux, Mac)? ...

How to determine a strings dna for likeness to another

I am hoping I am wording this correctly to get across what I am looking for. I need to compare two pieces of text. If the two strings are alike I would like to get scores that are very alike if the strings are very different i need scores that are very different. If i take a md5 hash of an email and change one character the hash change...

How to turn a Ruby Hash into HTTP Params

That is pretty easy with a plain hash like {:a => "a", :b => "b"} which would translate into "a=a&b=b" but what do you do with something more complex like {:a => "a", :b => ["c", "d", "e"]} which should translate in "a=a&b[0]=c&b[1]=d&b[2]=e" or even worse, with something like: {:a => "a", :b => [{:c => "c", :d => "d"},...

Fast Cross-Platform C/C++ Hashing Library

What's a high performance hashing library that's also cross platform for C/C++. For algorithms such as MD5, SHA1, CRC32 and Adler32. I initially had the impression that Boost had these, but apparently not (yet). The most promising one I have found so far is Crypto++, any other suggestions? http://www.cryptopp.com/ This seems to be qui...

Best way to convert strings to symbols in hash

What's the (fastest/cleanest/straightforward) way to convert all keys in a hash from strings to symbols in Ruby? This would be handy when parsing YAML. my_hash = YAML.load_file('yml') I'd like to be able to use: my_hash[:key] Rather than: my_hash['key'] ...

How do I check if more than one record has been returned from DBI query in Perl?

Hi, I searched for this on the site already but couldn't locate anything that answered my question. Which brings me to the details: I am querying database using a simple select query, realistically (given the scenario) it should never return more than about 5 to 6 records. I just want to check if more than one has been returned. And if...

iPhone and Crypto Libraries

Hi, I think I'm going to have to use the Crypto libraries in my iPhone application. I wanted to ask you about the implications regarding the crypto export policy applied by Apple. Do I need to do something extra (such as filling forms etc.) 1) If I use hashing with MD5. 2) If I use symmetric encryption. Thanks, ...

How to hash a large object (dataset) in Python?

I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of md5 or sha1. The problem is that most of the data is stored in NumPy arrays; these do not provide a __hash__() member. Currently I do a pickle.dumps() for each member and calculate a...

Does an uninitialized hash key have a default value of zero in Perl?

I have Perl code similar to the following: # -- start -- my $res; # run query to fetch IPv6 resources while( my $row = $org_ip6_res->fetchrow_arrayref ) { if( $row->[4] =~ /PA/ ) { $res->{ipv6}{pa}{$row->[2]}++; } elsif( $row->[4] eq 'PI' ) { $res->{ipv6}{pi}{$row->[2]}++; } } # -- stop -- At no point is...

Ruby: change each value in a hash with something like #collect for arrays?

Hi! I'd like to replace each value in a hash with value.some_method. For example in a simple hash {"a" => "b", "c" => "d"} every value should be .upcase-d so it looks like {"a" => "B", "c" => "D"}. I tried #collect and #map but always just get arrays back. Is there an 'elegant' way to do this? Thanks in advance, Adam Nonymous UPDAT...

Ultimate Hash Protection - Discussion of Concepts

Ok, so the whole problem with hashes is that users don't enter passwords over 15 characters long. Most only use 4-8 characters making them easy for attackers to crack with a rainbow table. Solution, use a user salt to make hash input more complex and over 50chars so that they will never be able to generate a table (way to big for string...

Detecting Retweets using computationally inexpensive Python hashing algorithms

In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database. What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way. My first attempt at this wa...

Distribution of user accounts to N tables

There are millions of user accounts, and I want to distribute their data into N tables(user_1, user_2,..., user_N) of a database. User accounts are comprised of 3~8 characters. So, I want a function that returns table suffix like int getTableSuffix(String userAccount); The result is a uniform distribution from 1 to N. Do you kno...

Run time to insert n elements into an empty hash table

People say it takes amortized O(1) to put into a hash table. Therefore, putting n elements must be O(n). That's not true for large n, however, since as an answerer said, "All you need to satisfy expected amortized O(1) is to expand the table and rehash everything with a new random hash function any time there is a collision." So: what ...

How can I sort Perl hashes whose values are array references?

Hey I was just wondering if there is a cool "one liner" that would sort my hash holding array references. So I have a bunch of key/values in my hash something like: $DataBase{$key} = \@value; However I would like to sort the hash by the array[0] element. Then loop through 'em. I had this to begin with: foreach my $key (sort {$DataBa...

C# MD5 hasher example

Edit: I've retitled this to an example as the code works as expected. I am trying to copy a file, get a MD5 hash, then delete the copy. I am doing this to avoid process locks on the original file, which another app writes to. However, I am getting a lock on the file I've copied. File.Copy(pathSrc, pathDest, true); String md5Result; ...