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

  • Home
  • SEARCH
  • 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 7967637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:57:20+00:00 2026-06-04T06:57:20+00:00

NSObject Protocol Reference says If two objects are equal, they must have the same

  • 0

NSObject Protocol Reference says “If two objects are equal, they must have the same hash value.”

Why must?
What could be the problem with two equal objects not having same hash value?

  • 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-06-04T06:57:20+00:00Added an answer on June 4, 2026 at 6:57 am

    Here is a simplified description of how a hash table works. NSSet is a hash table.

    The basic structure

    Allocate an NSArray of N NSMutableArrays. Let’s call the outer array “table” and the inner arrays “lists”. This structure is our hash table.

    How inserting works

    To insert an object, call ‘hash’ on it. This gives us a number. Truncate the number to be between 0 and (N – 1). Treat that result as an index in table. Go to the mutable array at that slot (list), and see if ‘object’ is already in the list, if not add it. If so, nothing to do.

    How lookup works

    To see if a value is in the hash table, call hash on it. This gives us a number. Truncate the number to be between 0 and (N – 1). Treat that result as an index in table. Go to the mutable array at that slot (list), and see if ‘object’ is already in the list. If it’s there, the table contains the object, otherwise it doesn’t.


    Why do equal objects have to have equal hash values?

    The hash code is used to find which list to search. If two objects are conceptually equal but have different hash values, then when we go to do the look up above in the outer table we won’t find the object in the expected list since our objects will resolve to two different lists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I have these two protocols: @protocol ivAuthorizationProtocol <NSObject> -(void)loginReply:(ivSession*)session; @end @protocol ivServerListsProtocol <NSObject>
I have defined a protocol like this: @protocol RSSItemParserDelegate <NSObject> - (void)RSSItemParser:(RSSItemParser *)parser didEndParsingSuccesfully:(BOOL)success;
On iOS4, if I have a non-public protocol like: @protocol HTTPDelegate <NSObject> @optional -
I have a protocol like this: #import <Foundation/Foundation.h> @protocol Prot1 <NSObject> @required - (void)methodInProtocol;
I am having a protocol in which I have two methods as follows. @protocol
I have been seeing some code around that resembles the following: @protocol MyProtocol <NSObject>
I have a simple protocol with a property: @protocol StopsSource <NSObject> @property (retain,readonly) NSArray
I found that I could do such things in objc: Protocol* aProtocol = @protocol(NSObject);
The NSObject protocol comes with the stock protocol templates, but it doesn't appear to
@protocol Eating @end @interface Eat : NSObject<Eating> { } - (id<Eating> *)me; @end @implementation

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.