Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.rcarray

Thread-safe reference-counted arrays and iterators

.
struct mir_rcarray(T);

alias RCArray = mir_rcarray(T);
Thread safe reference counting array.
__xdtor if any is used to destruct objects.
The implementation never adds roots into the GC.
Examples:
auto a = RCArray!double(10);
foreach(i, ref e; a)
    e = i;
auto b = a;
assert(b[$ - 1] == 9);
foreach(i, ref e; b)
    assert(e == i);
b[4] = 100;
assert(a[4] == 100);

import mir.ndslice.slice;

auto s = a.asSlice; // as RC random access range (ndslice)
static assert(is(typeof(s) == Slice!(RCI!double)));
static assert(is(typeof(s) == mir_slice!(mir_rci!double)));

auto r = a[]; // scope array
static assert(is(typeof(r) == double[]));

auto fs = r.sliced; // scope fast random access range (ndslice)
static assert(is(typeof(fs) == Slice!(double*)));
Examples:
auto a = RCArray!double.create(1.0, 2, 5, 3);
assert(a[0] == 1);
assert(a[$ - 1] == 3);

auto s = RCArray!char.create("hello!");
assert(s[0] == 'h');
assert(s[$ - 1] == '!');

alias rcstring = RCArray!(immutable char).create;
auto r = rcstring("string");
assert(r[0] == 's');
assert(r[$ - 1] == 'g');
nothrow @nogc scope @system bool initialize(size_t length, uint alignment, bool deallocate, bool initialize);
Extern constructor
pure nothrow @nogc @trusted this(ref const typeof(this) rhs);
Defined if T is const
pure nothrow @nogc this(ref typeof(this) rhs);
Defined if T isn't const
@property scope auto asSlice() return;
@nogc @trusted this(size_t length, uint alignment = T.alignof, bool deallocate = true, bool initialize = true);
Parameters:
size_t length array length
uint alignment alignment, must be power of 2
bool deallocate Flag, never deallocates memory if false.
bool initialize Flag, don't initialize memory with default value if false.
static @nogc @safe typeof(this) create(V[] values...);
Contructor is defined if hasIndirections!T == true.
static @nogc typeof(this) create(scope V[] values...);
Contructor is defined if hasIndirections!T == false.
const pure nothrow @nogc @property scope @trusted size_t length();
const pure nothrow @nogc @property scope @trusted size_t counter();
inout scope @system inout(T)* ptr();
inout ref scope @trusted auto opIndex(size_t i);
pure nothrow @nogc @property scope @safe bool opEquals(typeof(null));
inout scope @trusted inout(T)[] opIndex();
const nothrow @nogc @property scope @trusted mir_rcarray!(const(T)) lightConst()() return;
struct mir_rci(T);

alias RCI = mir_rci(T);
Thread safe reference counting iterator.
Examples:
import mir.ndslice.slice;
import mir.rcarray;
auto array = mir_rcarray!double(10);
auto slice = array.asSlice;
static assert(is(typeof(slice) == Slice!(RCI!double)));
auto matrix = slice.sliced(2, 5);
static assert(is(typeof(matrix) == Slice!(RCI!double, 2)));
array[7] = 44;
assert(matrix[1, 2] == 44);
Examples:
import mir.ndslice.slice;
import mir.rcarray;

alias rcvec = Slice!(RCI!double);

RCI!double a, b;
size_t c = a - b;

void foo(scope ref rcvec x, scope ref rcvec y)
{
    x[] = y[];
    x[1] = y[1];
    x[1 .. $] += y[1 .. $];
    x = x.save;
}
T* _iterator;
RCArray!T _array;
inout ref scope inout(T) opUnary(string op : "*")() return;
inout ref scope inout(T) opIndex(ptrdiff_t index) return;
scope void opUnary(string op)()
if (op == "--" || op == "++");
scope void opOpAssign(string op)(ptrdiff_t index)
if (op == "-" || op == "+");
mir_rci!T opBinary(string op)(ptrdiff_t index)
if (op == "+" || op == "-");
const mir_rci!(const(T)) opBinary(string op)(ptrdiff_t index)
if (op == "+" || op == "-");
immutable mir_rci!(immutable(T)) opBinary(string op)(ptrdiff_t index)
if (op == "+" || op == "-");
const scope ptrdiff_t opBinary(string op : "-")(ref scope const typeof(this) right);
const scope bool opEquals()(ref scope const typeof(this) right);
const scope ptrdiff_t opCmp()(ref scope const typeof(this) right);