Talk:LZW compression: Difference between revisions

Decompression routine for C#
(Not a problem.)
(Decompression routine for C#)
Line 4:
:: I see it hard (1), since most OO-lang implementation must be split by the people who wrote the code or know the language; (1) by hard I mean, I can't do it by myself, I could just add a new decompression task and write an impl. for Obj-C that would be the "complement" of the one here, then mark all other examples as ... hm... they do the task, but do also more... so they are task-compliant in some way... (what?) --[[User:ShinTakezou|ShinTakezou]] 16:43, 13 February 2009 (UTC)
::: Not a problem, currently. I can understand the currently-listed languages enough to do the separation myself. I'll get to it as soon as I can, which will likely be some time after midnight EST. --[[User:Short Circuit|Short Circuit]] 21:27, 13 February 2009 (UTC)
 
==C# Decompression function==
I'm not sure if it would be acceptable to just post the decompression, so I'm posting it here. Since I'm lazy, and only need decomp (which seems to be easier anyway), I only wrote that.
<lang csharp>
class LZWDecompress
{
static void Main(string[] args)
{
int[] Compressed = { 84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263 };
 
String Decompressed = DeCompress(Compressed);
//Decompressed should now contain "TOBEORNOTTOBEORTOBEORNOT"
}
static String DeCompress(int[] Compressed)
{
ArrayList Dictionary = new ArrayList();
 
String Output = "";
String tmpOut = "";
String tmpIn = "";
bool JustOnce = false;
 
//Build dictionary
for (int i = 0; i < 256; i++)
Dictionary.Add(Convert.ToChar(i).ToString());
 
foreach (int Character in Compressed)
{
if (JustOnce == false)
{
JustOnce = true;
Output = tmpIn = (String)Dictionary[Character];
continue;
}
 
if (Character < Dictionary.Count)
tmpOut = (String)Dictionary[Character];
else if (Character == Dictionary.Count)
tmpOut = tmpIn + tmpIn.Substring(0, 1);
else
break;
 
Output = Output + tmpOut;
Dictionary.Add((tmpIn + tmpOut.Substring(0, 1)));
tmpIn = tmpOut;
}
return Output;
}
}
</lang>
Cyberman (not registered here) --[[Special:Contributions/85.127.79.163|85.127.79.163]] 19:10, 2 April 2011 (UTC)
Anonymous user