openMSX
TigerTree.hh
Go to the documentation of this file.
1 
28 #ifndef TIGERTREE_HH
29 #define TIGERTREE_HH
30 
31 #include <string>
32 #include <cstdint>
33 #include <ctime>
34 #include <functional>
35 
36 namespace openmsx {
37 
38 struct TigerHash;
39 
43 class TTData
44 {
45 public:
50  virtual uint8_t* getData(size_t offset, size_t size) = 0;
51 
60  virtual bool isCacheStillValid(time_t& time) = 0;
61 
62 protected:
63  ~TTData() = default;
64 };
65 
66 struct TTCacheEntry;
67 
72 class TigerTree
73 {
74 public:
78  TigerTree(TTData& data, size_t dataSize, const std::string& name);
79 
82  const TigerHash& calcHash(const std::function<void(size_t, size_t)>& progressCallback);
83 
89  void notifyChange(size_t offset, size_t len, time_t time);
90 
91 private:
92  // functions to navigate in binary tree
93  struct Node {
94  Node(size_t n_, size_t l_) : n(n_), l(l_) {}
95  size_t n; // node number
96  size_t l; // level number
97  };
98  Node getTop() const;
99  Node getLeaf(size_t block) const;
100  Node getParent(Node node) const;
101  Node getLeftChild(Node node) const;
102  Node getRightChild(Node node) const;
103 
104  const TigerHash& calcHash(Node node, const std::function<void(size_t, size_t)>& progressCallback);
105 
106  TTData& data;
107  const size_t dataSize;
108  TTCacheEntry& entry;
109 };
110 
111 } // namespace openmsx
112 
113 #endif
virtual uint8_t * getData(size_t offset, size_t size)=0
Return the requested portion of the to-be-hashed data block.
This struct represents the result of a tiger-hash.
Definition: tiger.hh:27
The TigerTree class will query the to-be-hashed data via this abstract interface. ...
Definition: TigerTree.hh:43
constexpr auto data(C &c) -> decltype(c.data())
Definition: span.hh:69
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
Calculate a tiger-tree-hash.
Definition: TigerTree.hh:72
~TTData()=default
virtual bool isCacheStillValid(time_t &time)=0
Because TTH calculation of a large file takes some time (a few 1/10s for a harddisk image) we try to ...
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.hh:62