Example #1
0
    public static void compress()
    {
        string text = BinaryStdIn.readString();
        TST    tST  = new TST();
        int    i;

        for (i = 0; i < 256; i++)
        {
            tST.put(new StringBuilder().append("").append((char)i).toString(), Integer.valueOf(i));
        }
        i = 257;
        while (java.lang.String.instancehelper_length(text) > 0)
        {
            string text2 = tST.longestPrefixOf(text);
            BinaryStdOut.write(((Integer)tST.get(text2)).intValue(), 12);
            int num = java.lang.String.instancehelper_length(text2);
            if (num < java.lang.String.instancehelper_length(text) && i < 4096)
            {
                TST    arg_A5_0 = tST;
                string arg_A5_1 = java.lang.String.instancehelper_substring(text, 0, num + 1);
                int    arg_A0_0 = i;
                i++;
                arg_A5_0.put(arg_A5_1, Integer.valueOf(arg_A0_0));
            }
            text = java.lang.String.instancehelper_substring(text, num);
        }
        BinaryStdOut.write(256, 12);
        BinaryStdOut.close();
    }
Example #2
0
File: LZW.cs Project: PajLe/paa-lab
        public LZW(string inputFileName, string outputFileName)
        {
            _fileToDecode = outputFileName;

            using (BinaryReader br = new BinaryReader(File.Open(inputFileName, FileMode.Open)))
            {
                using (BinaryWriter bw = new BinaryWriter(File.Open(outputFileName, FileMode.Create)))
                {
                    TST <uint>    st         = new TST <uint>();
                    StringBuilder inputChars = new StringBuilder();
                    //br.BaseStream.Position = 0;
                    while (br.BaseStream.Position != br.BaseStream.Length)
                    {
                        inputChars.Append(Convert.ToChar(br.ReadByte()));
                    }
                    string input = inputChars.ToString();
                    _inputLength = input.Length;

                    for (uint i = 0; i < R; i++)
                    {
                        st.put("" + (char)i, i);
                    }
                    uint code = R + 1;  // R is codeword for EOF

                    int inputStartIndex = 0;
                    while (_inputLength > inputStartIndex)
                    {
                        string s = st.longestPrefixOf(input, inputStartIndex); // Find max prefix match s.

                        bw.WriteIntBits(st.get(s), W);                         // Print s's code.
                        int t = s.Length;
                        if (t < _inputLength - inputStartIndex && code < L)
                        {
                            st.put(input.Substring(inputStartIndex, t + 1), code++); // Add s to symbol table.
                        }
                        inputStartIndex += t;                                        // instead of the slow substring operation
                    }

                    bw.WriteIntBits(R, W);
                }
            }
        }
Example #3
0
 public void insert(string key, int pageindex)
 {
     tst.put(key, pageindex);
 }