hash

浅谈HashMap

假如想象 提交于 2020-01-13 22:57:04
目录 浅谈HashMap 基本特性 定义 历遍 HashMap的模型 初始化 Get和Put方法 浅谈HashMap 基本特性 定义 hashMap是一个无序的,非空的容器,而且是非同步的容器会造成线程不安全的这类问题,即有许多人都想要同一份学习资料,系统会复制出多份资料后,给每个人一份资料,而不同的人对这份资料有着不同的看法并对该资料进行修改,再上传到系统中。可想而知资料会有多少个版本,但是系统只能存放一个版本的资料,因而会丢失大量版本信息。线程不安全:简单来说,就是用户读到的信息有一定可能是错误的,从而做出错误的操作(抢票时,可能抢到重票或抢到一张不存在的票) 历遍 HashMap的容量太大或太小,不利于literation(迭代器)查询目标。 HashMap的模型 HashMap是数组和单向列表的结合体,即用数组来装列表的表头,因此在做增删等操作时,所消耗的时间和空间会比数组小,查询容器的中元素的速度会比列表快。类似于下图 初始化 HashMash中常量: HashMap有4个构造函数; public HashMap() { this.loadFactor = DEFAULT_LOAD_FACTOR; //使用默认的加速因子,bucket 的大小为默认的16 } 1 public HashMap(int initialCapacity, float loadFactor) {

Should I choose a hash, an object or an array to represent a data instance in Perl?

▼魔方 西西 提交于 2020-01-13 16:22:33
问题 I was always wondering about this, but never really looked thoroughly into it. The situation is like this: I have a relatively large set of data instances. Each instance has the same set or properties, e.g: # a child instance name age height weight hair_color favorite_color list_of_hobbies Usually I would represent a child as a hash and keep all children together in a hash of hashes (or an array of hashes). What always bothered me with this approach is that I don't really use the fact that

C# and SQL Server: Passwords. Where to do what?

徘徊边缘 提交于 2020-01-13 13:10:34
问题 Ok, I have an application written in C#. We have data in an SQL Server. Among that data we have user accounts, which will give access to the application. I've read around, and I know that you should salt and hash and possibly hash a bunch of times, etc. But, where do I do what? What do I send to and from the SQL Server? Exactly what do I store in the database? Do I hash it in SQL? (possibly a hash function there, like in mysql?) Do I hash and do the fancy stuff in my code? Do I send the hash

C# and SQL Server: Passwords. Where to do what?

不想你离开。 提交于 2020-01-13 13:09:14
问题 Ok, I have an application written in C#. We have data in an SQL Server. Among that data we have user accounts, which will give access to the application. I've read around, and I know that you should salt and hash and possibly hash a bunch of times, etc. But, where do I do what? What do I send to and from the SQL Server? Exactly what do I store in the database? Do I hash it in SQL? (possibly a hash function there, like in mysql?) Do I hash and do the fancy stuff in my code? Do I send the hash

Will keys and values of a hash have the same “order” in Perl?

倾然丶 夕夏残阳落幕 提交于 2020-01-13 11:28:18
问题 I understand that a hash is not ordered in perl. What I am concerned about is if I can depend on the keys and values coming out with an index relationship. Say I have this hash my %h = ("a" => 1, "b" => 2, "c" => 3, "d" => 4); If I do keys %h , I might get ("b", "a", "d", "c") Would I be guaranteed that values %h would come out in the same order to match keys? Can I expect? (2, 1, 4, 3) Or is there no guarantee that there's any index relationship between keys %h and values %h ? 回答1: Yes. As

How can I make hash key lookup case-insensitive?

前提是你 提交于 2020-01-13 08:11:46
问题 Evidently hash keys are compared in a case-sensitive manner. $ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{foo} ) ? "Yes" : "No";' No $ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{FOO} ) ? "Yes" : "No";' Yes Is there a setting to change that for the current script? 回答1: You will have to use a tied hash. For example Hash::Case::Preserve. 回答2: The hash of a string and the same string with the case changed are not equal. So you can't do what you want, short of

Looking for a fast hash-function

為{幸葍}努か 提交于 2020-01-13 08:08:16
问题 I'm looking for a special hash-function. Let's say I have a large list of strings, if I order them by their hash-values they should be ordered quasi randomly. The most important point is: it must be super fast. I've tried md5 and sha1 and they're using to much cpu power. Clashes are not a problem. I'm using javascript, so it shouldn't be too complicated to implement. 回答1: Take a look at Murmur hash. It has a nice space/collision trade-off: http://sites.google.com/site/murmurhash/ 回答2: It

Looking for a fast hash-function

自古美人都是妖i 提交于 2020-01-13 08:07:09
问题 I'm looking for a special hash-function. Let's say I have a large list of strings, if I order them by their hash-values they should be ordered quasi randomly. The most important point is: it must be super fast. I've tried md5 and sha1 and they're using to much cpu power. Clashes are not a problem. I'm using javascript, so it shouldn't be too complicated to implement. 回答1: Take a look at Murmur hash. It has a nice space/collision trade-off: http://sites.google.com/site/murmurhash/ 回答2: It

How can I make hash key lookup case-insensitive?

有些话、适合烂在心里 提交于 2020-01-13 08:07:07
问题 Evidently hash keys are compared in a case-sensitive manner. $ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{foo} ) ? "Yes" : "No";' No $ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{FOO} ) ? "Yes" : "No";' Yes Is there a setting to change that for the current script? 回答1: You will have to use a tied hash. For example Hash::Case::Preserve. 回答2: The hash of a string and the same string with the case changed are not equal. So you can't do what you want, short of

对称加密和非对称加密

穿精又带淫゛_ 提交于 2020-01-13 05:08:08
一、简介: 对称加密:加密和解密的秘钥使用的是同一个。 非对称加密:加密需要公钥、私钥两种。“公钥加密,私钥解密;私钥加密,公钥解密” 二、特点: 对称加密: AES,DES,3DES,IDEA,Blowfish,RC4、RC5、RC6 等。 在数据传送前,发送方和接收方必须商定好秘钥,然后双方都能保存好秘钥,使用该秘钥进行数据的加解密。 优点:算法公开、计算量小、加密速度快、加密效率高。 缺点:如果一方的秘钥被泄露,那么加密信息也就不安全了。另外,每对用户每次使用对称加密算法时,都需要使用其他人不知道的唯一秘钥,这会使得收、发双方所拥有的钥匙数量巨大,密钥管理成为双方的负担。 非对称加密 : RSA、ECC(移动设备用)、Diffie-Hellman、El Gamal、DSA(数字签名用) 甲方生成一对密钥并将其中的一把作为公用密钥向其它方公开;得到该公用密钥的乙方,使用该密钥对机密信息进行加密后再发送给甲方;甲方再用自己保存的另一把专用密钥对加密后的信息进行解密。甲方只能用其专用密钥解密由其公用密钥加密后的任何信息。 优点: 安全 缺点: 速度较慢 Hash算法 (摘要算法):MD2、MD4、MD5、HAVAL、SHA Hash算法特别的地方在于它是一种单向算法,用户可以通过hash算法对目标信息生成一段特定长度的唯一hash值,却不能通过这个hash值重新获得目标信息