order independent hash?

Lie Ryan lie.1296 at gmail.com
Sun Dec 4 08:40:20 EST 2011


On 12/02/2011 04:48 PM, 88888 Dihedral wrote:
> On Friday, December 2, 2011 1:00:10 PM UTC+8, Chris Angelico wrote:
>> On Fri, Dec 2, 2011 at 3:29 PM, 88888 Dihedral
>> <dihedr... at googlemail.com>  wrote:
>>> I clear my point a hash is a collection of (key, value) pairs that have
>>> well defined methods and behavior to be used in programming.
>>>
>>> The basic operations of a hash normally includes the following:
>>>
>>> 1. insertion of a (key, value) pair  into the hash
>>> 2. deletion of a (key, value) from the hash
>>> 3. inquiring  a hash by a key to retrieve the value if the (key, value)
>>> pair available in the hash. If no key matched, the hash will return
>>> a not found result.
>>>
>>> The hash can grow with (k,v) pairs accumulated in the run time.
>>> An auto memory management mechanism is required for a hash of a non-fixed size of (k,v) pairs.
>>
>> That's a hash table - think of a Python dictionary:
>>
>> On Fri, Dec 2, 2011 at 3:33 PM, Steven D'Aprano
>> <steve+comp.... at pearwood.info>  wrote:
>>> Python dicts are hash tables.
>>
>> Although strictly speaking, isn't that "Python dicts are implemented
>> as hash tables in CPython"? Or is the hashtable implementation
>> mandated? Anyway, near enough.
>>
>
>
>> Cryptography and data verification use hashing too (look at the
>> various historic hashing algorithms - CRC, MD5, SHA, etc). The concept
>> of a hash is a number (usually of a fixed size) that is calculated
>> from a string or other large data type, such that hashing the same
>> input will always give the same output, but hashing different input
>> will usually give different output. It's then possible to identify a
>> large object solely by its hash, as is done in git, for instance; or
>> to transmit both the data and the hash, as is done in message
>> protection schemes (many archiving programs/formats include a hash of
>> the uncompressed data). These have nothing to do with (key,value)
>> pairs, but are important uses of hashes.
>>
>> ChrisA
>
> If one tries to insert a (k,v1) and then a (k,v2) pair into a
> hash with v1 not equals V2, what could happen in your understanding of
> a hash?

Don't try to argue, in English, `hash != hash` is true; it's just a 
typical occurence of homonyms. Just because they have the same name 
doesn't mean hash (function) has to have somewhat similar properties to 
hash (table).

> A hash function is different from a hash or so called a hash table in
> my post.

Indeed.

> If the hash collision rate is not specified, then  it is  trivial to write a hash function with the conditions you specified. A hash function applied to a set of data items only  is of very limited use at all.

It's trivial indeed, but a hashtable couldn't exist without hash 
function. And without a good hash function, a hash table's performance 
may degrade into O(n) access/insertion/deletion.

> A hash stores (k,v) pairs specified in the run time with auto memory
> management build in is not a simple hash function to produce data signatures only clearly in my post.
>
> What I said a hash which is lifted as a basic type in python  is called a dictionary in python.
>
> It is called a map in c++'s generics library.

Putting aside all these, it's pretty obvious from the beginning that OP 
was referring to hash functions, not hash tables.




More information about the Python-list mailing list