huffman_codec.h 904 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include "codecs.h"
  3. #include <util/generic/ptr.h>
  4. #include <util/string/cast.h>
  5. namespace NCodecs {
  6. // for types greater than char, pipeline with TFreqCodec.
  7. class THuffmanCodec: public ICodec {
  8. class TImpl;
  9. TIntrusivePtr<TImpl> Impl;
  10. public:
  11. THuffmanCodec();
  12. ~THuffmanCodec() override;
  13. static TStringBuf MyName() {
  14. return "huffman";
  15. }
  16. TString GetName() const override {
  17. return ToString(MyName());
  18. }
  19. ui8 Encode(TStringBuf in, TBuffer& bbb) const override;
  20. void Decode(TStringBuf in, TBuffer& bbb) const override;
  21. void LearnByFreqs(const TArrayRef<std::pair<char, ui64>>& freqs);
  22. protected:
  23. void DoLearn(ISequenceReader& in) override;
  24. void Save(IOutputStream* out) const override;
  25. void Load(IInputStream* in) override;
  26. };
  27. }