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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:22:21+00:00 2026-05-29T18:22:21+00:00

template<class KEY, class VALUE> unsigned int HashMap<KEY, VALUE>::hashCode(KEY key) { unsigned int k =

  • 0
template<class KEY, class VALUE>
unsigned int HashMap<KEY, VALUE>::hashCode(KEY key)
{
    unsigned int k = key & 0xffffffff; //error: no match for ‘operator&’ in ‘key & 4294967295u’
    k += ~(k<<9);
    k ^= (k>>14);
    k += (k<<4);
    k ^= (k>>10);
    return k;
};

As you see, I’m trying to implement the hashCode by manipulating bits in the object. Obviously, bit operators don’t easily apply to user-defined objects.

I want to take some bits of an object of any type, given its memory location, and manipulate the bits as I wish. Then I’ll reinterpret the bits as int and apply bitwise operators to the int.

Does that sound like a good idea? And How can I take bits from objects of ANY TYPE at a given memory location?

Thanks a lot!

  • 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-29T18:22:26+00:00Added an answer on May 29, 2026 at 6:22 pm

    No, it’s a terrible idea, because it doesn’t respect the type’s definition of equality. A type might be defined so that several different representations can be considered equal (think of a std::string, which contains a couple of pointers, and nothing else. Two strings might be equal (both contain "hello world", but have different pointers because they point to different blocks of memory, and so your hash key implementation would return different hash key for two equal objects.

    In other words, you’d break the hash table, and users would be unable to find the objects they put in the table.

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

Sidebar

Related Questions

I have a template class like below. template<int S> class A { private: char
I have the following models: # Group for Key/Value pairs class Group(models.Model): name =
Is there any problem with this code? bool Spellcheck::smart_comp(string value, string key){ return true;
I'm writing a simple hash map class: template <class K, class V> class HashMap;
I have a Map whose key and value and custom classes. The key class
I have a template class that I serialize (call it C), for which I
I have a C++ template class that gets instantiated with 3 different type parameters.
I am extending a template class using C++ in Visual Studio 2005. It is
Consider a template class like: template<typename ReturnType, ReturnType Fn()> class Proxy { void run()
I have got a template class as follows: class MyClass<T> { T field; public

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.