Good hash function for unordered set of string?

Viewed 94

Is there a method for multiple unordered string sets, in which the string elements are the same. for example:

set1 = [ "ab3567cd", "123", "789012" ]

set2 = [ "789012", "ab3567cd", "123" ]

set3 = [ "123", "789012", "ab3567cd" ]

And hash these sets return the same result without sorting them.

Is there such a hash function?

1 Answers

Without sorting them to have the same position you will get always different hashes.

This are always different strings:

ab3567cd 123 789012

789012 ab3567cd 123

123 ab3567cd 789012

Do identical strings always have the same SHA-256 value?

What is a Hashing Algorithm and How Does it Work?

How does file hashing works?

UPDATE:

There are two solutions, but i don't now if this is the right way.

This is only an logical example, it maybe not the right function/count way!

  1. Solution

If i count the values of the set, with the right function.

set1 = [ "ab3567cd", "123", "789012" ]

count:

 "ab3567cd" (+ or *) "123" (+ or *) "789012" = RESULT_VALUE

Than you hash the RESULT_VALUE you will get always the same hash value for set1, set2 and set3.

RESULT_HASH = HASH(RESULT_VALUE)
  1. Solution

set1 = [ "ab3567cd", "123", "789012" ]

create hash1 from "ab3567cd"

create hash2 from "123"

create hash3 from "789012"

Count:

hash1 (+ or *) hash2 (+ or *) hash3 = RESULT_VALUE

Than you hash the RESULT_VALUE you will get always the same hash value for set1, set2 and set3.

RESULT_HASH = HASH(RESULT_VALUE)

This logical example works with all languages that can hash.

Related