什么是Hi / Lo算法? [英] What's the Hi/Lo algorithm?

查看:234
本文介绍了什么是Hi / Lo算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Hi / Lo算法?

What's the Hi/Lo algorithm?

我在 NHibernate 文档(它是一种生成唯一键的方法,第5.1.4.2节),但我没有找到一个很好的解释它是如何工作的。

I've found this in the NHibernate documentation (it's one method to generate unique keys, section 5.1.4.2), but I haven't found a good explanation of how it works.

我知道Nhibernate处理它,我不需要知道里面,但我只是好奇。

I know that Nhibernate handles it, and I don't need to know the inside, but I'm just curious.

推荐答案

基本思想是你有两个数字来组成一个主键 - 一个高数字和一个低数字。客户端可以基本上增加高序列,知道它可以安全地生成从以前的高值的整个范围与各种低值的密钥。

The basic idea is that you have two numbers to make up a primary key- a "high" number and a "low" number. A client can basically increment the "high" sequence, knowing that it can then safely generate keys from the entire range of the previous "high" value with the variety of "low" values.

例如,假设您具有当前值为35的高序列,并且低数的范围为0-1023。然后客户端可以将序列递增到36(对于其他客户端,在使用35时能够生成密钥),并知道密钥35/0,35/1,35/2,35/3 ... 35/1023

For instance, supposing you have a "high" sequence with a current value of 35, and the "low" number is in the range 0-1023. Then the client can increment the sequence to 36 (for other clients to be able to generate keys while it's using 35) and know that keys 35/0, 35/1, 35/2, 35/3... 35/1023 are all available.

它可以非常有用(特别是对于ORM)能够在客户端设置主键,而不是没有主键插入值,然后将它们提取回客户端。除了其他方面,这意味着您可以轻松地建立父/子关系,并在您进行任何插入操作之前将所有键都置于适当位置,这样可以更简单地对其进行批量处理。

It can be very useful (particularly with ORMs) to be able to set the primary keys on the client side, instead of inserting values without primary keys and then fetching them back onto the client. Aside from anything else, it means you can easily make parent/child relationships and have the keys all in place before you do any inserts, which makes batching them simpler.

这篇关于什么是Hi / Lo算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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