BitRateWindow.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "BitRateWindow.h"
  3. using namespace ml;
  4. std::pair<BitRateWindow::Edge, size_t> BitRateWindow::insert(bool Bit) {
  5. Edge E;
  6. BBC.insert(Bit);
  7. switch (CurrState) {
  8. case State::NotFilled: {
  9. if (BBC.isFilled()) {
  10. if (BBC.numSetBits() < SetBitsThreshold) {
  11. CurrState = State::BelowThreshold;
  12. } else {
  13. CurrState = State::AboveThreshold;
  14. }
  15. } else {
  16. CurrState = State::NotFilled;
  17. }
  18. E = {State::NotFilled, CurrState};
  19. break;
  20. } case State::BelowThreshold: {
  21. if (BBC.numSetBits() >= SetBitsThreshold) {
  22. CurrState = State::AboveThreshold;
  23. }
  24. E = {State::BelowThreshold, CurrState};
  25. break;
  26. } case State::AboveThreshold: {
  27. if ((BBC.numSetBits() < SetBitsThreshold) ||
  28. (CurrLength == MaxLength)) {
  29. CurrState = State::Idle;
  30. }
  31. E = {State::AboveThreshold, CurrState};
  32. break;
  33. } case State::Idle: {
  34. if (CurrLength == IdleLength) {
  35. CurrState = State::NotFilled;
  36. }
  37. E = {State::Idle, CurrState};
  38. break;
  39. }
  40. }
  41. Action A = EdgeActions[E];
  42. size_t L = (this->*A)(E.first, Bit);
  43. return {E, L};
  44. }
  45. void BitRateWindow::print(std::ostream &OS) const {
  46. switch (CurrState) {
  47. case State::NotFilled:
  48. OS << "NotFilled";
  49. break;
  50. case State::BelowThreshold:
  51. OS << "BelowThreshold";
  52. break;
  53. case State::AboveThreshold:
  54. OS << "AboveThreshold";
  55. break;
  56. case State::Idle:
  57. OS << "Idle";
  58. break;
  59. default:
  60. OS << "UnknownState";
  61. break;
  62. }
  63. OS << ": " << BBC << " (Current Length: " << CurrLength << ")";
  64. }