[issue18241] Add unique option to heapq functions

2022-03-23 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18241] Add unique option to heapq functions

2022-03-21 Thread Irit Katriel


Irit Katriel  added the comment:

I would dedup when extracting items from the queue, because it is trivial to 
find duplicates then. It can be done with a simple wrapper, without any changes 
to the queue.

--
nosy: +iritkatriel

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18241] Add unique option to heapq functions

2013-06-17 Thread Antoine Pitrou

New submission from Antoine Pitrou:

In one application, I would like to use a heap as an allocation pool. I also 
want to check that a given value isn't released twice, therefore that the heap 
contains unique values. My use case would be solved nicely if heappush() took 
an optional unique=False parameter.

Note that I haven't checked if doing so is possible while maintaining the O(log 
n) complexity :-)

--
messages: 191341
nosy: pitrou, rhettinger
priority: low
severity: normal
status: open
title: Add unique option to heapq functions
type: enhancement
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18241
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18241] Add unique option to heapq functions

2013-06-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

No, it's impossible without additional structure. And with a set it is trivial.

def uniqueheappush(heap, inheap, item):
if id(item) in inheap:
return False
heappush(heap, item)
inheap.add(id(item))
return True

def uniqueheappop(heap, inheap):
item = heappop(heap, inheap)
inheap.discard(id(item))
return item

I recomend reject this issue.

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18241
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18241] Add unique option to heapq functions

2013-06-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 No, it's impossible without additional structure. And with a set it is 
 trivial.

Yeah, I wanted to avoid the memory overhead of a set.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18241
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com