选择显示字体大小

lzw算法的 c#实现

#undef debug
#define debugdisplay
#undef debugdictionary
using system;
using system.collections;

namespace lzw
{
 public class clzw
 {
  #region constrcut
  public clzw()
  {
  }
  #endregion
  
  #region coding
  public string incharstream
  {
   set { _incharstream = value; }
   get {return _incharstream; }
  }
  public arraylist codingcodestream
  {
   get {return _codingcodestream;}
  }
  public arraylist codingdictionary
  {
   get {return _codingdictionary;}
  }
  private void initcodingdictionary()
  {
   _codingdictionary.clear();
#if debug
   _codingdictionary.add("a");
   _codingdictionary.add("b");
   _codingdictionary.add("c");
#else
   for(int i = 0; i < 256; i++)
   {
    _codingdictionary.add((char)i);
   }
#endif
  }
  private void addcodingdictionary(object str)
  {
   _codingdictionary.add(str);
  }
  private void addcodingcodestream(object str)
  {
   _codingcodestream.add(str);
  }
  private bool isincodingdictionary(string prefix)
  {
   bool result = false;
   int  count = _codingdictionary.count;
   for(int i = 0; i < count; i++)
   {
    string temp = _codingdictionary[i].tostring();
    if (temp.indexof(prefix) >= 0)
    {
     result = true;
     break;
    }
   }
   return result;
  }
  private string  getindexcodingdictionary(string prefix)
  {
   string result ="0";
   int  count = _codingdictionary.count;
   for(int i = 0; i < count; i++)
   {
    string temp = _codingdictionary[i].tostring();
    if (temp.indexof(prefix) >= 0)
    {
     result = convert.tostring(i + 1);
     break;
    }
   }
   return result;
  }
  private void displaycodingcodestream()
  {
   system.console.writeline("*********_codingcodestream************");
   for(int i = 0; i < _codingcodestream.count; i++)
   {
    system.console.writeline(_codingcodestream[i].tostring());
   }
  }
  private void displaycodingdictionary()
  {
   system.console.writeline("*********_codingdictionary************");
   for(int i = 0; i < _codingdictionary.count; i++)
   {
    system.console.writeline(_codingdictionary[i].tostring());
   }
  }
  private void displayincharstream()
  {
   system.console.writeline("*********_incharstream************");
   system.console.writeline(_incharstream);
  }
  private void initcodingcodestream()
  {
   _codingcodestream.clear();
  }
  private arraylist _codingdictionary = new arraylist();
  private string _incharstream = "";
  private arraylist _codingcodestream = new arraylist();
  public void coding()
  {
   string prefix ="" ;
   string c ="";
   string prefixindex= "0";
   int  count = _incharstream.length;
   if (count == 0) return ;
   initcodingdictionary();
   initcodingcodestream();
   prefix = _incharstream[0].tostring();
   for(int i = 1; i < count; i++)
   {
    c = _incharstream[i].tostring();
    if (isincodingdictionary( prefix + c))
    {
     prefix += c;
    }
    else
    {
     prefixindex = getindexcodingdictionary(prefix);
     addcodingcodestream(prefixindex);
     addcodingdictionary( prefix + c);
     prefix = c;
    }
   }
   prefixindex = getindexcodingdictionary(prefix);
   addcodingcodestream(prefixindex);
#if debugdisplay
   displayincharstream();
   displaycodingcodestream();
#if debugdictionary
   displaycodingdictionary();
#endif
#endif
  }
  
  #endregion
  
  #region decode
  private arraylist _decodedictionary = new arraylist();
  private arraylist _outcharstream = new arraylist();
  private int[] _decodecodestream ;
  public void setdecodescodetream(int[] obj)
  {
   int count = obj.length;
   _decodecodestream = new int[count];
   for(int i =0; i < count ; i++)
   {
    _decodecodestream[i] = obj[i];
   }
  }
  public void setdecodescodetream(arraylist obj)
  {
   int count = obj.count;
   _decodecodestream = new int[count];
   for(int i =0; i < count ; i++)
   {
    _decodecodestream[i] = system.convert.toint32(obj[i]);
   }
  
  }
  public int[] getdecodecodestream()
  {
   return _decodecodestream;
  }
  public string outcharstream
  {
   get
   {
    string result = "";
    for(int i = 0,count = _outcharstream.count; i < count; i++)
    {
     result += _outcharstream[i].tostring();
    }
    return result;
   }
  }
  public arraylist decodedictionary
  {
   get
   {
    return _decodedictionary;
   }
  }
  private void initdecodedictionary()
  {
   _decodedictionary.clear();
#if debug
   _decodedictionary.add("a");
   _decodedictionary.add("b");
   _decodedictionary.add("c");
#else
   for(int i = 0; i < 256; i++)
   {
    _decodedictionary.add((char)i);
   }
#endif
  }
  private void initoutcharstream()
  {
   _outcharstream.clear();
  }
  private void displayoutcharstream()
  {
   system.console.writeline("*********_outcharstream************");
   string temp = "";
   for(int i = 0; i < _outcharstream.count; i++)
   {
    temp = temp + (_outcharstream[i].tostring());
   }
 
   system.console.writeline(temp);
  }
  private void displaydecodedictionary()
  {
   system.console.writeline("*********_decodedictionary************");
   for(int i = 0; i < _decodedictionary.count; i++)
   {
    system.console.writeline(_decodedictionary[i].tostring());
   }
   
  }

本新闻共2


 


关键字 本文所属关键字

  • NET  

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons