hash

Java浅拷贝和深拷贝的区别

旧城冷巷雨未停 提交于 2020-01-15 08:53:22
浅拷贝和深拷贝的区别 浅拷贝和深拷贝都是复制对象, 复制出来的对象,它们的内存地址都是重新分配的 ,区别在于 浅拷贝对象中的引用类型和原对象中的引用类型指向同一个内存地址 ,而 深拷贝对象中的引用类型的内存地址是重新分配的 ,也就是说, 浅拷贝对象和原对象的引用类型的数据是同步的,深拷贝对象和原对象的引用类型的数据是互不干扰的 。 注意: 这里说的是引用类型 !对于对象中直接定义的 基本数据类型及其包装类型、 String 类型 这些数据类型, 由于原对象和拷贝对象的内存地址是重新分配的,因此这些数据的改变不会影响到另一个对象 。 注意: 再强调一次,请区分对象中的 基本数据类型及其包装类型、 String 类型 ,这些不属于引用类型!特别要注意的是, 浅拷贝中,对象中的引用类型的地址是同一个内存地址 ,引用类型中的 基本数据类型及其包装类型、 String 类型 的改变会同步到所有浅拷贝对象及原对象中! 浅拷贝的实现 方法一:类要实现 Cloneable 接口,重写 Object 的 clone 方法,在 clone 方法中调用 super.clone() 方法即可。 方法二:只要能实现一个对象的所有属性都拷贝到另一个新对象的属性中即可,通常使用方法一 public class ShallowCopy implements Cloneable { public

Linear probing huge sequences of keys with unequal hash

人走茶凉 提交于 2020-01-15 08:12:48
问题 There is one thing about linear probing (hash tables) that is not intuitive to me. If I put key1 which hash results to array index 1. Then I put key2 -> array index 2. Then I put key3 -> again array index 1, this will go to array index 3. Then when I search for key3 I should go through indexes that contain keys that do not have the same hash as mine at all. Isn't this waste? If the sequence is really big and contains many keys (for example I have 20 elements, then null, for any key that

constructing a new hash from the given values

你离开我真会死。 提交于 2020-01-15 07:47:06
问题 I seem lost trying to achieve the following, I tried all day please help I HAVE h = { "kv1001"=> { "impressions"=>{"b"=>0.245, "a"=>0.754}, "visitors" =>{"b"=>0.288, "a"=>0.711}, "ctr" =>{"b"=>0.003, "a"=>0.003}, "inScreen"=>{"b"=>3.95, "a"=>5.031} }, "kv1002"=> { "impressions"=>{"c"=>0.930, "d"=>0.035, "a"=>0.004, "b"=>0.019,"e"=>0.010}, "visitors"=>{"c"=>0.905, "d"=>0.048, "a"=>0.005, "b"=>0.026, "e"=>0.013}, "ctr"=>{"c"=>0.003, "d"=>0.006, "a"=>0.004, "b"=>0.003, "e"=>0.005}, "inScreen"=>{

Measuring a hash functions quality (for use with maps/assosiative arrays)

时光毁灭记忆、已成空白 提交于 2020-01-15 07:30:11
问题 I'm looking into an associative array library in C (which I didn't write). Similar to a map in C++ or Python's dict's. There are some non-standard hashing functions which I'm not certain if they are even very good. (maybe the original developer just threw some magic-numbers, xor-operators and hoped for the best) . I wrote a test which measures how well the hashing function performs given some sample input, to measure how evenly it distributes items into a fixed number of buckets (modulo array

Git hash-object is yielding different SHA1 in Powershell, CMD and Bash?

荒凉一梦 提交于 2020-01-15 06:10:19
问题 I thought SHA1 value would be same regardless of the platform. And I encountered this today and I hope I can get some clarification here. My test string is: 'Apple Pie' In Bash: echo 'Apple Pie' | git hash-object --stdin 23991897e13e47ed0adb91a0082c31c82fe0cbe5 In CMD (Windows 10): echo 'Apple Pie' | git hash-object --stdin f554ff1fdde0e3c2ca9f67849791456302b5c12b In Powershell 5.0 (Windows 10): echo 'Apple Pie' | git hash-object --stdin 157cb7be4778a9cfad23b6fb514e364522167053 I am now

Git hash-object is yielding different SHA1 in Powershell, CMD and Bash?

那年仲夏 提交于 2020-01-15 06:09:21
问题 I thought SHA1 value would be same regardless of the platform. And I encountered this today and I hope I can get some clarification here. My test string is: 'Apple Pie' In Bash: echo 'Apple Pie' | git hash-object --stdin 23991897e13e47ed0adb91a0082c31c82fe0cbe5 In CMD (Windows 10): echo 'Apple Pie' | git hash-object --stdin f554ff1fdde0e3c2ca9f67849791456302b5c12b In Powershell 5.0 (Windows 10): echo 'Apple Pie' | git hash-object --stdin 157cb7be4778a9cfad23b6fb514e364522167053 I am now

How to reduce hash value's length?

六月ゝ 毕业季﹏ 提交于 2020-01-15 05:21:09
问题 I'd like to squeeze or compress the result hash value from MD5 or SHA1 at a server side application so that at the client can decompress it or desqueeze it , is this possible ? its a usability issue for my application. 回答1: No, hash values cannot be compressed. By design their bits are highly random and have maximum entropy, so there is no redundancy to compress. If you want to make the hash values easier to read for users you can use different tricks, such as: Displaying fewer digits.

Sum values in array of hash if they have the same value

一曲冷凌霜 提交于 2020-01-15 03:58:10
问题 I saw this piece of code in this post, because I'm trying to sum values in an array of hashes based on some criteria. Rails sum values in an array of hashes array = [ {loading: 10, avg: 15, total: 25 }, {loading: 20, avg: 20, total: 40 }, {loading: 30, avg: 25, total: 55 } ] sum = Hash.new(0) array.each_with_object(sum) do |hash, sum| hash.each { |key, value| sum[key] += value } end # => {:loading=>60, :avg=>60, :total=>120} What I'm trying to do and I don't know how, is to sum total key if

Algorithm to turn numeric IDs in to short, different alphanumeric codes

天涯浪子 提交于 2020-01-15 03:56:13
问题 I have IDs from a database, and I want them to be short and easily differentiatable by eye (i.e., two close numbers look different). Like this: 13892359163211 -> ALO2WE7 13992351216421 -> 52NBEK3 or similar, algorithmically. So kind of like a hash, except it needs to be reversible? An encryption algorithm like AES is almost ideal, except that its outputs are way too long. (and overkill). I'm using Python (3), although I don't think that should really matter 回答1: New answer with 'close'

qHash function for QRect

北战南征 提交于 2020-01-15 01:50:04
问题 What is the best way to calculate the qHash value of a QRect ? I need to use QRect (and maybe QRectF ) as the key of QCache . Right now I am using something like this: inline uint qHash(const QRect & r) { return qHash(QByteArray::fromRawData((const char*)&r, sizeof(r))); } It seems to work but I don't like casting it into some raw bytes and since QRect is noy a simple struct, this may break sooner than later in future versions of Qt. BTW. I don't store the hash values so it doesn't have to be