Exemplo n.º 1
0
void
HashGrid::addHitPoint(HitInfo* hi){
	// Vector3 BMin = ((hi->P - initialRadius) - minBVHCorner) * scale;
	// Vector3 BMax = ((hi->P + initialRadius) - minBVHCorner) * scale;
	Vector3 BMin = hi->P - initialRadius;
	Vector3 BMax = hi->P + initialRadius;
	// for (int iz = abs(int(BMin.z)); iz <= abs(int(BMax.z)); iz++) {
	// 	for (int iy = abs(int(BMin.y)); iy <= abs(int(BMax.y)); iy++) {
	// 		for (int ix = abs(int(BMin.x)); ix <= abs(int(BMax.x)); ix++) {

	// int intBMinz = static_cast<int>(BMin.z);
	// int intBMiny = static_cast<int>(BMin.y);
	// int intBMinx = static_cast<int>(BMin.x);
	// int intBMaxz = static_cast<int>(BMax.z);
	// int intBMaxy = static_cast<int>(BMax.y);
	// int intBMaxx = static_cast<int>(BMax.x);


	for (int iz = static_cast<int>(BMin.z); iz <= static_cast<int>(BMax.z); iz++) {
		if(iz < minBVHCorner.z) continue;
		for (int iy = static_cast<int>(BMin.y); iy <= static_cast<int>(BMax.y); iy++) {
			if(iy < minBVHCorner.y) continue;
			for (int ix = static_cast<int>(BMin.x); ix <= static_cast<int>(BMax.x); ix++) {
				if(ix < minBVHCorner.x) continue;
				unsigned int hv = doHash(ix,iy,iz); 
				hash[hv]->push_front(hi);
			}
		}
	}
}
Exemplo n.º 2
0
    void rehash()
    {
        // grow the number of buckets by 60%
        const size_type     theNewSize = size_type(1.6 * size());
        assert(theNewSize != 0);

        BucketTableType     temp(
            theNewSize,
            BucketType(*m_memoryManager),
            *m_memoryManager);

        // rehash each entry assign to bucket and insert into list
        EntryListIterator   entryPos = m_entries.begin();

        while (entryPos != m_entries.end())
        {
            const size_type     index =
                doHash(
                    entryPos->value->first,
                    theNewSize);

            temp[index].push_back(entryPos);

            ++entryPos;
        }

        // Now that we've rebuilt the buckets, swap the rebuilt
        // buckets with our existing buckets.
        m_buckets.swap(temp);
    }
Exemplo n.º 3
0
QT_BEGIN_NAMESPACE

uint qHash(const String &str)
{
    const unsigned short *p = (unsigned short *)str.constData();
    const int s = str.size();
    switch (s) {
        case 0: return 0;
        case 1: return *p;
        case 2: return *(unsigned int *)p;
        case 3: return (*(unsigned int *)p) ^ *(p + 2);
        //case 3: return (*p << 11) + (*(p + 1) << 22) + *(p + 2);
    }
    uint h = 0;
    doHash(p, h);
    doHash(p + s / 2 - 2, h);
    doHash(p + s - 4, h);
    return h;
}
Exemplo n.º 4
0
    iterator doCreateEntry(const key_type & key, const data_type*  data = 0)
    {
        // if there are no buckets, create initial minimum set of buckets
        if (m_buckets.empty())
        {
            m_buckets.insert(
                m_buckets.begin(),
                m_minBuckets,
                BucketType(*m_memoryManager));
        }

        // if the load factor has been reached, rehash
        if (size_type(m_loadFactor * size()) > m_buckets.size())
        {
            rehash();
        }

        const size_type     index = doHash(key);

        if (m_freeEntries.empty())
        {
            m_freeEntries.push_back(Entry(allocate(1)));
        }

        // insert a new entry as the first position in the bucket
        Entry&  newEntry = m_freeEntries.back();
        newEntry.erased = false;

        FirstConstructor::construct(
            const_cast<key_type*>(&newEntry.value->first),
            key,
            *m_memoryManager);

        if (data != 0)
        {
            SecondConstructor::construct(
                &newEntry.value->second,
                *data,
                *m_memoryManager);
        }
        else
        {
            SecondConstructor::construct(
                &newEntry.value->second,
                *m_memoryManager);
        }

        m_entries.splice(m_entries.end(), m_freeEntries, --m_freeEntries.end());

        m_buckets[index].push_back(--m_entries.end());

        ++m_size;

        return iterator(--m_entries.end());
    }
Exemplo n.º 5
0
int main(int argc, char *argv[]) {
    char temp[100];

    if (argc>1) {

        strncpy(temp,argv[1],100);

        temp[99] = '\0';    // Forced termination

        if (strlen(temp)>0)
            printf("Passcode for %s is %d\n",temp,doHash(temp));

    } else
        printf("Usage:callpass <callsign>\n");

    return(0);
}
Exemplo n.º 6
0
    iterator find(const key_type& key)
    {
        if (m_size != 0)
        {
            assert(m_buckets.empty() == false);

            const size_type     index = doHash(key);
            assert(index < m_buckets.size());

            BucketType&     bucket = m_buckets[index];
            BucketIterator  pos = bucket.begin();

            while (pos != bucket.end())
            {
                if (!(*pos)->erased && m_equals(key, (*pos)->value->first))
                {
                    return iterator(*pos);
                }
                ++pos;
            }
        }

        return end();
    }
Exemplo n.º 7
0
std::list<HitInfo*>
HashGrid::lookup(Vector3 position) {
	unsigned int index = doHash(position.x, position.y, position.z);
	return lookup(index);
}
Exemplo n.º 8
0
 size_type doHash(const Key & key) const
 {
     return doHash(key, m_buckets.size());
 }
Exemplo n.º 9
0
short checkHash(char *theCall, short theHash) {
    return (short)(doHash(theCall) == theHash);
}