// Document Word Frequency

#include "dw_frequency.h"

cDWF::cDWF()
{
}

cDWF::~cDWF()
{
}


int cDWF::AddOccur(const std::string & str)
{
    ISR::WordMap::iterator i;
       
    i = mOccur.find(str);    
   
    // if it wasnt found in the map, add it, otherwise increment its occurance
    if ( i == mOccur.end() )
      mOccur[str] = 1;
    else
     i->second++;
     
    return i->second;
}

int cDWF::SubOccur( const std::string & str)
{
    ISR::WordMap::iterator i;
    
    i = mOccur.find(str);
    
    // if it wasnt found in the map return 0, otherwise decrement its occurance
    if ( i == mOccur.end() )
     return 0;
    else
    {
     i->second--;
     
     if ( i->second <= 0 ) // remove from table?
     {
       mOccur.erase(i);
       return 0;
     }
    }
    
    return i->second;
}

// Return number of references to a certain string
int cDWF::GetOccur( const std::string & str)
{
    ISR::WordMap::iterator i;
    
    i = mOccur.find(str);
    
    // if it wasnt found in the map, add it, otherwise increment its occurance
    if ( i == mOccur.end() )
     return 0;
    
    return i->second;
}