0
2
0
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2009 |
|
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef RADIX_SORT_H |
20 | 20 |
#define RADIX_SORT_H |
21 | 21 |
|
... | ... |
@@ -335,45 +335,45 @@ |
335 | 335 |
std::copy(first, last, buffer); |
336 | 336 |
for (int i = 0; i < int(sizeof(Value)) - 1; ++i) { |
337 | 337 |
if (dir) { |
338 | 338 |
stableRadixIntroSort(buffer, buffer + length, buffer + length, |
339 | 339 |
i, functor); |
340 | 340 |
} else { |
341 | 341 |
stableRadixIntroSort(buffer + length, buffer + 2 * length, buffer, |
342 | 342 |
i, functor); |
343 | 343 |
} |
344 | 344 |
dir = !dir; |
345 | 345 |
} |
346 | 346 |
if (dir) { |
347 | 347 |
signedStableRadixIntroSort(buffer, buffer + length, buffer + length, |
348 | 348 |
sizeof(Value) - 1, functor); |
349 | 349 |
std::copy(buffer + length, buffer + 2 * length, first); |
350 | 350 |
} else { |
351 |
signedStableRadixIntroSort(buffer + length, buffer + 2 * length, |
|
351 |
signedStableRadixIntroSort(buffer + length, buffer + 2 * length, |
|
352 | 352 |
buffer, sizeof(Value) - 1, functor); |
353 | 353 |
std::copy(buffer, buffer + length, first); |
354 | 354 |
} |
355 | 355 |
} catch (...) { |
356 | 356 |
allocator.deallocate(buffer, 2 * length); |
357 | 357 |
throw; |
358 | 358 |
} |
359 | 359 |
allocator.deallocate(buffer, 2 * length); |
360 | 360 |
} |
361 | 361 |
|
362 | 362 |
template <typename Value, typename Iterator, typename Functor> |
363 |
void stableRadixUnsignedSort(Iterator first, Iterator last, |
|
363 |
void stableRadixUnsignedSort(Iterator first, Iterator last, |
|
364 | 364 |
Functor functor) { |
365 | 365 |
if (first == last) return; |
366 | 366 |
typedef typename std::iterator_traits<Iterator>::value_type Key; |
367 | 367 |
typedef std::allocator<Key> Allocator; |
368 | 368 |
Allocator allocator; |
369 | 369 |
|
370 | 370 |
int length = std::distance(first, last); |
371 | 371 |
Key *buffer = allocator.allocate(2 * length); |
372 | 372 |
try { |
373 | 373 |
bool dir = true; |
374 | 374 |
std::copy(first, last, buffer); |
375 | 375 |
for (int i = 0; i < int(sizeof(Value)); ++i) { |
376 | 376 |
if (dir) { |
377 | 377 |
stableRadixIntroSort(buffer, buffer + length, |
378 | 378 |
buffer + length, i, functor); |
379 | 379 |
} else { |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2009 |
|
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <lemon/time_measure.h> |
20 | 20 |
#include <lemon/smart_graph.h> |
21 | 21 |
#include <lemon/maps.h> |
0 comments (0 inline)