Esempio n. 1
0
    /* TODO: implement case where value not found*/
    int find(T value){
        int home = firstHash(value),
            step = secondHash(value);

        while(table[home]!=value) {
            home += step;
            if(home >size) home -= size;
        }
        return home;
    }
Esempio n. 2
0
     void load(T value){
        int home = firstHash(value),
            step = secondHash(value);

        while(getStatus(home) != Empty ) {
            if(getStatus(home) == Deleted) break;

            ++col;
            home +=step;
            if(home > size) home -= size;
        }
        table[home] = value;
    }
Esempio n. 3
0
	  // search function for double probing
		// See the private search function for pre- and post-conditions
		bool searchD(std::string key, int& subscript, char type)
		{
	    // initialize and set hashcode for key base on hashType
			int hash;    
			if (hashType == 'g') 
				hash = goodHash(key);
			else
			  hash = poorHash(key);

			int increment = secondHash(key);  // set increment to second Hashcode

			int pos = hash;         //set current pos to hash
			subscript = pos;

			temp_probe = 1;

			if (type == 's') // lookup
			{
				while(table[pos] != NULL) 
				{
					if (key.compare(table[pos]->getKey()) == 0) //found
			    {
						return true;
					}
					if (temp_probe >= TABLE_SIZE) // should not need to probe more the table_size times
					{
						is_full = true; 
						return false;
					}
					
					// check next spot
					pos = (pos + increment) %  TABLE_SIZE;
					subscript = pos;
					temp_probe++;
					
				}
				return false;
			}
			else // insert case
			{
				while(table[pos] != NULL && ((table[pos]->getValue()) != -1)) // a value of -1 is 
				                                                                    // the tombstone
		    {
					if (key.compare(table[pos]->getKey()) == 0) //found
					{
						return true;
					}
					if (temp_probe >= TABLE_SIZE) // should not need to probe more the table_size times
					{
						is_full = true;  
						return false;
					}
					
					// check next spot
					pos = (pos + increment) %  TABLE_SIZE;
					subscript = pos;
					temp_probe++;
				}
				return false;
			}
		}