Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50389
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'pop': 0.05; 'element': 0.07; 'indexing': 0.07; 'smallest': 0.07; 'replied': 0.09; 'subject:number': 0.09; 'cc:addr:python-list': 0.11; 'anyway': 0.14; 'dictionary,': 0.16; 'element.': 0.16; 'heap': 0.16; 'heapq': 0.16; 'inserting': 0.16; 'iterating': 0.16; 'likewise': 0.16; 'subject:Prime': 0.16; 'subject:generator': 0.16; 'swaps': 0.16; 'pushed': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'dependent': 0.19; 'cc:addr:python.org': 0.22; 'fine': 0.24; 'cc:2**0': 0.24; 'performing': 0.26; 'push': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; 'getting': 0.31; '>>>>': 0.31; "i'd": 0.34; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'module.': 0.36; 'too': 0.37; 'list': 0.37; 'implement': 0.38; 'minimum': 0.38; 'saves': 0.38; 'ian': 0.60; 'removing': 0.60; 'new': 0.61; 'matter': 0.61; 'real': 0.63; 'july': 0.63; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'jul': 0.74; 'actually,': 0.84; 'hood': 0.84; 'working,': 0.84; 'imagine': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=EtSXHW27bosKECKVAIpNRo15QtTwUpBJtQMWNiV8OqA=; b=TzonEqwd1mDDMm+k0SI4nyYdYYVGsoiNyPdo9C0dDEBENsfiK9OW6Qsbw+6kozc2X0 9uICkV03cIaJWxrRGcy4AbIC+zkcLEVFRN1Hy4UuPv2iGtEYmtlOVP2cqt9lcZ1R3q+B 1PBj5H4NBBwCcrKDytbviZ1OC+Pc4/icjtXDr7Zdls1RoCN/EYUpdfAKE/fv9OuasCzS ZKLNAIu9vj+Fcqppa9uTtsL/9IJUaKo86/j+QxTqRjiwy7VqTBLp/Dx3pW33PjetiYyQ fDp/JHQ93u5Lq78q4Y8DEBzXkU2vIpmPoQ/+ZWviZYy4Q0CzK1iC5PP5o5czBKLLKOjS 38kg== |
| X-Received | by 10.112.42.44 with SMTP id k12mr15643911lbl.63.1373483245129; Wed, 10 Jul 2013 12:07:25 -0700 (PDT) |
| MIME-Version | 1.0 |
| Sender | joshua.landau.ws@gmail.com |
| In-Reply-To | <CALwzidn_pHhvNCX9xgbiH-j=YYiimCZkN=H0Zd432=o3R=3xJg@mail.gmail.com> |
| References | <mailman.4522.1373464867.3114.python-list@python.org> <15167633-b6e7-46cc-a043-8dfe8aaad11e@googlegroups.com> <mailman.4525.1373469147.3114.python-list@python.org> <ff09d214-1962-4500-a2a3-483872ce2cb9@googlegroups.com> <CAPTjJmqY6_gaGqvRSYzccWU1EjHPFxYkWWXHhPcwE+iZoDW2zg@mail.gmail.com> <CAN1F8qXajvvpUjFnMNRzQiBbvrPUz4b9QXck1RRNhWJYxkQDhw@mail.gmail.com> <CALwzidn_pHhvNCX9xgbiH-j=YYiimCZkN=H0Zd432=o3R=3xJg@mail.gmail.com> |
| From | Joshua Landau <joshua@landau.ws> |
| Date | Wed, 10 Jul 2013 20:06:44 +0100 |
| X-Google-Sender-Auth | i5yRtz2bNO9Gq2fr-MmOLZhI_Z0 |
| Subject | Re: Prime number generator |
| To | Ian Kelly <ian.g.kelly@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | Python <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.4546.1373483247.3114.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1373483247 news.xs4all.nl 15886 [2001:888:2000:d::a6]:37871 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50389 |
Show key headers only | View raw
On 10 July 2013 19:56, Ian Kelly <ian.g.kelly@gmail.com> wrote: > On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau <joshua@landau.ws> wrote: >>>> If you care about speed, you might want to check the heapq module. Removing the smallest item and inserting a new item in a heap both cost O(log(N)) time, while finding the minimum in a dictionary requires iterating over the whole dictionary, which cost O(N) time. >> >> Actually, because it's a list under the hood I'd imagine push and pop >> still take O(n) time :/. > > It shouldn't. You can implement push by appending the new item and > then getting it into the right place by performing O(log n) swaps. > Likewise for pop, you can update the heap with O(log n) swaps and then > removing the tail element. Appending or removing the tail element of > a list is amortized O(1). Genius. Bas replied off-list that it won't matter too much anyway as they're over-allocated, but this makes tons of sense. >> PS: It's faster to use heapreplace(...) than >> heappop(...);heappush(...) but it only saves a few %. > > The problem with heapreplace here is that the value to be pushed > is dependent on the value returned by pop. That's fine because indexing is much faster than pop. The "few %" was a real statistic from working, timed code.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Prime number generator Chris Angelico <rosuav@gmail.com> - 2013-07-11 00:00 +1000
Re: Prime number generator Bas <wegwerp@gmail.com> - 2013-07-10 07:35 -0700
Re: Prime number generator Chris Angelico <rosuav@gmail.com> - 2013-07-11 01:12 +1000
Re: Prime number generator bas <blswinkels@gmail.com> - 2013-07-10 08:47 -0700
Re: Prime number generator Chris Angelico <rosuav@gmail.com> - 2013-07-11 02:15 +1000
Re: Prime number generator Joshua Landau <joshua@landau.ws> - 2013-07-10 18:47 +0100
Re: Prime number generator Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-10 12:56 -0600
Re: Prime number generator Joshua Landau <joshua@landau.ws> - 2013-07-10 20:06 +0100
Re: Prime number generator bryanjugglercryptographer@yahoo.com - 2013-07-30 21:57 -0700
Re: Prime number generator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-10 16:01 +0000
Re: Prime number generator Chris Angelico <rosuav@gmail.com> - 2013-07-11 02:52 +1000
Re: Prime number generator albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-30 10:58 +0000
Re: Prime number generator Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-30 11:33 -0600
csiph-web