Git Product home page Git Product logo

Comments (4)

pjvandehaar avatar pjvandehaar commented on May 21, 2024 1

object() < object() raises an exception in Python3, but this works and is fast:

class CmpFalse(object): __eq__ = __lt__ = __gt__ = lambda s,o: False
import heapq
h = []
heapq.heappush(h, (0, CmpFalse(), ['x']))
heapq.heappush(h, (0, CmpFalse(), {1:2}))
print(heapq.heappop(h))
print(heapq.heappop(h))

That's likely too simple to warrant adding to boltons.queueutils.

So, http://boltons.readthedocs.io/en/latest/queueutils.html should mention that task must be hashable and then this issue is finished.

from boltons.

ConorHenry avatar ConorHenry commented on May 21, 2024 1

Would float('nan') behave the same as your CmpFalse()?
Given that:

    >>> float('nan')==float('nan')
    False
    >>> float('nan')<float('nan')
    False
    >>> float('nan')>float('nan')
    False

from boltons.

tilboerner avatar tilboerner commented on May 21, 2024

heapq won't work either, because if I store tuples (-priority, item), I can get comparisons between dicts if priorities match.

Just a note: As a workaround, it's possible put something that will always compare to False in between:

(-priority, object(), item)

The overhead should be manageable in many cases; even unpacking a 3-tuple vs. a 2-tuple in a single assignment seems to take almost the same (very short) time.

from boltons.

mahmoud avatar mahmoud commented on May 21, 2024

Docs updated, but I would like to think some more about this. I'm not sure there's a way to update priority without a uniqueness constraint, thus one of the original features would be defeated. That said, it has come up in discussion that someone may need a priority queue for non-unique items, but I haven't had any need over the years :)

I'm definitely fine with adding more simple queues, as long as their use case is clear! :)

from boltons.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.