-3

文字列からハッシュコードを int として生成したい。

そのための事前定義されたアルゴリズムはありますか? Cでそのアルゴリズムの実装はありますか?

char name[100]="langage c"

そのバッファのハッシュコードをname整数変数に生成します

int hash_code;

そんな感じ

int algo_hash(char *name) {
    //hash algorithme
}
hash_code = algo_hash(name);

できるだけシンプルなコードを探しています

4

2 に答える 2

2

The general technique is called "hashing". If you have a know list of strings, you can use the tool gperf to generate a perfect hash function for them.

If the strings are random, this isn't possible in the general case with these constraints. You could use an SHA-1 hash algorithm but that produces a 160 bit number from a string and there is no 100% guarantee that the values are unique (collisions with SHA-1 are just very unlikely but not impossible).

于 2013-01-07T15:10:43.610 に答える
1

必要なのはhashingを実装することだと思います。それでも一意ではありません-衝突を回避できるとは思えません。

于 2013-01-07T15:08:44.780 に答える