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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:18:00+00:00 2026-05-27T23:18:00+00:00

Maybe this has been asked before (where I didn’t find it)… I have a

  • 0

Maybe this has been asked before (where I didn’t find it)…

I have a java.util.Set of aprox. 50000 Strings. I would like to generate some sort of hash to check if it has been changed (comparing hashes of two versions of the Set)?

If the Set changes, the hash has to be different.

How can that be achieved? Thanks!

EDIT:
Sorry for that misleading wording. I don’t want to check if “it” has been changed (the same instance). Instead I want to check if two database queries, which are generating two – maybe identical – instances of a Set of Strings are equal.

  • 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-27T23:18:01+00:00Added an answer on May 27, 2026 at 11:18 pm

    Based on this statement:

    If the Set changes, the hash has to be different

    It really can’t be achieved, unless you have more constraints. In general, a hash is a value in some fixed space. For example, your hash may be a 32 bit integer, so there are 2^32 possible hash values. In general, b bits gets you 2^b possible hash values. In order to achieve what you want, you have to make sure that every possible set (i.e. – the set of all sets!) is less than or equal to 2^b. But my guess is that you can have arbitrary strings so this isn’t possible. And even if it was possible, you’d have to come up with a way to map onto the hash space, which can be challenging.

    However, with a good hash function, it’s not very likely that changing the set will end up producing the same hash value. So you can use the hash to determine inequality, but if the hash is the same, you still need to check for equality. (This is the same idea behind a hash set or a hash map, where elements map to buckets based on a hashcode, but you have to check for equality).

    Similar to what Paul mentioned but different: you can instead make a set implementation that has version numbers and ensure that you always generate a new version number when the set is mutated. Then you can compare the version number? I’m not sure if you care about immutable sets or whether the mutable set changes back to a version you have seen (i.e. – if it should always get the same version).

    Hope this helps.

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

Sidebar

Related Questions

Maybe this has been asked before, but I couldn't find it. My question is
Maybe this question has been asked many times before, but I never found a
I'm sorry if this questions has been asked before, but I couldn't find an
This has been asked before, but I couldn't find a newer result than 2010.
I feel like this one has been asked before, but I'm unable to find
I know that maybe this question has been asked before, but I can't seem
this has been asked before on WP forums, but none of the solutions worked
Sorry if this has been asked before, but as I understand it, in C++11,
I am not sure whether this has been asked before; I did a few
This question has been asked many times before but none of the previous ones

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.