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(_pred p, size_t size)

constructor for given size

this
this(_pred p, Stuff data)

constructor taking a range

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

memUsage
size_t memUsage()

Allocated heap memory in bytes. This is recursive if V has a .memUsage property.

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

Mixins

__anonymous
mixin PredicateHelper!(_pred, V)
Undocumented in source.

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);

custom predicate

struct Cmp
{
	bool opCall(int a, int b)
	{
		return a > b;
	}
}

// The function Cmp.opCall is not static. Therefore the constructor of
// PriorityArray takes an instance of Cmp
auto a = PriorityArray!(int, Cmp)(Cmp.init, [-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