hash

Why does this hash syntax not work in Rails?

session[:user => user, :user_id => [user.id, user.salt]] For some reason, that never worked for me. Thoughts on how I can achieve the following code in one line: session[:user] = user session[:user_id] = [user.id, user.salt] ...

What is the default hash code that Mathematica uses?

The online documentation says Hash[expr] gives an integer hash code for the expression expr. Hash[expr,"type"] gives an integer hash code of the specified type for expr. It also gives "possible hash code types": "Adler32" Adler 32-bit cyclic redundancy check "CRC32" 32-bit cyclic redundancy check "MD2" 128-bit MD2 code "MD5" ...

Perl: hash-keys have lost their class information

Hi there, I have a package X.pm with a method data_x(); I use instances of class X as keys of a hash %seen, say. Now the elements of keys %seen seem to have forgotten their blessing: use X; my( $x, $y, %seen ); $x = X->new(); $x->data_x( 1 ); print " x: ", $x, "\n"; print " x.data: ", $x->data_x(), "\n"; $seen{ $x } = 1; $y =...

How should I map long to int in hashCode()?

I have a range of objects that have a long field whose value uniquely identifies a particular object across my entire system, much like a GUID. I have overriden Object.equals() to use this id for comparison, beause I want it to work with copies of the object. Now I want to override Object.hashCode(), too, which basically means mapping my...

Merging inner hashes in Perl

I have 3 dimensional hash and a 2 dimensional hash, and I want to merge the 2 dimensional hash with one of the inner hashes of the 3 dimensional hash, something like this, which is similar to what I do to merge a pair of 2d hashes: my %3dhash; my %2dhash; my $key = "some string"; %3dhash{$key} = ($3dhash{$key}, %2dhash); But when I tr...

Convert string to hash and then reform the string later

Hi - I need to hash some strings so I can pass them into some libraries, this is straight forward using the String.hashCode call. However once everything is processed I'd like to convert the integer generated from the hashCode back into the String value. I could obviously track the string and hashcode values somewhere else and do the...

Compare programs

Hello everybody, I'm looking for a freeware program that compares two binary files with each other, and can do the following things give % of similarity Hash the files (give a few basic, asswel as fuzzy hashes, md5, sh1/sh2, etc etc) Compare more then 2 programs with each other, and list them in some sort of database If you know a pr...

hash.delete_if { |key, value| true } doesn't delete ... why?

I am working on the acts_as_taggable_on plugin, but there is something I can't really understand (even if it is just a very simple code line). puts "before: " + cache.inspect # cache.delete_if { |key, value| key.id == owner.id TaggableUser id: 1, name: nil>=>["dog"]} after: {# TaggableUser id: 1, name: nil>=>["dog"]} My problem is tha...

how to merge 2 deep hashes in perl

I write a sub in Perl to merge 2 hashes of the same structure; so that merge($a,$b) $a = { k1 => { sk1 => 'v1' }, k2 => { sk3 => 'v3', sk4 => 'v4' } }; $b = { k1 => { sk2 => 'v2'}, k3 => { sk5 => 'v5'} }; would result in $c = { k1 => { sk1 => 'v1', sk2 => 'v2' }, k2 => { sk3 => 'v3', sk4 => 'v4' } k3 => { sk5 => 'v5'} }; B...

Iteratively filling an array with hashes from an each/do block gives me all repeat values..help!

I am trying to fill an array of hashes with hashes created through an each loop, If I print each individual hash within the iteration they are distinct, but when I try to push them to an array, the resulting array has the last hash repeated whatever number of times. Here's the code: def get_tweets tweet_array = Array.new tweet = {} ...