Git Product home page Git Product logo

Comments (2)

windelbouwman avatar windelbouwman commented on June 12, 2024

Hi @bifunctor ,

Good point! Never really thought about it, but it might be convenient to make the ir nodes hashable. One reason why they perhaps are not hashable is that they might be modified (in other words, they might not be immutable). For example the python list is mutable, and hence not hashable. A tuple on the other hand is immutable, and hence hashable. The IR nodes shoud probably be immutable, but I know that they are sometimes modified in place, for example in some optimization passes.

So in short: no specific reason, just never thought about it.

from ppci.

obround avatar obround commented on June 12, 2024

tl;dr: Its a good idea to implement __eq__, and (maybe) an okay idea to implement __hash__.

I believe that support should be added for __eq__ and __hash__ (or at very least __eq__). As you said, hashing might be problematic in the case of mutability. A way to get around this would be to hash only some defining attributes. For example, Block's name and function won't be changed (once function is set that is). So Block could be hashed as so:

class Block:
    ...
    def __hash__(self):
        assert self.function, "function should have been set"
        return hash((self.name, self.function))

or if you wish to be able to compare blocks without having added them to functions:

class Block:
    ...
    def __hash__(self):
        return hash(self.name)

and so on.

from ppci.

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.