public List <byte> Decode() { var encodedModel = new EncodedModel(_encodedBytes); var mtfBytes = encodedModel.Bytes; if (encodedModel.IsUnary) { var unaryModel = new UnaryModel(encodedModel.Frequencies, encodedModel.Bytes); var unaryCoder = new UnaryCoder(); mtfBytes = unaryCoder.Decode(unaryModel); } var mtfCoder = new MtfCoder(); var bwtBytes = mtfCoder.Decode(mtfBytes); var bwtModel = new BwtModel(encodedModel.OriginalIndex, bwtBytes); var bwtCoder = new BwtCoder(); var rleBytes = bwtCoder.Decode(bwtModel); if (encodedModel.IsRle) { var rleCoder = new RleCoder(); _decodedBytes = rleCoder.Decode(rleBytes); } else { _decodedBytes = rleBytes; } return(_decodedBytes); }
public List <byte> Encode() { var isRle = false; var nextBytes = _originalBytes; var rleCoder = new RleCoder(); var rleBytes = rleCoder.Encode(_originalBytes); if (rleBytes.Count < _originalBytes.Count) { nextBytes = rleBytes; isRle = true; } var bwtCoder = new BwtCoder(); var bwtModel = bwtCoder.Encode(nextBytes); var mtfCoder = new MtfCoder(); var mtfBytes = mtfCoder.Encode(bwtModel.Bytes); var unaryCoder = new UnaryCoder(); var unaryModel = unaryCoder.Encode(mtfBytes); if (unaryModel.Bytes.Count < mtfBytes.Count) { var encodedModel = new EncodedModel(isRle, true, bwtModel.OriginalIndex, unaryModel.Frequencies, unaryModel.Bytes); _encodedBytes = encodedModel.ToByteList(); } else { var encodedModel = new EncodedModel(isRle, false, bwtModel.OriginalIndex, null, mtfBytes); _encodedBytes = encodedModel.ToByteList(); } return(_encodedBytes); }