hash

How do I control how an object is hashed by a hashset

I'm using a HashSet<T> to store a collection of objects. These objects already have a unique ID of System.Guid, so I'd rather the HashSet<> just use that existing ID rather then trying to figure out itself how to hash the object. How do I override the build in hashing and force my program to use the build in ID value as the hash value? ...

Why does perl "hash of lists" do this?

I have a hash of lists that is not getting populated. I checked that the block at the end that adds to the hash is in fact being called on input. It should either add a singleton list if the key doesn't exist, or else push to the back of the list (referenced under the right key) if it does. I understand that the GOTO is ugly, but I've ...

removing duplicate hash value and keeping a count of it in perl

Lets say %hash = ( key1 => 'one', key2 => 'two', key3 => 'three', key4 => 'two', key5 => 'one', ); I want to have two arrays: This array should have unique key/value @array1=(key1 one key2 two key3 three) this array should have count of duplicates by value (eg here only three value are unique...

Is there a way to access an Image's bitmap data using Javascript?

I am looking for a way to create a hash for an image displayed on an XHTML page using Javascript. ...

how can I simply merge a hash into a new one?

I have a simple hash like so { "1234" => "5", "2345" => "6" } How can I create a new hash with both the keys and values in side it? Like so: { key_id = "1234", value_id = "5" }, { key_id = "2345", value_id = "6" } ...

Random hash in Python

What is the easiest way to generate a random hash (MD5) in Python? ...

Data structure for finding nearby keys with similar bitvalues

I have some data, up to a between a million and a billion records, each which is represented by a bitfield, about 64 bits per key. The bits are independent, you can imagine them basically as random bits. If I have a test key and I want to find all values in my data with the same key, a hash table will spit those out very easily, in O(1)...

Additional hash lookup using 'exists'?

I sometimes access a hash like this: if(exists $ids{$name}){ $id = $ids{$name}; } Is that good practice? I'm a bit concerned that it contains two lookups where really one should be done. Is there a better way to check the existence and assign the value? ...

How can I get a only part of a hash in Perl?

Is there a way to get a sub-hash? Do I need to use a hash slice? For example: %hash = ( a => 1, b => 2, c => 3 ); I want only %hash = ( a => 1, b => 2 ); ...

ruby add to array... simple question

I'm sure this is simple but I can't seem to get it: Works: @build1 = Booking.build_booking('2009-06-13',3,2,18314) @build2 = Booking.build_booking('2009-06-13',3,4,18317) @build = @build1 + @build2 What I want to work... #for item in @cart.items do # @build << Booking.build_booking('2009-06-13',3,2,18314) #end Doesn't work either...

Sorting Hash of Hashes by value (and return the hash, not an array)

I have the following hash: user = { 'user' => { 'title' => {'weight' => 1, .... } 'body' => {'weight' => 4, ....} .... .... } } Is is possible to get the User sorted by the weight key of its child hashes? I looked in the Hash.sort, but it looks like it returns array rather than my original hash sorted. ...

Difference in SHA hashes between ruby and C#

I'm developing an application, that makes use of some REST web services. It's technical documentation says that I should pass SHA256 hash of some string in the request. In an example request (in the documentation) a string: hn-Rw2ZHYwllUYkklL5Zo_7lWJVkrbShZPb5CD1expires=1893013926label[0]=any/somestatistics=1d,2d,7d,28d,30d,31d,life...

How can I generate this hash?

I'm new to programming (just started!) and have hit a wall recently. I am making a fansite for World of Warcraft, and I want to link to a popular site (wowhead.com). The following page shows what I'm trying to figure out: http://www.wowhead.com/?talent#ozxZ0xfcRMhuVurhstVhc0c From what I understand, the "ozxZ0xfcRMhuVurhstVhc0c" part of...

What portability issues are associated with byte-level access to pointers in C?

Purpose I am writing a small library for a larger project which supplies malloc/realloc/free wrapper-functions as well as a function which can tell you whether or not its parameter (of type void *) corresponds to live (not yet freed) memory allocated and managed by the library's wrapper-functions. Let's refer to this function as isgood_...

Idiomatic Ruby: data structure transformation

What's the "Rubyist" way to do the following data structure transformation: I have incoming = [ {:date => 20090501, :width => 2}, {:date => 20090501, :height => 7}, {:date => 20090501, :depth => 3}, {:date => 20090502, :width => 4}, {:date => 20090502, :heigh...

hash collision and appending data

Assume I have two strings (or byte arrays) A and B which both have the same hash (with hash I mean things like MD5 or SHA1). If I concatenate another string behind it, will A+C and B+C have the same hash H' as well? What happens to C+A and C+B? I tested it with MD5 and in all my tests, appending something to the end made the hash the sa...

When is CRC more appropriate to use than MD5/SHA1?

When is it appropriate to use CRC for error detection versus more modern hashing functions such as MD5 or SHA1? Is the former easier to implement on embedded hardware? ...

Hash method and UnicodeEncodeError

In Python 2.5, I have the following hash function: def __hash__(self): return hash(str(self)) It works well for my needs, but now I started to get the following error message. Any idea of what is going on? return hash(str(self)) UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in position 16: ordinal not in range(...

How can I see if a Perl hash already has a certain key?

Hey simple question probably. I have a Perl script that is counting the number of occurrences of various strings in a text file. I want to be able to check if a certain string is not yet a key in the hash. Is there a better way of doing this altogether? Here is what I am doing: foreach $line (@lines){ if(($line =~ m|my regex|) ) ...

Most Efficient Unicode Hash Function for Delphi 2009

I am in need of the fastest hash function possible in Delphi 2009 that will create hashed values from a Unicode string that will distribute fairly randomly into buckets. I originally started with Gabr's HashOf function from GpStringHash: function HashOf(const key: string): cardinal; asm xor edx,edx { result := 0 } and eax,eax ...