Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Sven R. Kunze" Newsgroups: comp.lang.python Subject: Re: How to remove item from heap efficiently? Date: Sun, 10 Jan 2016 19:50:18 +0100 Lines: 14 Message-ID: References: <568EEC40.7070807@mail.de> <87lh7ywqm7.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de aFzUXP7noDoH/JSUn3PhiAbHR/2BIWa5HdBD2VtvLaHg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:How': 0.09; 'dict': 0.09; 'indexes': 0.09; 'item,': 0.09; 'thrown': 0.09; 'received:io': 0.16; 'received:psf.io': 0.16; 'sorting': 0.16; 'subject:item': 0.16; 'subject:remove': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'tree': 0.18; 'suggested': 0.20; 'keys': 0.22; 'header:In-Reply-To:1': 0.24; 'paul': 0.24; 'header:User-Agent:1': 0.26; 'separate': 0.27; 'query': 0.30; 'task': 0.30; 'table': 0.32; 'items.': 0.33; 'received:10.0': 0.34; 'best,': 0.35; 'tasks': 0.35; 'too': 0.36; 'structures': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'received:de': 0.40; 'real': 0.62; 'charset:windows-1252': 0.62; 'different': 0.63; 'balanced': 0.84; 'dict.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mail201212; t=1452451819; bh=eqWq43CqZ2BunfQED1ITQXTSdgN4s7ukGWu27NGXAds=; h=Subject:To:References:From:Date:In-Reply-To:From; b=cEFD19O6ANFDDRAkzoqyAtOfiPKWmwfkn8UkI1jE77/41umIQgfN3NxSIvZDAeM4N UhHCgUaVwcP2Ex5i6E+gaoMTQwGLvZ/tBBc24ZBPGz5ipWf0LUzYNg8He8FauORci4 bummir7rbJBcRh2vu6UUQ15jW4UQ5pBZ7EZRAAS0= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: <87lh7ywqm7.fsf@nightsong.com> X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 591 X-purgate-ID: 154282::1452451819-000009F3-CE11669C/0/0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101446 On 09.01.2016 19:32, Paul Rubin wrote: > "Sven R. Kunze" writes: >> Basically a task scheduler where tasks can be thrown away once they >> are too long in the queue. > I don't think there's a real nice way to do this with heapq. The > computer-sciencey way would involve separate balanced tree structures > for the two sorting keys (think of a database table with indexes on two > different columns). Others suggested using an additional dict where to store the indexes of the items. Then, when removing an item, I just need to query the dict. Best, Sven