如何创建数据块或文件的哈希树 [英] how to create hash tree of data blocks or file

查看:97
本文介绍了如何创建数据块或文件的哈希树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我想创建数据块的哈希树.我的意思是我想在c#ASP.net.net中创建数据块或文件的merkle哈希树,因此如何计算数据块的哈希,以便我可以将其存储在数据库中.我已经看到 ThexCS-C#中的TTH(老虎树哈希)制造商 [ ^ ]此链接无用.



链接转换为实际链接-OriginalGriff [/edit]

hi friend I want to create an hash tree of my data blocks.I mean I want to create an merkle hash tree of data blocks or files in c# ASP.net.so how to calculet hash of data block so that i can store it in database .I have see ThexCS - TTH (tiger tree hash) maker in C#[^] this link not useful.



[edit]Link converted to an actual link - OriginalGriff[/edit]

推荐答案

.NET中的每个对象都有一个方法Object.GetHashCode,该方法可以被覆盖(即使对于结构).此方法产生的值恰好是基于哈希的容器使用的值;因此您也应该在哈希树中使用它.

对于像结构或类这样的复合对象,哈希码值应反映每个重要成员的唯一值,该值有助于这种类型的整个实例的特定值.在这种情况下,默认GetHashCode不适合,您需要覆盖它.

一种简单合理的哈希码值计算方法是对所有重要成员值的所有哈希码进行XOR操作.如果这些成员中的一些也是自定义类型,则应使用相同的原理来计算这些组合类型的哈希码.

哈希码的确切值不会影响功能,但会间接影响基于哈希码的容器中插入和搜索操作的性能.

—SA
Each object in .NET has a method Object.GetHashCode which can be overridden (even for structures). This method and the value is produces is exactly the value used by hash-based containers; so you should use it in your hash tree, too.

For the compound object like a structure or class, the hash code value should reflect unique value of each significant member which value contributes to the particular value of the whole instance of such type. In such cases, default GetHashCode is not suitable, you need to override it.

One simple and reasonable method of calculating of the hash code value is getting XOR operation of all the hash code of all significant member values. If some of those members are also custom types, the hash code for those composed type should be calculated using the same principles.

The exact value of the hash code does not effect functionality, but it will indirectly effect performance of the insert and search operation in hash code based containers.

—SA


这篇关于如何创建数据块或文件的哈希树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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