String to unique integer hashing

前端 未结 7 1373
日久生厌
日久生厌 2020-12-18 18:49

I\'m trying to develop a system that can change my string into a unique integral value, meaning say for example the word \"account\" has an encrypted numerical value of 0891

7条回答
  •  一整个雨季
    2020-12-18 19:00

    This is not possible with the constraints you have given, unless you impose a maximum length.

    Assume that k("a") and k("b") are the codes of these two strings.

    With your constraints, you are looking for a unique integer number that falls inbetween these two values, but k("a") < k("a....a") < k("b"). As there is an infinite number of strings of style "a....a" (and "akjhdsfkjhs") that would need to fit inbetween the two codes, such an order preserving general, unique, fixed-length code cannot exist for strings of arbitrary length. Because you would need as many integers as strings, and since strings are not bounded by length this cannot work.

    Drop either general (so don't allow inserting new strings), unique (allow collissions - e.g. use the first four letters as code!), the unbounded length (to e.g. 3 characters) or the order-preserving property.

提交回复
热议问题