Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // snf_saccades.hpp
  2. // Saccades engine adaptation for MessageSniffer
  3. // Copyright 2014-2020 MicroNeil Research Corporation (www.microneil.com)
  4. // Licensed to ARM Research Labs for use in Message Sniffer.
  5. #pragma once
  6. #include <set>
  7. #include <vector>
  8. class saccades_engine;
  9. class saccade {
  10. friend class saccades_engine;
  11. private:
  12. const static unsigned int stretchSize = 8;
  13. const static unsigned int stretchMark = stretchSize / 2;
  14. const static unsigned int stretchMask = ((~0U) ^ (stretchSize - 1));
  15. unsigned int stretchLeft(unsigned int s) {
  16. s = (stretchMark > s) ? s : (s - (stretchMark));
  17. return (s & stretchMask);
  18. }
  19. unsigned int stretchRight(unsigned int f) {
  20. f = (start > f) ? start : f;
  21. return ((f + stretchSize + stretchMark) & stretchMask);
  22. }
  23. saccade() : start(0), finish(0) {}
  24. static saccade unstretched(unsigned int s, unsigned int f) {
  25. saccade u;
  26. u.start = s;
  27. u.finish = f;
  28. return u;
  29. }
  30. public:
  31. unsigned int start;
  32. unsigned int finish;
  33. saccade(unsigned int s, unsigned int f) :
  34. start(stretchLeft(s)),
  35. finish(stretchRight(f)) {}
  36. bool operator<(const saccade& r) const {
  37. if(start < r.start) return true;
  38. if(start > r.start) return false;
  39. return (finish < r.finish);
  40. }
  41. bool operator==(const saccade& r) const {
  42. return (
  43. start == r.start &&
  44. finish == r.finish
  45. );
  46. }
  47. };
  48. class saccade_marker {
  49. public:
  50. const saccade theSaccade;
  51. unsigned int theSlot;
  52. saccade_marker(saccade key, unsigned int slot) :
  53. theSaccade(key),
  54. theSlot(slot) {}
  55. bool operator<(const saccade_marker& r) const {
  56. return (theSaccade < r.theSaccade);
  57. }
  58. };
  59. struct saccade_engram {
  60. static const int NoneMore = -1;
  61. int nextFresh;
  62. int nextStale;
  63. saccade theSaccade;
  64. saccade_engram() :
  65. nextFresh(NoneMore),
  66. nextStale(NoneMore),
  67. theSaccade(0,0) {}
  68. saccade_engram(saccade s) :
  69. nextFresh(NoneMore),
  70. nextStale(NoneMore),
  71. theSaccade(s) {}
  72. };
  73. class saccades_engine {
  74. private:
  75. std::vector<saccade_engram> engrams;
  76. std::set<saccade_marker> markers;
  77. const unsigned int capacity;
  78. int mostFresh;
  79. int mostStale;
  80. void evoke(saccade s);
  81. void disconnectEngram(int theSlot);
  82. void connectFreshestEngram(int theSlot);
  83. void freshenEngram(int theSlot);
  84. void makeEngram(saccade s);
  85. void recycleEngram(saccade s);
  86. public:
  87. saccades_engine(unsigned int c) :
  88. capacity(c),
  89. mostFresh(saccade_engram::NoneMore),
  90. mostStale(saccade_engram::NoneMore) {
  91. engrams.reserve(capacity);
  92. }
  93. std::vector<saccade> recall();
  94. void learn(std::vector<saccade>& experiences);
  95. };