Shortest hash in python to name cache files

后端 未结 8 649
春和景丽
春和景丽 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: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...

提交回复
热议问题