1
/***************************************************************************
2
* Copyright (C) 2005 by Joris Guisson *
3
* joris.guisson@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
23
#include <util/constants.h>
33
Key::Key(const bt::SHA1Hash & k) : bt::SHA1Hash(k)
37
Key::Key(const Uint8* d) : bt::SHA1Hash(d)
41
Key::Key(const QByteArray & ba)
43
for (int i = 0;i < 20 && i < ba.size();i++)
50
bool Key::operator == (const Key & other) const
52
return bt::SHA1Hash::operator ==(other);
55
bool Key::operator != (const Key & other) const
57
return !operator == (other);
60
bool Key::operator < (const Key & other) const
62
for (int i = 0;i < 20;i++)
64
if (hash[i] < other.hash[i])
66
else if (hash[i] > other.hash[i])
72
bool Key::operator <= (const Key & other) const
74
return operator < (other) || operator == (other);
77
bool Key::operator > (const Key & other) const
79
for (int i = 0;i < 20;i++)
81
if (hash[i] < other.hash[i])
83
else if (hash[i] > other.hash[i])
89
bool Key::operator >= (const Key & other) const
91
return operator > (other) || operator == (other);
94
Key Key::distance(const Key & a,const Key & b)
103
for (int i = 0;i < 20;i++)
105
k.hash[i] = (Uint8)rand() % 0xFF;