summaryrefslogtreecommitdiff
path: root/src/core/utils
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-08 16:12:01 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-08 16:12:01 +0100
commite7f97a4c8da44a696bb7e71b9dd54e8d271e24d0 (patch)
treea9b58f48cb4c1fd0114a3cb27b755633fe47fc6f /src/core/utils
parent79903130b6240347743f191bb9b8d670524a300e (diff)
added more unit test for the new BufferClass, fixed a few bugs (merely inefficiencies -- no major problems found so far)
Diffstat (limited to 'src/core/utils')
-rw-r--r--src/core/utils/CharReader.cpp34
-rw-r--r--src/core/utils/CharReader.hpp12
2 files changed, 38 insertions, 8 deletions
diff --git a/src/core/utils/CharReader.cpp b/src/core/utils/CharReader.cpp
index 84f562d..33eab45 100644
--- a/src/core/utils/CharReader.cpp
+++ b/src/core/utils/CharReader.cpp
@@ -16,7 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <iostream>
+
#include <algorithm>
+#include <limits>
#include "CharReader.hpp"
@@ -34,8 +37,8 @@ Buffer::Buffer(ReadCallback callback, void *userData)
startOffset(0),
firstDead(0)
{
- // Insert a first empty bucket and set the start buffer correctly
- nextBucket();
+ // Load a first block of data from the stream
+ stream();
startBucket = buckets.begin();
}
@@ -72,20 +75,39 @@ void Buffer::advance(BucketList::const_iterator &it) const
}
}
-
Buffer::Bucket &Buffer::nextBucket()
{
+ constexpr size_t MAXVAL = std::numeric_limits<size_t>::max();
+
// Fetch the minimum bucket index
- size_t minBucketIdx = 0;
+ size_t minBucketIdx = MAXVAL;
for (size_t i = 0; i < cursors.size(); i++) {
if (alive[i]) {
- minBucketIdx = std::min(minBucketIdx, cursors[i].bucketIdx);
+ // Fetch references to the bucket and the cursor
+ const Cursor &cur = cursors[i];
+ const Bucket &bucket = *(cur.bucket);
+
+ // Increment the bucket index by one, if the cursor is at the end
+ // of the bucket (only valid if the LOOKBACK_SIZE is set to zero)
+ size_t bIdx = cur.bucketIdx;
+ if (LOOKBACK_SIZE == 0 && cur.bucketOffs == bucket.size()) {
+ bIdx++;
+ }
+
+ // Decrement the bucket index by one, if the previous bucket still
+ // needs to be reached and cannot be overridden
+ if (bIdx > 0 && cur.bucketOffs < LOOKBACK_SIZE) {
+ bIdx--;
+ }
+
+ // Set the bucket index to the minium
+ minBucketIdx = std::min(minBucketIdx, bIdx);
}
}
// If there is space between the current start bucket and the read
// cursor, the start bucket can be safely overridden.
- if (minBucketIdx > 0) {
+ if (minBucketIdx > 0 && minBucketIdx != MAXVAL) {
// All cursor bucket indices will be decreased by one
for (size_t i = 0; i < cursors.size(); i++) {
cursors[i].bucketIdx--;
diff --git a/src/core/utils/CharReader.hpp b/src/core/utils/CharReader.hpp
index 4986d3e..23e88b7 100644
--- a/src/core/utils/CharReader.hpp
+++ b/src/core/utils/CharReader.hpp
@@ -63,9 +63,17 @@ public:
private:
/**
- * Number of bytes to request from the input stream.
+ * Number of bytes to request from the input stream. Set to 64 KiB because
+ * this seems to be a nice value for I/O operations according to multiple
+ * sources.
*/
- static constexpr size_t REQUEST_SIZE = 16 * 1024;
+ static constexpr size_t REQUEST_SIZE = 64 * 1024;
+
+ /**
+ * Number of bytes the buffer guarantees to be capable of looking back
+ * for extracting the current context.
+ */
+ static constexpr size_t LOOKBACK_SIZE = 128;
/**
* Type used internally to represent one chunk of memory.