Skip to content

Commit 183ea48

Browse files
committed
Starting cleanup of algo stuff.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/libtorrent@451 e378c898-3ddf-0310-93e7-cc216c733640
1 parent 99c8a08 commit 183ea48

9 files changed

+375
-110
lines changed

Makefile.am

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pkgconfig_DATA = libtorrent.pc
66
EXTRA_DIST= \
77
autogen.sh \
88
scripts/checks.m4 \
9+
scripts/common.m4 \
910
algo/algo.h \
1011
algo/common.h \
1112
algo/common_impl.h \
@@ -19,4 +20,7 @@ EXTRA_DIST= \
1920
algo/ref_anchored.h \
2021
doc/main.xml \
2122
doc/http.xml \
22-
doc/torrent.xml
23+
doc/torrent.xml \
24+
rak/algorithm.h \
25+
rak/functional.h
26+

TODO

+8-11
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,14 @@ BUGS:
9797
Snubing seems borked... why?
9898

9999

100-
CURRENT:
100+
THINGS:
101101

102102
Move mkdir stuff out of Path?
103103

104104
Cleanup HashQueue, seperate out nodes etc.
105105
* Make it a private list.
106106
* Don't pass Chunk in SlotDone.
107107

108-
Make HashChunk::remaining inline.
109-
110108
SocketManager must be enabled.
111109

112110

@@ -128,25 +126,24 @@ Add buffer read of piece.
128126
Fix tracker so it checks regulary when too few peers are connected.
129127

130128

131-
RELEASE:
132-
133-
Remove debug checks in SocketSet. (Next release)
134-
135-
136129
POLLING:
137130

138131
Consider sorting SocketSet so we can get maxFd cheaper. Epoll might
139132
not need this, so consider the value.
140133

141134
Rename poll.h.
142135

136+
Do we need seperate ip for each torrent?
137+
138+
Resync upon loading a torrent, to reset it's timestamp?
139+
143140

144141
CLEANUP:
145142

146143
ref_anchored... urgh...
147144

148145

149-
FIFO QUEUE:
146+
CURRENT:
150147

151-
Program received signal SIGABRT, Aborted. ( See mail May-25)
152-
?Propably solved?
148+
Make sure setting stuff in torrent::Download does not restrict more
149+
thatn it should. 1000 is too low.

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
AC_INIT(libtorrent, 0.6.3, [email protected])
1+
AC_INIT(libtorrent, 0.6.4, [email protected])
22

33
dnl Find a better way to do this
44
AC_DEFINE(PEER_NAME,
5-
"-lt0603-",
5+
"-lt0604-",
66
Identifier that is part of the default peer id)
77

88
LIBTORRENT_CURRENT=3

doc/RELEASE_CHECKLIST

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ release.
88
* Package releases.
99
* Upload to host.
1010

11+
* Update frontpage.
1112
* Download, compile and test.
1213
* Tag the release in SVN.
13-
* Update frontpage, send mail to the ML, update ChangeLog page.
14+
* Send mail to the ML, update ChangeLog page.

rak/algorithm.h

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// rTorrent - BitTorrent client
2+
// Copyright (C) 2005, Jari Sundell
3+
//
4+
// This program is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation; either version 2 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program; if not, write to the Free Software
16+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
//
18+
// Contact: Jari Sundell <[email protected]>
19+
//
20+
// Skomakerveien 33
21+
// 3185 Skoppum, NORWAY
22+
23+
#ifndef RTORRENT_UTILS_ALGORITHM_H
24+
#define RTORRENT_UTILS_ALGORITHM_H
25+
26+
#include <algorithm>
27+
28+
namespace rak {
29+
30+
template <typename _InputIter, typename _Function>
31+
_Function
32+
for_each_pre(_InputIter __first, _InputIter __last, _Function __f) {
33+
_InputIter __tmp;
34+
35+
while (__first != __last) {
36+
__tmp = __first++;
37+
38+
__f(*__tmp);
39+
}
40+
41+
return __f;
42+
}
43+
44+
// Return a range with a distance of no more than __distance and
45+
// between __first and __last, centered on __middle1.
46+
template <typename _InputIter, typename _Distance>
47+
std::pair<_InputIter, _InputIter>
48+
advance_bidirectional(_InputIter __first, _InputIter __middle1, _InputIter __last, _Distance __distance) {
49+
_InputIter __middle2 = __middle1;
50+
51+
do {
52+
if (!__distance)
53+
break;
54+
55+
if (__middle1 != __first) {
56+
--__middle1;
57+
--__distance;
58+
59+
} else if (__middle2 == __last) {
60+
break;
61+
}
62+
63+
if (!__distance)
64+
break;
65+
66+
if (__middle2 != __last) {
67+
++__middle2;
68+
--__distance;
69+
70+
} else if (__middle1 == __first) {
71+
break;
72+
}
73+
} while (true);
74+
75+
return std::make_pair(__middle1, __middle2);
76+
}
77+
78+
template <typename _Value>
79+
struct
80+
compare_base : public std::binary_function<_Value, _Value, bool> {
81+
bool operator () (const _Value& complete, const _Value& base) const {
82+
return !complete.compare(0, base.size(), base);
83+
}
84+
};
85+
86+
// Count the number of elements from the start of the containers to
87+
// the first inequal element.
88+
template <typename _InputIter>
89+
typename std::iterator_traits<_InputIter>::difference_type
90+
count_base(_InputIter __first1, _InputIter __last1,
91+
_InputIter __first2, _InputIter __last2) {
92+
93+
typename std::iterator_traits<_InputIter>::difference_type __n = 0;
94+
95+
for ( ;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2, ++__n)
96+
if (*__first1 != *__first2)
97+
return __n;
98+
99+
return __n;
100+
}
101+
102+
template <typename _InputIter>
103+
typename std::iterator_traits<_InputIter>::value_type
104+
make_base(_InputIter __first, _InputIter __last) {
105+
if (__first == __last)
106+
return "";
107+
108+
typename std::iterator_traits<_InputIter>::value_type __base = *__first++;
109+
110+
for ( ;__first != __last; ++__first) {
111+
typename std::iterator_traits<_InputIter>::difference_type __pos = count_base(__base.begin(), __base.end(),
112+
__first->begin(), __first->end());
113+
114+
if (__pos < (typename std::iterator_traits<_InputIter>::difference_type)__base.size())
115+
__base.resize(__pos);
116+
}
117+
118+
return __base;
119+
}
120+
121+
}
122+
123+
#endif

rak/functional.h

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// rTorrent - BitTorrent client
2+
// Copyright (C) 2005, Jari Sundell
3+
//
4+
// This program is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation; either version 2 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program; if not, write to the Free Software
16+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
//
18+
// Contact: Jari Sundell <[email protected]>
19+
//
20+
// Skomakerveien 33
21+
// 3185 Skoppum, NORWAY
22+
23+
#ifndef RTORRENT_UTILS_FUNCTIONAL_H
24+
#define RTORRENT_UTILS_FUNCTIONAL_H
25+
26+
#include <functional>
27+
28+
namespace rak {
29+
30+
template <typename Type, typename Ftor>
31+
struct _accumulate {
32+
_accumulate(Type& t, Ftor f) : m_t(t), m_f(f) {}
33+
34+
template <typename Arg>
35+
void operator () (Arg& a) { m_t += m_f(a); }
36+
37+
Type& m_t;
38+
Ftor m_f;
39+
};
40+
41+
template <typename Type, typename Ftor>
42+
inline _accumulate<Type, Ftor>
43+
accumulate(Type& t, Ftor f) {
44+
return _accumulate<Type, Ftor>(t, f);
45+
}
46+
47+
template <typename Type, typename Ftor>
48+
struct _equal {
49+
_equal(Type t, Ftor f) : m_t(t), m_f(f) {}
50+
51+
template <typename Arg>
52+
bool operator () (Arg& a) {
53+
return m_t == m_f(a);
54+
}
55+
56+
Type m_t;
57+
Ftor m_f;
58+
};
59+
60+
template <typename Type, typename Ftor>
61+
inline _equal<Type, Ftor>
62+
equal(Type t, Ftor f) {
63+
return _equal<Type, Ftor>(t, f);
64+
}
65+
66+
template <typename Src, typename Dest>
67+
struct _on : public std::unary_function<typename Src::argument_type, typename Dest::result_type> {
68+
_on(Src s, Dest d) : m_dest(d), m_src(s) {}
69+
70+
typename Dest::result_type operator () (typename Src::argument_type arg) {
71+
return m_dest(m_src(arg));
72+
}
73+
74+
Dest m_dest;
75+
Src m_src;
76+
};
77+
78+
template <typename Src, typename Dest>
79+
inline _on<Src, Dest>
80+
on(Src s, Dest d) {
81+
return _on<Src, Dest>(s, d);
82+
}
83+
84+
// Creates a functor for accessing a member.
85+
template <typename Class, typename Member>
86+
struct _mem_ptr_ref : public std::unary_function<Class&, Member&> {
87+
_mem_ptr_ref(Member Class::*m) : m_member(m) {}
88+
89+
Member& operator () (Class& c) {
90+
return c.*m_member;
91+
}
92+
93+
Member Class::*m_member;
94+
};
95+
96+
template <typename Class, typename Member>
97+
inline _mem_ptr_ref<Class, Member>
98+
mem_ptr_ref(Member Class::*m) {
99+
return _mem_ptr_ref<Class, Member>(m);
100+
}
101+
102+
template <typename Cond, typename Then>
103+
struct _if_then {
104+
_if_then(Cond c, Then t) : m_cond(c), m_then(t) {}
105+
106+
template <typename Arg>
107+
void operator () (Arg& a) {
108+
if (m_cond(a))
109+
m_then(a);
110+
}
111+
112+
Cond m_cond;
113+
Then m_then;
114+
};
115+
116+
template <typename Cond, typename Then>
117+
inline _if_then<Cond, Then>
118+
if_then(Cond c, Then t) {
119+
return _if_then<Cond, Then>(c, t);
120+
}
121+
122+
template <typename T>
123+
struct call_delete : public std::unary_function<T*, void> {
124+
void operator () (T* t) {
125+
delete t;
126+
}
127+
};
128+
129+
}
130+
131+
#endif

0 commit comments

Comments
 (0)