Exemplo n.º 1
0
 void operator()(SV **&sp, HashTable &result) {
     EXTEND(sp, result.length() * 2);
     for (HashTableIterator it = result.begin(); it != result.end(); ++it) {
         PUSHs(String((*it).first).dispose());
         PUSHs((*it).second);
     }
 }
const filmPyrolysisRadiativeCoupledMixedFvPatchScalarField::
pyrolysisModelType&
filmPyrolysisRadiativeCoupledMixedFvPatchScalarField::
pyrModel() const
{
    HashTable<const pyrolysisModelType*> models =
        db().time().lookupClass<pyrolysisModelType>();

    forAllConstIter(HashTable<const pyrolysisModelType*>, models, iter)
    {
        if (iter()->regionMesh().name() == pyrolysisRegionName_)
        {
            return *iter();
        }
    }

    FatalErrorIn
    (
        "const filmPyrolysisRadiativeCoupledMixedFvPatchScalarField::"
        "pyrolysisModelType& "
        "filmPyrolysisRadiativeCoupledMixedFvPatchScalarField::"
        "pyrModel() const"
    )
        << "Unable to locate pyrolysis region " << pyrolysisRegionName_
        << abort(FatalError);

    return **models.begin();
}
void Foam::distributedTriSurfaceMesh::distributeFields
(
    const mapDistribute& map
)
{
    typedef DimensionedField<Type, triSurfaceGeoMesh> DimensionedSurfField;

    HashTable<DimensionedSurfField*> fields
    (
        objectRegistry::lookupClass<DimensionedSurfField>()
    );

    for
    (
        typename HashTable<DimensionedSurfField*>::iterator fieldIter =
            fields.begin();
        fieldIter != fields.end();
        ++fieldIter
    )
    {
        DimensionedSurfField& field = *fieldIter();

        label oldSize = field.size();

        map.distribute(field);

        if (debug)
        {
            Info<< "Mapped " << field.typeName << ' ' << field.name()
                << " from size " << oldSize << " to size " << field.size()
                << endl;
        }
    }
}
bool StaticHashTableBuilder::generateHashCode (FILE * out, const std::string& typeName) {
	if (mHashes.empty()) return false;
	int mod = calcBestModulus();
	HashTable table;
	calcHashTable(mod, &table);

	// Lookup structure
	fprintf (out, "\t// hash table lookup structure\n");
	fprintf (out, "\tconst int hashTable[] = {0");
	{
		int current     = table[0].size() + 1; // + null element
		int nullElement = table[0].size();
		for (int i = 1; i < mod; i++) {
			if (table[i].empty()){
				fprintf (out, ", %d", nullElement); // just point to null element
			} else {
				fprintf (out, ", %d", current);     // full entry.
				current+=table[i].size() + 1;
			}
		}
		fprintf (out, "};\n");
	}

	// Table
	fprintf (out, "\t// hash table\n");
	fprintf (out, "\tstruct HashEntry { const char * name; %s value; };\n", typeName.c_str());
	fprintf (out, "\tconst HashEntry entries[] = {\n");
	bool firstOutElement = true;
	bool firstInElement  = true;
	for (HashTable::const_iterator i = table.begin(); i != table.end(); i++){
		if (!firstInElement && i->empty()) continue;
		for (std::vector<StaticHashTableBuilder::KeyValue>::const_iterator j = i->begin(); j != i->end(); j++){
			fprintf (out, "\t\t");
			if (!firstOutElement) { fprintf (out, ","); }
			firstOutElement = false;
			fprintf (out, "{\"%s\", %s}\n", j->first.c_str(), j->second.c_str());
		}
		fprintf (out, "\t\t");
		if (!firstOutElement) { fprintf (out, ","); }
		firstOutElement = false;
		fprintf (out, "{0, %s()}\n", typeName.c_str());
		firstInElement = false;
	}
	fprintf (out, "\t};\n");

	// Lookup function
	fprintf (out, "\t// lookup\n");
	fprintf (out, "\t%s value;\n", typeName.c_str());
	fprintf (out, "\tbool foundKey = false;\n");
	fprintf (out, "\tint hashCode = sf::hash ((unsigned char*) key) %% %d;\n", mod);
	fprintf (out, "\tconst HashEntry * entry = entries + hashTable[hashCode];\n");
	fprintf (out, "\twhile (entry->name != 0){\n");
	fprintf (out, "\t\tif(strcmp (entry->name, key) == 0) {value = entry->value; foundKey = true; break; }\n");
	fprintf (out, "\t\tentry++;\n");
	fprintf (out, "\t}\n");
	return true;
}
Exemplo n.º 5
0
void free_hashtab(HashTable &hashtab) {
    llist* temp;
    for ( auto it = hashtab.begin(); it != hashtab.end(); ++it ) {
        while(it->second!=NULL) {
            temp=it->second;
            it->second = it->second->next;
            delete temp;
        }
    }
}
Exemplo n.º 6
0
void collisionTest() {
    printf("test collision add/remove\n");
    
    HashTable<int,collisionHash,intEqual> collisiontable;
    for(int i=0;i<100;i++) {
	collisiontable.add(i);
    }
    for(int i=0;i<100;i+=2) {
	collisiontable.remove(i);
	size_t count = 0;
	for (HashTable<int,collisionHash,intEqual>::iterator i = collisiontable.begin();
	     i != collisiontable.end();i++) {
	    count++;
	}
	INVARIANT(count == collisiontable.size(),
		  boost::format("?! %d %d") % count % collisiontable.size());
    }

    // multiple adds of the same key are *supposed* to add multiple times.
    collisiontable.clear();
    SINVARIANT(collisiontable.size() == 0);
    for(int i=0;i<100;i++) {
	collisiontable.add(i);
	collisiontable.add(i);
    }
    SINVARIANT(collisiontable.size() == 200);

    // remove the keys (each twice)
    for(int i=0;i<100;i++) {
	collisiontable.remove(i, true);
	collisiontable.remove(i, true);
    }
    SINVARIANT(collisiontable.size() == 0);

    // an efficient way to do add/replace
    collisiontable.clear();
    SINVARIANT(collisiontable.size() == 0);
    for(int i=0;i<100;i++) {
	bool replaced;
	collisiontable.addOrReplace(i, replaced);
	SINVARIANT(replaced == false);
	collisiontable.addOrReplace(i, replaced);
	SINVARIANT(replaced == true);
    }
    SINVARIANT(collisiontable.size() == 100);

    // remove, add, remove the keys
    for(int i=0;i<100;i++) {
	collisiontable.remove(i, true);
	collisiontable.add(i);
	collisiontable.remove(i);
    }
    SINVARIANT(collisiontable.size() == 0);
}
Exemplo n.º 7
0
void print_hashtab(const HashTable &hashtab) {
    llist* temp;
    for ( auto it = hashtab.begin(); it != hashtab.end(); ++it ) {
        std::cout << it->first << ":";
        temp=it->second;
        while(temp!=NULL) {
            std::cout <<"--> [ " << temp->readid << "," << temp->pos <<" ] " ;
            temp=temp->next;
        }
        std::cout << "\n";
    }
}
Exemplo n.º 8
0
int main()
{
	string s;
	HashTable ht;
	HashTable::iterator it = ht.begin();
	ht.Add("pumpururum");
	ht.Add("12345");
	ht.Add("80931283");
	ht.Add("uieiuf");
	cout << ht.Size() << endl;
	system("pause");
	return 0;
}
Exemplo n.º 9
0
static bool dumpEngineDocs( const char *outputFile )
{
   // Create the output stream.
   FileStream stream;
   if ( !stream.open( outputFile, Torque::FS::File::Write ) )
   {
      Con::errorf( "dumpEngineDocs - Failed to open output file." );
      return false;
   }

   // First dump all global ConsoleDoc fragments.
   
   for( ConsoleDocFragment* fragment = ConsoleDocFragment::smFirst; fragment != NULL; fragment = fragment->mNext )
      if( !fragment->mClass )
         dumpFragment( stream, fragment );
   
   // Clear the doc groups before continuing,
   smDocGroups.clear();
   
   // Dump enumeration types.
   dumpEnums( stream );
   
   // Dump all global variables.
   dumpVariables( stream );

   // Now dump the global functions.
   Namespace *g = Namespace::find( NULL );
   while( g ) 
   {
      dumpNamespaceEntries( stream, g );
      
      // Dump callbacks.
      dumpGroupStart( stream, "Callbacks" );
      dumpNamespaceEntries( stream, g, true );
      dumpGroupEnd( stream );

      g = g->mParent;
   }

   // Now dump all the classes.
   dumpClasses( stream );

   // Dump pre-declarations for any groups we encountered
   // so that we don't have to explicitly define them.
   HashTable<String,U32>::Iterator iter = smDocGroups.begin();
   for ( ; iter != smDocGroups.end(); iter++ )
      stream.writeText( String::ToString( "/*! @addtogroup %s */\r\n\r\n", iter->key.c_str() ) );

   return true;
}
Exemplo n.º 10
0
int main()
{
    HashTable mHash; // C++ hash table
    mHash["Mike C"] = 1234;
    mHash["Charlie M"] = 5678;
    
    mHash.insert(make_pair("peter q", 3456));

    cout << "Hash Table size: " << mHash.size() << endl;

    for(HashTable::iterator hIter= mHash.begin(); hIter != mHash.end(); ++hIter)
    {
	cout << hIter->first << " : " << hIter->second << endl;
    }

    return 0;
}
Exemplo n.º 11
0
static const char* test_iterator()
{
    HashTable<int, int> tmp;
    size_t cnt = 0;

    for (HashTable<int, int>::iterator it = tmp.begin();
         it != tmp.end(); ++it)
    {
        ++cnt;
    }
    KJSD_CUNIT_ASSERT(cnt == 0);

    cnt = 0;
    for (HashTable<int, int>::iterator it = htv_->begin();
         it != htv_->end(); ++it)
    {
        ++cnt;
    }
    KJSD_CUNIT_ASSERT(cnt == NUM_OF_TESTELEMENT);

    cnt = 0;
    for (HashTable<string, int>::iterator it = htc_->begin();
         it != htc_->end(); ++it)
    {
        ++cnt;
    }
    KJSD_CUNIT_ASSERT(cnt == NUM_OF_TESTELEMENT);

    cnt = 0;
    for (HashTable<const char*, int>::iterator it = htp_->begin();
         it != htp_->end(); ++it)
    {
        ++cnt;
    }
    KJSD_CUNIT_ASSERT(cnt == NUM_OF_TESTELEMENT);

    HashTable<int, int>::iterator it = htv_->begin();
    int v = (*(it++)).second;
    KJSD_CUNIT_ASSERT(v != (*it).second);

    v = (*(++it)).second;
    KJSD_CUNIT_ASSERT(v == (*it).second);
    return 0;
}
void printFreq(WorkerThread* threads, int cpus, float totalCount) {
    HashTable<KEY_SIZE> sum;
    for (int i=0; i<cpus; i++) {
        merge_table(sum, *((HashTable<KEY_SIZE>*)threads[i].hashByLength(KEY_SIZE)));
    }

    typedef std::pair< Key<KEY_SIZE>, uint32_t > hash_pair_t;
    std::vector<hash_pair_t> list(sum.begin(), sum.end());
    std::sort(list.begin(), list.end(), greater_second<hash_pair_t>());

    for (typename std::vector<hash_pair_t>::iterator it = list.begin(); it < list.end(); ++it) {
        char key[KEY_SIZE+1];
        for (int i=0; i<KEY_SIZE; i++) key[i] = toupper((*it).first.key[i]);
        key[KEY_SIZE] = 0;
        printf("%s %.3f\n", key, (float)((*it).second) * 100.0f / totalCount);
    }
    printf("\n");

}
Exemplo n.º 13
0
 virtual void printResult() {
     printf("Begin-%s\n",__PRETTY_FUNCTION__);
     vector<hteData *> vals;
     for (HashTable<hteData, hteHash, hteEqual>::iterator i = stats_table.begin();
         i != stats_table.end();++i) {
         vals.push_back(&(*i));
     }
     sort(vals.begin(),vals.end(),sortByType());
     for (vector<hteData *>::iterator i = vals.begin();
         i != vals.end();++i) {
         hteData *j = *i;
         printf("%10s %ld ents, %.2f MB total size, %.2f kB avg size, %.0f max bytes\n",
                j->type.c_str(),
                j->file_size->count(),
                j->file_size->total() / (1024*1024.0),
                j->file_size->mean() / (1024.0),
                j->file_size->max());
     }
     printf("End-%s\n",__PRETTY_FUNCTION__);
 }
Exemplo n.º 14
0
	HashTable(const HashTable& hash_table) : hasher(), n(0), table(*(new table_type(hash_table.Size())))
	{
		for (hash_iterator_type it = hash_table.begin(); it != hash_table.end(); ++it)
			Add(*it);
	}
void merge_table(HashTable<KEY_SIZE>& dest, HashTable<KEY_SIZE>& src) {
    for (typename HashTable<KEY_SIZE>::iterator it = src.begin(); it != src.end(); ++it) {
        dest[(*it).first] += (*it).second;
    }
}
Exemplo n.º 16
0
void character_histogram()
{
	HashTable<char, long long> ht;
	std::ifstream input("/home/jacob/Documents/Eclipse Workspace/C++/GenericDataStructures/test_files/PG-MobyDick.txt");
	char c;
	if(input.is_open())
	{
		while(input.get(c))
		{
			if(ht.contains(c))
			{
				ht[c]+=1;
			}
			else
			{
				ht[c] = 1;
			}
		}
	}
	ht.remove('c');
	HashTable<char, long long>::iterator it = *ht.begin();
	while(it.pos() < it.end())
	{
		//std::cout<<"'"<< it.key()<<"'" << "=>"<< it.value() << std::endl;
		it++;
	}
	it--;
	while(it.pos() >= it.begin())
	{
		//std::cout<<"'"<< it.key()<<"'" << "=>"<< it.value() << std::endl;
		it--;
	}

	MinHeap<huff_node*> heap1;
	HashTable<char, long long>::iterator it2 = *ht.begin();
	while(it2.pos() < it2.end())
	{
		huff_node * node = new huff_node;
		node->c = it2.key();
		node->freq = it2.value();
		node->is_leaf = true;
		heap1.insert(node);
		it2++;
	}

	while(heap1.size() > 2)
	{
		huff_node *left = heap1.remove_min(), *right = heap1.remove_min(), *new_node= new huff_node;
		new_node->is_leaf = false;
		new_node->freq = left->freq + right->freq;
		new_node->left = left;
		new_node->right = right;
		heap1.insert(new_node);
	}
	huff_node *left = heap1.remove_min(), *right = heap1.remove_min(), *root= new huff_node;
	root->is_leaf = false;
	root->freq = left->freq + right->freq;
	root->left = left;
	root->right = right;
	//HashTable<char, long long>::iterator it3 = *ht.begin();
	//root is a huffman tree, could be traversed to create a compression algorithm
}
Exemplo n.º 17
0
void setUpdater::updateSets(const mapPolyMesh& morphMap) const
{
    //
    // Update all sets in memory.
    //

    HashTable<const Type*> memSets = 
        morphMap.mesh().objectRegistry::lookupClass<Type>();

    for
    (
        typename HashTable<const Type*>::iterator iter = memSets.begin();
        iter != memSets.end();
        ++iter
    )
    {
        Type& set = const_cast<Type&>(*iter());

        if (debug)
        {
            Pout<< "Set:" << set.name() << " size:" << set.size()
                << " updated in memory" << endl;
        }

        set.updateMesh(morphMap);

        // Write or not? Debatable.
        set.write();
    }


    //
    // Update all sets on disk
    //

    // Get last valid mesh (discard points-only change)
    IOobjectList Objects
    (
        morphMap.mesh().time(),
        morphMap.mesh().time().findInstance
        (
            morphMap.mesh().meshDir(),
            "faces"
        ),
        "polyMesh/sets"
    );

    IOobjectList fileSets(Objects.lookupClass(Type::typeName));

    for
    (
        IOobjectList::const_iterator iter = fileSets.begin();
        iter != fileSets.end();
        ++iter
    )
    {
        if (!memSets.found(iter.key()))
        {
            // Not in memory. Load it.
            Type set(*iter());

            if (debug)
            {
                Pout<< "Set:" << set.name() << " size:" << set.size()
                    << " updated on disk" << endl;
            }

            set.updateMesh(morphMap);

            set.write();
        }
        else
        {
            if (debug)
            {
                Pout<< "Set:" << iter.key() << " already updated from memory"
                    << endl;
            }
        }
    }
}