Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TigerTree.h

Go to the documentation of this file.
00001 //
00002 // TigerTree.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Construction
00035 public:
00036         CTigerTree();
00037         ~CTigerTree();
00038 
00039         void (*pTiger)(WORD64*, WORD64*);
00040 
00041 // Operations
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 // Inlines
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 // Attributes
00074 protected:
00075         DWORD           m_nHeight;
00076         CTigerNode*     m_pNode;
00077         DWORD           m_nNodeCount;
00078 
00079 // Processing Data
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 // Implementation
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 //      inline void     Tiger(WORD64* str, WORD64* state);
00097 };
00098 
00099 
00100 class CTigerNode
00101 {
00102 // Construction
00103 public:
00104         inline CTigerNode()
00105         {
00106                 v1 = v2 = v3 = 0;
00107                 bValid = FALSE;
00108         }
00109 
00110 // Attributes
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 // Operations
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_)

Generated on Thu Dec 15 10:39:50 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2