bool WordBagImpl::getNextWord(string& word, int& count)
{
    string key;
    int* c = m_token->getNext(key);
    if (c == NULL)
        return false;
    else
    {
        word = key;
        count = *c;
        return true;
    }
}
bool WordBagImpl::getNextWord(string& word, int& count)
{
	int *getNextVal = m_map.getNext(word);

	if (getNextVal == nullptr)
		return false;

	else
	{
		count = *getNextVal;
		return true;
	}
}
Example #3
0
bool IndexerImpl::save(string filenameBase)
{
    ofstream outfile(filenameBase+".txt");
    if ( ! outfile )		 
	{
	    cerr << "Error: Cannot create data.txt!" << endl;
	    return false;
	}
    //Map to store locations to grab from array
    MyMap<int, int>* h2pull = new MyMap<int, int>;
    //Save size of urlToCount to outfile
    outfile << urlToCount->size() << endl;
    string word;
    vector<point>* value = urlToCount->getFirst(word);
    while (value!=NULL)
    {
        //save word and size of vector
        outfile << word << " " << value->size() << endl;
        vector<point>::iterator it = value->begin();
        while (it!=value->end())
        {
            int hash = it->m_hash;
            outfile << hash << " " << it->m_count << endl;
            h2pull->associate(hash%MAX_MAP_SIZE, hash%MAX_MAP_SIZE);
            it++;
        }
        value = urlToCount->getNext(word);
    }
    //Save size of h2pull (number of elements in array to visit)
    outfile << h2pull->size() << endl;
    int temp;
    int* location = h2pull->getFirst(temp);
    while (location!=NULL)
    {
        int size = idToUrl[temp]->size();
        outfile << temp << " " << size <<endl;
        int hash;
        string* url = idToUrl[temp]->getFirst(hash);
        while(url!=NULL)
        {
            outfile << hash << " "<< *url << endl;
            url = idToUrl[temp]->getNext(hash);
        }
        location = h2pull->getNext(temp);
    }
    
    delete h2pull;
    return true;
}
bool saveMyMap(string filename, MyMap<KeyType, ValueType>& m)
{
    // save contents of m to a file
    ofstream stream("filename");    // Create an ofstream object to create the file
    if (! stream) return false;     // Return false if we can't create the file
    writeItem(stream, m.size());    // Save the number of associations in m to stream
    KeyType x;
    ValueType* y = m.getFirst(x);
    for (int i = 0; i < m.size(); i++) {
        writeItem(stream, x);
        writeItem(stream, *y);
        y = m.getNext(x);
    }
    return true;
}