Sorted

Wrapper container around array-like type A.

Constructors

this
this(A source)
Undocumented in source.

Alias This

source

Members

Functions

capacity
auto capacity()
Undocumented in source.
insert
bool insert(U value)

Insert value into this.

insert
size_t insert(R values)

Insert values into this.

opSlice
auto opSlice()
Undocumented in source. Be warned that the author may not have intended to support it.
reserve
auto reserve(size_t capacity)
Undocumented in source.
source
auto source()
Undocumented in source. Be warned that the author may not have intended to support it.
source
auto source()
Undocumented in source. Be warned that the author may not have intended to support it.

Unions

__anonymous
union __anonymous
Undocumented in source.

Examples

construct from dynamic array

alias A = int[];
scope A x = [3,2,1];

auto sx = Sorted!(A, false)(x);
assert(sx[].isSorted);

assert(sx.reserve(3));
assert(!sx.insert(1));
assert(!sx.insert(2));
assert(!sx.insert(3));
assert(sx.length == 3);

assert(sx.insert(0));
assert(sx.length == 4);
assert(isIota(sx));

assert(sx.insert([4,5]));
assert(sx.length == 6);
assert(isIota(sx));

assert(sx.insert([4,5]));
assert(sx.length == 8);

assert(sx.release == [0, 1, 2, 3, 4, 4, 5, 5]);

construct from static array

alias A = int[3];
A x = [3,2,1];

auto sx = Sorted!(A, true)(x);
assert(sx[].isSorted);

static assert(!is(typeof(x.reserve(0))));
static assert(!is(typeof(sx.insert(0))));

construct from dynamic container

import std.stdio;
import nxt.container.dynamic_array : DynamicArray;

alias A = DynamicArray!(int);

auto sx = Sorted!(A, true)(A([3,2,1]));
assert(sx.capacity >= 3);
assert(sx[].release == [1,2,3]);
assert(sx[].isSorted);

sx.reserve(4);
assert(sx.capacity >= 4);

See Also

https://en.wikipedia.org/wiki/Sorted_array

nxt.container.cyclic.Cyclic.

TODO: Implement support for storing duplicate elements by setting uniqueElements to false

TODO: Parameterize sorting algorithm sort and add test and benchmark for hybridSort in test/containers/source/app.d

TODO: Add template parameter GrowthStrategy (and reference the term growth factor) and reuse in other dynamic containers, such as growScaleP and growScaleQ in flat_hashmap.d and SoA._growthP and SoA._growthQ in soa.d.

Meta