网站首页站长博客下载中心域名交易站长论坛域名主机免费电邮免费域名中文排行排名查询站长书库书籍教程下载
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
学院首页 网络编程 网页设计 图形图象 数 据 库 服 务 器 网络媒体 网络安全 个人专栏 站长CLUB 业界新闻 信息公告
 当前位置:首页 >> 网络编程 >> NET专区 >> 正文
公告通知
返回上级列表
资料搜索
相关文章
用户自定义控件的应用
c#.net常用函数和方法集
在VB中使用水晶报表的一种简易编
C#调用父类的父类的方法
浏览.NET Framework 2.0 类型库中
为.Text Blog 添加 计数器
编程实现邮件地址有效性检测 
VB/VB.NET/C#导出到Excel的方法
c#高性能在WEB端产生验证图片
用System.Web.Caching.Cache保存
LZW算法的 C#实现
[ 来源:中国站长学院 | 作者:无从考证 | 时间:2005-8-13 13:23:27 | 浏览:人次 ]
收藏到新浪ViVi 收藏到365KEY 收藏到我摘  字号选择〖    〗/ 双击滚屏 单击停止  

#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页,当前在第1页  1  2  


[发送给好友]  [打印本页]  [关闭窗口]  [返回顶部]   转载请注明来源:http://edu.chinaz.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
栏目编辑: 设计风 责任编辑: 郁郁小蝎
原始作者: 无从考证 录入时间: 2005-8-13 13:23:27
信息来源: 中国站长学院 投稿信箱: Edu#chinaz.com
设为首页 - 加入收藏 - 关于我们 - 广告服务 - 版权申明 - 友情链接 - 联系方式 - 总编信箱 - 会员投稿