我看到你如何通过密钥访问你的收藏.但是,哈希函数本身在幕后有很多操作,不是吗?
假设你有一个很好的哈希函数非常有效,它仍然可能需要很多操作.
这可以解释一下吗?
我试图确定列表和字典的最大大小(在RAM中).我也很好奇每个元素/条目可容纳的最大数量,以及每个条目的内存占用量.
我的理由很简单:我和大多数程序员一样,有些懒惰(这是一种美德).当我编写程序时,我喜欢编写一次程序,并尽可能地尝试将来证明它.我目前正在编写一个使用Lists的程序,但注意到迭代器需要一个整数.由于我的程序的功能仅受可用内存/编码样式的限制,我想编写它以便我可以使用带有Int64s的List或可能使用BigInts(作为迭代器).我在这里看到IEnumerable是一种可能性,但是想知道我是否可以将Int64填入Dictionary对象作为键,而不是重写所有内容.如果可以的话,我想知道与重写它相比可能会花费多少成本.
我的希望是,如果我的程序证明有用,我只需要在5年时间内重新编译以利用内存的增加.
我有一个HashSet类型:
public Class Person
{
int? _requestedHashCode;
long Id;
Name string;
DateTime BirthDate;
// Other properties
public bool IsTransient()
{
return this.Id == default(long);
}
public override int GetHashCode()
{
if (!IsTransient())
{
if (!_requestedHashCode.HasValue)
_requestedHashCode = this.Id.GetHashCode() ^ 31;
return _requestedHashCode.Value;
}
else
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null || !(obj is Person))
return false;
if (Object.ReferenceEquals(this, obj))
return true;
if (this.GetType() != obj.GetType())
return false;
Entity item = (Entity)obj; …Run Code Online (Sandbox Code Playgroud)