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 3213864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:59:37+00:00 2026-05-17T14:59:37+00:00

I have to store objects that have two attributes (ida and idb) inside a

  • 0

I have to store objects that have two attributes (ida and idb) inside a dict. Both attributes are 64 bit positive integers and I can only store one object for a unique arrangement(combination in which the order matters) of ida and idb. For example:

obj1 = SomeClass(ida=5223372036854775807, idb=2)
obj2 = SomeClass(ida=2, idb=5223372036854775807)
obj3 = SomeClass(ida=5223372036854775807, idb=2)

Since the objects themselves are mutable, I’m using hashes of tuples ‘(ida, idb,)’ as keys. Following the example, consider this:

d = {}
# storing obj1
k1 = hash((obj1.ida, obj1.idb,))
d[k1] = obj1
# storing obj2
k2 = hash((obj2.ida, obj2.idb,))
d[k2] = obj2
# storing obj3
k3 = hash((obj3.ida, obj3.idb,)) # note that k3 hash should be the same as k1
d[k3] = obj3
#at this point 'd' should contain only 'obj2' and 'obj3' since 'k1' == 'k3'

I tested the above example in my 64 bit machine and it worked as expected.

I have the following questions:

  • Is it possible for two tuples of big integers to compute the same hash if they have differences either in elements or in ordering?
  • What about in 32 bit platforms?
  • If not, is there a platform independent way to guarantee that the above example will work no matter the values of ida and idb?
  • 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-17T14:59:38+00:00Added an answer on May 17, 2026 at 2:59 pm
    In [33]: hash?
    

    Return a hash value for the object. Two objects with the same
    value have the same hash value. The reverse is not necessarily true, but
    likely
    .

    Why not just use the tuple (ida,idb) as the key?

    import pprint
    class SomeClass(object):
        def __init__(self,ida,idb):
            self.ida=ida
            self.idb=idb
    obj1 = SomeClass(ida=5223372036854775807, idb=2)
    obj2 = SomeClass(ida=2, idb=5223372036854775807)
    obj3 = SomeClass(ida=5223372036854775807, idb=2)
    
    d={}
    for obj in (obj1,obj2,obj3):
        d[obj.ida,obj.idb]=obj
    
    pprint.pprint(d)
    # {(2, 5223372036854775807L): <__main__.SomeClass object at 0xb78839ec>,
       (5223372036854775807L, 2): <__main__.SomeClass object at 0xb7883a0c>}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains two arraylists which I'm trying to store objects
I have an object called users that I use to store user objects that
I have been working with NSArray s and NSMutableArray s that store NSDate objects
I have a large amout of objects that all have a filename stored inside.
I have a core data context with objects that have a date stored in
Lets say I have an object that has stringProp1, stringProp2. I wish to store
I have a C program that stores some object in java store using JNI.
I have to be able to store data in a new object, that I
I have to be able to store data in a new object, that I
In my application, I have three collection objects which store data. The data which

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.