TPIE

v1.1rc1-6-g0c97303
sort.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2008-2012, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef _AMI_SORT_H
21 #define _AMI_SORT_H
22 
40 
41 // Get definitions for working with Unix and Windows
42 #include <tpie/portability.h>
43 
44 // The typename that actually does the sorting
45 #include <tpie/sort_manager.h>
46 #include <tpie/mergeheap.h>
47 #include <tpie/internal_sort.h>
48 
51 
52 namespace tpie {
53 
58 template<typename T, typename Compare>
59 void sort(file_stream<T> &instream, file_stream<T> &outstream,
60  Compare comp, progress_indicator_base & indicator) {
61 
62  ami::Internal_Sorter_Obj<T,Compare> myInternalSorter(comp);
63  ami::merge_heap_obj<T,Compare> myMergeHeap(comp);
65  mySortManager(&myInternalSorter, &myMergeHeap);
66 
67  mySortManager.sort(&instream, &outstream, &indicator);
68 }
69 
73 template<typename T>
74 void sort(file_stream<T> &instream, file_stream<T> &outstream,
75  tpie::progress_indicator_base* indicator=NULL) {
76  std::less<T> comp;
77  sort(instream, outstream, comp, *indicator);
78 }
79 
80 
81 // ********************************************************************
82 // * *
83 // * Duplicates of the above versions that only use 2x space and *
84 // * overwrite the original input stream *
85 // * *
86 // ********************************************************************/
87 
92 template<typename T, typename Compare>
93 void sort(file_stream<T> &instream, Compare comp,
94  progress_indicator_base & indicator) {
95  sort(instream, instream, comp, indicator);
96 }
97 
101 template<typename T>
102 void sort(file_stream<T> &instream,
103  progress_indicator_base &indicator) {
104  sort(instream, instream, &indicator);
105 }
106 
111 template <typename T>
112 void sort(file_stream<T> & instream) {
113  sort(instream, instream);
114 }
115 
116 } // tpie namespace
117 
118 #include <tpie/sort_deprecated.h>
119 
120 #endif // _AMI_SORT_H
The base class for indicating the progress of some task.
Null-object progress indicator.
Comparision object based Internal_Sorter_base subclass implementation; uses quick_sort_obj().
This file contains a few deprecated definitions for legacy code.
void sort(file_stream< T > *in, file_stream< T > *out, progress_indicator_base *indicator=NULL)
Sort in stream to out stream an save in stream (uses 3x space)
Definition: sort_manager.h:174
Internal sorter objects.
Merge heap templates.
Contains deprecated sorting algorithms.
Progress indicator base.
External merge sorting.
Simple class acting both as file and a file::stream.
Definition: file_stream.h:44
A class of manager objects for merge sorting objects of type T.
Definition: sort_manager.h:58
void sort(file_stream< T > &instream, file_stream< T > &outstream, Compare comp, progress_indicator_base &indicator)
Sort elements of a stream using the given STL-style comparator object.
Definition: sort.h:59