我正在编写一个字典类的实现。我目前正在编写add方法。
(公共V加法 (K键,V值))
算法:
if the table is too full
rehash
grab the index based on the key
probe with the index and key to resolve collisions
if the table at the index is null, or has been removed
increment the number of entries
increment the number of locations used
我想使用ConcurrentDictionary来检查以前是否添加了这个数据键,但是看起来我仍然可以添加前面添加的键。
代码:
public class pKeys
{
public pKeys()
{ }
public pKeys(long sID, long pID)
{
this.seID = sID;
this.pgID = pID;
}
public long seID;
public long pgID;
嘿,伙计们,我如何分别输出这两个值,然后依次从这个方法返回?
public static int[] getLargestAndSmallest (int[] numbers){ // semi-done
int largest = numbers[0];
int smallest = numbers[0];
for (int i = 0; i < numbers.length; i++){
if (numbers[i] > largest){
largest = numbers[i];
}
我必须实现一个哈希表,它将使用一个数组,但是必须遵循指南并为每个过程创建函数。如果有人能帮我完成这项工作,我将不胜感激,因为我遇到了一些麻烦。
public class HashTable {
// public for testing purposes
public int buckets[];
public HashTable(long _a, long _c, long _m) {
}
public void insert(int key) {
}
}
到目前为止,我得到的是:
public class HashTable {
// public for testing purp
目前我有一个问题,当我覆盖GetHashCode和Equals时,我的绑定就会中断。
这是我的模特
class A
{
private string name;
public string Name
{
get { return name; }
set { name = value; /*Some notification stuff*/ }
}
public override bool Equals(object obj)
{
if (obj == null)
{
我目前正在读Troelsen的“C#和.NET 4.5框架”一书。书中有一节,他有一个重写的例子。
public virtual int GetHashCode(); // Defined in System.Object
他说(以下引文摘自Troelsen的书):
鉴于String类已经有了一个坚实的散列代码算法,该算法使用字符串的字符数据来计算哈希值,如果您可以识别类上的一段字段数据,对于所有实例(例如社会保险号码)都应该是唯一的,那么只需在字段数据的这一点上调用GetHashCode()。
基本上,他说的是某个类有一个成员(自动只读属性)。
public string SSN {