00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(AFX_TIGERTREE_H__59910156_59A2_454F_A0FE_0A66B7D37218__INCLUDED_)
00023 #define AFX_TIGERTREE_H__59910156_59A2_454F_A0FE_0A66B7D37218__INCLUDED_
00024
00025 #pragma once
00026
00027 typedef unsigned __int64 WORD64;
00028
00029 class CTigerNode;
00030
00031
00032 class CTigerTree
00033 {
00034
00035 public:
00036 CTigerTree();
00037 ~CTigerTree();
00038
00039 void (*pTiger)(WORD64*, WORD64*);
00040
00041
00042 public:
00043 void SetupAndAllocate(DWORD nHeight, QWORD nLength);
00044 void SetupParameters(QWORD nLength);
00045 void Clear();
00046 void Serialize(CArchive& ar);
00047 DWORD GetSerialSize() const;
00048 public:
00049 BOOL GetRoot(TIGEROOT* pTiger) const;
00050 CString RootToString() const;
00051 void Assume(CTigerTree* pSource);
00052 public:
00053 void BeginFile(DWORD nHeight, QWORD nLength);
00054 void AddToFile(LPCVOID pInput, DWORD nLength);
00055 BOOL FinishFile();
00056 public:
00057 void BeginBlockTest();
00058 void AddToTest(LPCVOID pInput, DWORD nLength);
00059 BOOL FinishBlockTest(DWORD nBlock);
00060 public:
00061 BOOL ToBytes(BYTE** pOutput, DWORD* pnOutput, DWORD nHeight = 0);
00062 BOOL FromBytes(BYTE* pOutput, DWORD nOutput, DWORD nHeight, QWORD nLength);
00063 BOOL CheckIntegrity();
00064 void Dump();
00065
00066
00067 public:
00068 inline BOOL IsAvailable() const { return m_pNode != NULL; }
00069 inline DWORD GetHeight() const { return m_nHeight; }
00070 inline DWORD GetBlockLength() const { return 1024 * m_nBlockCount; }
00071 inline DWORD GetBlockCount() const { return m_nBaseUsed; }
00072
00073
00074 protected:
00075 DWORD m_nHeight;
00076 CTigerNode* m_pNode;
00077 DWORD m_nNodeCount;
00078
00079
00080 protected:
00081 DWORD m_nNodeBase;
00082 DWORD m_nNodePos;
00083 DWORD m_nBaseUsed;
00084 DWORD m_nBlockCount;
00085 DWORD m_nBlockPos;
00086 CTigerNode* m_pStackBase;
00087 CTigerNode* m_pStackTop;
00088 protected:
00089 static WORD64 m_pTable[4*256];
00090
00091
00092 protected:
00093 inline void Collapse();
00094 inline void BlocksToNode();
00095 inline void Tiger(LPCVOID pInput, WORD64 nInput, WORD64* pOutput, WORD64* pInput1 = NULL, WORD64* pInput2 = NULL);
00096
00097 };
00098
00099
00100 class CTigerNode
00101 {
00102
00103 public:
00104 inline CTigerNode()
00105 {
00106 v1 = v2 = v3 = 0;
00107 bValid = FALSE;
00108 }
00109
00110
00111 public:
00112 union
00113 {
00114 WORD64 value[3];
00115 struct
00116 {
00117 WORD64 v1;
00118 WORD64 v2;
00119 WORD64 v3;
00120 };
00121 };
00122
00123 BYTE bValid;
00124
00125
00126 public:
00127 CString ToString();
00128 static CString HashToString(const TIGEROOT* pTiger, BOOL bURN = FALSE);
00129 static BOOL HashFromString(LPCTSTR pszHash, TIGEROOT* pTiger);
00130 static BOOL HashFromURN(LPCTSTR pszHash, TIGEROOT* pTiger);
00131 static BOOL IsNull(TIGEROOT* pTiger);
00132
00133 };
00134
00135 inline bool operator==(const TIGEROOT& tigera, const TIGEROOT& tigerb)
00136 {
00137 return memcmp( &tigera, &tigerb, 24 ) == 0;
00138 }
00139
00140 inline bool operator!=(const TIGEROOT& tigera, const TIGEROOT& tigerb)
00141 {
00142 return memcmp( &tigera, &tigerb, 24 ) != 0;
00143 }
00144
00145 #endif // !defined(AFX_TIGERTREE_H__59910156_59A2_454F_A0FE_0A66B7D37218__INCLUDED_)