hash

What's the best hashing algorithm to use on a stl string when using hash_map?

I've found the standard hashing function on VS2005 is painfully slow when trying to achieve high performance look ups. What are some good examples of fast and efficient hashing algorithms that should void most collisions? ...

How does c# figure out the hash code for an object?

This question comes out of the discussion on tuples. I started thinking about the hash code that a tuple should have. What if we will accept KeyValuePair class as a tuple? It doesn't override the GetHashCode() method, so probably it won't be aware of the hash codes of it's "children"... So, run-time will call Object.GetHashCode(), whic...

Why is '397' used for ReSharper GetHashCode override?

Like many of you, I use ReSharper to speed up the development process. When you use it to override the equality members of a class, the code-gen it produces for GetHashCode() looks like: public override int GetHashCode() { unchecked { int result = (Key != null ? Key.GetHashCode() : 0); res...

Best way to prevent duplicate use of credit cards

We have a system where we want to prevent the same credit card number being registered for two different accounts. As we don't store the credit card number internally - just the last four digits and expiration date - we cannot simply compare credit card numbers and expiration dates. Our current idea is to store a hash (SHA-1) in our sys...

What is a javascript hash table implementation that avoids object namespace collisions?

First off: I'm using a rather obscure implementation of javascript embedded as a scripting engine for Adobe InDesign CS3. This implementation sometimes diverges from "standard" javascript, hence my problem. I'm using John Resig's jsdiff library (source here) to compare selections of text between two documents. jsdiff uses vanilla object...

sorting hashes/arrays in awk

Is there an easy way to do any of the following things in awk? Sorting array/hash by it's data Sorting a hash by it's string key ...

How to find the amount of physical memory occupied by a hash in Perl?

I have a Perl script where I maintain a very simple cache using a hash table. I would like to clear the hash once it occupies more than n bytes, to avoid Perl (32-bit) running out of memory and crashing. I can do a check on the number of keys-value pairs: if (scalar keys %cache > $maxSize) { %cache = (); } But is it possible to c...

Hash Code implementation

How do we decide on the best implementation of hashcode method for a collection?(assuming that equals method has been overridden correctly) ...

What is a performant string hashing function that results in a 32 bit integer with low collision rates?

I have lots of unrelated named things that I'd like to do quick searches against. An "aardvark" is always an "aardvark" everywhere, so hashing the string and reusing the integer would work well to speed up comparisons. The entire set of names is unknown (and changes over time). What is a fast string hashing algorithm that will generate s...

Is a Python dictionary an example of a hashmap?

One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hashmap? If not, what is it? ...

Hash-algorithm

I am looking for a hash-algorithm, to create as close to a unique hash of a string (max len = 255) as possible, that produces a long integer (DWORD). I realize that 26^255 >> 2^32, but also know that the number of words in the English language is far less than 2^32. The strings I need to 'hash' would be mostly single words or some simp...

How to compute the hashCode() from the object's address?

In Java, I have a subclass Vertex of the Java3D class Point3f. Now Point3f computes equals() based on the values of its coordinates, but for my Vertex class I want to be stricter: two vertices are only equal if they are the same object. So far, so good: class Vertex extends Point3f { // ... public boolean equals(Object other) ...

Is the Hash of a GUID unique?

I create a GUID (as a string) and get the Hash of it. Can I consider this Hash to be unique? ...

Why do you need $ when accessing array and hash elements in Perl?

Since arrays and hashes can only contain scalars in Perl, why do you have to use the $ to tell the interpreter that the value is a scalar when accessing array or hash elements? In other words, assuming you have an array @myarray and a hash %myhash, why do you need to do: $x = $myarray[1]; $y = $myhash{'foo'}; instead of just doing : ...

What's the difference between SHA and MD5 (in PHP)?

When you're hashing a password (or anything else) in PHP, does it make any difference if you use SHA or MD5? ...

hashing sensitive data

Hi I need to scramble the names and logins of all the users in a UAT database we have. (because of the data protection act) However, there is a catch. The testers still need to be able to login using the hashed login names so if a user login is "Jesse.J.James" then the hash should be something like Ypois.X.Qasdf i.e. approximately ...

How to decrypt a password from SQL server?

I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted string of 'AAAA': 0x0100CF465B7B12625EF019E157120D58DD46569AC7BF4118455D12625EF019E157120D58DD46569AC7BF4118455D How can I convert (decrypt) the output from its origin (which is 'AAAA')? ...

Hash of a string to be of specific length

Is there a way to generate a hash of a string so that the hash itself would be of specific length? I've got a function that generates 41-byte hashes (SHA-1), but I need it to be 33-bytes max (because of certain hardware limitations). If I truncate the 41-byte hash to 33, I'd probably (certainly!) lost the uniqueness. Or actually I suppo...

How do I get the unique elements from an array of hashes in Ruby?

I have an array of hashes, and I want the unique values out of it. Calling Array.uniq doesn't give me what I expect. a = [{:a => 1},{:a => 2}, {:a => 1}] a.uniq # => [{:a => 1}, {:a => 2}, {:a => 1}] Where I expected: [{:a => 1}, {:a => 2}] In searching around on the net, I didn't come up with a solution that I was happy with. Fo...

What is the difference between Obfuscation, Hashing, and Encryption?

What is the difference between Obfuscation, Hashing, and Encryption? Here is my understanding: Hashing is a one-way algorithm; cannot be reversed Obfuscation is similar to encryption but doesn't require any "secret" to understand (ROT13 is one example) Encryption is reversible but a "secret" is required to do so ...