Shortest hash in python to name cache files

后端 未结 8 643
春和景丽
春和景丽 2020-12-23 22:45

What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save cache files for some objects. The objects mu

相关标签:
8条回答
  • 2020-12-23 23:21

    We use hashlib.sha1.hexdigest(), which produces even longer strings, for cache objects with good success. Nobody is actually looking at cache files anyway.

    0 讨论(0)
  • 2020-12-23 23:24

    The builtin hash function of strings is fairly collision free, and also fairly short. It has 2**32 values, so it is fairly unlikely that you encounter collisions (if you use its abs value, it will have only 2**31 values).

    You have been asking for the shortest hash function. That would certainly be

    def hash(s):
      return 0
    

    but I guess you didn't really mean it that way...

    0 讨论(0)
提交回复
热议问题