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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:03:28+00:00 2026-06-11T01:03:28+00:00

Hi I’m using a Set backed by a HashMap to keep track of what

  • 0

Hi I’m using a Set backed by a HashMap to keep track of what edges I have already traversed in a graph.
I was planning on keying the set by the result of adding the hashcodes of the data stored in each edge.

v.getData().hashCode() + wordV.getData().hashCode()

But how reliable is this when using contains to check to see if the edge is in the set? Couldn’t I hypothetically get a false positive? Is there anyway to overcome this?

the exact statement that causes me concern is:

edgeSet.contains(v.getData().hashCode() + wordV.getData().hashCode())

thanks!

Oh by the way I’m using Java.

EDIT:

I should have made this clear in the question. In my graph there is no edge object, there are vertex objects which each hold a list of more vertex objects, which is the edge. So I guess the question that follows from that combined with your responses is:

Can I use a Set to store references to information as opposed to objects….?
i.e. can I store the result of adding the two hashcodes for the vertices’ data objects?

EDIT2:

I am indeed using the Java library for my hashmap, I declare it as below:

Set<Integer> edgeSet = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
  • 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-11T01:03:29+00:00Added an answer on June 11, 2026 at 1:03 am

    Note: from your question I couldn’t tell whether you were using HashSet, or your own home rolled implementation. Be aware that Java’s HashSet is simply a wrapper for a HashMap where the values are ignored. HashSet.contains simply calls containsKey on the inner map.

    HashMap.containsKey uses the same lookup as get. That will compute the hash and use it to find the right bucket. From there it will walk the bucket and use equals until it finds the exact match. Assuming the element type implements both hashCode and equals correctly, there’s no chance of getting a false positive using containsKey since equals is ultimately used to confirm.

    The relevant source code is in the package-private method getEntry, which is used by both containsKey and get:

    final Entry<K,V> getEntry(Object key) {
        int hash = (key == null) ? 0 : hash(key.hashCode());
        for (Entry<K,V> e = table[indexFor(hash, table.length)];
             e != null;
             e = e.next) {
            Object k;
            if (e.hash == hash &&
                ((k = e.key) == key || (key != null && key.equals(k))))
                return e;
        }
        return null;
    }
    

    EDIT:

    Can I use a Set to store references to information as opposed to
    objects….? i.e. can I store the result of adding the two hashcodes
    for the vertices’ data objects?

    No, you would need to implement a new class representing this information and store instances of it in the Set. This could be a simple POJO with a field for each piece of information, and with hashCode and equals overridden correctly.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.