Ejemplo n.º 1
0
// Adds key and move into the hashtable. This function assumes that the key has
// been checked with get and is not in the table.
void Hash::add(Board &b, uint64_t data, int depth, uint8_t age) {
    uint64_t h = b.getZobristKey();
    uint64_t index = h & (size-1);
    HashNode *node = table + index;

    // Decide whether to replace the entry
    // A more recent update to the same position should always be chosen
    if ((node->slot1.zobristKey ^ node->slot1.data) == b.getZobristKey())
        node->slot1.setEntry(b, data);
    
    else if ((node->slot2.zobristKey ^ node->slot2.data) == b.getZobristKey())
        node->slot2.setEntry(b, data);
    
    // Replace an entry from a previous search space, or the lowest
    // depth entry with the new entry if the new entry's depth is higher
    else {
        HashEntry *toReplace = NULL;
        int score1 = 128*((int) (age - getHashAge(node->slot1.data)))
            + depth - getHashDepth(node->slot1.data);
        int score2 = 128*((int) (age - getHashAge(node->slot2.data)))
            + depth - getHashDepth(node->slot2.data);
        if (score1 >= score2)
            toReplace = &(node->slot1);
        else
            toReplace = &(node->slot2);
        // The node must be from a newer search space or be a
        // higher depth if from the same search space.
        if (score1 < -2 && score2 < -2)
            toReplace = NULL;

        if (toReplace != NULL) 
            toReplace->setEntry(b, data);
    }
}
Ejemplo n.º 2
0
unsigned int HashMap::setValue(string key)
{
    unsigned long hash = this->hashFunction(key, this->lengthM);
    if (this->hashNodes[hash] == NULL)
    {
        this->hashNodes[hash] = new HashEntry(key);
        return 1;   // first occurance
    }
    else 
    {
        HashEntry* nextNode = this->hashNodes[hash];
        while (nextNode != NULL) 
        {
            if (nextNode->getKey().compare(key) == 0)
            {
                nextNode->incrementCounter();
                return nextNode->getValue();
            }
            if (nextNode->nextM == NULL)
            {
                nextNode->nextM = new HashEntry(key);
                return 1;   // first occurance
            }
            else nextNode = nextNode->nextM;
        }
    }
}
Ejemplo n.º 3
0
void UploadXML::Found(const char *name,double lat,double lon)
{
	WPVERIFY_DEF *f;
	HashEntry *he;
	int h,hh;

#if 0
	f=(WPVERIFY_DEF *)m_names.Find(name);
	if(f)
	{
		if(fabs(f->lat-lat)<0.0001f && fabs(f->lon-lon)<0.0001f)
		{
			f->found=true;
			return;
		}
	}
#endif

	/* no direct name match, so scan through and find */

	he=m_names.GetFirst();
	hh=m_names.GetNum();
	for(h=0;h<hh;++h)
	{
		f=(WPVERIFY_DEF *)he->m_data;
		if(fabs(f->lat-lat)<0.0001f && fabs(f->lon-lon)<0.0001f)
		{
			f->found=true;
		//	return;
		}
		he=he->GetNext();
	}

	/* this point is not one we downloaded */
}
Ejemplo n.º 4
0
void HashMap::Add(ReadSequence *rs)
{
    uint32_t rid_hash = _GetHash((*rs).readID) % this->size;

    HashEntry *h = new HashEntry(rid_hash);
    h->SetValue(rs);

    if(this->Get(rs) == NULL)
    {
        this->_map[rid_hash]->push_back(h);
        this->item_count++;
    }
}
Ejemplo n.º 5
0
// stringer
string Hashmap::toString() {
	int i = 0;
	stringstream ss;
	HashEntry * entry;
	for (i = 0; i < size; i += 1) {
		if (entries[i]) {
			for (entry = entries[i]; entry; entry = entry->next) {
				ss << "[" << i << "] - " << entry->toString() << "\n";
			}
		}
	}

	return ss.str();
}
Ejemplo n.º 6
0
unsigned int HashMap::getValue(string key)
{
    unsigned long hash = this->hashFunction(key, this->lengthM);
    HashEntry* nextNode = this->hashNodes[hash];
    while (nextNode != NULL)
    {
        if (nextNode->getKey().compare(key) == 0)
        {
            return nextNode->getValue();
        }
        else nextNode = nextNode->nextM;
    }
    return 0;
}
void HashTable::createTable(VM* vm) const
{
    ASSERT(!table);
    int linkIndex = compactHashSizeMask + 1;
    HashEntry* entries = new HashEntry[compactSize];
    for (int i = 0; i < compactSize; ++i)
        entries[i].setKey(0);
    for (int i = 0; values[i].key; ++i) {
        StringImpl* identifier = Identifier::add(vm, values[i].key).leakRef();
        int hashIndex = identifier->existingHash() & compactHashSizeMask;
        HashEntry* entry = &entries[hashIndex];

        if (entry->key()) {
            while (entry->next()) {
                entry = entry->next();
            }
            ASSERT(linkIndex < compactSize);
            entry->setNext(&entries[linkIndex++]);
            entry = entry->next();
        }

        entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2, values[i].intrinsic);
    }
    table = entries;
}
Ejemplo n.º 8
0
void HashTable::createTable(JSGlobalData* globalData) const
{
    ASSERT(!table);
    int linkIndex = compactHashSizeMask + 1;
    HashEntry* entries = new HashEntry[compactSize];
    for (int i = 0; i < compactSize; ++i)
        entries[i].setKey(0);
    for (int i = 0; values[i].key; ++i) {
        StringImpl* identifier = Identifier::add(globalData, values[i].key).leakRef();
        int hashIndex = identifier->existingHash() & compactHashSizeMask;
        HashEntry* entry = &entries[hashIndex];

        if (entry->key()) {
            while (entry->next()) {
                entry = entry->next();
            }
            ASSERT(linkIndex < compactSize);
            entry->setNext(&entries[linkIndex++]);
            entry = entry->next();
        }

        entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2
#if ENABLE(JIT)
                          , values[i].generator
#if ENABLE(DFG_JIT)
                          , values[i].intrinsic
#endif
#endif
                          );
    }
    table = entries;
}
Ejemplo n.º 9
0
nsresult
nsCommandParams::GetOrMakeEntry(const char * name, PRUint8 entryType, HashEntry*& outEntry)
{

  HashEntry *foundEntry = (HashEntry *)PL_DHashTableOperate(&mValuesHash, (void *)name, PL_DHASH_LOOKUP);
  if (PL_DHASH_ENTRY_IS_BUSY(foundEntry))   // reuse existing entry  
  {
    foundEntry->Reset(entryType);
    foundEntry->mEntryName.Assign(name);
    outEntry = foundEntry;
    return NS_OK;
  }

  foundEntry = (HashEntry *)PL_DHashTableOperate(&mValuesHash, (void *)name, PL_DHASH_ADD);
  if (!foundEntry) return NS_ERROR_OUT_OF_MEMORY;
  
  // placement new that sucker. Our ctor does not clobber keyHash, which is important.
  outEntry = new (foundEntry) HashEntry(entryType, name);  
  return NS_OK;
}
Ejemplo n.º 10
0
nsCommandParams::HashEntry*
nsCommandParams::GetOrMakeEntry(const char* aName, uint8_t entryType)
{
  HashEntry *foundEntry =
    (HashEntry *)PL_DHashTableSearch(&mValuesHash, (void *)aName);
  if (foundEntry) { // reuse existing entry
    foundEntry->Reset(entryType);
    return foundEntry;
  }

  foundEntry = static_cast<HashEntry*>
    (PL_DHashTableAdd(&mValuesHash, (void *)aName, fallible));
  if (!foundEntry) {
    return nullptr;
  }

  // Use placement new. Our ctor does not clobber keyHash, which is important.
  new (foundEntry) HashEntry(entryType, aName);
  return foundEntry;
}
Ejemplo n.º 11
0
void kGUIDb::UpdateLocks(void)
{
    int i,numtables;
    HashEntry *he;
    int *lcount;
    kGUIString ls;
    int numlocked;
    kGUIDbCommand *c;

    if(m_lockschanged==false)
        return;

    c=new kGUIDbCommand(this,"UNLOCK TABLES;");
    delete c;

    numlocked=0;
    numtables=m_lockedtables.GetNum();
    he=m_lockedtables.GetFirst();
    ls.SetString("LOCK TABLES ");
    for(i=0; i<numtables; ++i)
    {
        lcount=(int *)(he->m_data);	/* get data pointer */
        if(lcount[0])
        {
            if(numlocked)
                ls.Append(", ");
            ls.ASprintf("%s WRITE",he->m_string);
            ++numlocked;
        }
        he=he->GetNext();
    }
    if(numlocked)
    {
        ls.Append(";");
        c=new kGUIDbCommand(this,ls.GetString());
        delete c;
    }
    m_lockschanged=false;
}
Ejemplo n.º 12
0
int UploadXML::GetNotFound(kGUIString *s)
{
	WPVERIFY_DEF *f;
	HashEntry *he;
	int h,hh;
	int notfound;

	notfound=0;
	he=m_names.GetFirst();
	hh=m_names.GetNum();
	for(h=0;h<hh;++h)
	{
		f=(WPVERIFY_DEF *)he->m_data;
		if(f->found==false)
		{
			s->ASprintf("%s\n",he->m_string);
			++notfound;
		}
		he=he->GetNext();
	}
	return(notfound);
}
Ejemplo n.º 13
0
void HashMap::sortHash(unsigned int size, MostRepeatedWord* words)
{
    for (int i = 0; i < size; i++) 
    {
        words[i].occurance = 0;
        words[i].word = "";
    }

    // every hash root
    for (int i = 0; i < this->lengthM; i++)
    {
        HashEntry* node = this->hashNodes[i];
        // every 'collided' node
        while(node != NULL) 
        {
            for (int j = 0; j < size; j++) 
            {
                if (node->getValue() > words[j].occurance) 
                {
                    // this loop offsets the remaining most frequent words to the right
                    for (int k = size - 1; k > j; k--) 
                    {
                        words[k].occurance = words[k - 1].occurance;
                        words[k].word = words[k - 1].word;
                    }
                    // afterwards, add the frequent word in place
                    words[j].occurance = node->getValue();
                    words[j].word = node->getKey();
                    break;
                }
            }
            if (node->nextM != NULL) node = node->nextM;
            else break;
        }
    }
}
Ejemplo n.º 14
0
void HashTable::createTable(JSGlobalData* globalData) const
{
#if ENABLE(PERFECT_HASH_SIZE)
    ASSERT(!table);
    HashEntry* entries = new HashEntry[hashSizeMask + 1];
    for (int i = 0; i <= hashSizeMask; ++i)
        entries[i].setKey(0);
    for (int i = 0; values[i].key; ++i) {
        UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
        int hashIndex = identifier->computedHash() & hashSizeMask;
        ASSERT(!entries[hashIndex].key());
        entries[hashIndex].initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
    }
    table = entries;
#else
    ASSERT(!table);
    int linkIndex = compactHashSizeMask + 1;
    HashEntry* entries = new HashEntry[compactSize];
    for (int i = 0; i < compactSize; ++i)
        entries[i].setKey(0);
    for (int i = 0; values[i].key; ++i) {
        UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
        int hashIndex = identifier->computedHash() & compactHashSizeMask;
        HashEntry* entry = &entries[hashIndex];

        if (entry->key()) {
            while (entry->next()) {
                entry = entry->next();
            }
            ASSERT(linkIndex < compactSize);
            entry->setNext(&entries[linkIndex++]);
            entry = entry->next();
        }

        entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
    }
    table = entries;
#endif
}