TopicCounts Struct Reference

#include <TopicCounts.h>

List of all members.

Public Member Functions

 TopicCounts ()
 TopicCounts (int length)
 TopicCounts (cnt_topic_t *it, int len)
 TopicCounts (const std::string &counts)
void init (cnt_topic_t *it, int len)
void init (const std::string &counts)
 ~TopicCounts ()
void assign (int length, bool setLen=true)
void setLength (int length_)
void findOldnNew (topic_t oldTopic, topic_t newTopic, topic_t **oldTop, topic_t **newTop)
int get_frequency ()
cnt_t get_counts (topic_t topic)
int convertTo (mapped_vec &map, int mult=1) const
void convertTo (simple_map &map, int mult=1) const
void convertTo (std::string &counts) const
int convertTo_d (mapped_vec &map, double mult) const
bool findAndIncrement (topic_t topic)
bool findAndDecrement (topic_t topic)
void compact ()
void addNewTop (topic_t topic, cnt_t count=1)
void addNewTopAftChk (topic_t topic, cnt_t count=1)
void upd_count (mapped_vec &delta, tbb::atomic< topic_t > *t=NULL)
void operator+= (TopicCounts &inp)
void operator-= (TopicCounts &inp)
void removeOldTop (topic_t ind, cnt_topic_t &ct)
void replace (TopicCounts &tc)
void decrement (topic_t ind, topic_t **newTop)
void increment (topic_t ind)
std::string print ()
 TopicCounts (mapped_vec &map)
bool equal (const TopicCounts &expected)

Public Attributes

cnt_topic_t * items
topic_t length
topic_t origLength
std::vector< cnt_topic_t > vec_items
int frequency
bool QUIT

Constructor & Destructor Documentation

TopicCounts::TopicCounts (  ) 
TopicCounts::TopicCounts ( int  length  ) 

Typical constructor usage. Constructs a TopicCounts structure which can hold length elements. However, this is a dynamic structure and length can change in the process of usage by the use of setter methods This also allocates sufficient storage to store length elements

TopicCounts::TopicCounts ( cnt_topic_t *  it,
int  len 
)

Constructs TopicCounts from it & len

TopicCounts::TopicCounts ( const std::string &  counts  ) 
TopicCounts::~TopicCounts (  ) 
TopicCounts::TopicCounts ( mapped_vec map  ) 

Initialize the structure from the map This is only for testing purposes and should be used with caution.


Member Function Documentation

void TopicCounts::addNewTop ( topic_t  topic,
cnt_t  count = 1 
)

Adds a new topic to the array making sure to resize it if required. Doesn't check for uniqueness Also assumes that memory allocation has happened

void TopicCounts::addNewTopAftChk ( topic_t  topic,
cnt_t  count = 1 
)

Same as above but also checks if memory has been allocated. If not, tries to allocate memory. The check for allocated memory is not very robust as all the members are public and malicious users can set things such that it does not work.

void TopicCounts::assign ( int  length,
bool  setLen = true 
)

The function that allocates memory. origLength memory must be allocated since length can grow upto origLenth. It supports finer granularity access. You can disable the block aligment of lenth which is done by default using setLen if you have already made sure of this

void TopicCounts::compact (  ) 

Checks if there is memory wastage and tries to reduce it by compacting memory. It does compaction only when there are more than INIT_TC_SIZE + SUBSEQ_ALLOCS entries and there is at least INIT_TC_ZISE memory being wasted. In such a case, it compact SUBSEQ_ALLOCS of memory. Usually SUBSEQ_ALLOCS should be set to half of INIT_TC_SIZE

***** All pointers to items are invalid once this runs successfully. Use extra caution when you use this or some method which uses this *********

void TopicCounts::convertTo ( std::string &  counts  )  const
void TopicCounts::convertTo ( simple_map map,
int  mult = 1 
) const
int TopicCounts::convertTo ( mapped_vec map,
int  mult = 1 
) const

Stores a map representation of this vector into map. You can specify an optional multiplier to get a representation of (-1 * TC) or (2 * TC) where TC is the current structure. This multiplies count of each topic by the multiplier

int TopicCounts::convertTo_d ( mapped_vec map,
double  mult 
) const
void TopicCounts::decrement ( topic_t  ind,
topic_t **  newTop 
)

Used to decrement the count of the topic found at index ind by 1. Also takes care of repointing newTop if its position changes.

bool TopicCounts::equal ( const TopicCounts expected  ) 
bool TopicCounts::findAndDecrement ( topic_t  topic  ) 
bool TopicCounts::findAndIncrement ( topic_t  topic  ) 

If you want to increment the count of a topic by 1 without knowing the index, you can use this method. But usually increment and decrement are joint operations and you would not want to iterate through the entire array twice. Its advantageous to use the findOldnNew function and increment & decrement methods directly as in TypeTopicCounts::upd_count(word,oldTop,newTop)

void TopicCounts::findOldnNew ( topic_t  oldTopic,
topic_t  newTopic,
topic_t **  oldTop,
topic_t **  newTop 
)

Typical ways of creating TopicCounts: 1.TopicCounts(length) 2.TopicCounts();assign(length);init(items,length) 3.TopicCounts();assign(-1,false);init(items,length) Find oldTopic & newTopic positions in items and retun them in oldTop & newTop. Note that cnt_topic_t is a packed structure. So accessing either the topic or count individually will modify your pointer arithmetic by two

cnt_t TopicCounts::get_counts ( topic_t  topic  ) 
int TopicCounts::get_frequency (  ) 
void TopicCounts::increment ( topic_t  ind  ) 

Used to increment by 1 the count of an existing topic found at index ind. This assumes that the ind is in range and hence that the topic exists

void TopicCounts::init ( const std::string &  counts  ) 
void TopicCounts::init ( cnt_topic_t *  it,
int  len 
)

This assumes that sufficient memory has already been allocated to hold len elems and just copies them to items

void TopicCounts::operator+= ( TopicCounts inp  ) 

Convenience operators for syntactic sugar

void TopicCounts::operator-= ( TopicCounts inp  ) 

Convenience operators for syntactic sugar

std::string TopicCounts::print (  ) 
void TopicCounts::removeOldTop ( topic_t  ind,
cnt_topic_t &  ct 
)

Should be called when you know that ct.choose.cnt==1 or ct.choose.cnt-1==0. This will logically remove this entry from the array also taking care of repointing the newTop to the correct position once ct is removed. After length is decremented it is checked if compaction is needed and if so, SUBSEQ_ALLOCS of memory is compacted. The removal is simply a swap with the last element since the current count is 1 and the items array is always sorted in descending order and only has non-zero entries. Also all pointers to items are going to be invalid if compaction runs successfully.

****** Be extra careful while using this *******

void TopicCounts::replace ( TopicCounts tc  ) 

Replace the current counts with thos in tc

void TopicCounts::setLength ( int  length_  ) 

Block aligns the length and sets the origLength parameter to suit that. origLength is always INIT_TC + i*SUBSEQ_ALLOCS where i=0,1,2....

void TopicCounts::upd_count ( mapped_vec delta,
tbb::atomic< topic_t > *  t = NULL 
)

Update items with the delta counts passed as a map Also update n(t) simultaneously using t. Note that delta is modified because elements are removed from it. If you don't want this, create a copy and send it along. The strategy is to update items with the counts in delta in place and sort it finally.


Member Data Documentation

cnt_topic_t* TopicCounts::items
std::vector<cnt_topic_t> TopicCounts::vec_items

The documentation for this struct was generated from the following files:
Generated on Tue Jul 19 11:45:28 2011 for Y!LDA by  doxygen 1.6.3