diff --git a/DB/MD5.h b/DB/MD5.h index b3684866..ec860ae5 100644 --- a/DB/MD5.h +++ b/DB/MD5.h @@ -1,64 +1,71 @@ /* Copyright (C) 2018 Johannes Zarl-Zierl Copyright (C) 2007-2010 Tuomas Suutari This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see the file COPYING); if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef DB_MD5_H #define DB_MD5_H #include #include namespace DB { class FileName; class MD5 { public: MD5(); explicit MD5(const QString& md5str); bool isNull() const; MD5& operator=(const QString& md5str); /** Get hex string representation of this. * If this->isNull(), returns null string. */ QString toHexString() const; bool operator==(const MD5 &other) const; bool operator!=(const MD5& other) const; bool operator<(const MD5& other) const; + inline uint hash() const { return (uint) m_v0 ^ m_v1; } + private: bool m_isNull; qulonglong m_v0; qulonglong m_v1; }; +inline uint qHash(const MD5 &key) +{ + return key.hash(); +} + DB::MD5 MD5Sum( const DB::FileName& fileName ); } #endif /* DB_MD5_H */ // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/DB/MD5Map.cpp b/DB/MD5Map.cpp index 27bd9902..a055c15c 100644 --- a/DB/MD5Map.cpp +++ b/DB/MD5Map.cpp @@ -1,66 +1,66 @@ /* Copyright (C) 2003-2010 Jesper K. Pedersen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "MD5Map.h" using namespace DB; void MD5Map::insert( const MD5& md5sum, const DB::FileName& fileName ) { m_map.insert( md5sum, fileName ); m_i_map.insert( fileName, md5sum ); } DB::FileName MD5Map::lookup( const MD5& md5sum ) const { return m_map[md5sum]; } MD5 MD5Map::lookupFile( const DB::FileName& fileName ) const { return m_i_map[fileName]; } bool MD5Map::contains( const MD5& md5sum ) const { return m_map.contains( md5sum ); } bool MD5Map::containsFile( const DB::FileName& fileName ) const { return m_i_map.contains( fileName ); } void MD5Map::clear() { m_map.clear(); m_i_map.clear(); } DB::FileNameSet DB::MD5Map::diff( const MD5Map& other ) const { DB::FileNameSet res; - for( QMap::ConstIterator it = m_map.begin(); it != m_map.end(); ++it ) { + for( MD5FileMap::ConstIterator it = m_map.begin(); it != m_map.end(); ++it ) { if ( other.lookup( it.key() ) != it.value() ) res.insert( it.value() ); } return res; } // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/DB/MD5Map.h b/DB/MD5Map.h index 28a3d078..fdb8d344 100644 --- a/DB/MD5Map.h +++ b/DB/MD5Map.h @@ -1,54 +1,57 @@ /* Copyright (C) 2003-2010 Jesper K. Pedersen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MD5MAP_H #define MD5MAP_H #include -#include +#include #include "MD5.h" #include namespace DB { + typedef QHash MD5FileMap; + typedef QHash FileMD5Map; + /** This class may be overridden by a which wants to store md5 information directly in a database, rather than in a map in memory. **/ class MD5Map { public: virtual ~MD5Map() {} virtual void insert( const MD5& md5sum, const DB::FileName& fileName ); virtual DB::FileName lookup( const MD5& md5sum ) const; virtual MD5 lookupFile( const DB::FileName& fileName ) const; virtual bool contains( const MD5& md5sum ) const; virtual bool containsFile( const DB::FileName& fileName ) const; virtual void clear(); virtual DB::FileNameSet diff( const MD5Map& other ) const; private: - QMap m_map; - QMap m_i_map; + MD5FileMap m_map; + FileMD5Map m_i_map; }; } #endif /* MD5MAP_H */ // vi:expandtab:tabstop=4 shiftwidth=4: