| 1 | #cxx . . $ `<file>/meryl/merge.C`/include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | #include "meryl.H"cxx . . $ `<file>/meryl/meryl.H`/ |
| 6 | #include "libmeryl.H"cxx . . $ `<file>/libmeryl/libmeryl.H`/ |
| 7 | |
| 8 | |
| 9 | |
| 10 | void |
| 11 | multipleOperationscxx . . $ multipleOperations(aab238e627804bcb).(merylArgscxx . . $ merylArgs# *args) { |
| 12 | |
| 13 | if (args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen. < 2) { |
| 14 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - must have at least two databases (you gave "uint32FMTcxx . . $ `libutil/util.h:65:10`!")!\n", args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.); |
| 15 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 16 | } |
| 17 | if (args->outputFilecxx . . $ merylArgs#outputFile. == 0L) { |
| 18 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - no output file specified.\n"); |
| 19 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 20 | } |
| 21 | if ((args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_MERGEcxx . . $ `meryl/meryl.H:6:9`!) && |
| 22 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_MINcxx . . $ `meryl/meryl.H:8:9`!) && |
| 23 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_MINEXISTcxx . . $ `meryl/meryl.H:9:9`!) && |
| 24 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_MAXcxx . . $ `meryl/meryl.H:10:9`!) && |
| 25 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_MAXEXISTcxx . . $ `meryl/meryl.H:11:9`!) && |
| 26 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_ADDcxx . . $ `meryl/meryl.H:12:9`!) && |
| 27 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_ANDcxx . . $ `meryl/meryl.H:17:9`!) && |
| 28 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_NANDcxx . . $ `meryl/meryl.H:18:9`!) && |
| 29 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_ORcxx . . $ `meryl/meryl.H:19:9`!) && |
| 30 | (args->personalitycxx . . $ merylArgs#personality. != PERSONALITY_XORcxx . . $ `meryl/meryl.H:20:9`!)) { |
| 31 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - only personalities min, minexist, max, maxexist, add, and, nand, or, xor\n"); |
| 32 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - are supported in multipleOperations(). (%d)\n", args->personalitycxx . . $ merylArgs#personality.); |
| 33 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - this is a coding error, not a user error.\n"); |
| 34 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 35 | } |
| 36 | |
| 37 | merylStreamReadercxx . . $ merylStreamReader# **R = new merylStreamReadercxx . . $ merylStreamReader#* [args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.]; |
| 38 | merylStreamWritercxx . . $ merylStreamWriter# *W = 0L; |
| 39 | |
| 40 | // Open the input files, read in the first mer |
| 41 | // |
| 42 | for (uint32cxx . . $ uint32# i=0; i<args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.; i++) { |
| 43 | R[i] = new merylStreamReadercxx . . $ merylStreamReader#(args->mergeFilescxx . . $ merylArgs#mergeFiles.[i]); |
| 44 | R[i]->nextMercxx . . $ merylStreamReader#nextMer(c9857a73d68e59ba).(); |
| 45 | } |
| 46 | |
| 47 | // Verify that the mersizes are all the same |
| 48 | // |
| 49 | bool fail = false; |
| 50 | uint32cxx . . $ uint32# merSize = R[0]->merSizecxx . . $ merylStreamReader#merSize(db52760e79bf9054).(); |
| 51 | uint32cxx . . $ uint32# merComp = R[0]->merCompressioncxx . . $ merylStreamReader#merCompression(db52760e79bf9054).(); |
| 52 | |
| 53 | for (uint32cxx . . $ uint32# i=0; i<args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.; i++) { |
| 54 | fail |= (merSize != R[i]->merSizecxx . . $ merylStreamReader#merSize(db52760e79bf9054).()); |
| 55 | fail |= (merComp != R[i]->merCompressioncxx . . $ merylStreamReader#merCompression(db52760e79bf9054).()); |
| 56 | } |
| 57 | |
| 58 | if (fail) |
| 59 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: mer sizes (or compression level) differ.\n"), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 60 | |
| 61 | // Open the output file, using the largest prefix size found in the |
| 62 | // input/mask files. |
| 63 | // |
| 64 | uint32cxx . . $ uint32# prefixSize = 0; |
| 65 | for (uint32cxx . . $ uint32# i=0; i<args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.; i++) |
| 66 | if (prefixSize < R[i]->prefixSizecxx . . $ merylStreamReader#prefixSize(db52760e79bf9054).()) |
| 67 | prefixSize = R[i]->prefixSizecxx . . $ merylStreamReader#prefixSize(db52760e79bf9054).(); |
| 68 | |
| 69 | W = new merylStreamWritercxx . . $ merylStreamWriter#(args->outputFilecxx . . $ merylArgs#outputFile., merSize, merComp, prefixSize, args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.); |
| 70 | |
| 71 | // We will find the smallest mer in any file, and count the number of times |
| 72 | // it is present in the input files. |
| 73 | |
| 74 | bool moreInput = true; |
| 75 | |
| 76 | kMercxx . . $ kMer# currentMercxx . . $ kMerTiny#kMerTiny(cb2f890c2fdad230).; // The current mer we're operating on |
| 77 | uint32cxx . . $ uint32# currentCount = uint32ZEROcxx . . $ `libutil/util.h:60:10`!; // The count (operation dependent) of this mer |
| 78 | uint32cxx . . $ uint32# currentTimes = uint32ZEROcxx . . $ `libutil/util.h:60:10`!; // Number of files it's in |
| 79 | |
| 80 | uint32cxx . . $ uint32# currentPositionsMax = 0; |
| 81 | uint32cxx . . $ uint32# *currentPositions = 0L; |
| 82 | |
| 83 | kMercxx . . $ kMer# thisMercxx . . $ kMerTiny#kMerTiny(cb2f890c2fdad230).; // The mer we just read |
| 84 | uint32cxx . . $ uint32# thisFile = ~uint32ZEROcxx . . $ `libutil/util.h:60:10`!; // The file we read it from |
| 85 | uint32cxx . . $ uint32# thisCount = uint32ZEROcxx . . $ `libutil/util.h:60:10`!; // The count of the mer we just read |
| 86 | |
| 87 | speedCountercxx . . $ speedCounter# *C = new speedCountercxx . . $ speedCounter#(" %7.2f Mmers -- %5.2f Mmers/second\r", 1000000.0, 0x1fffff, args->beVerbosecxx . . $ merylArgs#beVerbose.); |
| 88 | |
| 89 | currentMer.setMerSizecxx . . $ kMerTiny#setMerSize(cb2f890c2fdad230).(merSize); |
| 90 | thisMer.setMerSizecxx . . $ kMerTiny#setMerSize(cb2f890c2fdad230).(merSize); |
| 91 | |
| 92 | while (moreInput) { |
| 93 | |
| 94 | // Find the smallest mer present in any input file. |
| 95 | // |
| 96 | moreInput = false; |
| 97 | thisMer.clearcxx . . $ kMerTiny#clear(49f6e7a06ebc5aa8).(); |
| 98 | thisFile = ~uint32ZEROcxx . . $ `libutil/util.h:60:10`!; |
| 99 | thisCount = uint32ZEROcxx . . $ `libutil/util.h:60:10`!; |
| 100 | |
| 101 | // Load thisMer with the first valid mer |
| 102 | for (uint32cxx . . $ uint32# i=0; i<args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen. && !moreInput; i++) |
| 103 | if (R[i]->validMercxx . . $ merylStreamReader#validMer(c9857a73d68e59ba).()) { |
| 104 | moreInput = true; |
| 105 | thisCount = R[i]->theCountcxx . . $ merylStreamReader#theCount(f708dce9a8856c70).(); |
| 106 | thisFile = i; |
| 107 | thisMer =cxx . . $ kMerTiny#`operator=`(5201545c79316968). R[i]->theFMercxx . . $ merylStreamReader#theFMer(2767e3d60d24e1a3).(); |
| 108 | } |
| 109 | |
| 110 | // Now find the smallest one |
| 111 | if (moreInput) { |
| 112 | for (uint32cxx . . $ uint32# i=thisFile+1; i<args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.; i++) |
| 113 | if ((R[i]->validMercxx . . $ merylStreamReader#validMer(c9857a73d68e59ba).()) && (R[i]->theFMercxx . . $ merylStreamReader#theFMer(2767e3d60d24e1a3).()) <cxx . . $ kMerTiny#`operator<`(3a2dde3078dcd13f). thisMer) { |
| 114 | moreInput = true; |
| 115 | thisCount = R[i]->theCountcxx . . $ merylStreamReader#theCount(f708dce9a8856c70).(); |
| 116 | thisFile = i; |
| 117 | thisMer =cxx . . $ kMerTiny#`operator=`(5201545c79316968). R[i]->theFMercxx . . $ merylStreamReader#theFMer(2767e3d60d24e1a3).(); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // If we've hit a different mer, write out the last one |
| 122 | if ((moreInput == false) || (thisMer !=cxx . . $ kMerTiny#`operator!=`(3a2dde3078dcd13f). currentMer)) { |
| 123 | switch (args->personalitycxx . . $ merylArgs#personality.) { |
| 124 | case PERSONALITY_MINcxx . . $ `meryl/meryl.H:8:9`!: |
| 125 | case PERSONALITY_MAXcxx . . $ `meryl/meryl.H:10:9`!: |
| 126 | if (currentTimes == args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.) |
| 127 | W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(currentMer, currentCount); |
| 128 | break; |
| 129 | case PERSONALITY_MERGEcxx . . $ `meryl/meryl.H:6:9`!: |
| 130 | case PERSONALITY_MINEXISTcxx . . $ `meryl/meryl.H:9:9`!: |
| 131 | case PERSONALITY_MAXEXISTcxx . . $ `meryl/meryl.H:11:9`!: |
| 132 | case PERSONALITY_ADDcxx . . $ `meryl/meryl.H:12:9`!: |
| 133 | W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(currentMer, currentCount, currentPositions); |
| 134 | break; |
| 135 | case PERSONALITY_ANDcxx . . $ `meryl/meryl.H:17:9`!: |
| 136 | if (currentTimes == args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.) |
| 137 | W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(currentMer, currentCount); |
| 138 | break; |
| 139 | case PERSONALITY_NANDcxx . . $ `meryl/meryl.H:18:9`!: |
| 140 | if (currentTimes != args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.) |
| 141 | W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(currentMer, currentCount); |
| 142 | break; |
| 143 | case PERSONALITY_ORcxx . . $ `meryl/meryl.H:19:9`!: |
| 144 | W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(currentMer, currentCount); |
| 145 | break; |
| 146 | case PERSONALITY_XORcxx . . $ `meryl/meryl.H:20:9`!: |
| 147 | if ((currentTimes % 2) == 1) |
| 148 | W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(currentMer, currentCount); |
| 149 | break; |
| 150 | default: |
| 151 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - invalid personality in multipleOperations::write\n"); |
| 152 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - this is a coding error, not a user error.\n"); |
| 153 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | currentMer =cxx . . $ kMerTiny#`operator=`(5201545c79316968). thisMer; |
| 158 | |
| 159 | currentCount = uint32ZEROcxx . . $ `libutil/util.h:60:10`!; |
| 160 | currentTimes = uint32ZEROcxx . . $ `libutil/util.h:60:10`!; |
| 161 | |
| 162 | C->tickcxx . . $ speedCounter#tick(c9857a73d68e59ba).(); |
| 163 | } |
| 164 | |
| 165 | // All done? Exit. |
| 166 | if (moreInput == false) |
| 167 | continue; |
| 168 | |
| 169 | // Perform the operation |
| 170 | switch (args->personalitycxx . . $ merylArgs#personality.) { |
| 171 | case PERSONALITY_MERGEcxx . . $ `meryl/meryl.H:6:9`!: |
| 172 | if (R[thisFile]->thePositionscxx . . $ merylStreamReader#thePositions(ac695d451f96e4aa).()) { |
| 173 | if (currentPositionsMax == 0) { |
| 174 | currentPositionsMax = 1048576; |
| 175 | currentPositions = new uint32cxx . . $ uint32# [currentPositionsMax]; |
| 176 | } |
| 177 | |
| 178 | if (currentPositionsMax < currentCount + thisCount) { |
| 179 | while (currentPositionsMax < currentCount + thisCount) |
| 180 | currentPositionsMax *= 2; |
| 181 | |
| 182 | uint32cxx . . $ uint32# *t = new uint32cxx . . $ uint32# [currentPositionsMax]; |
| 183 | memcpy(t, currentPositions, sizeof(uint32cxx . . $ uint32#) * currentCount); |
| 184 | delete [] currentPositions; |
| 185 | currentPositions = t; |
| 186 | } |
| 187 | |
| 188 | if (thisCount < 16) { |
| 189 | uint32cxx . . $ uint32# *p = R[thisFile]->thePositionscxx . . $ merylStreamReader#thePositions(ac695d451f96e4aa).(); |
| 190 | for (uint32cxx . . $ uint32# i=0; i<thisCount; i++) |
| 191 | currentPositions[currentCount + i] = p[i]; |
| 192 | } else { |
| 193 | memcpy(currentPositions + currentCount, R[thisFile]->thePositionscxx . . $ merylStreamReader#thePositions(ac695d451f96e4aa).(), sizeof(uint32cxx . . $ uint32#) * thisCount); |
| 194 | } |
| 195 | } |
| 196 | // Otherwise, we're the same as ADD. |
| 197 | currentCount += thisCount; |
| 198 | break; |
| 199 | case PERSONALITY_MINcxx . . $ `meryl/meryl.H:8:9`!: |
| 200 | case PERSONALITY_MINEXISTcxx . . $ `meryl/meryl.H:9:9`!: |
| 201 | if (currentTimes == 0) { |
| 202 | currentCount = thisCount; |
| 203 | } else { |
| 204 | if (currentCount > thisCount) |
| 205 | currentCount = thisCount; |
| 206 | } |
| 207 | break; |
| 208 | case PERSONALITY_MAXcxx . . $ `meryl/meryl.H:10:9`!: |
| 209 | case PERSONALITY_MAXEXISTcxx . . $ `meryl/meryl.H:11:9`!: |
| 210 | if (currentCount < thisCount) |
| 211 | currentCount = thisCount; |
| 212 | break; |
| 213 | case PERSONALITY_ADDcxx . . $ `meryl/meryl.H:12:9`!: |
| 214 | currentCount += thisCount; |
| 215 | break; |
| 216 | case PERSONALITY_ANDcxx . . $ `meryl/meryl.H:17:9`!: |
| 217 | case PERSONALITY_NANDcxx . . $ `meryl/meryl.H:18:9`!: |
| 218 | case PERSONALITY_ORcxx . . $ `meryl/meryl.H:19:9`!: |
| 219 | case PERSONALITY_XORcxx . . $ `meryl/meryl.H:20:9`!: |
| 220 | currentCount = 1; |
| 221 | break; |
| 222 | default: |
| 223 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - invalid personality in multipleOperations::operate\n"); |
| 224 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - this is a coding error, not a user error.\n"); |
| 225 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | currentTimes++; |
| 230 | |
| 231 | // Move the file we just read from to the next mer |
| 232 | R[thisFile]->nextMercxx . . $ merylStreamReader#nextMer(c9857a73d68e59ba).(); |
| 233 | } |
| 234 | |
| 235 | for (uint32cxx . . $ uint32# i=0; i<args->mergeFilesLencxx . . $ merylArgs#mergeFilesLen.; i++) |
| 236 | delete R[i]; |
| 237 | delete R; |
| 238 | delete W; |
| 239 | delete C; |
| 240 | } |