Changeset 5740 for icGREP/icgrepdevel
 Timestamp:
 Nov 18, 2017, 1:38:49 PM (18 months ago)
 Location:
 icGREP/icgrepdevel/icgrep
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

icGREP/icgrepdevel/icgrep/UCD/unicode_set.cpp
r5739 r5740 141 141 } 142 142 143 144 143 /**  * 145 144 * @brief at … … 152 151 assert ((base % QUAD_BITS) == 0); 153 152 if (typeOf(r) == Empty) { 154 base += QUAD_BITS * lengthOf(r);153 base += lengthOf(r) * QUAD_BITS; 155 154 } else if (typeOf(r) == Full) { 156 const auto m = QUAD_BITS * lengthOf(r);155 const auto m = lengthOf(r) * QUAD_BITS; 157 156 if (LLVM_UNLIKELY(remaining < m)) { 158 157 return base + remaining; … … 299 298 const auto e2 = other.quad_end(); 300 299 auto i1 = quad_begin(), i2 = other.quad_begin(); 301 while ((i1 != e1) && (i2 != e2)) { 300 for (;;) { 301 assert ("neither run can be zero length unless both are of zero length" && ((i1.length() != 0) ^ (i2.length() == 0))); 302 302 const auto n = std::min(i1.length(), i2.length()); 303 if (LLVM_UNLIKELY(n == 0)) { 304 break; 305 } 303 306 if ((i1.type() == Full) && (i2.type() == Full)) { 304 307 append_run(Full, n, runs); … … 320 323 i2 += n; 321 324 } else { // both Mixed 325 assert (i1.type() == Mixed && i2.type() == Mixed); 322 326 for (unsigned i = 0; i != n; ++i, ++i1, ++i2) { 323 327 append_quad(i1.quad() & i2.quad(), quads, runs); … … 325 329 } 326 330 } 331 assert (i1 == e1 && i2 == e2); 327 332 return UnicodeSet(std::move(runs), std::move(quads)); 328 333 } … … 337 342 const auto e2 = other.quad_end(); 338 343 auto i1 = quad_begin(), i2 = other.quad_begin(); 339 while ((i1 != e1) && (i2 != e2)) { 344 for (;;) { 345 assert ("neither run can be zero length unless both are of zero length" && ((i1.length() != 0) ^ (i2.length() == 0))); 340 346 const auto n = std::min(i1.length(), i2.length()); 347 if (LLVM_UNLIKELY(n == 0)) { 348 break; 349 } 341 350 if ((i1.type() == Empty) && (i2.type() == Empty)) { 342 351 append_run(Empty, n, runs); … … 348 357 i2 += n; 349 358 } else if (i1.type() == Empty) { 359 assert (i2.type() == Mixed); 350 360 for (unsigned i = 0; i != n; ++i, ++i2) { 351 361 append_quad(i2.quad(), quads, runs); … … 353 363 i1 += n; 354 364 } else if (i2.type() == Empty) { 365 assert (i1.type() == Mixed); 355 366 for (unsigned i = 0; i != n; ++i, ++i1) { 356 367 append_quad(i1.quad(), quads, runs); … … 358 369 i2 += n; 359 370 } else { // both Mixed 371 assert (i1.type() == Mixed && i2.type() == Mixed); 360 372 for (unsigned i = 0; i < n; ++i, ++i1, ++i2) { 361 373 append_quad(i1.quad()  i2.quad(), quads, runs); … … 363 375 } 364 376 } 365 // append any remaining blocks 366 if ((i1 != e1)  (i2 != e2)) { 367 assert ((i1 != e1) ^ (i2 != e2)); 368 auto i3 = (i1 != e1) ? i1 : i2; 369 const auto e3 = (i1 != e1) ? e1 : e2; 370 while (i3 != e3) { 371 const auto n = i3.length(); 372 if (i3.type() == Empty  i3.type() == Full) { 373 append_run(i3.type(), n, runs); 374 i3 += n; 375 } else { 376 for (unsigned i = 0; i != n; ++i3) { 377 append_quad(i3.quad(), quads, runs); 378 } 379 } 380 } 381 } 377 378 assert (i1 == e1 && i2 == e2); 382 379 return UnicodeSet(std::move(runs), std::move(quads)); 383 380 } … … 392 389 const auto e2 = other.quad_end(); 393 390 auto i1 = quad_begin(), i2 = other.quad_begin(); 394 while ((i1 != e1) && (i2 != e2)) { 395 unsigned n = std::min(i1.length(), i2.length()); 391 for (;;) { 392 assert ("neither run can be zero length unless both are of zero length" && ((i1.length() != 0) ^ (i2.length() == 0))); 393 const auto n = std::min(i1.length(), i2.length()); 394 assert (n != 0  (i1 == e1 && i2 == e2)); 395 if (LLVM_UNLIKELY(n == 0)) { 396 break; 397 } 396 398 if ((i1.type() == Empty)  (i2.type() == Full)) { 397 399 append_run(Empty, n, runs); … … 413 415 } 414 416 i2 += n; 415 } else { 417 } else { // both Mixed 418 assert (i1.type() == Mixed && i2.type() == Mixed); 416 419 for (unsigned i = 0; i != n; ++i, ++i1, ++i2) { 417 420 append_quad(i1.quad() &~ i2.quad(), quads, runs); … … 419 422 } 420 423 } 421 while (i1 != e1) { 422 const auto n = i1.length(); 423 if (i1.type() == Empty  i1.type() == Full) { 424 append_run(i1.type(), n, runs); 425 i1 += n; 426 } else { 427 for (unsigned i = 0; i != n; ++i1) { 428 append_quad(i1.quad(), quads, runs); 429 } 430 } 431 } 424 assert (i1 == e1 && i2 == e2); 432 425 return UnicodeSet(std::move(runs), std::move(quads)); 433 426 } … … 442 435 const auto e2 = other.quad_end(); 443 436 auto i1 = quad_begin(), i2 = other.quad_begin(); 444 while ((i1 != e1) && (i2 != e2)) { 445 unsigned n = std::min(i1.length(), i2.length()); 437 for (;;) { 438 assert ("neither run can be zero length unless both are of zero length" && ((i1.length() != 0) ^ (i2.length() == 0))); 439 const auto n = std::min(i1.length(), i2.length()); 440 if (LLVM_UNLIKELY(n == 0)) { 441 break; 442 } 446 443 if (i1.type() != Mixed && i2.type() != Mixed) { 447 444 append_run(i1.type() == i2.type() ? Empty : Full, n, runs); … … 468 465 } 469 466 i2 += n; 470 } else { 467 } else { // both Mixed 468 assert (i1.type() == Mixed && i2.type() == Mixed); 471 469 for (unsigned i = 0; i != n; ++i, ++i1, ++i2) { 472 470 append_quad(i1.quad() ^ i2.quad(), quads, runs); … … 474 472 } 475 473 } 476 // append any remaining blocks 477 if ((i1 != e1)  (i2 != e2)) { 478 assert ((i1 != e1) ^ (i2 != e2)); 479 auto i3 = (i1 != e1) ? i1 : i2; 480 const auto e3 = (i1 != e1) ? e1 : e2; 481 while (i3 != e3) { 482 const auto n = i3.length(); 483 if (i3.type() == Empty  i3.type() == Full) { 484 append_run(i3.type(), n, runs); 485 i3 += n; 486 } else { 487 for (unsigned i = 0; i != n; ++i3) { 488 append_quad(i3.quad(), quads, runs); 489 } 490 } 491 } 492 } 474 assert (i1 == e1 && i2 == e2); 493 475 return UnicodeSet(std::move(runs), std::move(quads)); 494 476 } … … 761 743 /**  * 762 744 * @brief intersects 763 * @param other _set745 * @param other 764 746 * 765 * Return true if this UnicodeSet has a nonempty intersection with other _set747 * Return true if this UnicodeSet has a nonempty intersection with other 766 748 **  */ 767 749 bool UnicodeSet::intersects(const UnicodeSet & other) const { 768 const auto e1 = quad_end(); 769 const auto e2 = other.quad_end(); 770 for (auto i1 = quad_begin(), i2 = other.quad_begin(); i1 != e1 && i2 != e2; ) { 750 for (auto i1 = quad_begin(), i2 = other.quad_begin();; ) { 771 751 auto n = std::min(i1.length(), i2.length()); 752 if (LLVM_UNLIKELY(n == 0)) { 753 return false; 754 } 772 755 if (i1.type() == Empty  i2.type() == Empty) { 773 756 i1 += n; … … 781 764 } 782 765 } 783 return false;784 766 } 785 767 … … 790 772 void UnicodeSet::quad_iterator::advance(unsigned n) { 791 773 while (n > 0) { 792 const unsigned remain = lengthOf(*mRunIterator)  mOffset; 793 if (remain > n) { 794 if (typeOf(*mRunIterator) == Mixed) { 774 assert (mRemaining > 0); 775 if (mRemaining > n) { 776 if (mType == Mixed) { 777 assert (mQuadIterator <= (mQuadEnd  n)); 795 778 mQuadIterator += n; 796 779 } 797 m Offset += n;780 mRemaining = n; 798 781 break; 799 782 } 800 if (typeOf(*mRunIterator) == Mixed) { 801 mQuadIterator += remain; 802 } 783 if (mType == Mixed) { 784 assert (mQuadIterator <= (mQuadEnd  mRemaining)); 785 mQuadIterator += mRemaining; 786 } 787 n = mRemaining; 803 788 ++mRunIterator; 804 mOffset = 0; 805 n = remain; 806 } 789 if (LLVM_UNLIKELY(mRunIterator == mRunEnd)) { 790 mType = Empty; 791 mRemaining = 0; 792 break; 793 } 794 mType = typeOf(*mRunIterator); 795 mRemaining = lengthOf(*mRunIterator); 796 } 797 assert ("remaining length cannot be 0 unless this is the final run" && ((mRunIterator != mRunEnd)  (mRemaining == 0))); 798 assert ("cannot be the final quad unless this is the final run" && ((mRunIterator != mRunEnd)  (mQuadIterator == mQuadEnd))); 807 799 } 808 800 … … 1063 1055 1064 1056 } 1057 
icGREP/icgrepdevel/icgrep/UCD/unicode_set.h
r5739 r5740 159 159 friend class boost::iterator_core_access; 160 160 public: 161 quad_iterator(RunIterator runIterator, QuadIterator quadIterator) 162 : mRunIterator(runIterator), mQuadIterator(quadIterator), mOffset(0) {} 161 quad_iterator(RunIterator runIterator, RunIterator runEnd, QuadIterator quadIterator, QuadIterator quadEnd, const run_type_t type, const length_t remaining) 162 : mRunIterator(runIterator) 163 , mRunEnd(runEnd) 164 , mQuadIterator(quadIterator) 165 #ifndef NDEBUG 166 , mQuadEnd(quadEnd) 167 #endif 168 , mType(type) 169 , mRemaining(remaining) {} 163 170 164 171 void advance(unsigned n); … … 173 180 174 181 inline run_type_t type() const { 175 return m RunIterator>first;182 return mType; 176 183 } 177 184 178 185 inline length_t length() const { 179 return mR unIterator>second  mOffset;186 return mRemaining; 180 187 } 181 188 182 189 inline bitquad_t quad() const { 190 assert (mQuadIterator != mQuadEnd); 183 191 return *mQuadIterator; 184 192 } 185 193 186 194 inline bool equal(const quad_iterator & other) const { 187 return (mRunIterator == other.mRunIterator) && (mQuadIterator == other.mQuadIterator); 195 const auto r = (mRunIterator == other.mRunIterator) && (mRemaining == other.mRemaining); 196 assert (!r  (mQuadIterator == other.mQuadIterator)); 197 return r; 188 198 } 189 199 190 200 private: 191 RunIterator mRunIterator; 192 QuadIterator mQuadIterator; 193 unsigned mOffset; 201 RunIterator mRunIterator; 202 const RunIterator mRunEnd; 203 QuadIterator mQuadIterator; 204 #ifndef NDEBUG 205 const QuadIterator mQuadEnd; 206 #endif 207 run_type_t mType; 208 length_t mRemaining; 194 209 }; 195 210 196 211 inline quad_iterator quad_begin() const { 197 return quad_iterator(mRuns.cbegin(), m Quads.cbegin());212 return quad_iterator(mRuns.cbegin(), mRuns.cend(), mQuads.cbegin(), mQuads.cend(), std::get<0>(*mRuns.cbegin()), std::get<1>(*mRuns.cbegin())); 198 213 } 199 214 200 215 inline quad_iterator quad_end() const { 201 return quad_iterator(mRuns.cend(), m Quads.cend());216 return quad_iterator(mRuns.cend(), mRuns.cend(), mQuads.cend(), mQuads.cend(), Empty, 0); 202 217 } 203 218 
icGREP/icgrepdevel/icgrep/grep_engine.cpp
r5735 r5740 381 381 if (fileDescriptor == 1) return 0; 382 382 EmitMatch accum(linePrefix(fileName), mResultStrs[fileIdx].get()); 383 uint64_t grepResult =f(fileDescriptor, reinterpret_cast<intptr_t>(&accum));383 f(fileDescriptor, reinterpret_cast<intptr_t>(&accum)); 384 384 close(fileDescriptor); 385 385 if (accum.mLineCount > 0) grepMatchFound = true; … … 424 424 425 425 void * DoGrepThreadFunction(void *args) { 426 re interpret_cast<GrepEngine *>(args)>DoGrepThreadMethod();426 return reinterpret_cast<GrepEngine *>(args)>DoGrepThreadMethod(); 427 427 } 428 428 … … 482 482 count_mutex.lock(); 483 483 fileIdx = mNextFileToPrint; 484 bool readyToPrint = ((fileIdx == 0)  (mFileStatus[fileIdx 1] == FileStatus::PrintComplete)) && (mFileStatus[fileIdx] == FileStatus::GrepComplete);484 bool readyToPrint = ((fileIdx == 0)  (mFileStatus[fileIdx  1] == FileStatus::PrintComplete)) && (mFileStatus[fileIdx] == FileStatus::GrepComplete); 485 485 if (fileIdx < inputFiles.size() && readyToPrint) { 486 486 mFileStatus[fileIdx] = FileStatus::Printing; … … 488 488 } 489 489 count_mutex.unlock(); 490 490 491 while (fileIdx < inputFiles.size()) { 491 492 if (readyToPrint) { 492 493 std::cout << mResultStrs[fileIdx]>str(); 493 } 494 else if (pthread_self() == mEngineThread) { 494 } else if (pthread_self() == mEngineThread) { 495 495 mGrepDriver>performIncrementalCacheCleanupStep(); 496 496 } … … 498 498 if (readyToPrint) mFileStatus[fileIdx] = FileStatus::PrintComplete; 499 499 fileIdx = mNextFileToPrint; 500 readyToPrint = (mFileStatus[fileIdx1] == FileStatus::PrintComplete) && (mFileStatus[fileIdx] == FileStatus::GrepComplete); 501 if (fileIdx < inputFiles.size() && readyToPrint) { 502 mFileStatus[fileIdx] = FileStatus::Printing; 503 mNextFileToPrint++; 500 if (fileIdx < inputFiles.size()) { 501 readyToPrint = ((fileIdx == 0)  (mFileStatus[fileIdx  1] == FileStatus::PrintComplete)) && (mFileStatus[fileIdx] == FileStatus::GrepComplete); 502 if (readyToPrint) { 503 mFileStatus[fileIdx] = FileStatus::Printing; 504 mNextFileToPrint++; 505 } 504 506 } 505 507 count_mutex.unlock(); … … 512 514 } 513 515 } 514 } 515 516 517 } 518
Note: See TracChangeset
for help on using the changeset viewer.