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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:59:46+00:00 2026-05-17T02:59:46+00:00

I am wondering if there is a way to generate a key based on

  • 0

I am wondering if there is a way to generate a key based on the relationship between two entities in a way that the key for relationship a->b is the same as the key for relationship b->a.

Desirably this would be a hash function which takes either relationship member but generates the same output regardless of the order the members are presented in.

Obviously you could do this with numbers (e.g. add(2,3) is equivalent to add(3,2)). The problem for me is that I do not want add(1,4) to equal add(2,3). Obviously any hash function has overlap but I mean a weak sense of uniqueness.

My naive (and performance undesirable) thought is:

function orderIndifferentHash(string val1, string val2)
{
  return stringMerge(hash(val1), hash(val2));
  /* String merge will 'add' each character (with wrapping).
     The pre-hash is to lengthen strings to at least 32 characters */
}
  • 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-17T02:59:47+00:00Added an answer on May 17, 2026 at 2:59 am

    You you are after:

    Some function f(x, y) such that

    • f(x, y) == f(y, x)
    • f(x, y) != f(a, b) => (x == a and y == b) or (x == b and y == a)

    There are going to be absolutely loads of these – off hand the one I can think of is “sorted concatenation”:

    1. Sort (x, y) by any ordering
    2. Apply a hash function u(a) to x and y individually (where u(a) == u(b) implies a == b, and the length of u(a) is constant)
    3. Concatenate u(x) and u(y).

    In this case:

    If x == y then then the two hashes are trivially the same, so without loss of generality x < y, hence:

    • f(y, x) = u(x) + u(y) = f(x, y)

    Also, if f(x, y) == f(a, b), this means that either:

    • u(x) == u(a) and u(y) == u(b) => x == a and y == b, or
    • u(y) == u(a) and u(x) == u(b) => y == a and x == b

    Short version:

    Sort x and y, and then apply any hash function where the resulting hash length is constant.

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

Sidebar

Related Questions

Wondering if there is a good way to generate temporary URLs that expire in
I was wondering if is there an easy way to generate views from form
I was wondering is there a way in PHP that you could tell where
Wondering if there is any way to get the lambda expressions that result from
I am wondering if it is possible to generate a key that is valid
I'm wondering if there is a way to generate scaffolding against a specific database.
Is there a way to generate a scaffold for Rails models that have either
I am wondering is there a way to render a partial view in the
I am wondering is there any way we can test the font size/color of
I am wondering is there any way to execute following shell script, which waits

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.