[PATCH 2 of 6] Provide a version independent way to use the set datatype
Eric Hopper
hopper at omnifarious.org
Tue Jun 12 17:03:42 UTC 2007
On 6/10/07, Matt Mackall <mpm at selenic.com> wrote:
>
> On Thu, Jun 07, 2007 at 03:58:08PM -0700, Eric Hopper wrote:
> > # HG changeset patch
> > # User Eric Hopper <hopper at omnifarious.org>
> > # Date 1181256552 25200
> > # Node ID d8f52bfc3b38809aff35efb8a34a6347ba228af7
> > # Parent 04f49562a1eb805adfa78349c64561a539538e6f
> > Provide a version independent way to use the set datatype.
> >
> > diff --git a/mercurial/util.py b/mercurial/util.py
> > --- a/mercurial/util.py
> > +++ b/mercurial/util.py
> > @@ -15,6 +15,13 @@ from i18n import _
> > from i18n import _
> > import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile
> > import os, threading, time, calendar, ConfigParser, locale, glob
> > +
> > +try:
> > + hgset = set
> > + hgfrozenset = frozenset
> > +except NameError, e:
> > + from sets import Set as hgset
> > + from sets import ImmutableSet as hgfrozenset
>
> Why do we want this?
>
> On my box:
> Python 2.4 Python 2.5
> set dict set dict
> add 10000 elements to a set: 3.8ms 2.7ms 3.5ms 2.8ms
> find 10000 members in a set: 3.5ms 3.4ms 3.3ms 3.4ms
> total: 7.3ms 6.1ms 6.8ms 6.2ms
I've though about this. The difference here isn't huge. And I really find
the set based code easier to read and understand. I think, for example,
that I could shave a few lines out of my nodesbetween algorithm and make it
clearer by using sets. It might be a fraction slower, but I bet that will
change in future versions of Python.
There is a lot of code that uses dict.fromkeys, and much of it doesn't use
the dictionary values for anything. But some of it does. And it's kind of
a pain to figure out which code is which. Using a set makes this
distinction much clearer.
--
Eric Hopper -- http://www.omnifarious.org/~hopper/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20070612/79919d90/attachment.html>
More information about the Mercurial-devel
mailing list