This commit is contained in:
JoelKatz
2011-11-14 19:48:46 -08:00
parent fbf6967d82
commit 7fb40e1c55

View File

@@ -4,6 +4,7 @@
#include <list>
#include <boost/shared_ptr.hpp>
#include <boost/bimap.hpp>
#include "uint256.h"
#include "ScopedLock.h"
@@ -20,8 +21,8 @@ class SHAMapNode
private:
static uint256 smMasks[11]; // AND with hash to get node id
int mDepth;
uint256 mNodeID;
int mDepth;
public:
@@ -42,8 +43,6 @@ public:
int selectBranch(const uint256 &hash);
static uint256 getNodeID(int depth, const uint256 &hash);
bool operator<(const SHAMapNode &) const;
bool operator>(const SHAMapNode &) const;
bool operator==(const SHAMapNode &) const;
@@ -52,6 +51,7 @@ public:
bool operator>=(const SHAMapNode &) const;
static void ClassInit();
static uint256 getNodeID(int depth, const uint256 &hash);
};
@@ -82,9 +82,9 @@ public:
int getHashCount() const { return mHashes.size(); }
const uint256& GetHash(int m) const;
bool hasHash(const uint256 &hash) const;
};
class SHAMapInnerNode : public SHAMapNode
{
friend class SHAMap;
@@ -99,15 +99,15 @@ private:
void updateHash();
protected:
void SetChildHash(int m, const uint256 &hash);
void setChildHash(int m, const uint256 &hash);
public:
SHAMapInnerNode(int Depth, const uint256 &NodeID);
virtual bool IsPopulated(void) const { return true; }
const uint256& GetNodeHash() const { return mHash; }
const uint256& GetChildHash(int m) const;
virtual bool isPopulated(void) const { return true; }
const uint256& getNodeHash() const { return mHash; }
const uint256& getChildHash(int m) const;
bool isEmpty() const;
};
@@ -122,7 +122,7 @@ private:
mutable boost::mutex mLock;
std::map<SHAMapNode, SHAMapLeafNode> mLeafByID;
std::map<SHAMapNode, SHAMapInnerNode> mInnerNodeByID;
std::map<uint256, SHAMapNode> mNodeByHash; // includes nodes not present
boost::bimap<uint256, SHAMapNode> NodeHash;
public:
SHAMap();
@@ -130,14 +130,14 @@ public:
ScopedLock Lock() const { return ScopedLock(mLock); }
// inner node access functions
bool HasInnerNode(const SHAMapNode &id);
bool GiveInnerNode(SHAMapInnerNode::pointer);
SHAMapInnerNode::pointer GetInnerNode(const SHAMapNode &);
bool hasInnerNode(const SHAMapNode &id);
bool giveInnerNode(SHAMapInnerNode::pointer);
SHAMapInnerNode::pointer getInnerNode(const SHAMapNode &);
// leaf node access functions
bool HasLeafNode(const SHAMapNode &id);
bool GiveLeafNode(SHAMapLeafNode::pointer);
SHAMapLeafNode::pointer GetLeafNode(const SHAMapNode &);
bool hasLeafNode(const SHAMapNode &id);
bool giveLeafNode(SHAMapLeafNode::pointer);
SHAMapLeafNode::pointer getLeafNode(const SHAMapNode &);
// generic node functions
std::vector<unsigned char> getRawNode(const SHAMapNode &id);
@@ -152,9 +152,15 @@ public:
bool nextHash(uint256 &hash);
bool prevHash(uint256 &hash);
// direct mapping
bool nodeToHash(const SHAMapNode &node, uint256 &hash);
bool hashToNode(const uint256& hash, SHAMapNode &node);
// comparison/sync functions
void getMissingNodes(std::vector<SHAMapNode> &nodeHashes, int max);
void getMissingObjects(std::vector<uint256> &objectHashes, int max);
bool getNodeFat(const SHAMapNode &node, std::vector<uint256> &nodeHashes, int max);
bool getNodeFat(const uint256 &hash, std::vector<uint256> &nodeHashes, int max);
bool addKnownNode(const std::vector<unsigned char>& rawNode);
// overloads for backed maps