Untitled

 avatar
unknown
plain_text
2 years ago
4.1 kB
6
Indexable
#region -> mg_63760_tryb  kompresji LZW
        public static void mg_63760_TrybKompresjiLZW(string mg_6376_source, ref List<string> mg_63760_dictionary, ref List<string> mg_63760_resultCode, int mg_63760_mode)
        {
           if (mg_63760_mode == 1)
            {
                mg_63760_ZainicjowanieSlownika(mg_6376_source, ref mg_63760_dictionary);
            }
           else if (mg_63760_mode == 2)
            {
                if (mg_63760_dictionary.Count < 2)
                {
                    Console.WriteLine("Wydaje się, że albo słownik jest za krótki, albo w ogóle go nie zdefiniowano!");
                    return;
                }
            }
            mg_63760_KompresjaLZW(mg_6376_source, mg_63760_dictionary, ref mg_63760_resultCode);
        }
        #endregion

        #region -> mg_63760_Zainicjowanie Slownika
        private static void mg_63760_ZainicjowanieSlownika(string mg_63760_source, ref List<string> mg_63760_dictionary)
        {
            string mg_63760_pozostaly = mg_63760_source;
            string mg_63760_roboczy = "";
            string mg_63760_znak = "";

            do
            {
                mg_63760_roboczy = mg_63760_pozostaly;
                mg_63760_znak = mg_63760_roboczy.Substring(0, 1);
                if (!mg_63760_dictionary.Contains(mg_63760_znak))
                {
                    mg_63760_dictionary.Add(mg_63760_znak);
                }

                mg_63760_pozostaly = mg_63760_roboczy.Remove(0, 1);
            }
            while (mg_63760_pozostaly.Length > 0);
        }
        #endregion

        #region -> mg_63760_Kompresja LZW
        private static void mg_63760_KompresjaLZW(string mg_63760_source, List<string> mg_63760_dictionary, ref List<string> mg_63760_resultCode)
        {
            string mg_63760_pozostaly = mg_63760_source;
            string mg_63760_roboczy = "";
            string mg_63760_znak = "";
            int mg_63760_sequenceLength = 1;
            int mg_63760_indexNb = 0;

            do
            {
                mg_63760_roboczy = mg_63760_pozostaly;
                if (mg_63760_sequenceLength <= mg_63760_roboczy.Length)
                {
                    mg_63760_znak = mg_63760_roboczy.Substring(0, mg_63760_sequenceLength);
                    if (mg_63760_dictionary.Contains(mg_63760_znak))
                    {
                        mg_63760_sequenceLength++;
                    }
                    else
                    {
                        mg_63760_indexNb = mg_63760_dictionary.IndexOf(mg_63760_roboczy.Substring(0, mg_63760_sequenceLength - 1)) + 1;
                        mg_63760_resultCode.Add(mg_63760_indexNb.ToString());
                        mg_63760_dictionary.Add(mg_63760_znak);
                        mg_63760_pozostaly = mg_63760_roboczy.Remove(0, mg_63760_sequenceLength - 1);
                        mg_63760_sequenceLength = 1;
                    }
                }
                else
                {
                    mg_63760_znak = mg_63760_roboczy.Substring(0, 1);
                    if (mg_63760_dictionary.Contains(mg_63760_znak))
                    {
                        mg_63760_indexNb = mg_63760_dictionary.IndexOf(mg_63760_znak) + 1;
                        mg_63760_resultCode.Add(mg_63760_indexNb.ToString());
                        mg_63760_pozostaly = mg_63760_roboczy.Remove(0, 1);
                    }
                    else
                    {
                        mg_63760_dictionary.Add(mg_63760_znak);
                        mg_63760_indexNb = mg_63760_dictionary.IndexOf(mg_63760_roboczy.Substring(0, mg_63760_sequenceLength - 1)) + 1;
                        mg_63760_resultCode.Add(mg_63760_indexNb.ToString());
                        mg_63760_pozostaly = mg_63760_roboczy.Remove(0, 1);
                    }
                }
            }
            while (mg_63760_pozostaly.Length > 0);
        }
        #endregion
Editor is loading...