aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-10-09 23:29:34 +0200
committerAdrian Kummerlaender2017-10-09 23:29:34 +0200
commit413195edd2990e0a9b4c3500360722cff76e1a0a (patch)
tree8058747833281e13527b85b50009b6e9ae75fc59
parentc7a82e67007aecb46315780b53a691a519d90513 (diff)
downloadDictzipQuery-master.tar
DictzipQuery-master.tar.gz
DictzipQuery-master.tar.bz2
DictzipQuery-master.tar.lz
DictzipQuery-master.tar.xz
DictzipQuery-master.tar.zst
DictzipQuery-master.zip
Support queries that overlap buffersHEADmaster
-rw-r--r--src/util/query.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/util/query.cc b/src/util/query.cc
index f71b257..8b2b55c 100644
--- a/src/util/query.cc
+++ b/src/util/query.cc
@@ -15,12 +15,12 @@ std::vector<std::string> get_lines_starting_with(
return std::vector<std::string>{};
}
-
posix_fadvise(fileno(file), 0, 0, 1); // FDADVICE_SEQUENTIAL
std::vector<std::string> result;
char buffer[16*1024 + 1];
char* start_of_match = nullptr;
+ std::string overlap;
while ( std::size_t n = std::fread(buffer,
sizeof(char),
@@ -30,14 +30,24 @@ std::vector<std::string> get_lines_starting_with(
(p = static_cast<char*>(std::memchr(p, '\n', (buffer + n) - p)));
++p ) {
if ( start_of_match != nullptr ) {
- result.emplace_back(start_of_match, p - start_of_match);
- start_of_match = nullptr;
+ if ( overlap.empty() ) {
+ result.emplace_back(start_of_match, p - start_of_match);
+ start_of_match = nullptr;
+ } else {
+ result.emplace_back(overlap.append(buffer, p - buffer));
+ start_of_match = nullptr;
+ overlap.clear();
+ }
}
if ( std::strncmp(substring.c_str(), p+1, substring.size()) == 0 ) {
start_of_match = p+1;
}
}
+
+ if ( start_of_match != nullptr ) {
+ overlap = std::string(start_of_match, (buffer + n) - start_of_match);
+ }
}
std::fclose(file);