~ubuntu-branches/ubuntu/trusty/libtorrent/trusty

« back to all changes in this revision

Viewing changes to src/torrent/utils/extents.h

  • Committer: Package Import Robot
  • Author(s): Rogério Brito, Benoît Knecht, Rogério Brito
  • Date: 2012-05-29 01:19:37 UTC
  • mfrom: (1.1.15) (4.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120529011937-lobv0fvgy5ps3o3d
Tags: 0.13.2-1
[ Benoît Knecht ]
* New upstream version. Closes: #632315.
* Run the test suite at build time.
* Let upstream's configure script choose between Linux's fallocate(2) and
  posix_fallocate(3).
* Put the complete MPL-1.1 in debian/copyright, as required by debian policy
  12.5.

[ Rogério Brito ]
* debian/control:
  + Remove useless coding indication.
  + Add Benoît to the list of uploaders. Thanks for reviving this!
* debian/copyright: Update my copyright years.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// libTorrent - BitTorrent library
2
 
// Copyright (C) 2005-2007, Jari Sundell
 
2
// Copyright (C) 2005-2011, Jari Sundell
3
3
//
4
4
// This program is free software; you can redistribute it and/or modify
5
5
// it under the terms of the GNU General Public License as published by
88
88
  typedef typename base_type::range_type        range_type;
89
89
  typedef typename base_type::mapped_type       mapped_type;
90
90
  typedef typename base_type::mapped_value_type mapped_value_type;
91
 
  //  typedef std::pair<key_type, mapped_type> value_type;
 
91
  typedef typename base_type::table_type        table_type;
92
92
 
93
93
  static const key_type mask_bits  = MaskBits;
94
94
  static const key_type table_bits = TableBits;
133
133
template <typename Key, typename Tp, unsigned int MaskBits, unsigned int TableSize, unsigned int TableBits>
134
134
void
135
135
extents<Key, Tp, MaskBits, TableSize, TableBits>::insert(key_type pos, unsigned int mb, const mapped_value_type& val) {
136
 
  // Temporarily removed.
 
136
  key_type mask = ~key_type() << mb;
 
137
 
 
138
  base_type::insert(pos & mask, mb, val);
137
139
}
138
140
 
139
141
template <typename Key, typename Tp, unsigned int TableSize, unsigned int TableBits>
140
142
void
141
143
extents_base<Key, Tp, TableSize, TableBits>::insert(key_type pos, unsigned int mb, const mapped_value_type& val) {
142
 
  // Temporarily removed.
 
144
  // RESTRICTED
 
145
  typename table_type::iterator first = partition_at(pos);
 
146
  typename table_type::iterator last = partition_at(pos) + mask_distance(mb) + 1;
 
147
 
 
148
  if (mb < mask_bits) {
 
149
    if (first->first == NULL)
 
150
      first->first = new extents_base(this, first);
 
151
    
 
152
    first->first->insert(pos, mb, val);
 
153
    return;
 
154
  }
 
155
 
 
156
  while (first != last) {
 
157
    if (first->first != NULL) {
 
158
      delete first->first;
 
159
      first->first = NULL;
 
160
    }
 
161
    
 
162
    (first++)->second = val;
 
163
  }
143
164
}
144
165
 
145
166
template <typename Key, typename Tp, unsigned int MaskBits, unsigned int TableSize, unsigned int TableBits>
146
167
bool
147
168
extents<Key, Tp, MaskBits, TableSize, TableBits>::is_equal_range(key_type first, key_type last, const mapped_value_type& val) const {
148
 
  // Temporarily removed.
149
 
  return false;
 
169
  // RESTRICTED
 
170
  first = std::max(first, key_type());
 
171
  last = std::min(last, key_type() + (~key_type() >> (sizeof(key_type) * 8 - MaskBits)));
 
172
 
 
173
  if (first <= last)
 
174
    return base_type::is_equal_range(first, last, val);
 
175
  else
 
176
    return true;
150
177
}
151
178
 
152
179
template <typename Key, typename Tp, unsigned int TableSize, unsigned int TableBits>
153
180
bool
154
181
extents_base<Key, Tp, TableSize, TableBits>::is_equal_range(key_type key_first, key_type key_last, const mapped_value_type& val) const {
155
 
  // Temporarily removed.
156
 
  return false;
 
182
  // RESTRICTED
 
183
  typename table_type::const_iterator first = partition_at(key_first);
 
184
  typename table_type::const_iterator last = partition_at(key_last) + 1;
 
185
 
 
186
  do {
 
187
    //    std::cout << "shift_amount " << key_first << ' ' << key_last << std::endl;
 
188
 
 
189
    if (first->first == NULL && val != first->second)
 
190
      return false;
 
191
 
 
192
    if (first->first != NULL && !first->first->is_equal_range(std::max(key_first, partition_pos(first)),
 
193
                                                              std::min(key_last, partition_pos(first + 1) - 1), val))
 
194
      return false;
 
195
 
 
196
  } while (++first != last);
 
197
 
 
198
  return true;
157
199
}
158
200
 
159
201
// Assumes 'key' is within the range of the range.