我正在实施 Charikar 对位置敏感哈希的快速搜索 我正在寻找一种在 C# 中排列位的快速方法(可以在 MMIX 中的一个操作中完成的那种事情)。
要求是:
- 始终小于 64 位,因此表示可以是长整数
- 随机生成排列(这可能很慢,因为只完成一次)。我可能会使用 Knuth shuffle。
- 多次使用生成的排列,因此这需要很快,
我知道 Knuth 对此进行了详细介绍,但我想知道是否有任何 .NET/C# 特定的解决方案。
编辑:我正在使用.NET 3.5 版本。
I'm implementing Charikar's fast search on a locality sensitive hash and I'm looking for a fast method of permuting bits (the kind of thing that can be done in one operation in MMIX) in C#.
The requirements are:
- Always less than 64 bits, so representation can be a long integer
- Randomly generate a permutation (this can be slow as it's only done once). I'll probably use a Knuth shuffle.
- Use the generated permutation many times, so this needs to be fast
I know Knuth goes into this in detail but I was wondering if there was any .NET/C# specific solution.
EDIT: I'm using .NET version 3.5.
发布评论
评论(1)
由于 C# 不提供 Knuth 在 C 中没有的任何位操作指令,因此不存在特定于 .NET/C# 的解决方案。
同时,.NET确实提供了动态编译,这将帮助您高效地重复执行shuffle。
.NET 是什么版本?最简单的方法可能是使用 Knuth 算法并将结果操作编码在
Expression>
中,然后将结果编译为Func 。委托。
Since C# doesn't provide any bit-manipulation instructions that Knuth didn't have in C, no, there's no .NET/C#-specific solution.
At the same time, .NET does offer dynamic compilation which will help you repeatedly perform the shuffle efficiently.
What version of .NET? The easiest approach will probably be to use Knuth's algorithm and encode the resulting operations in an
Expression<Func<ulong, ulong>>
, then compile the result as aFunc<long, long>
delegate.