hash

hashtable size and significant bits of key

孤街醉人 提交于 2019-12-24 03:09:40
问题 I have a question regarding hashtable size and modular hashing. The hashing algorithm I'm referring to is the following: hash_key % table_size = array_index. I'm reading an algorithms textbook where the following bit of advice is given: If the table size is not prime, it may be the case that all of the bits of the key do not play a role in determining the array_index. Can anyone explain what this means exactly with an example? 回答1: What you want to avoid is common factors. There is a theorem

Redis数据类型及使用场景

…衆ロ難τιáo~ 提交于 2019-12-24 02:58:11
摘要:Redis相比其它的KV数据库,其一大特点是支持丰富的数据类型.它一共支持5种数据类型,下面逐一介绍这5种数据类型及其使用场景... Redis相比其它的KV数据库,其一大特点是支持丰富的数据类型。它一共支持5种数据类型,下面逐一介绍这5种数据类型及其使用场景和内部实现方式。 string 简介:Strings数据类型是最常用、简单的key-value类型,普通的key/ value 存储都可以归为此类。value不仅可以是字符串,也可以是数字。因为是二进制安全的,所以你完全可以把一个图片文件的内容作为string来存储。Redis的string可以完全实现目前 memcache d的功能,并且效率更高。除了提供与 Memcached 一样的get、set、incr、decr 等操作外,Redis还额外提供了下面一些操作: 获取字符串长度 往字符串append内容 设置和获取字符串的某一段内容 设置及获取字符串的某一位(bit) 批量设置一系列字符串的内容 常用命令: set,get,decr,incr,mget 等。 应用场景: 应用 Memcached和CKV的所有场景。字符串和数字直接存取。结构化数据需要先序列化,再set到value;相应的,get到value后需要反序列化。 可以利用redis的INCR、INCRBY、DECR、DECRBY等指令来实现原子计数的效果

How to embed hash in exe file with signtool.exe

夙愿已清 提交于 2019-12-24 02:43:24
问题 I am using signtool.exe to sign exe file. I am trying to embed my exe file with the .pfx certificate along with the signed hash of exe(generated signed hash using openssl). I am able to sign only with certificate. But I need to embed the signed hash in the exe as well. Probably signtool.exe sign /as could help. /as option does not expect any argument so not able to pass my hash there. Could someone please help me sign my exe with certificate and hash. Thanks, 回答1: The version of Signtool

FUNCTION databasename.SHA2 does not exist

柔情痞子 提交于 2019-12-24 02:35:25
问题 I am hosting my domain on goddady and am trying to hash the passwords in the database. However, it throws the error: MySQL said: #1305 - FUNCTION dbname.SHA2 does not exist This is the command I'm using to insert the data in the db. insert into `dbname`.`tbl_members` values ('1', 'admin', SHA2('password', 224)); This works perfectly fine when I execute it on my local server. 回答1: It's probably a version problem. SHA2() was added in MySQL 5.5.5. 来源: https://stackoverflow.com/questions/5596238

Adding a class to an a element with a particular href using hash

自闭症网瘾萝莉.ら 提交于 2019-12-24 02:27:18
问题 I'm trying to add an 'active' class to a particular element based on the URL hash but it's not working as I expect. Here's my code: var hash = window.location.hash.substr(1); if(hash != false) { $('.products #copy div, #productNav li a').removeClass('active'); $('.products #copy div#'+hash+'').addClass('active'); $('#productNav li a[href*="'+hash+'"').addClass('active'); } The second jQuery statement (the one that adds the 'active' class to the div) works as expected, but the third (the one

How to truncate data in a hash so that the resulting JSON isn't longer than n bytes?

两盒软妹~` 提交于 2019-12-24 01:46:16
问题 I have a hash that looks something like this: { :a => "some string", :b => "another string", :c => "yet another string" } I wan't to call to_json on it eventually, but the resulting json-string cannot be longer than n bytes. If the string is too big, then first :c should be truncated first. If that's not enough, :b should be truncated. Finally :a . Also the strings can contain multi-byte characters like German umlauts and the Ruby version is 1.8.7. (The umlauts first take 2 bytes, but as json

Replace one matched value in a hash with another

六月ゝ 毕业季﹏ 提交于 2019-12-24 01:43:11
问题 I have an array of hashes: arr = [ {:key1=>"one", :key2=>"two", :key3=>"three"}, {:key1=>"four", :key2=>"five", :key3=>"six"}, {:key1=>"seven", :key2=>"eight", :key3=>"nine"} ] and I would like to search through and replace the value of :key1 with "replaced" if :key = "one" . The resultant array would then read: arr = [ {:key1=>"replaced", ;key2=>"two", :key3=>"three"}, {:key1=>"four", ;key2=>"five", :key3=>"six"}, {:key1=>"seven", ;key2=>"eight", :key3=>"nine"} ] Can anyone point me in the

.Net equivalent of Java's System.identityHashCode()

ぐ巨炮叔叔 提交于 2019-12-24 01:07:56
问题 Java's System.identityHashCode() Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode(). That hash code is based on the object identity, so it will always be the same for the same object, no matter if the object is mutated between calls to identityHashCode() . In addition to that, there will not be hash collisions between any two living objects (with some Java runtimes): (the former is

Hash算法

人走茶凉 提交于 2019-12-24 00:56:04
  Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值。这种转换是一种压缩映射,也就是,散列值的空间通常远小于输入的空间,不同的输入可能会散列成相同的输出,而不可能从散列值来唯一的确定输入值。简单的说就是一种将任意长度的消息压缩到某一固定长度的 消息摘要 的函数。   HASH主要用于信息安全领域中加密算法,它把一些不同长度的信息转化成杂乱的128位的编码,这些编码值叫做HASH值. 也可以说,hash就是找到一种数据内容和数据存放地址之间的映射关系 基本概念    * 若结构中存在和关键字K相等的记录,则必定在f(K)的存储位置上。由此,不需比较便可直接取得所查记录。称这个对应关系f为 散列函数 (Hash function),按这个思想建立的表为 散列表 。   * 对不同的关键字可能得到同一散列地址,即key1≠key2,而f(key1)=f(key2),这种现象称冲突。具有相同函数值的关键字对该散列函数来说称做同义词。综上所述,根据散列函数H(key)和处理冲突的方法将一组关键字映象到一个有限的连续的地址集(区间)上,并以关键字在地址集中的“象” 作为记录在表中的存储位置,这种表便称为散列表,这一映象过程称为散列造表或散列,所得的存储位置称散列地址。   *

How to enforce 32bit of .net String GetHashCode() [duplicate]

試著忘記壹切 提交于 2019-12-24 00:34:30
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: GetHashCode() gives different results on different servers? I used string GetHashCode() in my .net 4.0 program and store the value in the DB. The problem is that when I run the program on different setup, 64 vs 32, .net use different hashing algorithm for string hashing. So I won’t get the match all the time. So does anyone know how can I just compute the 32bit of string hashing even on a 64bit build. 回答1: The