/// (C) 2010, Andrew Polar under GPL ver. 3. // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 3 of // the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details at // Visit . // // This is DEMO of Dictionary class, which is part of iROLZ algorithm. #include #include #include #include #include #include class Dictionary { public: Dictionary(int PrefixSize, int OffsetLen); ~Dictionary(); void updateDictionary(unsigned char byte); int getNextPosition(int position); private: int* m_last_position_lookup; int* m_self_addressed_dictionary; int m_prefix_mask, m_buffer_mask, m_context, m_index; }; Dictionary::Dictionary(int PrefixSize, int OffsetLen) { if (PrefixSize == 1) m_prefix_mask = 0xff; else if (PrefixSize == 2) m_prefix_mask = 0xffff; else m_prefix_mask = 0xffffff; m_last_position_lookup = (int*)malloc((m_prefix_mask + 1) * sizeof(int)); memset(m_last_position_lookup, 0x00, (m_prefix_mask + 1) * sizeof(int)); m_buffer_mask = (1<updateDictionary(data[index]); int position = index; while (true) { int new_position = dictionary->getNextPosition(position); if (new_position >= position) break; //positions should only going back in history if (new_position < prefix_size-1) break; //should not go to negative array index //next word match verification is optional, it works without it since in encoding //and decoding operations are going in the same way int current_word = 0; int offset_word = 0; for (int k=0; k