data.dhover×251all
/**
Benchmark corpus loading.

Small datasets are pinned by `nix/packages/wired-bench-data.nix` and exposed
to the devshell as `$WIRED_BENCH_DATA`. Multi-gigabyte corpora are deliberately
not copied into every developer's Nix store: put their normalized files in
`$WIRED_BENCH_EXTERNAL_DATA` and select them explicitly with
`$WIRED_BENCH_DATASETS` (see $(MREF sparkles,wired_bench,runner)).
*/
module 
(package) sparkles
sparkles
.
(package) sparkles.wired_bench
wired_bench
.
(module) sparkles.wired_bench.data

Benchmark corpus loading.

Small datasets are pinned by nix/packages/wired-bench-data.nix and exposed to the devshell as $WIRED_BENCH_DATA. Multi-gigabyte corpora are deliberately not copied into every developer's Nix store: put their normalized files in $WIRED_BENCH_EXTERNAL_DATA and select them explicitly with $WIRED_BENCH_DATASETS (see sparkles.wired_bench.runner).

data
;
import
(package) std
std
.
(package) std.algorithm
algorithm
.
(module) std.algorithm.iteration

This is a submodule of std.algorithm. It contains generic iteration algorithms.

Function Name Description
cache Eagerly evaluates and caches another range's front.
lazyCache Lazily evaluates and caches another range's front, unlike cache.
cacheBidirectional As above, but also provides back and popBack.
chunkBy chunkBy!((a,b) => a[1] == b[1])([[1, 1], [1, 2], [2, 2], [2, 1]]) returns a range containing 3 subranges: the first with just [1, 1]; the second with the elements [1, 2] and [2, 2]; and the third with just [2, 1].
cumulativeFold cumulativeFold!((a, b) => a + b)([1, 2, 3, 4]) returns a lazily-evaluated range containing the successive reduced values 1, 3, 6, 10.
each each!writeln([1, 2, 3]) eagerly prints the numbers 1, 2 and 3 on their own lines.
filter filter!(a => a > 0)([1, -1, 2, 0, -3]) iterates over elements 1 and 2.
filterBidirectional Similar to filter, but also provides back and popBack at a small increase in cost.
fold fold!((a, b) => a + b)([1, 2, 3, 4]) returns 10.
group group([5, 2, 2, 3, 3]) returns a range containing the tuples tuple(5, 1), tuple(2, 2), and tuple(3, 2).
joiner joiner(["hello", "world!"], "; ") returns a range that iterates over the characters "hello; world!". No new string is created - the existing inputs are iterated.
map map!(a => a * 2)([1, 2, 3]) lazily returns a range with the numbers 2, 4, 6.
mean Colloquially known as the average, mean([1, 2, 3]) returns 2.
permutations Lazily computes all permutations using Heap's algorithm.
reduce reduce!((a, b) => a + b)([1, 2, 3, 4]) returns 10. This is the old implementation of fold.
splitWhen Lazily splits a range by comparing adjacent elements.
splitter Lazily splits a range by a separator, element predicate or whitespace.
substitute [1, 2].substitute(1, 0.1) returns [0.1, 2].
sum Same as fold, but specialized for accurate summation.
uniq Iterates over the unique elements in a range, which is assumed sorted.

Source

std/algorithm/iteration.d

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
iteration
:
(alias template) sparkles.wired_bench.data.filter = std.algorithm.iteration.filter(alias predicate) if (is(typeof(unaryFun!predicate)))

``filter!(predicate)(range) returns a new range containing only elements x in range for which predicate(x) returns true.

The predicate is passed to unaryFun, and can be either a string, or any callable that can be executed via pred(element).

@parampredicate Function to apply to each element of range@returnsAn input range that contains the filtered elements. If range is at least a forward range, the return value of filter will also be a forward range.@seeFilter (higher-order function), filterBidirectional
filter
,
(alias template) sparkles.wired_bench.data.map = std.algorithm.iteration.map(fun...) if (fun.length >= 1)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call ``map!(fun)(range) returns a range of which elements are obtained by applying fun(a) left to right for all elements a in range. The original ranges are not changed. Evaluation is done lazily.

@paramfun one or more transformation functions@seeMap (higher-order function)
map
,
(alias template) sparkles.wired_bench.data.splitter = std.algorithm.iteration.splitter(alias pred = "a == b", Flag keepSeparators = No.keepSeparators, Range, Separator)(Range r, Separator s) if (is(typeof(binaryFun!pred(r.front, s)) : bool) && (hasSlicing!Range && hasLength!Range || isNarrowString!Range) && (is(ElementType!Range : Separator) || !(isForwardRange!Separator && (hasLength!Separator || isNarrowString!Separator))))

Lazily splits a range using an element or range as a separator. Separator ranges can be any narrow string type or sliceable range type.

Two adjacent separators are considered to surround an empty element in the split range. Use filter!(a => !a.empty) on the result to compress empty elements.

The predicate is passed to binaryFun and accepts any callable function that can be executed via pred(element, s).

Note

If splitting a string on whitespace and token compression is desired, consider using the ``splitter(r) overload.

Constraints

The predicate pred needs to accept an element of r and the separator s.

@parampred The predicate for comparing each element with the separator, defaulting to "a == b".@paramr The input range to be split. Must support slicing and .length or be a narrow string type.@params The element (or range) to be treated as the separator between range segments to be split.@paramkeepSeparators The flag for deciding if the separators are kept@returns

An input range of the subranges of elements between separators. If r is a forward range or bidirectional range, the returned range will be likewise. When a range is used a separator, bidirectionality isn't possible.

If keepSeparators is equal to Yes.keepSeparators the output will also contain the separators.

If an empty range is given, the result is an empty range. If a range with one separator is given, the result is a range with two empty elements.

@see
  • splitter for a version that splits using a regular expression defined separator.

  • split for a version that splits eagerly.

  • splitWhen, which compares adjacent elements instead of element against separator.

splitter
;
import
(package) std
std
.
(module) std.array

Functions and types that manipulate built-in arrays and associative arrays.

This module provides all kinds of functions to create, manipulate or convert arrays:

Function Name Description

| array | Returns a copy of the input in a newly allocated dynamic array. | | appender | Returns a new Appender or RefAppender initialized with a given array. | | assocArray | Returns a newly allocated associative array from a range/ranges of keys and values. | | byPair | Construct a range iterating over an associative array by key/value tuples. | | insertInPlace | Inserts into an existing array at a given position. | | join | Concatenates a range of ranges into one array. | | minimallyInitializedArray | Returns a new array of type T. | | replace | Returns a new array with all occurrences of a certain subrange replaced. | | replaceFirst | Returns a new array with the first occurrence of a certain subrange replaced. | | replaceInPlace | Replaces all occurrences of a certain subrange and puts the result into a given array. | | replaceInto | Replaces all occurrences of a certain subrange and puts the result into an output range. | | replaceLast | Returns a new array with the last occurrence of a certain subrange replaced. | | replaceSlice | Returns a new array with a given slice replaced. | | replicate | Creates a new array out of several copies of an input array or range. | | sameHead | Checks if the initial segments of two arrays refer to the same place in memory. | | sameTail | Checks if the final segments of two arrays refer to the same place in memory. | | split | Eagerly split a range or string into an array. | | staticArray | Creates a new static array from given data. | | uninitializedArray | Returns a new array of type T without initializing its elements. |

Source

std/array.d

@copyrightCopyright Andrei Alexandrescu 2008- and Jonathan M Davis 2011-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu and Jonathan M Davis
array
:
(alias template) sparkles.wired_bench.data.array = std.array.array(Range)(Range r) if (isIterable!Range && !isAutodecodableString!Range && !isInfinite!Range)

Allocates an array and initializes it with copies of the elements of range r.

Narrow strings are handled as follows:

  • If autodecoding is turned on (default), then they are handled as a separate overload.

  • If autodecoding is turned off, then this is equivalent to duplicating the array.

@paramr range (or aggregate with opApply function) whose elements are copied into the allocated array@returnsallocated and initialized array
array
;
import
(package) std
std
.
(module) std.exception

This module defines functions related to exceptions and general error handling. It also defines functions intended to aid in unit testing.

Category Functions
Assumptions assertNotThrown assertThrown assumeUnique assumeWontThrow mayPointTo
Enforce doesPointTo enforce errnoEnforce
Handlers collectException collectExceptionMsg ifThrown handle
Other basicExceptionCtors emptyExceptionMsg ErrnoException RangePrimitive

Source

std/exception.d

Examples

Synopis

import core.stdc.stdlib : malloc, free;
import std.algorithm.comparison : equal;
import std.algorithm.iteration : map, splitter;
import std.algorithm.searching : endsWith;
import std.conv : ConvException, to;
import std.range : front, retro;

// use enforce like assert
int a = 3;
enforce(a > 2, "a needs to be higher than 2.");

// enforce can throw a custom exception
enforce!ConvException(a > 2, "a needs to be higher than 2.");

// enforce will return it's input
enum size = 42;
auto memory = enforce(malloc(size), "malloc failed")[0 .. size];
scope(exit) free(memory.ptr);

// collectException can be used to test for exceptions
Exception e = collectException("abc".to!int);
assert(e.file.endsWith("conv.d"));

// and just for the exception message
string msg = collectExceptionMsg("abc".to!int);
assert(msg == "Unexpected 'a' when converting from type string to type int");

// assertThrown can be used to assert that an exception is thrown
assertThrown!ConvException("abc".to!int);

// ifThrown can be used to provide a default value if an exception is thrown
assert("x".to!int().ifThrown(0) == 0);

// handle is a more advanced version of ifThrown for ranges
auto r = "12,1337z32,54".splitter(',').map!(a => to!int(a));
auto h = r.handle!(ConvException, RangePrimitive.front, (e, r) => 0);
assert(h.equal([12, 0, 54]));
assertThrown!ConvException(h.retro.equal([54, 0, 12]));

// basicExceptionCtors avoids the boilerplate when creating custom exceptions
static class MeaCulpa : Exception
{
    mixin basicExceptionCtors;
}
e = collectException((){throw new MeaCulpa("diagnostic message");}());
assert(e.msg == "diagnostic message");
assert(e.file == __FILE__);
assert(e.line == __LINE__ - 3);

// assumeWontThrow can be used to cast throwing code into `nothrow`
void exceptionFreeCode() nothrow
{
    // auto-decoding only throws if an invalid UTF char is given
    assumeWontThrow("abc".front);
}

// assumeUnique can be used to cast mutable instance to an `immutable` one
// use with care
char[] str = "  mutable".dup;
str[0 .. 2] = "im";
immutable res = assumeUnique(str);
assert(res == "immutable");
@copyrightCopyright Andrei Alexandrescu 2008-, Jonathan M Davis 2011-.@licenseBoost License 1.0@authorsAndrei Alexandrescu and Jonathan M Davis
exception
:
(alias template) sparkles.wired_bench.data.enforce = std.exception.enforce(E : Throwable = Exception) if (is(typeof(new E("", string.init, size_t.init)) : Throwable) || is(typeof(new E(string.init, size_t.init)) : Throwable))

Enforces that the given value is true. If the given value is false, an exception is thrown. The

  • msg - error message as a string

  • dg - custom delegate that return a string and is only called if an exception occurred

  • ex - custom exception to be thrown. It is lazy and is only created if an exception occurred

@paramvalue The value to test.@paramE Exception type to throw if the value evaluates to false.@parammsg The error message to put in the exception if it is thrown.@paramdg The delegate to be called if the value evaluates to false.@paramex The exception to throw if the value evaluates to false.@paramfile The source file of the caller.@paramline The line number of the caller.@returns

value, if cast(bool) value is true. Otherwise, depending on the chosen overload, new Exception(msg), dg() or ex is thrown.

enforce is used to throw exceptions and is therefore intended to aid in error handling. It is not intended for verifying the logic of your program - that is what assert is for.

Do not use enforce inside of contracts (i.e. inside of in and out blocks and invariants), because contracts are compiled out when compiling with -release.

If a delegate is passed, the safety and purity of this function are inferred from Dg's safety and purity.

enforce
;
import
(package) std
std
.
(module) std.file

Utilities for manipulating files and scanning directories. Functions in this module handle files as a unit, e.g., read or write one file at a time. For opening files and manipulating them via handles refer to module std.stdio.

Category Functions
General exists isDir isFile isSymlink rename thisExePath
Directories chdir dirEntries getcwd mkdir mkdirRecurse rmdir rmdirRecurse tempDir
Files append copy read readText remove slurp write
Symlinks symlink readLink
Attributes attrIsDir attrIsFile attrIsSymlink getAttributes getLinkAttributes getSize setAttributes
Timestamp getTimes getTimesWin setTimes timeLastModified timeLastAccessed timeStatusChanged
Other DirEntry FileException PreserveAttributes SpanMode getAvailableDiskSpace

Source

std/file.d

@copyrightCopyright The D Language Foundation 2007 - 2011.@seeThe official tutorial for an introduction to working with files in D, module std.stdio for opening files and manipulating them via handles, and module std.path for manipulating path strings.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis
file
:
(alias template) sparkles.wired_bench.data.exists = std.file.exists(R)(R name) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)

Determine whether the given file (or directory) exists.

@paramname string or range of characters representing the file name@returnstrue if the file name specified as input exists
exists
,
(alias template) sparkles.wired_bench.data.readText = std.file.readText(S = string, R)(auto ref R name) if (isSomeString!S && (isSomeFiniteCharInputRange!R || is(StringTypeOf!R)))

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
;
import
(package) std
std
.
(module) std.mmfile

Read and write memory mapped files.

Memory mapped files are a mechanism in operating systems that allows file access through virtual memory. After opening a file with MmFile, the contents can be read from or written to with standard slice / pointer operations. Changes to the memory are automatically reflected in the underlying file.

Memory mapping can increase I/O performance of large files, compared to buffered read / write operations from std.file and std.stdio. However, I/O errors are not handled as safely: when for example the disk that the file is on gets removed, reading from it may result in a segfault.

References

https://en.wikipedia.org/wiki/Memory-mapped_file

Source

std/mmfile.d

@copyrightCopyright The D Language Foundation 2004 - 2009.@licenseBoost License 1.0.@authorsWalter Bright, Matthew Wilson
mmfile
:
(class) std.mmfile.MmFile

MmFile objects control the memory mapped file resource.

Examples

Read an existing file

import std.file;
std.file.write(deleteme, "hello"); // deleteme is a temporary filename
scope(exit) remove(deleteme);

// Use a scope class so the file will be closed at the end of this function
scope mmfile = new MmFile(deleteme);

assert(mmfile.length == "hello".length);

// Access file contents with the slice operator
// This is typed as `void[]`, so cast to `char[]` or `ubyte[]` to use it
const data = cast(const(char)[]) mmfile[];

// At this point, the file content may not have been read yet.
// In that case, the following memory access will intentionally
// trigger a page fault, causing the kernel to load the file contents
assert(data[0 .. 5] == "hello");

Write a new file

import std.file;
scope(exit) remove(deleteme);

scope mmfile = new MmFile(deleteme, MmFile.Mode.readWriteNew, 5, null);
assert(mmfile.length == 5);

auto data = cast(ubyte[]) mmfile[];

// This write to memory will be reflected in the file contents
data[] = '\n';

mmfile.flush();

assert(std.file.read(deleteme) == "\n\n\n\n\n");
MmFile
;
import
(package) std
std
.
(module) std.path

This module is used to manipulate path strings.

All functions, with the exception of expandTilde (and in some cases absolutePath and relativePath), are pure string manipulation functions; they don't depend on any state outside the program, nor do they perform any actual file system actions. This has the consequence that the module does not make any distinction between a path that points to a directory and a path that points to a file, and it does not know whether or not the object pointed to by the path actually exists in the file system. To differentiate between these cases, use isDir and exists.

Note that on Windows, both the backslash (\) and the slash (/) are in principle valid directory separators. This module treats them both on equal footing, but in cases where a new separator is added, a backslash will be used. Furthermore, the buildNormalizedPath function will replace all slashes with backslashes on that platform.

In general, the functions in this module assume that the input paths are well-formed. (That is, they should not contain invalid characters, they should follow the file system's path format, etc.) The result of calling a function on an ill-formed path is undefined. When there is a chance that a path or a file name is invalid (for instance, when it has been input by the user), it may sometimes be desirable to use the isValidFilename and isValidPath functions to check this.

Most functions do not perform any memory allocations, and if a string is returned, it is usually a slice of an input string. If a function allocates, this is explicitly mentioned in the documentation.

Category Functions
Normalization absolutePath asAbsolutePath asNormalizedPath asRelativePath buildNormalizedPath buildPath chainPath expandTilde
Partitioning baseName dirName dirSeparator driveName pathSeparator pathSplitter relativePath rootName stripDrive
Validation isAbsolute isDirSeparator isRooted isValidFilename isValidPath
Extension defaultExtension extension setExtension stripExtension withDefaultExtension withExtension
Other filenameCharCmp filenameCmp globMatch CaseSensitive

Source

std/path.d

@authorsLars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Khne, Andrei Alexandrescu@copyrightCopyright (c) 2000-2014, the authors. All rights reserved.@licenseBoost License 1.0
path
:
(alias template) sparkles.wired_bench.data.buildPath = std.path.buildPath(Range)(scope Range segments) if (isInputRange!Range && !isInfinite!Range && isSomeString!(ElementType!Range))

Combines one or more path segments.

This function takes a set of path segments, given as an input range of string elements or as a set of string arguments, and concatenates them with each other. Directory separators are inserted between segments if necessary. If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped.

On Windows, if one of the path segments are rooted, but not absolute (e.g. \foo), all preceding path segments down to the previous root will be dropped. (See below for an example.)

This function always allocates memory to hold the resulting path. The variadic overload is guaranteed to only perform a single allocation, as is the range version if paths is a forward range.

@paramsegments An input range of segments to assemble the path from.@returnsThe assembled path.
buildPath
;
import
(package) std
std
.
(module) std.process

Functions for starting and interacting with other processes, and for working with the current process' execution environment.

Process handling

  • `spawnProcess` spawns a new `process`, optionally assigning it an
        

    arbitrary set of standard input, output, and error streams. The function returns immediately, leaving the child process to execute in parallel with its parent. All other functions in this module that spawn processes are built around spawnProcess.

  • `wait` makes the parent `process` wait for a child `process` to
        

    terminate. In general one should always do this, to avoid child processes becoming "zombies" when the parent process exits. Scope guards are perfect for this – see the spawnProcess documentation for examples. tryWait is similar to wait, but does not block if the process has not yet terminated.

  • `pipeProcess` also spawns a child `process` which runs
        

    in parallel with its parent. However, instead of taking arbitrary streams, it automatically creates a set of pipes that allow the parent to communicate with the child through the child's standard input, output, and/or error streams. This function corresponds roughly to C's popen function.

  • `execute` starts a new `process` and waits for it
        

    to complete before returning. Additionally, it captures the process' standard output and error streams and returns the output of these as a string.

  • `spawnShell`, `pipeShell` and `executeShell` work like
        

    spawnProcess, pipeProcess and execute, respectively, except that they take a single command string and run it through the current user's default command interpreter. executeShell corresponds roughly to C's system function.

  • `kill` attempts to terminate a running `process`.
    
    

The following table compactly summarises the different process creation functions and how they relate to each other:

Runs program directly
Runs shell command
Low-level process creation
spawnProcess
spawnShell
Automatic input/output redirection using pipes
pipeProcess
pipeShell
Execute and wait for completion, collect output
execute
executeShell

Other functionality

  • `pipe` is used to create unidirectional pipes.
    
  • `environment` is an interface through which the current `process`'
        

    environment variables can be read and manipulated.

  • `escapeShellCommand` and `escapeShellFileName` are useful
        

    for constructing shell command lines in a portable way.

Source

std/process.d

Note

Most of the functionality in this module is not available on iOS, tvOS and watchOS. The only functions available on those platforms are: environment, thisProcessID and thisThreadID.

@authorsLars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev@copyrightCopyright (c) 2013, the authors. All rights reserved.@licenseBoost License 1.0.
process
:
(class) std.process.environment

Manipulates environment variables using an associative-array-like interface.

This class contains only static methods, and cannot be instantiated. See below for examples of use.

environment
;
import
(package) std
std
.
(module) std.string

String handling functions.

Category Functions
Searching
column
indexOf
indexOfAny
indexOfNeither
lastIndexOf
lastIndexOfAny
lastIndexOfNeither
Comparison
isNumeric
Mutation
capitalize
Pruning and Filling
center
chomp
chompPrefix
chop
detabber
detab
entab
entabber
leftJustify
outdent
rightJustify
strip
stripLeft
stripRight
wrap
Substitution
abbrev
soundex
soundexer
succ
tr
translate
Miscellaneous
assumeUTF
fromStringz
lineSplitter
representation
splitLines
toStringz
Objects of types string, wstring, and dstring are value types
and cannot be mutated element-by-element. For using mutation during building
strings, use char[], wchar[], or dchar[]. The xxxstring
types are preferable because they don't exhibit undesired aliasing, thus
making code more robust.

The following functions are publicly imported:

Module Functions
Publicly imported functions
std.algorithm
cmp, std,algorithm,comparison
count, std,algorithm,searching
endsWith, std,algorithm,searching
startsWith, std,algorithm,searching
std.array
join, std,array
replace, std,array
replaceInPlace, std,array
split, std,array
empty, std,array
std.format
format, std,format
sformat, std,format
std.uni
icmp, std,uni
toLower, std,uni
toLowerInPlace, std,uni
toUpper, std,uni
toUpperInPlace, std,uni
There is a rich set of functions for string handling defined in other modules.
Functions related to Unicode and ASCII are found in std.uni
and std.ascii, respectively. Other functions that have a
wider generality than just strings can be found in std.algorithm
and std.range.

Source

std/string.d

@seestd.algorithm and std.range for generic range algorithms , std.ascii for functions that work with ASCII strings , std.uni for functions that work with unicode strings@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
string
:
(alias template) sparkles.wired_bench.data.strip = std.string.strip(Range)(Range str) if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && !isConvertibleToString!Range && isSomeChar!(ElementEncodingType!Range))

Strips both leading and trailing whitespace (as defined by isWhite) or as specified in the second argument.

@paramstr string or random access range of characters@paramchars string of characters to be stripped@paramleftChars string of leading characters to be stripped@paramrightChars string of trailing characters to be stripped@returnsslice of str stripped of leading and trailing whitespace or characters as specified in the second argument.@seeGeneric stripping on ranges: strip
strip
;
/// How one corpus is divided into JSON documents. enum
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
{
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, /// one RFC 8259 JSON text
(enum value) sparkles.wired_bench.data.DatasetFormat.ndjson = 1

one complete JSON text per non-empty line

ndjson
, /// one complete JSON text per non-empty line
(enum value) sparkles.wired_bench.data.DatasetFormat.jsonArrayLines = 2

[/] plus one comma-terminated value per line

jsonArrayLines
, /// `[`/`]` plus one comma-terminated value per line
} /// One known corpus and its on-disk convention. struct
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
{
(alias) object.string = string
string
(field) string sparkles.wired_bench.data.DatasetSource.name
name
;
(alias) object.string = string
string
(field) string sparkles.wired_bench.data.DatasetSource.fileName
fileName
;
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
(field) sparkles.wired_bench.data.DatasetFormat sparkles.wired_bench.data.DatasetSource.format
format
;
bool
(field) bool sparkles.wired_bench.data.DatasetSource.bundled
bundled
;
} /// The normal, reproducible benchmark matrix. External corpora are opt-in. immutable
(alias) object.string = string
string
[]
(immutable global) immutable(string[]) sparkles.wired_bench.data.defaultDatasetNames

The normal, reproducible benchmark matrix. External corpora are opt-in.

defaultDatasetNames
=
["twitter", "citm_catalog", "canada", "github_events", "mesh", "mesh_pretty"]; /// Every dataset name accepted by `$WIRED_BENCH_DATASETS`. immutable
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
[]
(immutable global) immutable(sparkles.wired_bench.data.DatasetSource[]) sparkles.wired_bench.data.datasetSources

Every dataset name accepted by $WIRED_BENCH_DATASETS.

datasetSources
=
[
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("twitter", "twitter.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, true),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("citm_catalog", "citm_catalog.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, true),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("canada", "canada.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, true),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("github_events", "github_events.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, true),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("mesh", "mesh.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, true),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("mesh_pretty", "mesh.pretty.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, true),
// The Wikidata dump is a single array on disk, but its documented physical // layout is one entity per line. Treating those lines as records keeps the // live parse tree bounded under sustained runs. `recordLine` removes the // surrounding array and each line's separator comma.
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("wikidata", "wikidata.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.jsonArrayLines = 2

[/] plus one comma-terminated value per line

jsonArrayLines
, false),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("osm", "osm.json",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
, false),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("cloudtrail", "cloudtrail.ndjson",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.ndjson = 1

one complete JSON text per non-empty line

ndjson
, false),
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
("elasticsearch", "elasticsearch.ndjson",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.ndjson = 1

one complete JSON text per non-empty line

ndjson
, false),
]; /// One loaded benchmark corpus. struct
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
{
(alias) object.string = string
string
(field) string sparkles.wired_bench.data.Dataset.name

dataset name, e.g. twitter

name
; /// dataset name, e.g. `twitter`
const(char)[]
(field) const(char)[] sparkles.wired_bench.data.Dataset.text

the raw corpus text

text
; /// the raw corpus text
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
(field) sparkles.wired_bench.data.DatasetFormat sparkles.wired_bench.data.Dataset.format

document framing

format
; /// document framing
private
(class) std.mmfile.MmFile

MmFile objects control the memory mapped file resource.

Examples

Read an existing file

import std.file;
std.file.write(deleteme, "hello"); // deleteme is a temporary filename
scope(exit) remove(deleteme);

// Use a scope class so the file will be closed at the end of this function
scope mmfile = new MmFile(deleteme);

assert(mmfile.length == "hello".length);

// Access file contents with the slice operator
// This is typed as `void[]`, so cast to `char[]` or `ubyte[]` to use it
const data = cast(const(char)[]) mmfile[];

// At this point, the file content may not have been read yet.
// In that case, the following memory access will intentionally
// trigger a page fault, causing the kernel to load the file contents
assert(data[0 .. 5] == "hello");

Write a new file

import std.file;
scope(exit) remove(deleteme);

scope mmfile = new MmFile(deleteme, MmFile.Mode.readWriteNew, 5, null);
assert(mmfile.length == 5);

auto data = cast(ubyte[]) mmfile[];

// This write to memory will be reflected in the file contents
data[] = '\n';

mmfile.flush();

assert(std.file.read(deleteme) == "\n\n\n\n\n");
MmFile
(field) std.mmfile.MmFile sparkles.wired_bench.data.Dataset.mapping

keeps an external corpus's read-only map alive

mapping
; /// keeps an external corpus's read-only map alive
/// A lazy range of JSON texts in a line-oriented corpus. auto
sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)) sparkles.wired_bench.data.Dataset.records() const pure nothrow @safe

A lazy range of JSON texts in a line-oriented corpus.

records
() const @safe
in (
(field) sparkles.wired_bench.data.DatasetFormat sparkles.wired_bench.data.Dataset.format

document framing

format
!=
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.document = 0

one RFC 8259 JSON text

document
)
{ const
(local variable) const(sparkles.wired_bench.data.DatasetFormat) framing
framing
=
(field) sparkles.wired_bench.data.DatasetFormat sparkles.wired_bench.data.Dataset.format

document framing

format
;
return
(field) const(char)[] sparkles.wired_bench.data.Dataset.text

the raw corpus text

text
.
std.algorithm.iteration.splitter!("a == b", Flag.no, const(char)[], char).Result std.algorithm.iteration.splitter!("a == b", Flag.no, const(char)[], char)(const(char)[] r, char s) pure nothrow @nogc @safe

Lazily splits a range using an element or range as a separator. Separator ranges can be any narrow string type or sliceable range type.

Two adjacent separators are considered to surround an empty element in the split range. Use filter!(a => !a.empty) on the result to compress empty elements.

The predicate is passed to binaryFun and accepts any callable function that can be executed via pred(element, s).

Note

If splitting a string on whitespace and token compression is desired, consider using the ``splitter(r) overload.

Constraints

The predicate pred needs to accept an element of r and the separator s.

Examples

Basic splitting with characters and numbers.

import std.algorithm.comparison : equal;

assert("a|bc|def".splitter('|').equal([ "a", "bc", "def" ]));

int[] a = [1, 0, 2, 3, 0, 4, 5, 6];
int[][] w = [ [1], [2, 3], [4, 5, 6] ];
assert(a.splitter(0).equal(w));

Basic splitting with characters and numbers and keeping sentinels.

import std.algorithm.comparison : equal;
import std.typecons : Yes;

assert("a|bc|def".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "a", "|", "bc", "|", "def" ]));

int[] a = [1, 0, 2, 3, 0, 4, 5, 6];
int[][] w = [ [1], [0], [2, 3], [0], [4, 5, 6] ];
assert(a.splitter!("a == b", Yes.keepSeparators)(0).equal(w));

Adjacent separators.

import std.algorithm.comparison : equal;

assert("|ab|".splitter('|').equal([ "", "ab", "" ]));
assert("ab".splitter('|').equal([ "ab" ]));

assert("a|b||c".splitter('|').equal([ "a", "b", "", "c" ]));
assert("hello  world".splitter(' ').equal([ "hello", "", "world" ]));

auto a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
auto w = [ [1, 2], [], [3], [4, 5], [] ];
assert(a.splitter(0).equal(w));

Adjacent separators and keeping sentinels.

import std.algorithm.comparison : equal;
import std.typecons : Yes;

assert("|ab|".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "", "|", "ab", "|", "" ]));
assert("ab".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "ab" ]));

assert("a|b||c".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "a", "|", "b", "|", "", "|", "c" ]));
assert("hello  world".splitter!("a == b", Yes.keepSeparators)(' ')
    .equal([ "hello", " ", "", " ", "world" ]));

auto a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
auto w = [ [1, 2], [0], [], [0], [3], [0], [4, 5], [0], [] ];
assert(a.splitter!("a == b", Yes.keepSeparators)(0).equal(w));

Empty and separator-only ranges.

import std.algorithm.comparison : equal;
import std.range : empty;

assert("".splitter('|').empty);
assert("|".splitter('|').equal([ "", "" ]));
assert("||".splitter('|').equal([ "", "", "" ]));

Empty and separator-only ranges and keeping sentinels.

import std.algorithm.comparison : equal;
import std.typecons : Yes;
import std.range : empty;

assert("".splitter!("a == b", Yes.keepSeparators)('|').empty);
assert("|".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "", "|", "" ]));
assert("||".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "", "|", "", "|", "" ]));

Use a range for splitting

import std.algorithm.comparison : equal;

assert("a=>bc=>def".splitter("=>").equal([ "a", "bc", "def" ]));
assert("a|b||c".splitter("||").equal([ "a|b", "c" ]));
assert("hello  world".splitter("  ").equal([ "hello", "world" ]));

int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
int[][] w = [ [1, 2], [3, 0, 4, 5, 0] ];
assert(a.splitter([0, 0]).equal(w));

a = [ 0, 0 ];
assert(a.splitter([0, 0]).equal([ (int[]).init, (int[]).init ]));

a = [ 0, 0, 1 ];
assert(a.splitter([0, 0]).equal([ [], [1] ]));

Use a range for splitting

import std.algorithm.comparison : equal;
import std.typecons : Yes;

assert("a=>bc=>def".splitter!("a == b", Yes.keepSeparators)("=>")
    .equal([ "a", "=>", "bc", "=>", "def" ]));
assert("a|b||c".splitter!("a == b", Yes.keepSeparators)("||")
    .equal([ "a|b", "||", "c" ]));
assert("hello  world".splitter!("a == b", Yes.keepSeparators)("  ")
    .equal([ "hello", "  ",  "world" ]));

int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
int[][] w = [ [1, 2], [0, 0], [3, 0, 4, 5, 0] ];
assert(a.splitter!("a == b", Yes.keepSeparators)([0, 0]).equal(w));

a = [ 0, 0 ];
assert(a.splitter!("a == b", Yes.keepSeparators)([0, 0])
    .equal([ (int[]).init, [0, 0], (int[]).init ]));

a = [ 0, 0, 1 ];
assert(a.splitter!("a == b", Yes.keepSeparators)([0, 0])
    .equal([ [], [0, 0], [1] ]));

Custom predicate functions.

import std.algorithm.comparison : equal;
import std.ascii : toLower;

assert("abXcdxef".splitter!"a.toLower == b"('x').equal(
             [ "ab", "cd", "ef" ]));

auto w = [ [0], [1], [2] ];
assert(w.splitter!"a.front == b"(1).equal([ [[0]], [[2]] ]));

Custom predicate functions.

import std.algorithm.comparison : equal;
import std.typecons : Yes;
import std.ascii : toLower;

assert("abXcdxef".splitter!("a.toLower == b", Yes.keepSeparators)('x')
    .equal([ "ab", "X", "cd", "x", "ef" ]));

auto w = [ [0], [1], [2] ];
assert(w.splitter!("a.front == b", Yes.keepSeparators)(1)
    .equal([ [[0]], [[1]], [[2]] ]));

Leading separators, trailing separators, or no separators.

import std.algorithm.comparison : equal;

assert("|ab|".splitter('|').equal([ "", "ab", "" ]));
assert("ab".splitter('|').equal([ "ab" ]));

Leading separators, trailing separators, or no separators.

import std.algorithm.comparison : equal;
import std.typecons : Yes;

assert("|ab|".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "", "|", "ab", "|", "" ]));
assert("ab".splitter!("a == b", Yes.keepSeparators)('|')
    .equal([ "ab" ]));

Splitter returns bidirectional ranges if the delimiter is a single element

import std.algorithm.comparison : equal;
import std.range : retro;
assert("a|bc|def".splitter('|').retro.equal([ "def", "bc", "a" ]));

Splitter returns bidirectional ranges if the delimiter is a single element

import std.algorithm.comparison : equal;
import std.typecons : Yes;
import std.range : retro;
assert("a|bc|def".splitter!("a == b", Yes.keepSeparators)('|')
    .retro.equal([ "def", "|", "bc", "|", "a" ]));
@parampred The predicate for comparing each element with the separator, defaulting to "a == b".@paramr The input range to be split. Must support slicing and .length or be a narrow string type.@params The element (or range) to be treated as the separator between range segments to be split.@paramkeepSeparators The flag for deciding if the separators are kept@returns

An input range of the subranges of elements between separators. If r is a forward range or bidirectional range, the returned range will be likewise. When a range is used a separator, bidirectionality isn't possible.

If keepSeparators is equal to Yes.keepSeparators the output will also contain the separators.

If an empty range is given, the result is an empty range. If a range with one separator is given, the result is a range with two empty elements.

@see
  • splitter for a version that splits using a regular expression defined separator.

  • split for a version that splits eagerly.

  • splitWhen, which compares adjacent elements instead of element against separator.

splitter
('\n')
.
sparkles.wired_bench.data.Dataset.records.MapResult!(__lambda_L77_C19, Result) sparkles.wired_bench.data.Dataset.records.map!(std.algorithm.iteration.splitter!("a == b", Flag.no, const(char)[], char).Result)(std.algorithm.iteration.splitter!("a == b", Flag.no, const(char)[], char).Result r) pure nothrow @nogc @safe

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call ``map!(fun)(range) returns a range of which elements are obtained by applying fun(a) left to right for all elements a in range. The original ranges are not changed. Evaluation is done lazily.

Examples

import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
    chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));

Multiple functions can be passed to map. In that case, the element type of map is a tuple containing one element for each function.

auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];

size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
    assert(result[0] == sums[i]);
    assert(result[1] == products[i]);
    ++i;
}

You may alias map with some function(s) to a symbol and use it separately:

import std.algorithm.comparison : equal;
import std.conv : to;

alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
@paramfun one or more transformation functions@seeMap (higher-order function)@paramr an input range@returnsA range with each fun applied to all the elements. If there is more than one fun, the element type will be Tuple containing one element for each fun.
map
!(line => recordLine(line, framing))
.
sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)) sparkles.wired_bench.data.Dataset.records.filter!(sparkles.wired_bench.data.Dataset.records.MapResult!(__lambda_L77_C19, Result))(sparkles.wired_bench.data.Dataset.records.MapResult!(__lambda_L77_C19, Result) range) pure nothrow @nogc @safe

filter`!(predicate)(`range`)` returns a new `range` containing only elements `x` in range`` for which predicate(x) returns true.

The predicate is passed to unaryFun, and can be either a string, or any callable that can be executed via pred(element).

Examples

import std.algorithm.comparison : equal;
import std.math.operations : isClose;
import std.range;

int[] arr = [ 1, 2, 3, 4, 5 ];

// Filter below 3
auto small = filter!(a => a < 3)(arr);
assert(equal(small, [ 1, 2 ]));

// Filter again, but with Uniform Function Call Syntax (UFCS)
auto sum = arr.filter!(a => a < 3);
assert(equal(sum, [ 1, 2 ]));

// In combination with chain() to span multiple ranges
int[] a = [ 3, -2, 400 ];
int[] b = [ 100, -101, 102 ];
auto r = chain(a, b).filter!(a => a > 0);
assert(equal(r, [ 3, 400, 100, 102 ]));

// Mixing convertible types is fair game, too
double[] c = [ 2.5, 3.0 ];
auto r1 = chain(c, a, b).filter!(a => cast(int) a != a);
assert(isClose(r1, [ 2.5 ]));
@parampredicate Function to apply to each element of range@returnsAn input range that contains the filtered elements. If range is at least a forward range, the return value of filter will also be a forward range.@seeFilter (higher-order function), filterBidirectional@paramrange An input range of elements@returnsA range containing only elements x in range for which predicate(x) returns true.
filter
!(line => line.length);
} } /// The corpus directory: the explicit value if given, else `$WIRED_BENCH_DATA`.
(alias) object.string = string
string
string sparkles.wired_bench.data.resolveDataDir(string explicitDir) @safe

The corpus directory: the explicit value if given, else $WIRED_BENCH_DATA.

resolveDataDir
(
(alias) object.string = string
string
(parameter) string explicitDir
explicitDir
) @safe
{ if (
(parameter) string explicitDir
explicitDir
.
(field) ulong string.length
length
)
return
(parameter) string explicitDir
explicitDir
;
const
(local variable) const(string) env
env
=
(class) std.process.environment

Manipulates environment variables using an associative-array-like interface.

This class contains only static methods, and cannot be instantiated. See below for examples of use.

environment
.
string std.process.environment.get(scope const(char)[] name, string defaultValue = null) @safe

Retrieves the value of the environment variable with the given name, or a default value if the variable doesn't exist.

Unlike environment.opIndex, this function never throws on Posix.

auto sh = environment.get("SHELL", "/bin/sh");

This function is also useful in checking for the existence of an environment variable.

auto myVar = environment.get("MYVAR");
if (myVar is null)
{
    // Environment variable doesn't exist.
    // Note that we have to use 'is' for the comparison, since
    // myVar == null is also true if the variable exists but is
    // empty.
}
@paramname name of the environment variable to retrieve@paramdefaultValue default value to return if the environment variable doesn't exist.@returnsthe value of the environment variable if found, otherwise null if the environment doesn't exist.@throwsUTFException if the variable contains invalid UTF-16 characters (Windows only).
get
("WIRED_BENCH_DATA");
bool std.exception.enforce!().enforce!bool(bool value, lazy const(char)[] msg = null, string file = __FILE__, ulong line = cast(ulong)__LINE__) pure @safe

Enforces that the given value is true. If the given value is false, an exception is thrown. The

  • msg - error message as a string

  • dg - custom delegate that return a string and is only called if an exception occurred

  • ex - custom exception to be thrown. It is lazy and is only created if an exception occurred

@paramvalue The value to test.@paramE Exception type to throw if the value evaluates to false.@parammsg The error message to put in the exception if it is thrown.@paramdg The delegate to be called if the value evaluates to false.@paramex The exception to throw if the value evaluates to false.@paramfile The source file of the caller.@paramline The line number of the caller.@returns

value, if cast(bool) value`` is true. Otherwise, depending on the chosen overload, new Exception(msg), dg() or ex is thrown.

enforce is used to throw exceptions and is therefore intended to aid in error handling. It is not intended for verifying the logic of your program - that is what assert is for.

Do not use enforce inside of contracts (i.e. inside of in and out blocks and invariants), because contracts are compiled out when compiling with -release.

If a delegate is passed, the safety and purity of this function are inferred from Dg's safety and purity.

enforce
(
(local variable) const(string) env
env
!is null &&
(local variable) const(string) env
env
.
(field) ulong const(string).length
length
,
"no data directory: export WIRED_BENCH_DATA to point at the benchmark " ~ "corpora (the devshell sets it)"); return
(local variable) const(string) env
env
;
} /// The external-corpus directory: explicit value, else the environment.
(alias) object.string = string
string
string sparkles.wired_bench.data.resolveExternalDataDir(string explicitDir) @safe

The external-corpus directory: explicit value, else the environment.

resolveExternalDataDir
(
(alias) object.string = string
string
(parameter) string explicitDir
explicitDir
) @safe
{ if (
(parameter) string explicitDir
explicitDir
.
(field) ulong string.length
length
)
return
(parameter) string explicitDir
explicitDir
;
return
(class) std.process.environment

Manipulates environment variables using an associative-array-like interface.

This class contains only static methods, and cannot be instantiated. See below for examples of use.

environment
.
string std.process.environment.get(scope const(char)[] name, string defaultValue = null) @safe

Retrieves the value of the environment variable with the given name, or a default value if the variable doesn't exist.

Unlike environment.opIndex, this function never throws on Posix.

auto sh = environment.get("SHELL", "/bin/sh");

This function is also useful in checking for the existence of an environment variable.

auto myVar = environment.get("MYVAR");
if (myVar is null)
{
    // Environment variable doesn't exist.
    // Note that we have to use 'is' for the comparison, since
    // myVar == null is also true if the variable exists but is
    // empty.
}
@paramname name of the environment variable to retrieve@paramdefaultValue default value to return if the environment variable doesn't exist.@returnsthe value of the environment variable if found, otherwise null if the environment doesn't exist.@throwsUTFException if the variable contains invalid UTF-16 characters (Windows only).
get
("WIRED_BENCH_EXTERNAL_DATA", "");
} /// Looks up one catalog entry, rejecting typos before touching the filesystem.
(struct) sparkles.wired_bench.data.DatasetSource

One known corpus and its on-disk convention.

DatasetSource
sparkles.wired_bench.data.DatasetSource sparkles.wired_bench.data.datasetSource(scope const(char)[] name) @safe

Looks up one catalog entry, rejecting typos before touching the filesystem.

datasetSource
(scope const(char)[]
(parameter) const(char)[] name
name
) @safe
{ foreach (
(parameter) immutable(sparkles.wired_bench.data.DatasetSource) source
source
;
(immutable global) immutable(sparkles.wired_bench.data.DatasetSource[]) sparkles.wired_bench.data.datasetSources

Every dataset name accepted by $WIRED_BENCH_DATASETS.

datasetSources
)
if (
(local variable) immutable(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) string sparkles.wired_bench.data.DatasetSource.name
name
==
(parameter) const(char)[] name
name
)
return
(local variable) immutable(sparkles.wired_bench.data.DatasetSource) source
source
;
bool std.exception.enforce!().enforce!bool(bool value, lazy const(char)[] msg = null, string file = __FILE__, ulong line = cast(ulong)__LINE__) pure @safe

Enforces that the given value is true. If the given value is false, an exception is thrown. The

  • msg - error message as a string

  • dg - custom delegate that return a string and is only called if an exception occurred

  • ex - custom exception to be thrown. It is lazy and is only created if an exception occurred

@paramvalue The value to test.@paramE Exception type to throw if the value evaluates to false.@parammsg The error message to put in the exception if it is thrown.@paramdg The delegate to be called if the value evaluates to false.@paramex The exception to throw if the value evaluates to false.@paramfile The source file of the caller.@paramline The line number of the caller.@returns

value, if cast(bool) value`` is true. Otherwise, depending on the chosen overload, new Exception(msg), dg() or ex is thrown.

enforce is used to throw exceptions and is therefore intended to aid in error handling. It is not intended for verifying the logic of your program - that is what assert is for.

Do not use enforce inside of contracts (i.e. inside of in and out blocks and invariants), because contracts are compiled out when compiling with -release.

If a delegate is passed, the safety and purity of this function are inferred from Dg's safety and purity.

enforce
(false, "unknown dataset '" ~
(parameter) const(char)[] name
name
~ "' (known: twitter, "
~ "citm_catalog, canada, github_events, mesh, mesh_pretty, wikidata, " ~ "osm, cloudtrail, elasticsearch)"); assert(false); } /// Loads the selected catalog entries from their bundled or external root.
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
[]
sparkles.wired_bench.data.Dataset[] sparkles.wired_bench.data.loadDatasets(const(string[]) names, string dataDir, string externalDataDir = null) @safe

Loads the selected catalog entries from their bundled or external root.

loadDatasets
(const
(alias) object.string = string
string
[]
(parameter) const(string[]) names
names
,
(alias) object.string = string
string
(parameter) string dataDir
dataDir
,
(alias) object.string = string
string
(parameter) string externalDataDir
externalDataDir
= null) @safe
{
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
[]
(local variable) sparkles.wired_bench.data.Dataset[] result
result
;
(local variable) sparkles.wired_bench.data.Dataset[] result
result
.
ulong object.reserve!(sparkles.wired_bench.data.Dataset)(ref sparkles.wired_bench.data.Dataset[] arr, ulong newcapacity) pure nothrow @trusted

Reserves capacity for a slice. The capacity is the size that the slice can grow to before the underlying array must be reallocated or extended.

Examples

//Static array slice: no capacity. Reserve relocates.
int[4] sarray = [1, 2, 3, 4];
int[]  slice  = sarray[];
auto u = slice.reserve(8);
assert(u >= 8);
assert(&sarray[0] !is &slice[0]);
assert(slice.capacity == u);

//Dynamic array slices
int[] a = [1, 2, 3, 4];
a.reserve(8); //prepare a for appending 4 more items
auto p = &a[0];
u = a.capacity;
a ~= [5, 6, 7, 8];
assert(p == &a[0]);      //a should not have been reallocated
assert(u == a.capacity); //a should not have been extended
@returnsThe new capacity of the array (which may be larger than the requested capacity).
reserve
(
(parameter) const(string[]) names
names
.
(field) ulong const(string[]).length
length
);
foreach (
(parameter) const(string) name
name
;
(parameter) const(string[]) names
names
)
{ const
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
=
sparkles.wired_bench.data.DatasetSource sparkles.wired_bench.data.datasetSource(scope const(char)[] name) @safe

Looks up one catalog entry, rejecting typos before touching the filesystem.

datasetSource
(
(local variable) const(string) name
name
);
const
(local variable) const(string) root
root
=
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) bool sparkles.wired_bench.data.DatasetSource.bundled
bundled
?
(parameter) string dataDir
dataDir
:
string sparkles.wired_bench.data.resolveExternalDataDir(string explicitDir) @safe

The external-corpus directory: explicit value, else the environment.

resolveExternalDataDir
(
(parameter) string externalDataDir
externalDataDir
);
if (
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) bool sparkles.wired_bench.data.DatasetSource.bundled
bundled
)
ulong std.exception.enforce!().enforce!ulong(ulong value, lazy const(char)[] msg = null, string file = __FILE__, ulong line = cast(ulong)__LINE__) pure @safe

Enforces that the given value is true. If the given value is false, an exception is thrown. The

  • msg - error message as a string

  • dg - custom delegate that return a string and is only called if an exception occurred

  • ex - custom exception to be thrown. It is lazy and is only created if an exception occurred

@paramvalue The value to test.@paramE Exception type to throw if the value evaluates to false.@parammsg The error message to put in the exception if it is thrown.@paramdg The delegate to be called if the value evaluates to false.@paramex The exception to throw if the value evaluates to false.@paramfile The source file of the caller.@paramline The line number of the caller.@returns

value, if cast(bool) value`` is true. Otherwise, depending on the chosen overload, new Exception(msg), dg() or ex is thrown.

enforce is used to throw exceptions and is therefore intended to aid in error handling. It is not intended for verifying the logic of your program - that is what assert is for.

Do not use enforce inside of contracts (i.e. inside of in and out blocks and invariants), because contracts are compiled out when compiling with -release.

If a delegate is passed, the safety and purity of this function are inferred from Dg's safety and purity.

enforce
(
(local variable) const(string) root
root
.
(field) ulong const(string).length
length
, "dataset '" ~
(local variable) const(string) name
name
~ "' is bundled: export WIRED_BENCH_DATA"); else
ulong std.exception.enforce!().enforce!ulong(ulong value, lazy const(char)[] msg = null, string file = __FILE__, ulong line = cast(ulong)__LINE__) pure @safe

Enforces that the given value is true. If the given value is false, an exception is thrown. The

  • msg - error message as a string

  • dg - custom delegate that return a string and is only called if an exception occurred

  • ex - custom exception to be thrown. It is lazy and is only created if an exception occurred

@paramvalue The value to test.@paramE Exception type to throw if the value evaluates to false.@parammsg The error message to put in the exception if it is thrown.@paramdg The delegate to be called if the value evaluates to false.@paramex The exception to throw if the value evaluates to false.@paramfile The source file of the caller.@paramline The line number of the caller.@returns

value, if cast(bool) value`` is true. Otherwise, depending on the chosen overload, new Exception(msg), dg() or ex is thrown.

enforce is used to throw exceptions and is therefore intended to aid in error handling. It is not intended for verifying the logic of your program - that is what assert is for.

Do not use enforce inside of contracts (i.e. inside of in and out blocks and invariants), because contracts are compiled out when compiling with -release.

If a delegate is passed, the safety and purity of this function are inferred from Dg's safety and purity.

enforce
(
(local variable) const(string) root
root
.
(field) ulong const(string).length
length
, "dataset '" ~
(local variable) const(string) name
name
~ "' is external: export "
~ "WIRED_BENCH_EXTERNAL_DATA to the directory containing " ~
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) string sparkles.wired_bench.data.DatasetSource.fileName
fileName
);
const
(local variable) const(string) path
path
=
(local variable) const(string) root
root
.
string std.path.buildPath!char(const(char)[][] paths...) pure nothrow @safe

Combines one or more path segments.

This function takes a set of path segments, given as an input range of string elements or as a set of string arguments, and concatenates them with each other. Directory separators are inserted between segments if necessary. If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped.

On Windows, if one of the path segments are rooted, but not absolute (e.g. \foo), all preceding path segments down to the previous root will be dropped. (See below for an example.)

This function always allocates memory to hold the resulting path. The variadic overload is guaranteed to only perform a single allocation, as is the range version if paths is a forward range.

Examples

version (Posix)
{
    assert(buildPath("foo", "bar", "baz") == "foo/bar/baz");
    assert(buildPath("/foo/", "bar/baz")  == "/foo/bar/baz");
    assert(buildPath("/foo", "/bar")      == "/bar");
}

version (Windows)
{
    assert(buildPath("foo", "bar", "baz") == `foo\bar\baz`);
    assert(buildPath(`c:\foo`, `bar\baz`) == `c:\foo\bar\baz`);
    assert(buildPath("foo", `d:\bar`)     == `d:\bar`);
    assert(buildPath("foo", `\bar`)       == `\bar`);
    assert(buildPath(`c:\foo`, `\bar`)    == `c:\bar`);
}
@paramsegments An input range of segments to assemble the path from.@returnsThe assembled path.
buildPath
(
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) string sparkles.wired_bench.data.DatasetSource.fileName
fileName
);
bool std.exception.enforce!().enforce!bool(bool value, lazy const(char)[] msg = null, string file = __FILE__, ulong line = cast(ulong)__LINE__) pure @safe

Enforces that the given value is true. If the given value is false, an exception is thrown. The

  • msg - error message as a string

  • dg - custom delegate that return a string and is only called if an exception occurred

  • ex - custom exception to be thrown. It is lazy and is only created if an exception occurred

@paramvalue The value to test.@paramE Exception type to throw if the value evaluates to false.@parammsg The error message to put in the exception if it is thrown.@paramdg The delegate to be called if the value evaluates to false.@paramex The exception to throw if the value evaluates to false.@paramfile The source file of the caller.@paramline The line number of the caller.@returns

value, if cast(bool) value`` is true. Otherwise, depending on the chosen overload, new Exception(msg), dg() or ex is thrown.

enforce is used to throw exceptions and is therefore intended to aid in error handling. It is not intended for verifying the logic of your program - that is what assert is for.

Do not use enforce inside of contracts (i.e. inside of in and out blocks and invariants), because contracts are compiled out when compiling with -release.

If a delegate is passed, the safety and purity of this function are inferred from Dg's safety and purity.

enforce
(
(local variable) const(string) path
path
.
bool std.file.exists!string(string name) nothrow @nogc @safe

Determine whether the given file (or directory) exists.

@paramname string or range of characters representing the file name@returnstrue if the file name specified as input exists
exists
, "dataset not found: " ~
(local variable) const(string) path
path
);
(local variable) sparkles.wired_bench.data.Dataset[] result
result
~=
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) bool sparkles.wired_bench.data.DatasetSource.bundled
bundled
?
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
(
(local variable) const(string) name
name
,
string std.file.readText!(string, const(string))(ref const(string) name) @safe

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

Examples

Read file with UTF-8 text.

write(deleteme, "abc"); // deleteme is the name of a temporary file
scope(exit) remove(deleteme);
string content = readText(deleteme);
assert(content == "abc");
@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
(
(local variable) const(string) path
path
),
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) sparkles.wired_bench.data.DatasetFormat sparkles.wired_bench.data.DatasetSource.format
format
)
:
sparkles.wired_bench.data.Dataset sparkles.wired_bench.data.mapDataset(string name, string path, sparkles.wired_bench.data.DatasetFormat format) @trusted

Maps a potentially enormous external corpus without a heap-sized input copy.

mapDataset
(
(local variable) const(string) name
name
,
(local variable) const(string) path
path
,
(local variable) const(sparkles.wired_bench.data.DatasetSource) source
source
.
(field) sparkles.wired_bench.data.DatasetFormat sparkles.wired_bench.data.DatasetSource.format
format
);
} return
(local variable) sparkles.wired_bench.data.Dataset[] result
result
;
} /// Maps a potentially enormous external corpus without a heap-sized input copy. private
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
sparkles.wired_bench.data.Dataset sparkles.wired_bench.data.mapDataset(string name, string path, sparkles.wired_bench.data.DatasetFormat format) @trusted

Maps a potentially enormous external corpus without a heap-sized input copy.

mapDataset
(
(alias) object.string = string
string
(parameter) string name
name
,
(alias) object.string = string
string
(parameter) string path
path
,
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
(parameter) sparkles.wired_bench.data.DatasetFormat format
format
)
@trusted { auto
(local variable) std.mmfile.MmFile mapping
mapping
= new
(class) std.mmfile.MmFile

MmFile objects control the memory mapped file resource.

Examples

Read an existing file

import std.file;
std.file.write(deleteme, "hello"); // deleteme is a temporary filename
scope(exit) remove(deleteme);

// Use a scope class so the file will be closed at the end of this function
scope mmfile = new MmFile(deleteme);

assert(mmfile.length == "hello".length);

// Access file contents with the slice operator
// This is typed as `void[]`, so cast to `char[]` or `ubyte[]` to use it
const data = cast(const(char)[]) mmfile[];

// At this point, the file content may not have been read yet.
// In that case, the following memory access will intentionally
// trigger a page fault, causing the kernel to load the file contents
assert(data[0 .. 5] == "hello");

Write a new file

import std.file;
scope(exit) remove(deleteme);

scope mmfile = new MmFile(deleteme, MmFile.Mode.readWriteNew, 5, null);
assert(mmfile.length == 5);

auto data = cast(ubyte[]) mmfile[];

// This write to memory will be reflected in the file contents
data[] = '\n';

mmfile.flush();

assert(std.file.read(deleteme) == "\n\n\n\n\n");
MmFile
(
(parameter) string path
path
);
return
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
(
(parameter) string name
name
, cast(const(char)[])
(local variable) std.mmfile.MmFile mapping
mapping
[],
(parameter) sparkles.wired_bench.data.DatasetFormat format
format
,
(local variable) std.mmfile.MmFile mapping
mapping
);
} /// Normalizes one physical line into a JSON record view. private const(char)[]
const(char)[] sparkles.wired_bench.data.recordLine(return scope const(char)[] raw, sparkles.wired_bench.data.DatasetFormat format) pure nothrow @safe

Normalizes one physical line into a JSON record view.

recordLine
(return scope const(char)[]
(parameter) const(char)[] raw
raw
,
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
(parameter) sparkles.wired_bench.data.DatasetFormat format
format
) @safe pure nothrow
{ auto
(local variable) const(char)[] line
line
=
(parameter) const(char)[] raw
raw
.
const(char)[] std.string.strip!(const(char)[])(const(char)[] str) pure nothrow @nogc @safe

Strips both leading and trailing whitespace (as defined by isWhite) or as specified in the second argument.

Examples

import std.uni : lineSep, paraSep;
assert(strip("     hello world     ") ==
       "hello world");
assert(strip("\n\t\v\rhello world\n\t\v\r") ==
       "hello world");
assert(strip("hello world") ==
       "hello world");
assert(strip([lineSep] ~ "hello world" ~ [lineSep]) ==
       "hello world");
assert(strip([paraSep] ~ "hello world" ~ [paraSep]) ==
       "hello world");
@paramstr string or random access range of characters@paramchars string of characters to be stripped@paramleftChars string of leading characters to be stripped@paramrightChars string of trailing characters to be stripped@returnsslice of str stripped of leading and trailing whitespace or characters as specified in the second argument.@seeGeneric stripping on ranges: strip
strip
;
if (
(parameter) sparkles.wired_bench.data.DatasetFormat format
format
==
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.jsonArrayLines = 2

[/] plus one comma-terminated value per line

jsonArrayLines
)
{ if (
(local variable) const(char)[] line
line
== "[" ||
(local variable) const(char)[] line
line
== "]")
return null; if (
(local variable) const(char)[] line
line
.
(field) ulong const(char)[].length
length
&&
(local variable) const(char)[] line
line
[$ - 1] == ',')
(local variable) const(char)[] line
line
=
(local variable) const(char)[] line
line
[0 .. $ - 1].
const(char)[] std.string.strip!(const(char)[])(const(char)[] str) pure nothrow @nogc @safe

Strips both leading and trailing whitespace (as defined by isWhite) or as specified in the second argument.

Examples

import std.uni : lineSep, paraSep;
assert(strip("     hello world     ") ==
       "hello world");
assert(strip("\n\t\v\rhello world\n\t\v\r") ==
       "hello world");
assert(strip("hello world") ==
       "hello world");
assert(strip([lineSep] ~ "hello world" ~ [lineSep]) ==
       "hello world");
assert(strip([paraSep] ~ "hello world" ~ [paraSep]) ==
       "hello world");
@paramstr string or random access range of characters@paramchars string of characters to be stripped@paramleftChars string of leading characters to be stripped@paramrightChars string of trailing characters to be stripped@returnsslice of str stripped of leading and trailing whitespace or characters as specified in the second argument.@seeGeneric stripping on ranges: strip
strip
;
} return
(local variable) const(char)[] line
line
;
} @("data.resolveDataDir.cliWins") @safe unittest { assert(
string sparkles.wired_bench.data.resolveDataDir(string explicitDir) @safe

The corpus directory: the explicit value if given, else $WIRED_BENCH_DATA.

resolveDataDir
("/some/dir") == "/some/dir");
} @("data.catalog.formatsAndDefaults") @safe unittest { assert(
sparkles.wired_bench.data.DatasetSource sparkles.wired_bench.data.datasetSource(scope const(char)[] name) @safe

Looks up one catalog entry, rejecting typos before touching the filesystem.

datasetSource
("mesh_pretty").
(field) string sparkles.wired_bench.data.DatasetSource.fileName
fileName
== "mesh.pretty.json");
assert(
sparkles.wired_bench.data.DatasetSource sparkles.wired_bench.data.datasetSource(scope const(char)[] name) @safe

Looks up one catalog entry, rejecting typos before touching the filesystem.

datasetSource
("wikidata").
(field) sparkles.wired_bench.data.DatasetFormat sparkles.wired_bench.data.DatasetSource.format
format
==
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.jsonArrayLines = 2

[/] plus one comma-terminated value per line

jsonArrayLines
);
assert(
sparkles.wired_bench.data.DatasetSource sparkles.wired_bench.data.datasetSource(scope const(char)[] name) @safe

Looks up one catalog entry, rejecting typos before touching the filesystem.

datasetSource
("wikidata").
(field) bool sparkles.wired_bench.data.DatasetSource.bundled
bundled
== false);
assert(
(immutable global) immutable(string[]) sparkles.wired_bench.data.defaultDatasetNames

The normal, reproducible benchmark matrix. External corpora are opt-in.

defaultDatasetNames
.
(field) ulong immutable(string[]).length
length
== 6);
} @("data.records.ndjsonAndWikidataArray") @safe unittest { auto
(local variable) sparkles.wired_bench.data.Dataset ndjson
ndjson
=
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
("logs", " {\"a\":1}\n\n{\"b\":2}\r\n",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.ndjson = 1

one complete JSON text per non-empty line

ndjson
);
assert(
(local variable) sparkles.wired_bench.data.Dataset ndjson
ndjson
.
sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)) sparkles.wired_bench.data.Dataset.records() const pure nothrow @safe

A lazy range of JSON texts in a line-oriented corpus.

records
.
const(char)[][] std.array.array!(sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)))(sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)) r) pure @safe

Allocates an array and initializes it with copies of the elements of range r.

Narrow strings are handled as follows:

  • If autodecoding is turned on (default), then they are handled as a separate overload.

  • If autodecoding is turned off, then this is equivalent to duplicating the array.

@paramr range (or aggregate with opApply function) whose elements are copied into the allocated array@returnsallocated and initialized array
array
== [`{"a":1}`, `{"b":2}`]);
auto
(local variable) sparkles.wired_bench.data.Dataset wikidata
wikidata
=
(struct) sparkles.wired_bench.data.Dataset

One loaded benchmark corpus.

Dataset
("wikidata",
"[\n{\"id\":\"Q1\"},\n {\"id\":\"Q2\"}\n]\n",
(enum) sparkles.wired_bench.data.DatasetFormat

How one corpus is divided into JSON documents.

DatasetFormat
.
(enum value) sparkles.wired_bench.data.DatasetFormat.jsonArrayLines = 2

[/] plus one comma-terminated value per line

jsonArrayLines
);
assert(
(local variable) sparkles.wired_bench.data.Dataset wikidata
wikidata
.
sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)) sparkles.wired_bench.data.Dataset.records() const pure nothrow @safe

A lazy range of JSON texts in a line-oriented corpus.

records
.
const(char)[][] std.array.array!(sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)))(sparkles.wired_bench.data.Dataset.records.FilterResult!(__lambda_L78_C22, MapResult!(__lambda_L77_C19, Result)) r) pure @safe

Allocates an array and initializes it with copies of the elements of range r.

Narrow strings are handled as follows:

  • If autodecoding is turned on (default), then they are handled as a separate overload.

  • If autodecoding is turned off, then this is equivalent to duplicating the array.

@paramr range (or aggregate with opApply function) whose elements are copied into the allocated array@returnsallocated and initialized array
array
==
[`{"id":"Q1"}`, `{"id":"Q2"}`]); }