Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6138665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:53:41+00:00 2026-05-23T17:53:41+00:00

I need to design object that support some sort of uncertainty (or wild characters,

  • 0

I need to design object that support some sort of uncertainty (or wild characters, if you wish) it its components.
The work is done in Python.

Consider the following class

class C():
    def __init__(self, p1):
        self.p1 = p1

The property p1 can be either “x”, “y”, “z”, but sometimes “x or y”, or any other combination.

It is required that if p1 of c1 is ‘x’ and p1 of c2 is ‘x or y’, then c1 == c2 will return True. This is easily achieved by supplying a proper __eq__ function.
However, these objects need also to be stored in sets, therefore I need to supply a __hash__ function.
How would you calculate hash function for this case, such if c1 == c2 then hash(c1) == hash(c2)?

Option 1: hashing the property

Not good Here’s why

c1 = C('x')
c2  = C('x or y or z')
c1 == c2 #True
hash(c1) == hash(c2)#False
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:53:42+00:00Added an answer on May 23, 2026 at 5:53 pm

    Your equality criterion is not transitive, and therefore invalid:

    C('x') == C('x or y') == C('y')
    

    but

    C('x') != C('y')
    

    Since you can construct an element that equals all others C('x or y or z or a or ...'), the only hash function that fulfills c1 == c2 ⇒ hash(c1) == hash(c2) is a constant one, i.e.

    def __hash__(self):
        return 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to design a data structure that supports the following operations: search element
I need to design a system that will control access to certain information. The
I need to design a page for a web application that makes sense for
I often need to design a dialog in Delphi/C++Builder that allows various properties of
Java design question. I have an object that needs to maintain sets of say
Lets say I have some domain objects that will need to be serialized/packed using
during the design of a component it turned out that I would need a
I have a file reader object that i need to read a file with
I have an object oriented framework that uses a page design, where each page
Why do we need design patterns like Factory, Abstract Factory and Singleton?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.