constructor for given size
constructor taking a range
constructor for given size
constructor taking a range
number of elements in the array
Allocated heap memory in bytes. This is recursive if V has a .memUsage property.
returns smallest element ( O(1) )
returns index of smallest element ( O(1) )
number of elements in the array
read-only access to the i'th element
set element at i to value v ( O(log n) )
read-only access to all elements
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);
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)