?? model.cpp
字號:
// Model.cpp: implementation of the CModel class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Model.h"
#include <stdio.h>
#include <stdlib.h>
//--------------------------------------------------------------------
//-------------------Construction/Destruction-------------------------
CModel::CModel()
{
start();
}//model
CModel::~CModel()
{
}
//====================================================================
//--------------------------------------------------------------------
//-------------------initialize the model-----------------------------
void CModel::start()
{
int i;
for(i=0; i<nof_chars; i++)
{
char_to_index[i] = i+1;
index_to_char[i+1] = i;
}
for(i=0; i<=nof_symbols; i++)
{
freq[i] = 1;
cum_freq[i] = nof_symbols-i;
}
freq[0] = 0;
}//start
//====================================================================
//--------------------------------------------------------------------
//-----------update the model to account for a new symbol-------------
void CModel::update(int symbol)
{
int i;
if ( cum_freq[0] == max_frequency )
{
int cum;
cum = 0;
for(i=nof_symbols; i>=0; i--)
{
freq[i] = (freq[i]+1)/2;
cum_freq[i] = cum;
cum += freq[i];
}
}
for(i=symbol; freq[i]==freq[i-1]; i--) {};// find symbol's new index
if ( i<symbol )
{
int ch_i, ch_symbol;
ch_i = index_to_char[i];
ch_symbol = index_to_char[symbol];
index_to_char[i] = ch_symbol;
index_to_char[symbol] = ch_i;
char_to_index[ch_i] = symbol;
char_to_index[ch_symbol] = i;
}
freq[i] += 1;
while(i>0)
{
i -= 1;
cum_freq[i] += 1;
}
}
//==================================================================
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -