字符串到唯一整数哈希 [英] String to unique integer hashing

查看:27
本文介绍了字符串到唯一整数哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个系统,可以将我的字符串更改为唯一的整数值,这意味着例如单词account"的加密数值为 0891,并且没有其他单词可以通过以下方式转换为 0891相同的转换过程,它不是但是需要能够将生成的整数转换回字符串.

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 and no other word can possibly be converted to 0891 with the same conversion process, it does not however need to be able to be converted back the generated integer to string.

同时会依赖词的结构规则,意思是accuracy"和announcement"等词的生成数大于0891,a"、abacus"、abbreviation"等词的生成数会大于0891" 将生成小于 0891 的数字.

At the same time it will be dependent on the word structure rules, meaning words such as "accuracy" and "announcement" will have a generated number greater than 0891 and words such as "a", "abacus" and "abbreviation" will have a generated number less than 0891.

此应用程序的目的类似于索引或主键.我不使用增量索引的原因是出于安全目的,并且是由于索引依赖于集合中的数据数量

The purpose of this application is to serve similar to an index or primary key. The reason why I'm not using an increment index is for security purposes and is due to the indexes dependency to the number of data in the set

(例如)

[0] A, [1] B, [2] C, [3] D, [4] E, [5] F

以上字母各有对应的索引,E的索引为4

The above letters has each corresponding index, E has the index of 4

但是如果数据突然增加或减少然后排序

However if the data is suddenly increased or decreased then sorted

[0] A, [1] AA, [2] AAB, [3] C, [4] D, [5] DA, [6] DZ, [7] E, [8] F

E 现在的索引为 7

每个词必须有一个唯一的独立积分等价物,并有相应的权重.

Each word must have a unique independent integral equivalent and has the corresponding weights.

我需要知道是否存在可以执行上述操作的算法.

I need to know if there exist an algorithm that can do the above.

任何帮助将不胜感激.

推荐答案

这在您提供的约束条件下是不可能的,除非您施加了最大长度.

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

假设 k("a")k("b") 是这两个字符串的代码.

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

根据您的限制,您正在寻找一个介于这两个值之间的唯一整数,但是 k("a") .由于有无数个 "a....a"(和 "akjhdsfkjhs")样式的字符串需要适合这两个代码,例如保持顺序 对于任意长度的字符串,不能存在通用的、唯一的、固定长度的代码.因为您将需要与字符串一样多的整数,而且由于字符串不受长度的限制,所以这是行不通的.

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.

删除通用(因此不允许插入新字符串)、唯一(允许冲突 - 例如使用前四个字母作为代码!)、无限长度(例如 3 个字符)或顺序保留属性.

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.

这篇关于字符串到唯一整数哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆