"L. Spiro Engine"
Classes | Public Types | Public Member Functions | Protected Attributes

lsc::CLzwEncodingDict Class Reference

A dictionary for the encoding of a bytestream using the LZW algorithm. More...

#include <LSCLzwEncodingDict.h>

List of all members.

Classes

struct  LSN_LZW_DICT_ENTRY

Public Types

enum  LSN_LZW_INVALID_CODE { LSN_LZW_INVALID_CODE = ~0UL, LSN_LZW_FORCE_DWORD = 0x7FFFFFFFUL }
typedef struct
lsc::CLzwEncodingDict::LSN_LZW_DICT_ENTRY
LPLSN_LZW_DICT_ENTRY
typedef struct
lsc::CLzwEncodingDict::LSN_LZW_DICT_ENTRY 
LPCLSN_LZW_DICT_ENTRY

Public Member Functions

LSVOID LSE_CALL Reset ()
LSVOID LSE_CALL SetAllocator (CStdAllocator *_psaAllocator)
LSBOOL LSE_CALL InitDict (LSUINT32 _ui32RootCodes, LSUINT32 _ui32MaxBits)
LSUINT32 LSE_CALL GetEntryIndex (LSUINT32 _ui32Code, LSUINT32 _ui32Char) const
const LSN_LZW_DICT_ENTRY &LSE_CALL GetEntry (LSUINT32 _ui32Index) const
LSVOID LSE_CALL AddEntry (LSUINT32 _ui32Index, LSUINT32 _ui32BaseCode, LSUINT32 _ui32Char)
LSUINT32 LSE_CALL TotalEntries () const
LSUINT32 LSE_CALL GetMaxDictionarySize () const
LSUINT32 LSE_CALL GetStartingBits () const
LSUINT32 LSE_CALL GetResetCode () const
LSUINT32 LSE_CALL GetEndStreamCode () const
LSUINT32 LSE_CALL GetBits () const

Protected Attributes

CAllocator m_caAllocator
LSUINT32 m_ui32AllocatedDictSize
LSUINT32 m_ui32MaxBits
LSUINT32 m_ui32DictSize
LSUINT16 m_ui16MinBits
LSUINT16 m_ui16StartingBits
LSUINT32 m_ui32RootCodes
LPLSN_LZW_DICT_ENTRY m_lpldeDictionary

Detailed Description

A dictionary for the encoding of a bytestream using the LZW algorithm.

Class CLzwEncodingDict Description: When encoding bytes, the dictionary for the LZW algorithm is stored differently from when the bytes are being decoded. During encryption, codes are referenced via (code+char) combination which requires a hash look-up. For this reason, we cannot store the codes in such a way that index = code. During decoding, however, codes are referenced only by code, so we are able to store the codes linearly such that index = code. This saves space over the encoding algorithm and gives us cause to keep the two dictionaries separate. The dictionary is created with a maximum size at the beginning, which depends on the maximum number of bits a code may have. This class can output variable-sized codes or predefined-sized codes as per the desires of the user. Variable-sized codes simply means that the smallest number of bits needed to access any code in the dictionary are output instead of using a fixed size such as 15 bits for every code. This is the typical method for encoding.


Member Typedef Documentation

A dictionary entry.


Member Enumeration Documentation

Flags we use.


Member Function Documentation

LSVOID LSE_CALL lsc::CLzwEncodingDict::AddEntry ( LSUINT32  _ui32Index,
LSUINT32  _ui32BaseCode,
LSUINT32  _ui32Char 
)

Add an entry at a given index. The index must have been returned by a previous call to GetEntryIndex() and must be unused.

Parameters:
_ui32IndexIndex, returned by a previous call to GetEntryIndex(), where the code is to be added.
_ui32BaseCodeThe base code of the new code to be added. The base code is the code of an existing entry off which this entry is based. This entry extends the base code by one character, given in _ui32Char.
_ui32CharThe character by which the new code extends the base code.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetBits ( ) const

Get the bits needed to read any code in the dictionary.

Returns:
Returns the bits needed to read any code in the dictionary.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetEndStreamCode ( ) const

Get the end-stream code.

Returns:
Returns the end-stream code.
const LSN_LZW_DICT_ENTRY& LSE_CALL lsc::CLzwEncodingDict::GetEntry ( LSUINT32  _ui32Index) const

Get an entry by index for read only. The entry is not guaranteed to contain a valid code.

Parameters:
_ui32IndexIndex of the entry to retrieve.
Returns:
Returns a constant reference to the entry at the given index.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetEntryIndex ( LSUINT32  _ui32Code,
LSUINT32  _ui32Char 
) const

Get the index of an entry in the dictionary. If the entry does not exist, the returned index is where it should be added to the dictionary.

Parameters:
_ui32CodeThe code of the entry to find.
_ui32CharThe allocator to use by this class.
Returns:
Returns false if allocation of the dictionary failed, or true otherwise.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetMaxDictionarySize ( ) const

Get the maximum dictionary size.

Returns:
Returns the maximum dictionary size.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetResetCode ( ) const

Get the reset-dictionary code.

Returns:
Returns the reset-dictionary code.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetStartingBits ( ) const

Get the number of bits needed at the beginning of the dictionary (when the dictionary is set to its root size).

Returns:
Returns the number of bits needed to access any code in the dictionary when the dictionary is in its default state.
LSBOOL LSE_CALL lsc::CLzwEncodingDict::InitDict ( LSUINT32  _ui32RootCodes,
LSUINT32  _ui32MaxBits 
)

Begin a compression. We need to know the maximum number of bits to create the dictionary. The dictionary can be cleared and recreated many times during compression.

Parameters:
_ui32RootCodesThe default dictionary is composed of this number of root codes.
_psaAllocatorThe allocator to use by this class.
Returns:
Returns false if allocation of the dictionary failed, or true otherwise.
LSVOID LSE_CALL lsc::CLzwEncodingDict::Reset ( )

Reset everything. Deallocates all resources.

LSVOID LSE_CALL lsc::CLzwEncodingDict::SetAllocator ( CStdAllocator *  _psaAllocator)

Set the allocator. If different from the current allocator, the dictionary is reset.

Parameters:
_psaAllocatorThe allocator to use by this class.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::TotalEntries ( ) const

Get the size of the dictionary.

Returns:
Returns the number of entries in the dictionary.

Member Data Documentation

CAllocator lsc::CLzwEncodingDict::m_caAllocator [protected]

Our allocator.

The dictionary.

The minimum number of bits needed to access every entry in the dictionary.

The starting size of each entry in bits.

Allocated size of the dictionary.

Actual number of entries in the dictionary.

Maximum bits in the dictionary entries.

Root codes.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator