【问题标题】:Hash Function to generate Hash Key from File Path哈希函数从文件路径生成哈希键
【发布时间】:2012-11-19 13:36:23
【问题描述】:

关于哈希函数从文件路径名生成哈希键的任何想法?我想用它来维护每个文件的信息,因为每个文件的路径都是唯一的,即使它们具有相同的文件名!

【问题讨论】:

    标签: linux operating-system filesystems hashtable linode


    【解决方案1】:

    您可以使用openssl 哈希函数,这只是一个示例:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <openssl/md5.h>    
    
    int main()
    {
      int i;
      unsigned char result[MD5_DIGEST_LENGTH];
      const char *string = "path/to/file";
    
      MD5(string, strlen(string), result);
    
      // output
      for(i = 0; i < MD5_DIGEST_LENGTH; i++)
        printf("%02x", result[i]);
      printf("\n");
    
      return EXIT_SUCCESS;
    }
    

    【讨论】:

    • 如何在程序中的 Hask 密钥生成函数中使用它?!
    • @neo 他没有指定任何编程语言。
    • C,例如?如果我在 C 中编写哈希函数?
    猜你喜欢
    • 1970-01-01
    • 2019-04-28
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2016-07-16
    相关资源
    最近更新 更多