//============================================================================== void InputStream::skipNextBytes (int64 numBytesToSkip) { if (numBytesToSkip > 0) { const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384); HeapBlock<char> temp ((size_t) skipBufferSize); while (numBytesToSkip > 0 && ! isExhausted()) numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize)); } }
int BufferedInputStream::read (void* destBuffer, int maxBytesToRead) { bassert (destBuffer != nullptr && maxBytesToRead >= 0); if (position >= bufferStart && position + maxBytesToRead <= lastReadPos) { memcpy (destBuffer, buffer + (int) (position - bufferStart), (size_t) maxBytesToRead); position += maxBytesToRead; return maxBytesToRead; } else { if (position < bufferStart || position >= lastReadPos) ensureBuffered(); int bytesRead = 0; while (maxBytesToRead > 0) { const int bytesAvailable = bmin (maxBytesToRead, (int) (lastReadPos - position)); if (bytesAvailable > 0) { memcpy (destBuffer, buffer + (int) (position - bufferStart), (size_t) bytesAvailable); maxBytesToRead -= bytesAvailable; bytesRead += bytesAvailable; position += bytesAvailable; destBuffer = static_cast <char*> (destBuffer) + bytesAvailable; } const int64 oldLastReadPos = lastReadPos; ensureBuffered(); if (oldLastReadPos == lastReadPos) break; // if ensureBuffered() failed to read any more data, bail out if (isExhausted()) break; } return bytesRead; } }
int BufferedInputStream::read (void* destBuffer, int maxBytesToRead) { jassert (destBuffer != nullptr && maxBytesToRead >= 0); if (position >= bufferStart && position + maxBytesToRead <= lastReadPos) { memcpy (destBuffer, buffer + (int) (position - bufferStart), (size_t) maxBytesToRead); position += maxBytesToRead; return maxBytesToRead; } if (position < bufferStart || position >= lastReadPos) ensureBuffered(); int bytesRead = 0; while (maxBytesToRead > 0) { auto numToRead = jmin (maxBytesToRead, (int) (lastReadPos - position)); if (numToRead > 0) { memcpy (destBuffer, buffer + (int) (position - bufferStart), (size_t) numToRead); maxBytesToRead -= numToRead; bytesRead += numToRead; position += numToRead; destBuffer = static_cast<char*> (destBuffer) + numToRead; } auto oldLastReadPos = lastReadPos; ensureBuffered(); if (oldLastReadPos == lastReadPos) break; // if ensureBuffered() failed to read any more data, bail out if (isExhausted()) break; } return bytesRead; }
bool setPosition (int64 wantedPos) { if (isError()) return false; if (wantedPos != position) { finished = false; if (wantedPos < position) return false; int64 numBytesToSkip = wantedPos - position; const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384); HeapBlock<char> temp ((size_t) skipBufferSize); while (numBytesToSkip > 0 && ! isExhausted()) numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize)); } return true; }
static really_inline int roseSomAdaptor_i(u64a from_offset, u64a to_offset, ReportID id, void *context, char is_simple) { assert(id != MO_INVALID_IDX); // Should never get an invalid ID. u32 flags = 0; struct hs_scratch *scratch = (struct hs_scratch *)context; struct core_info *ci = &scratch->core_info; const struct RoseEngine *rose = ci->rose; const struct internal_report *ri = getInternalReport(rose, id); /* internal events should be handled by rose directly */ assert(ri->type == EXTERNAL_CALLBACK); DEBUG_PRINTF("internal match at %llu: IID=%u type=%hhu RID=%u " "offsetAdj=%d\n", to_offset, id, ri->type, ri->onmatch, ri->offsetAdjust); if (unlikely(can_stop_matching(scratch))) { DEBUG_PRINTF("pre broken - halting\n"); return MO_HALT_MATCHING; } if (!is_simple && ri->hasBounds) { assert(ri->minOffset || ri->minLength || ri->maxOffset < MAX_OFFSET); if (to_offset < ri->minOffset || to_offset > ri->maxOffset) { DEBUG_PRINTF("match fell outside valid range %llu !: [%llu,%llu]\n", to_offset, ri->minOffset, ri->maxOffset); return MO_CONTINUE_MATCHING; } } int halt = 0; if (!is_simple && unlikely(isExhausted(ci->exhaustionVector, ri->ekey))) { DEBUG_PRINTF("ate exhausted match\n"); goto do_return; } #ifdef DEDUPE_MATCHES u64a offset = to_offset; #endif to_offset += ri->offsetAdjust; assert(from_offset == HS_OFFSET_PAST_HORIZON || from_offset <= to_offset); if (!is_simple && ri->minLength) { if (from_offset != HS_OFFSET_PAST_HORIZON && (to_offset - from_offset < ri->minLength)) { return MO_CONTINUE_MATCHING; } if (ri->quashSom) { from_offset = 0; } } DEBUG_PRINTF(">> reporting match @[%llu,%llu] for sig %u ctxt %p <<\n", from_offset, to_offset, ri->onmatch, ci->userContext); #ifndef RELEASE_BUILD if (ri->offsetAdjust != 0) { // alert testing tools that we've got adjusted matches flags |= HS_MATCH_FLAG_ADJUSTED; } #endif #ifdef DEDUPE_MATCHES u32 dkeyCount = rose->dkeyCount; if (offset != scratch->deduper.current_report_offset) { assert(scratch->deduper.current_report_offset == ~0ULL || scratch->deduper.current_report_offset < offset); if (offset == scratch->deduper.current_report_offset + 1) { fatbit_clear(scratch->deduper.log[offset % 2]); } else { fatbit_clear(scratch->deduper.log[0]); fatbit_clear(scratch->deduper.log[1]); } halt = flushStoredSomMatches(scratch, offset); if (halt) { goto do_return; } scratch->deduper.current_report_offset = offset; } u32 dkey = ri->dkey; if (dkey != MO_INVALID_IDX) { if (ri->quashSom) { DEBUG_PRINTF("checking dkey %u at offset %llu\n", dkey, to_offset); assert(ri->offsetAdjust == 0 || ri->offsetAdjust == -1); if (fatbit_set(scratch->deduper.log[to_offset % 2], dkeyCount, dkey)) { /* we have already raised this report at this offset, squash * dupe match. */ DEBUG_PRINTF("dedupe\n"); goto do_return; } } else { /* SOM external event */ DEBUG_PRINTF("checking dkey %u at offset %llu\n", dkey, to_offset); assert(ri->offsetAdjust == 0 || ri->offsetAdjust == -1); u64a *starts = scratch->deduper.som_start_log[to_offset % 2]; if (fatbit_set(scratch->deduper.som_log[to_offset % 2], dkeyCount, dkey)) { starts[dkey] = MIN(starts[dkey], from_offset); } else { starts[dkey] = from_offset; } if (ri->offsetAdjust) { scratch->deduper.som_log_dirty |= 1; } else { scratch->deduper.som_log_dirty |= 2; } goto do_return; } } #endif halt = ci->userCallback((unsigned int)ri->onmatch, from_offset, to_offset, flags, ci->userContext); if (!is_simple) { markAsMatched(ci->exhaustionVector, ri->ekey); } do_return: if (halt) { DEBUG_PRINTF("callback requested to terminate matches\n"); setBroken(ci->state, BROKEN_FROM_USER); ci->broken = BROKEN_FROM_USER; return MO_HALT_MATCHING; } return MO_CONTINUE_MATCHING; }
void main() { int i; int j; int k; int m; #if 0 while(1) { scanf("%s", Seqs); if(is_hui_wen(Seqs, strlen(Seqs)) == TRUE) { printf("yes\n"); } else { printf("no\n"); } } #endif int seq_len = 0; int hui_wen_subseq_count = 0; scanf("%s", Seqs); //读取待处理字符串 seq_len = strlen(Seqs); //待处理字符串长度 j = 0; for(k = 1; k <= seq_len; k++) //要处理的子序列长度 { for(m = 0; m < k; m++) { Pointers[m] = m; //初始化待处理子序列位置 } while (1) { for(i = 0; i < k; i++) //打印待处理子序列 { sub_seq[i] = Seqs[Pointers[i]]; } sub_seq[i] = 0; printf("Case %d:\n", j+1); j++; printf("%s\n", sub_seq); if(is_hui_wen(sub_seq, strlen(sub_seq)) == TRUE) { hui_wen_subseq_count++; printf("yes\n"); } else { printf("no\n"); } printf("\n"); if (!isExhausted(Pointers, k, seq_len)) { //正在处理的子序列位置,序列总长度 updatePointers(Pointers, seq_len, k - 1); //更新正在处理的子序列指针 } else { break; } } } printf("hui_wen_subseq_count = %d\n", hui_wen_subseq_count); }