hash

Is using 2 different hash functions a good way to check for file integrity?

微笑、不失礼 提交于 2020-01-23 06:58:26
问题 I have a website where users can upload their files; these are stored on the server and their metadata recorded in a database. I'm implementing some simple integrity checks, i.e. "is the content of this file now byte-for-byte identical as when it was uploaded?" An example: for content of userfile.jpg , MD5 hash is 39f9031a154dc7ba105eb4f76f1a0fd4 and SHA-1 hash is 878d8d667721e356bf6646bd2ec21fff50cdd4a9 . If this file's content changes, but has the same MD5 hash before and after, is it

What is the fastest way to map group names of numpy array to indices?

人盡茶涼 提交于 2020-01-23 05:18:25
问题 I'm working with 3D pointcloud of Lidar. The points are given by numpy array that looks like this: points = np.array([[61651921, 416326074, 39805], [61605255, 416360555, 41124], [61664810, 416313743, 39900], [61664837, 416313749, 39910], [61674456, 416316663, 39503], [61651933, 416326074, 39802], [61679969, 416318049, 39500], [61674494, 416316677, 39508], [61651908, 416326079, 39800], [61651908, 416326087, 39802], [61664845, 416313738, 39913], [61674480, 416316668, 39503], [61679996,

Sign PDF hash using java and iText

一笑奈何 提交于 2020-01-23 03:52:05
问题 I have an application that generates a PDF, and that needs to be signed. We have not the certificates to sign the document, because they're in a HSM, and the only way we could make use of the certificates is using a webservice. PdfReader reader = new PdfReader(src); reader.setAppendable(true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileOutputStream fout = new FileOutputStream(dest); PdfStamper stamper = PdfStamper.createSignature(reader, fout, '\0'); PdfSignatureAppearance

Python: How do sets work

醉酒当歌 提交于 2020-01-22 10:28:08
问题 I have a list of objects which I want to turn into a set. My objects contain a few fields that some of which are o.id and o.area . I want two objects to be equal if these two fields are the same. ie: o1==o2 if and only if o1.area==o2.area and o1.id==o2.id . I tried over-writing __eq__ and __cmp__ but I get the error: TypeError: unhashable instance . What should I over-write? 回答1: Define the __hash__ method to return a meaningful hash based on the id and area fields. E.g.: def __hash__(self):

How can I convert strings to an html color code hash?

…衆ロ難τιáo~ 提交于 2020-01-22 07:29:53
问题 I'd like to represent strings as arbitrary html colors. Example: "blah blah" = #FFCC00 "foo foo 2" = #565656 It doesn't matter what the actual color code is, so long as it's a valid hexadecimal HTML color code and the whole spectrum is fairly well represented. I guess the first step would be to do an MD5 on the string and then somehow convert that to hexadecimal color code? Update: Usage example is to generate a visual report of file requests on a server. The colors don't have to look pretty,

散列表

只愿长相守 提交于 2020-01-22 00:41:02
散列表类似于数组,可以把散列表的散列值看成数组的索引值。访问散列表和访问数组元素一样快速,它可以在常数时间内实现查找和插入操作。 由于无法通过散列值知道键的大小关系,因此散列表无法实现有序性操作。 查找 用散列函数将被查找的键转化程数组的一个索引(理想状态下,不同的键都能转化为不同的索引值。当然这只是理想情况,所以我们需要面对两个或者多个键都会散列到相同的索引值也就是碰撞 处理碰撞(拉链法和线性探索法 散列函数 散列函数应该满足以下三个条件: 一致性:相等的键应当有相等的 hash 值,两个键相等表示调用 equals() 返回的值相等。 高效性:计算应当简便,有必要的话可以把 hash 值缓存起来,在调用 hash 函数时直接返回。 均匀性:所有键的 hash 值应当均匀地分布到 [0, M-1] 之间,如果不能满足这个条件,有可能产生很多冲突,从而导致散列表的性能下降。 软缓存 如果散列值的计算很耗时,那么我们或许可以将每个键的散列值缓存起来 碰撞处理 基于拉链法的散列表 拉链法使用链表来存储 hash 值相同的键,从而解决冲突。 查找需要分两步,首先查找 Key 所在的链表,然后在链表中顺序查找。 基于线性探测法的散列表 线性探测法使用空位来解决冲突,当冲突发生时,向前探测一个空位来存储冲突的键。 使用线性探测法,数组的大小 M 应当大于键的个数 N(M>N)。 实现

Spring Boot整合Redis

会有一股神秘感。 提交于 2020-01-21 21:27:00
目录 1.spring-data-redis项目简介 1.1 spring-data-redis项目的设计 1.2 RedisTemplate 1.3 Spring对Redis数据类型操作的封装 1.4 SessionCallback和RedisCallback 2.Spring Boot中配置和使用Redis 2.1 配置Redis 2.2 操作Redis数据类型 2.2.1 字符串和散列的操作 2.2.2 列表操作 2.2.3 集合操作 2.3 Redis的特殊用法 2.3.1 Redis事务 2.3.2 Redis流水线 2.3.3 Redis发布订阅 2.3.4 使用Lua脚本 在现今互联网应用中,NoSql已经广泛应用,在互联网中起到加速系统的作用。有两种NoSQL使用最为广泛,那就是Redis和MongoDB。 Redis是一种运行在内存的数据库,支持7种数据类型的存储。Redis的运行速度很快,大约是关系数据库几倍到几十倍的速度。如果我们将常用的数据存储在Redis中,用来代替关系数据库的查询访问,网站性能将可以得到大幅提高。在现实中,查询数据要远远大于更新数据,一般一个正常的网站查询和更新的比例大约是1:9到3:7,在查询比例较大的网站使用Redis可以数倍地提升网站的性能。 Redis自身数据类型比较少,命令功能也比较有限,运算能力一直不强,所以在Redis2

【Java】HashMap 常用方法总结

谁说我不能喝 提交于 2020-01-21 16:27:31
HashMap 简单知识点 Map 集合即 Key-Value 的集合,前面加个 Hash,即散列,无序的。所以 HashMap 是一个用于存储Key-Value键值对的无序集合,每一个键值对也叫做Entry。 在 JDK1.8 之前,HashMap 采用数组+链表实现,即使用链表处理冲突,同一 hash 值的节点都存储在一个链表里。但是当位于一个桶中的元素较多,即 hash 值相等的元素较多时,通过 key 值查找要遍历链表,时间复杂度为 O(N),效率较低。 因此 JDK1.8 中,HashMap 采用数组+链表+红黑树实现,当链表长度超过阈值(8)时,将链表转换为红黑树,时间复杂度为 O(logN),这样大大减少了查找时间。 用一段代码来介绍常用方法: package a ; import java . util . HashMap ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { HashMap < String , Integer > mp = new HashMap < String , Integer > ( ) ; mp . put ( "one" , 1 ) ; //存放键值对 System . out .

Can a hash key have multiple 'subvalues' in perl?

▼魔方 西西 提交于 2020-01-21 13:57:12
问题 I have a list of genes and the following information: Their name 'XLOC_0000...' The genomic scaffold on which they're located 'Scaffold...' The location of each feature on its Scaffold ('start', 'stop') I've written a piece of Perl code that finds each gene in the genomic scaffolds and saves it to a file. Briefly, first I put each gene in a hash of arrays, e.g. my %geneID = map { $xloc[$_] => [ $scaffold[$_], $start[$_], $stop[$_] ] } (0 .. $#xloc); I then make a hash of the fasta file

Can a hash key have multiple 'subvalues' in perl?

本小妞迷上赌 提交于 2020-01-21 13:55:07
问题 I have a list of genes and the following information: Their name 'XLOC_0000...' The genomic scaffold on which they're located 'Scaffold...' The location of each feature on its Scaffold ('start', 'stop') I've written a piece of Perl code that finds each gene in the genomic scaffolds and saves it to a file. Briefly, first I put each gene in a hash of arrays, e.g. my %geneID = map { $xloc[$_] => [ $scaffold[$_], $start[$_], $stop[$_] ] } (0 .. $#xloc); I then make a hash of the fasta file