什么是哈希的4/16? [英] What is 4/16 in hashes?

查看:88
本文介绍了什么是哈希的4/16?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (%hash){
     print "That was a true value!\n";
}

当(且仅当)哈希至少具有一个时,这将是正确的 核心价值 对.

That will be true if (and only if) the hash has at least one key-value pair.

实际结果是内部调试字符串,对于 人们 谁维护Perl. 它看起来像"4/16" ,但值 当散列为非空时,保证为true;当散列为非空时,保证为false 它是空的. -骆驼书

The actual result is an internal debugging string useful to the people who maintain Perl. It looks something like "4/16," but the value is guaranteed to be true when the hash is nonempty, and false when it's empty. --Llama book

这是什么4/16?谁能给我看一个小程序,从中我可以看到结果是4/16?

What is this 4/16? Can anyone show me a small program from where I can see that the result is 4/16?

推荐答案

来自 perldoc perldata :

如果您在标量上下文中评估哈希,则如果哈希计算返回false 是空的.如果有任何键/值对,则返回true;否则,返回true.更多的 确切地说,返回的值是一个字符串,其中包含 已使用的存储区和已分配存储区的数量,以 削减.这仅对于确定Perl是否 内部哈希算法在您的数据集上的效果不佳.为了 例如,您将10,000个东西粘贴在哈希中,但在其中计算%HASH 标量上下文显示"1/16",表示十六分之一 桶已被触及,大概包含了您所有的10,000 项目.

If you evaluate a hash in scalar context, it returns false if the hash is empty. If there are any key/value pairs, it returns true; more precisely, the value returned is a string consisting of the number of used buckets and the number of allocated buckets, separated by a slash. This is pretty much useful only to find out whether Perl's internal hashing algorithm is performing poorly on your data set. For example, you stick 10,000 things in a hash, but evaluating %HASH in scalar context reveals "1/16" , which means only one out of sixteen buckets has been touched, and presumably contains all 10,000 of your items.

因此,4/16将是已使用/已分配的存储区计数,如下所示将显示该值:

so, 4/16 would be the buckets used/allocated count, and something like the following will display this value:

%hash = (1, 2);
print scalar(%hash); #prints 1/8 here

这篇关于什么是哈希的4/16?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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