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:
78  TigerTree(TTData& data, size_t dataSize, const std::string& name);
79 
82  [[nodiscard]] 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  [[nodiscard]] Node getTop() const;
99  [[nodiscard]] Node getLeaf(size_t block) const;
100  [[nodiscard]] Node getParent(Node node) const;
101  [[nodiscard]] Node getLeftChild(Node node) const;
102  [[nodiscard]] Node getRightChild(Node node) const;
103 
104  [[nodiscard]] 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
openmsx::TigerHash
This struct represents the result of a tiger-hash.
Definition: tiger.hh:28
openmsx::TTCacheEntry
Definition: TigerTree.cc:14
openmsx::TTData
The TigerTree class will query the to-be-hashed data via this abstract interface.
Definition: TigerTree.hh:44
openmsx::TigerTree
Calculate a tiger-tree-hash.
Definition: TigerTree.hh:73
openmsx::TTData::~TTData
~TTData()=default
openmsx::TigerTree::notifyChange
void notifyChange(size_t offset, size_t len, time_t time)
Inform this calculator about changes in the input data.
Definition: TigerTree.cc:59
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
openmsx::TTData::getData
virtual uint8_t * getData(size_t offset, size_t size)=0
Return the requested portion of the to-be-hashed data block.
openmsx::TigerTree::TigerTree
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:47
openmsx::TTData::isCacheStillValid
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 ...
openmsx::TigerTree::calcHash
const TigerHash & calcHash(const std::function< void(size_t, size_t)> &progressCallback)
Calculate the hash value.
Definition: TigerTree.cc:54
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5