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

QueryHashGroup.cpp

Go to the documentation of this file.
00001 //
00002 // QueryHashGroup.cpp
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 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "QueryHashGroup.h"
00026 #include "QueryHashTable.h"
00027 #include "QueryHashMaster.h"
00028 
00029 #ifdef _DEBUG
00030 #undef THIS_FILE
00031 static char THIS_FILE[]=__FILE__;
00032 #define new DEBUG_NEW
00033 #endif
00034 
00035 
00037 // CQueryHashGroup construction
00038 
00039 CQueryHashGroup::CQueryHashGroup(DWORD nHash)
00040 {
00041         m_nHash = nHash ? nHash : (DWORD)pow( 2, Settings.Library.QueryRouteSize );
00042         m_pHash = new BYTE[ m_nHash ];
00043         ZeroMemory( m_pHash, m_nHash );
00044         m_nCount = 0;
00045 }
00046 
00047 CQueryHashGroup::~CQueryHashGroup()
00048 {
00049 #ifdef _DEBUG
00050         BYTE* pTest = m_pHash;
00051 
00052         for ( DWORD nHash = m_nHash ; nHash ; nHash-- )
00053         {
00054                 ASSERT( *pTest++ == 0 );
00055         }
00056 #endif
00057 
00058         delete [] m_pHash;
00059 }
00060 
00062 // CQueryHashGroup add a table
00063 
00064 void CQueryHashGroup::Add(CQueryHashTable* pTable)
00065 {
00066         ASSERT( pTable != NULL );
00067         ASSERT( pTable->m_pGroup == NULL );
00068         ASSERT( m_pTables.Find( pTable ) == NULL );
00069 
00070         pTable->m_pGroup = this;
00071         m_pTables.AddTail( pTable );
00072 
00073         Operate( pTable, TRUE );
00074         QueryHashMaster.Invalidate();
00075 }
00076 
00078 // CQueryHashGroup remove a table
00079 
00080 void CQueryHashGroup::Remove(CQueryHashTable* pTable)
00081 {
00082         ASSERT( pTable != NULL );
00083         ASSERT( pTable->m_pGroup == this );
00084 
00085         POSITION pos = m_pTables.Find( pTable );
00086         ASSERT( pos != NULL );
00087 
00088         m_pTables.RemoveAt( pos );
00089         pTable->m_pGroup = NULL;
00090 
00091         Operate( pTable, FALSE );
00092         QueryHashMaster.Invalidate();
00093 }
00094 
00096 // CQueryHashGroup operate
00097 
00098 void CQueryHashGroup::Operate(CQueryHashTable* pTable, BOOL bAdd)
00099 {
00100         ASSERT( m_pHash != NULL );
00101         ASSERT( pTable->m_nHash == m_nHash );
00102         //ToDo: Check this
00103         //ASSERT( pTable->m_nInfinity == 1 ); //This causes problems with G1 leaves
00104 
00105         BYTE* pSource = pTable->m_pHash;
00106         BYTE* pTarget = m_pHash;
00107 
00108         if ( bAdd )
00109         {
00110                 for ( DWORD nHash = m_nHash >> 3 ; nHash ; nHash-- )
00111                 {
00112                         register BYTE nSource = *pSource++;
00113 
00114                         if ( ( nSource & 0x01 ) == 0 ) (*pTarget++) ++; else pTarget++;
00115                         if ( ( nSource & 0x02 ) == 0 ) (*pTarget++) ++; else pTarget++;
00116                         if ( ( nSource & 0x04 ) == 0 ) (*pTarget++) ++; else pTarget++;
00117                         if ( ( nSource & 0x08 ) == 0 ) (*pTarget++) ++; else pTarget++;
00118                         if ( ( nSource & 0x10 ) == 0 ) (*pTarget++) ++; else pTarget++;
00119                         if ( ( nSource & 0x20 ) == 0 ) (*pTarget++) ++; else pTarget++;
00120                         if ( ( nSource & 0x40 ) == 0 ) (*pTarget++) ++; else pTarget++;
00121                         if ( ( nSource & 0x80 ) == 0 ) (*pTarget++) ++; else pTarget++;
00122                 }
00123         }
00124         else
00125         {
00126                 for ( DWORD nHash = m_nHash >> 3 ; nHash ; nHash-- )
00127                 {
00128                         register BYTE nSource = *pSource++;
00129 
00130                         if ( ( nSource & 0x01 ) == 0 ) (*pTarget++) --; else pTarget++;
00131                         if ( ( nSource & 0x02 ) == 0 ) (*pTarget++) --; else pTarget++;
00132                         if ( ( nSource & 0x04 ) == 0 ) (*pTarget++) --; else pTarget++;
00133                         if ( ( nSource & 0x08 ) == 0 ) (*pTarget++) --; else pTarget++;
00134                         if ( ( nSource & 0x10 ) == 0 ) (*pTarget++) --; else pTarget++;
00135                         if ( ( nSource & 0x20 ) == 0 ) (*pTarget++) --; else pTarget++;
00136                         if ( ( nSource & 0x40 ) == 0 ) (*pTarget++) --; else pTarget++;
00137                         if ( ( nSource & 0x80 ) == 0 ) (*pTarget++) --; else pTarget++;
00138                 }
00139         }
00140 }

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