Octane v1.01.20 - The Open Compression Toolkit for C++ http://octane.sourceforge.net/
Homepage | Main | Modules | Class Hierarchy | Compound List | File List | Compound Members | Related Pages

SymbolWeightVector Class Reference

#include <symbolweightvector.hpp>

Inheritance diagram for SymbolWeightVector:

OctaneClass List of all members.

Detailed Description

The SymbolWeightVector class is a helper class which holds a vector of probabilities, typically associated with a modeler.

It provides basic functionality to save and load state and display debugging information, and report memory usage.

Definition at line 61 of file symbolweightvector.hpp.

Public Member Functions

 SymbolWeightVector ()
 constructor

virtual ~SymbolWeightVector ()
 destructor

virtual std::string GetName ()
 provide a unique name for the coder, used in some cases to automatically register the object with a manager

virtual std::string GetDescription ()
 optionally provide a longer (maybe 20-60 characters) description

virtual std::string GetHelpInformation ()
 optionally provide more information about the object on request for help

virtual void ShowDebuggingInfo ()
 show any debugging info on request (used by various derived classes) [optional]

virtual unsigned int GetMemoryUsed ()
 Report actual current memory usage (in bytes).

virtual unsigned int GetDiskspaceUsed (bool fortempdecompressiononly)
 Report disk space (in bytes) that would be used when saving state to file (in bytes).

virtual bool SaveState (bitwriter &to, bool fortempdecompressiononly)
 Save state of object to output stream (if appropriate).

virtual bool LoadState (bitreader &from)
 Load state of object from input stream (if appropriate).

void ResetWeights ()
 Reset all probabilities.

void NormalizeToProbabilityDistribution ()
 Normalize vector values into a probability distribution.

void SetSymbolCount (int newsize)
 Set the number of symbols we should store weights for; can be called at any time to shrink or grow size.

int GetSymbolCount ()
 Get count of symbols.

TSymbolWeightVectorWeight GetSymbolWeight (int index)
 Get the weight (probability or freq count) of a symbol.

void SetSymbolWeight (int index, TSymbolWeightVectorWeight weight)
 Set the weight (probability or freq count) of a symbol.

void IncremementSymbolWeight (int index)
 Increment the weight of a given entry.

bool CountSymbolFrequencies (OctaneParser *parserp, bitreader &from)
 Higher level function for automatic setting of frequencies with help of parser.

void EnforceZeroCountFloor (TSymbolWeightVectorWeight symbolfloorval)
 It's common that we may have symbols for characters we dont see for completeness and it's common to want to force these to some minimal value (like 1); some coders (like huffman), will break without this.


Protected Attributes

int symbolcount
 size of vector (# of symbol probabilities)

vector< TSymbolWeightVectorWeight > weightvector
 vector of probabilities


Member Function Documentation

virtual std::string SymbolWeightVector::GetName  )  [inline, virtual]
 

provide a unique name for the coder, used in some cases to automatically register the object with a manager

Returns:
a short *unique* name

Reimplemented from OctaneClass.

Definition at line 76 of file symbolweightvector.hpp.

00076 {return "SymbolWeightVector";}

virtual std::string SymbolWeightVector::GetDescription  )  [inline, virtual]
 

optionally provide a longer (maybe 20-60 characters) description

Returns:
a one line description

Reimplemented from OctaneClass.

Definition at line 77 of file symbolweightvector.hpp.

00077 {return "Symbol Weight Vector";}

virtual std::string SymbolWeightVector::GetHelpInformation  )  [inline, virtual]
 

optionally provide more information about the object on request for help

Returns:
a long string (can be multiple
newlines)

Reimplemented from OctaneClass.

Definition at line 78 of file symbolweightvector.hpp.

00078 {return "";}

bool SymbolWeightVector::SaveState bitwriter to,
bool  fortempdecompressiononly
[virtual]
 

Save state of object to output stream (if appropriate).

Returns:
true on success (or if no information needs to be saved).

Reimplemented from OctaneClass.

Definition at line 58 of file symbolweightvector.cpp.

References bitwriter::put(), symbolcount, and weightvector.

Referenced by OctaneModeler_WeightVectored::SaveState().

00059 {
00060         // save state
00061         // return true on success
00062         to.put(symbolcount);
00063         for (int count=0;count<symbolcount;++count)
00064                 to.put(weightvector[count]);
00065         return true;
00066 }

bool SymbolWeightVector::LoadState bitreader from  )  [virtual]
 

Load state of object from input stream (if appropriate).

Returns:
true on success (or if no information needs to be loaded).

Reimplemented from OctaneClass.

Definition at line 68 of file symbolweightvector.cpp.

References bitreader::get(), SetSymbolCount(), symbolcount, and weightvector.

Referenced by OctaneModeler_WeightVectored::LoadState().

00069 {
00070         // load state
00071         from.get(symbolcount);
00072         // force size of vector
00073         SetSymbolCount(symbolcount);
00074         // read weights
00075         for (int count=0;count<symbolcount;++count)
00076                 from.get(weightvector[count]);
00077         // return true on success
00078         return true;
00079 }

bool SymbolWeightVector::CountSymbolFrequencies OctaneParser parserp,
bitreader from
 

Higher level function for automatic setting of frequencies with help of parser.

This will actually parse the input using the parser, and count frequency of each symbol, and then normalize it into a probability distribution.

Returns:
true on success

Definition at line 116 of file symbolweightvector.cpp.

References OctaneParser::GetSymbolCount(), IncremementSymbolWeight(), OctaneParser::ParseNextSymbolFromInput(), ResetWeights(), and SetSymbolCount().

Referenced by ZeroOrderModeler::CreateModelUsingStream().

00117 {
00118         // higher level function for automatic setting of frequencies with help of parser; returns true on success
00119         bool bretv=true;
00120         int symbolnumber;
00121 
00122         // set our weight vector to size of symbolcount
00123         SetSymbolCount(parserp->GetSymbolCount());
00124         // reset probabilities
00125         ResetWeights();
00126 
00127         // now parse input and count frequencies, OOP parsing a symbol from parser until we hit end
00128         while (parserp->ParseNextSymbolFromInput(from,symbolnumber))
00129                 IncremementSymbolWeight(symbolnumber);
00130                 
00131         // return success
00132         return bretv;
00133 
00134 }


The documentation for this class was generated from the following files:  
Generated on 20 May 2004 by doxygen 1.3.3