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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:07:21+00:00 2026-06-10T23:07:21+00:00

I would like to use an integer array as a key of an unordered_map.

  • 0

I would like to use an integer array as a key of an unordered_map. The basic idea is that I have many different states of a problem which are represented as int state[16]. The values of the array are permutations of numbers from 0 to 15, like:

a= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 
b= { 14, 1, 9, 6, 4, 8, 12, 5, 7, 2, 3, 0, 10, 11, 13, 15}; ...

and those will be the key in the unordered_map (the value will be a class with other stuff). How can I do that? Do I need to implement a new hash function to compare the values or I can use some provided by C++?
My goal is using this as a hash-table, is there any other better alternative?

  • 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-10T23:07:22+00:00Added an answer on June 10, 2026 at 11:07 pm

    16! is approximately 2*10^13, so you can store the ordinal of the permutation in a 64-bit integer and use that as a map key, without needing to store or hash the permutation.

    See http://en.wikipedia.org/wiki/Permutation#Numbering_permutations for the natural bijection between permutations of 0 … N-1 and the numbers 0 … N! – 1.

    Alternatively, you could just use a std::map; permutations will be efficient to compare lexicographically.

    A third alternative would be to use a std::string as the key, since your values easily fit within a char; std::hash is specialized for std::string.

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

Sidebar

Related Questions

I have an array of Integers in Java, I would like use only a
I have an array that contains several arrays and I would like to order
Lets say you have various objects of arbitrary type that you would like to
I have a library which expects a array and fills it. I would like
I have an array of 32766 values, which I would like to upsample to
I'd like to convert an array of integer values I have received over USB
I have a Fortran derived type T that contains data arrays of (many) different
I would like to convert an integer array in java, to an Inputstream, after
I would like to have an array model objects to be serialized to a
I have an application that does some long calculations, and I would like to

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.