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  [[nodiscard]] virtual uint8_t* getData(size_t offset, size_t size) = 0;
51 
60  [[nodiscard]] 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:
75  static constexpr size_t BLOCK_SIZE = 64 * 1024;
76 
80  TigerTree(TTData& data, size_t dataSize, const std::string& name);
81 
84  [[nodiscard]] const TigerHash& calcHash(const std::function<void(size_t, size_t)>& progressCallback);
85 
91  void notifyChange(size_t offset, size_t len, time_t time);
92 
93 private:
94  // functions to navigate in binary tree
95  struct Node {
96  Node(size_t n_, size_t l_) : n(n_), l(l_) {}
97  size_t n; // node number
98  size_t l; // level number
99  };
100  [[nodiscard]] Node getTop() const;
101  [[nodiscard]] Node getLeaf(size_t block) const;
102  [[nodiscard]] Node getParent(Node node) const;
103  [[nodiscard]] Node getLeftChild(Node node) const;
104  [[nodiscard]] Node getRightChild(Node node) const;
105 
106  [[nodiscard]] const TigerHash& calcHash(Node node, const std::function<void(size_t, size_t)>& progressCallback);
107 
108 private:
109  TTData& data;
110  const size_t dataSize;
111  TTCacheEntry& entry;
112 };
113 
114 } // namespace openmsx
115 
116 #endif
The TigerTree class will query the to-be-hashed data via this abstract interface.
Definition: TigerTree.hh:44
~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 ...
virtual uint8_t * getData(size_t offset, size_t size)=0
Return the requested portion of the to-be-hashed data block.
Calculate a tiger-tree-hash.
Definition: TigerTree.hh:73
const TigerHash & calcHash(const std::function< void(size_t, size_t)> &progressCallback)
Calculate the hash value.
Definition: TigerTree.cc:52
TigerTree(TTData &data, size_t dataSize, const std::string &name)
Create TigerTree calculator for the given (abstract) data block of given size.
Definition: TigerTree.cc:45
void notifyChange(size_t offset, size_t len, time_t time)
Inform this calculator about changes in the input data.
Definition: TigerTree.cc:57
static constexpr size_t BLOCK_SIZE
Definition: TigerTree.hh:75
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)
This struct represents the result of a tiger-hash.
Definition: tiger.hh:28