Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16695

Re: order independent hash?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.031
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'python,': 0.01; 'behave': 0.07; 'python': 0.08; 'url:pypi': 0.08; 'to:addr:comp.lang.python': 0.09; 'accesses': 0.16; 'computation': 0.16; 'integers.': 0.16; 'subject:independent': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; 'computing': 0.18; 'yet.': 0.18; 'cc:no real name:2**0': 0.20; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'table.': 0.23; 'tree': 0.25; 'cc:addr:gmail.com': 0.28; 'needed,': 0.28; 'sound': 0.28; 'message-id:@mail.gmail.com': 0.28; 'elements': 0.29; 'mapping': 0.29; 'cc:addr:python.org': 0.29; 'hash': 0.30; 'received:mail- bw0-f46.google.com': 0.30; 'least': 0.30; 'subject:?': 0.31; "i'll": 0.31; 'go.': 0.32; 'pure': 0.32; 'list': 0.32; 'received:209.85.214': 0.32; "isn't": 0.33; 'sort': 0.33; "won't": 0.33; 'agree': 0.33; 'too': 0.34; 'things': 0.34; 'operations': 0.35; 'url:python': 0.36; 'cc:2**1': 0.36; 'members': 0.37; 'two': 0.37; 'but': 0.37; 'list,': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'could': 0.37; 'doing': 0.38; 'bunch': 0.38; 'monday,': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'url:org': 0.39; 'should': 0.39; "it's": 0.40; 'received:209': 0.40; 'might': 0.40; 'once': 0.60; 'range': 0.61; 'more': 0.61; '2011': 0.61; 'your': 0.61; 'life': 0.64; 'url:0': 0.67; 'methods:': 0.67; 'often,': 0.84; 'ordered.': 0.84; 'scatter': 0.84; 'fast,': 0.91; 'sum.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=7zMAm+ikL0Ndd7zziZ61wYBlfiyjVBZPJEEYegnyqTI=; b=Ad6hxyXoc7NTAHii4mxzp7C5T0Aui6dTD84ArB6i3EJ03wQUg7vuPr62Sron1kd1F5 3NpK0nF10Ss7YkMNGdJgbJuIGZqP3CecqV+uOmFQsTJxdXI5SNqLDngVkT7xYtHxqbly KlJi1MgahcWM1MoqHtVB8BGXRbu2zovk87yP0=
MIME-Version 1.0
In-Reply-To <952995.674.1323086974877.JavaMail.geo-discussion-forums@preu18>
References <jb57p7$b1j$1@dough.gmane.org> <mailman.3287.1323064211.27778.python-list@python.org> <952995.674.1323086974877.JavaMail.geo-discussion-forums@preu18>
Date Mon, 5 Dec 2011 15:05:26 -0800
Subject Re: order independent hash?
From Dan Stromberg <drsalists@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc Neal Becker <ndbecker2@gmail.com>, python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3327.1323126329.27778.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323126329 news.xs4all.nl 6871 [2001:888:2000:d::a6]:47556
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16695

Show key headers only | View raw


On 12/5/11, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> On Monday, December 5, 2011 1:50:08 PM UTC+8, Dan Stromberg wrote:
>> Two methods:
>> 1) If you need your hash only once in an infrequent while, then save
>> the elements in a list, appending as needed, and sort prior to
>> hashing, as needed
>>
>> 2) If you need your hash more often, you could keep your elements in a
>> treap or red-black tree; these will maintain sortedness throughout the
>> life of the datastructure.
>>
>> 3) If A bunch of log(n) or n or nlog(n) operations doesn't sound
>> appealing, then you might try this one: Create some sort of mapping
>> from your elements to the integers.  Then just use a sum.  This won't
>> scatter things nearly as well as a cryptographic hash, but it's very
>> fast, because you don't need to reevaluate some of your members as you
>> go.
>>
>> HTH
>>
> A sorted list can behave like a hash table.  This is of O(log(n)) in
> accesses
> of n items in theory.
>
> I agree with you a hash key computation method too slow than a list of n
> items  in accesses for a range of n items  should be reloadable.
>
> But this is not supported in Python yet.
>
> For tedious trivial jobs of non-heavy computing , I'll opt for easy use.

A sorted list is O(log(n)) for lookups, but O(n) for insertions.  If
you have a process doing both, the table operations are O(n).

A hash table that isn't overfilled is O(1) for lookups, O(1) for
insertions.  But this is not ordered.

Here's a straightforward treap implementation for python, with pure
python and cython versions:
http://pypi.python.org/pypi/treap/0.995

There's also at least one red-black tree implementation available.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: order independent hash? Dan Stromberg <drsalists@gmail.com> - 2011-12-04 21:50 -0800
  Re: order independent hash? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-05 04:09 -0800
  Re: order independent hash? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-05 04:09 -0800
    Re: order independent hash? Dan Stromberg <drsalists@gmail.com> - 2011-12-05 15:05 -0800

csiph-web