For fun: Expressive C++ 17 Coding Challenge in D
Biotronic
simen.kjaras at gmail.com
Wed Oct 4 10:15:51 UTC 2017
On Wednesday, 4 October 2017 at 09:04:58 UTC, Biotronic wrote:
> Since the code uses ranges though, a simple replacement of
> readText with an mmapped equivalent should enable humongous
> file support with no other code change required.
Drop-in replacement for readText:
struct MmText {
import std.mmfile;
ulong _fileOffset;
MmFile _file;
this(string filename) {
_file = new MmFile(filename);
}
dchar front() {
auto end = min(_file.length, _fileOffset+4);
auto data = cast(string)_file[_fileOffset..end];
return decodeFront(data);
}
void popFront() {
auto end = min(_file.length, _fileOffset+4);
auto data = cast(string)_file[_fileOffset..end];
size_t bytes;
decodeFront(data, bytes);
_fileOffset += bytes;
}
bool empty() {
return _fileOffset >= _file.length;
}
}
--
Biotronic
More information about the Digitalmars-d-learn
mailing list