GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
merge.hpp
1 
2 // This code is part of the Problem Based Benchmark Suite (PBBS)
3 // Copyright (c) 2010 Guy Blelloch and Harsha Vardhan Simhadri and the PBBS team
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights (to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included
14 // in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 
25 #ifndef DEF_MERGE
26 #define DEF_MERGE
27 
28 template <class ET, class F>
29 void merge(ET* S1, int l1, ET* S2, int l2, ET* R, F f) {
30  ET* pR = R;
31  ET* pS1 = S1;
32  ET* pS2 = S2;
33  ET* eS1 = S1+l1;
34  ET* eS2 = S2+l2;
35  while (true) {
36  *pR++ = f(*pS2,*pS1) ? *pS2++ : *pS1++;
37  if (pS1==eS1) {std::copy(pS2,eS2,pR); break;}
38  if (pS2==eS2) {std::copy(pS1,eS1,pR); break;}
39  }
40 }
41 
42 
43 #endif
44