PriorityArray

Array-like structure with fast access to the smallest element.

Implemented using a segment tree. TODO: more array-like operations (e.g. pushBack, popBack, maybe iteration)

Constructors

this
this(size_t size)

constructor for given size

this
this(Stuff data)

constructor taking a range

Members

Functions

length
size_t length()

number of elements in the array

min
const(V) min()

returns smallest element ( O(1) )

minIndex
size_t minIndex()

returns index of smallest element ( O(1) )

opDollar
size_t opDollar()

number of elements in the array

opIndex
inout(V) opIndex(size_t i)

read-only access to the i'th element

opIndexAssign
void opIndexAssign(V v, size_t _i)

set element at i to value v ( O(log n) )

opSlice
const(V)[] opSlice()

read-only access to all elements

Examples

auto a = PriorityArray!int([7,9,2,3,4,1,6,5,8,0]);
assert(a[] == [7,9,2,3,4,1,6,5,8,0]);

assert(a.minIndex == 9);
assert(a.min == 0);

a[9] = 100;

assert(a.minIndex == 5);
assert(a.min == 1);

a[2] = -3;

assert(a.minIndex == 2);
assert(a.min == -3);

Meta