Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: srinivas devaki Newsgroups: comp.lang.python Subject: Re: How to remove item from heap efficiently? Date: Fri, 8 Jan 2016 18:51:36 +0530 Lines: 29 Message-ID: References: <568EEC40.7070807@mail.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de IsN+CBYGwjc7bIFrFKgNdwWcq8loOWnm8zTEovD2km2Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'everybody,': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; 'timestamp': 0.09; 'tuple': 0.09; 'underlying': 0.09; 'jan': 0.11; '(say': 0.16; '2016': 0.16; 'heap': 0.16; 'i.e': 0.16; 'popping': 0.16; 'priority).': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:item': 0.16; 'subject:remove': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cc:no real name:2**0': 0.22; 'am,': 0.23; 'elements': 0.23; 'insert': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; 'url:mailman': 0.30; 'creating': 0.30; 'primary': 0.31; 'url:python': 0.33; 'url:listinfo': 0.34; 'received:google.com': 0.35; 'best,': 0.35; 'item': 0.35; 'problem.': 0.35; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209': 0.38; 'subject:from': 0.39; 'url:mail': 0.40; 'where': 0.40; 'oldest': 0.66; 'mention.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Iq4sSWruW32P29SfRPGKcAM5mBilxDnU8amxN9MOkXM=; b=BBky8p69CArTPu/1q8yavrOt1T3yQxeNyzSGpgZF4N6DxXu8zagNf473zNA/kPEs7p 81MEO853vg5/sMxzdQsDQ/dBsmP72i7/QvnDravvGeGDp6B3R4RO4/3xTXO2xnaoe/2+ fxvRvx2ELPCh5F888CiYokIRJiieQDMU53p41kk2fPid+jotqRtsA2sKW6sXujLMYa+V zMjm5N9+ch+/YDiSkpAvyznkBTbttsfidaf0v1epvd6NAataMe9H8laplFeOd+1pmYcU 6FmCmT7o2TYc7SitKdRpAESqi9B06ppxijbZMYzBVQ0gBoSzI/9C3oVyTU2FGtAPrD0m T79w== X-Received: by 10.107.41.206 with SMTP id p197mr94778818iop.80.1452259335869; Fri, 08 Jan 2016 05:22:15 -0800 (PST) In-Reply-To: <568EEC40.7070807@mail.de> 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:101374 You can create a single heap with primary key as timestamp and secondary key as priority, i.e by creating a tuple insert the elements into the heap as (timestamp, priority) If there is any underlying meaning for creating 2 heaps. please mention. On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze wrote: > Hi everybody, > > suppose, I need items sorted by two criteria (say timestamp and priority). > For that purpose, I use two heaps (heapq module): > > heapA # items sorted by timestamp > heapB # items sorted by priority > > Now my actual problem. When popping an item of heapA (that's the oldest > item), I need to remove the very same item from heapB, regardlessly where it > is in heapB. And vice versa. > > Is there a datastructure or a simple trick to achieve that in an efficient > matter? > > Best, > Sven > -- > https://mail.python.org/mailman/listinfo/python-list