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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:07:52+00:00 2026-06-11T02:07:52+00:00

I’ve got a simple list of objects. I would like to compute a kind

  • 0

I’ve got a simple list of objects. I would like to compute a kind of hash value for each object, used to sort the list.

My question is : Who is responsible for computing the hash ?

1/ The list

Because the hash method is specific to the list, and applied to each object.
Objects are just objects, they don’t know about sorting and hashing.

2/ Each object

Because the object is the best candidate as he have all the data to do it.
And this may be computed on internal data not accessible to others.

3/ Another challenger ? Like a controller between the list and the objects ?

  • 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-11T02:07:53+00:00Added an answer on June 11, 2026 at 2:07 am

    The class that defines the concept of equivalence used.

    If an object defines a general purpose concept of equality, then it should define a hashcode that corresponds with that, as part of that job.

    After all, it is that class that “knows” how the Equals(), isEqual(), areEqual, == or whatever is defined. It is necessary that when a == b that hash(a) == hash(b), so it is the only class that can do so.

    However, if another class defines a concept of equality, (perhaps to use a different one for different ways, in which the different ways one might consider strings equal or not is a classic example) then that class must define the hashcode for similar reasons.

    .NET expresses this linking of responsibility, as an example. In .NET all objects have a Equals(). Whether that’s a good thing or not is debatable (some would prefer the C++ approach where an object need not have any sense of being equal to another), but once done it does make sense that all objects also have a GetHashCode(), because of the link between one and the other. .NET also though has IEqualityComparer<T> and IEqualityComparer which defines a means for a class to have responsibility for a particular non-built-in sense of equality. Here again, to take responsibility for one requires taking responsibility for the other.

    Now. Which is better?

    Well, if there is an overwhelmingly obvious sense of what “equals” means in a given case, it should probably be handled by the class: Two representations of the same co-ordinate or the same complex number or which refer to the same real-world object, should probably be considered equal most of the time. So that gives a default use.

    If there’s an overwhelmingly obvious sense of what equals should mean in the context of a given container type, then that should be applied there.

    Otherwise there should be a connector that defines it. We can hence separate the concerns nicely.

    However we can tie the three together quite neatly. We define a default connector. It’s implementation merely passes the call to get a hashcode or test for equality to that defined on the object.

    We define any general-purpose hash-tables, hash-sets etc. to always make use of connectors, with defaults upon construction or default template parameters (if the language has the sort of generic/templates approach that allows this, which C++ for example does and C# for example does not), so that by default we are using this default connector.

    When defining special-purpose collection types which depend upon a particular view of concept for their very purpose, we build it from one of those collections, overriding the connector.

    The flip-side of this rule, is that if you don’t have a defined means for all equatable objects to give a hashcode (e.g you have an == override mechanism, but not deep support for a GetHashCode()), then you have to use the connector approach. Note that while C++ for example does have ==, it doesn’t have that sort of support for knowing how to has a given object. Hence the STL having to have a hash_map and there being only very limited support for out-of-the-box defaults for it.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
i got an object with contents of html markup in it, for example: string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

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.