tango.core.Array

The array module provides array manipulation routines in a manner that balances performance and flexibility. Operations are provided for sorting, and for processing both sorted and unsorted arrays.

Members

Aliases

Elem
alias Elem = int
Undocumented in source.
Elem2
alias Elem2 = int
Undocumented in source.
Map2E
alias Map2E = Elem2 function(Elem, Elem)
Undocumented in source.
Num
alias Num = int
Undocumented in source.
Oper1A
alias Oper1A = size_t function(size_t)
Undocumented in source.
Pred1E
alias Pred1E = bool function(Elem)
Undocumented in source.
Pred2E
alias Pred2E = bool function(Elem, Elem)
Undocumented in source.
Reduce2E
alias Reduce2E = Elem function(Elem, Elem)
Undocumented in source.

Functions

bsearch
bool bsearch(Elem[] buf, Elem pat, Pred2E pred)

Performs a binary search of buf, returning true if an element equivalent to pat is found. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

contains
equals_t contains(Elem[] buf, Elem pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning true if an element matching pat is found. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

contains
equals_t contains(Elem[] buf, Elem[] pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning true if a sequence matching pat is found. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

count
size_t count(Elem[] buf, Elem pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning a count of the number of elements matching pat. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

countIf
size_t countIf(Elem[] buf, Pred1E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning a count of the number of elements where pred returns true.

differenceOf
Elem[] differenceOf(Elem[] setA, Elem[] setB, Pred2E pred)

Returns a new array containing all elements in setA which are not present in setB and the elements in setB which are not present in setA. Both setA and setB are required to be sorted. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

distinct
size_t distinct(Elem[] buf, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), moving all but the first element of each consecutive group of duplicate elements to the end of the sequence. The relative order of all remaining elements will be preserved. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

filter
Elem[] filter(Elem[] array, Pred1E pred, Elem[] buf)

Performs a linear scan of buf from [0 .. buf.length$(RP), creating a new array with just the elements that satisfy pred. The relative order of elements will be preserved.

find
size_t find(Elem[] buf, Elem pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

find
size_t find(Elem[] buf, Elem[] pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

findAdj
size_t findAdj(Elem[] buf, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning the index of the first element that compares equal to the next element in the sequence. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

findIf
size_t findIf(Elem[] buf, Pred1E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning the index of the first element where pred returns true.

includes
bool includes(Elem[] setA, Elem[] setB, Pred2E pred)

Performs a parallel linear scan of setA and setB from [0 .. N$(RP) where N = min(setA.length, setB.length), returning true if setA includes all elements in setB and false if not. Both setA and setB are required to be sorted, and duplicates in setB require an equal number of duplicates in setA. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

intersectionOf
Elem[] intersectionOf(Elem[] setA, Elem[] setB, Pred2E pred)

Computes the intersection of setA and setB as a set operation and returns the retult in a new sorted array. Both setA and setB are required to be sorted. If either setA or setB contain duplicates, the result will contain the smaller number of duplicates from setA and setB. All entries will be copied from setA. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

kfind
size_t kfind(Elem[] buf, Elem pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

kfind
size_t kfind(Elem[] buf, Elem[] pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

krfind
size_t krfind(Elem[] buf, Elem pat, Pred2E pred)

Performs a linear scan of buf from $(LP)buf.length .. 0], returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

krfind
size_t krfind(Elem[] buf, Elem[] pat, Pred2E pred)

Performs a linear scan of buf from $(LP)buf.length .. 0], returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

lbound
size_t lbound(Elem[] buf, Elem pat, Pred2E pred)

Performs a binary search of buf, returning the index of the first location where pat may be inserted without disrupting sort order. If the sort order of pat precedes all elements in buf then 0 will be returned. If the sort order of pat succeeds the largest element in buf then buf.length will be returned. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

makeHeap
void makeHeap(Elem[] buf, Pred2E pred)

Converts buf to a heap using the supplied predicate or '<' if none is supplied.

map
Elem2[] map(Elem[] array, Map2E func, Elem2[] buf)

Apply a function to each element an array. The function's return values are stored in another array.

mismatch
size_t mismatch(Elem[] bufA, Elem[] bufB, Pred2E pred)

Performs a parallel linear scan of bufA and bufB from [0 .. N$(RP) where N = min(bufA.length, bufB.length), returning the index of the first element in bufA which does not match the corresponding element in bufB or N if no mismatch occurs. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

missingFrom
Elem[] missingFrom(Elem[] setA, Elem[] setB, Pred2E pred)

Returns a new array containing all elements in setA which are not present in setB. Both setA and setB are required to be sorted. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

partition
size_t partition(Elem[] buf, Pred1E pred)

Partitions buf such that all elements that satisfy pred will be placed before the elements that do not satisfy pred. The algorithm is not required to be stable.

popHeap
void popHeap(Elem[] buf, Pred2E pred)

Removes the top element from buf by swapping it with the bottom element, adjusting it down the heap, and reducing the length of buf by one.

pushHeap
void pushHeap(Elem[] buf, Elem val, Pred2E pred)

Adds val to buf by appending it and adjusting it up the heap.

reduce
Elem reduce(Elem[] array, Reduce2E func)

Reduce an array of elements to a single element, using a user-supplied reductor function.

remove
size_t remove(Elem[] buf, Elem pat, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), moving all elements matching pat to the end of the sequence. The relative order of elements not matching pat will be preserved. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

remove
size_t remove(Elem[] buf, Elem pat)

Performs a linear scan of buf from [0 .. buf.length$(RP), moving all elements matching pat to the end of the sequence. The relative order of elements not matching pat will be preserved. Comparisons will be performed '=='.

removeIf
size_t removeIf(Elem[] buf, Pred1E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), moving all elements that satisfy pred to the end of the sequence. The relative order of elements that do not satisfy pred will be preserved.

replace
size_t replace(Elem[] buf, Elem pat, Elem val, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), replacing occurrences of pat with val. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

replaceIf
size_t replaceIf(Elem[] buf, Elem val, Pred2E pred)

Performs a linear scan of buf from [0 .. buf.length$(RP), replacing elements where pred returns true with val.

rfind
size_t rfind(Elem[] buf, Elem pat, Pred2E pred)

Performs a linear scan of buf from $(LP)buf.length .. 0], returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

rfind
size_t rfind(Elem[] buf, Elem[] pat, Pred2E pred)

Performs a linear scan of buf from $(LP)buf.length .. 0], returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

rfindIf
size_t rfindIf(Elem[] buf, Pred1E pred)

Performs a linear scan of buf from $(LP)buf.length .. 0], returning the index of the first element where pred returns true.

select
size_t select(Elem[] buf, Num num, Pred2E pred)

Partitions buf with num - 1 as a pivot such that the first num elements will be less than or equal to the remaining elements in the array. Comparisons will be performed using the supplied predicate or '<' if none is supplied. The algorithm is not required to be stable.

shuffle
void shuffle(Elem[] buf, Oper1A oper)

Performs a linear scan of buf from [2 .. buf.length$(RP), exchanging each element with an element in the range [0 .. pos$(RP), where pos represents the current array position.

sort
void sort(Elem[] buf, Pred2E pred)

Sorts buf using the supplied predicate or '<' if none is supplied. The algorithm is not required to be stable. The current implementation is based on quicksort, but uses a three-way partitioning scheme to improve performance for ranges containing duplicate values (Bentley and McIlroy, 1993).

sortHeap
void sortHeap(Elem[] buf, Pred2E pred)

Sorts buf as a heap using the supplied predicate or '<' if none is supplied. Calling makeHeap and sortHeap on an array in succession has the effect of sorting the array using the heapsort algorithm.

ubound
size_t ubound(Elem[] buf, Elem pat, Pred2E pred)

Performs a binary search of buf, returning the index of the first location beyond where pat may be inserted without disrupting sort order. If the sort order of pat precedes all elements in buf then 0 will be returned. If the sort order of pat succeeds the largest element in buf then buf.length will be returned. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

unionOf
Elem[] unionOf(Elem[] setA, Elem[] setB, Pred2E pred)

Computes the union of setA and setB as a set operation and returns the retult in a new sorted array. Both setA and setB are required to be sorted. If either setA or setB contain duplicates, the result will contain the larger number of duplicates from setA and setB. When an overlap occurs, entries will be copied from setA. Comparisons will be performed using the supplied predicate or '<' if none is supplied.

Templates

bsearch
template bsearch(Buf, Pat, Pred)
Undocumented in source.
bsearch
template bsearch(Buf, Pat)
Undocumented in source.
bsearch_
template bsearch_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
contains
template contains(Buf, Pat)
Undocumented in source.
contains
template contains(Buf, Pat, Pred)
Undocumented in source.
count
template count(Buf, Pat)
Undocumented in source.
count
template count(Buf, Pat, Pred)
Undocumented in source.
countIf
template countIf(Buf, Pred)
Undocumented in source.
countIf_
template countIf_(Elem, Pred)
Undocumented in source.
count_
template count_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
differenceOf
template differenceOf(BufA, BufB, Pred)
Undocumented in source.
differenceOf
template differenceOf(BufA, BufB)
Undocumented in source.
differenceOf_
template differenceOf_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
distinct
template distinct(Buf, Pred)
Undocumented in source.
distinct
template distinct(Buf)
Undocumented in source.
distinct_
template distinct_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
filter
template filter(Array, Pred)
Undocumented in source.
find
template find(Buf, Pat, Pred)
Undocumented in source.
find
template find(Buf, Pat)
Undocumented in source.
findAdj
template findAdj(Buf, Pred)
Undocumented in source.
findAdj
template findAdj(Buf)
Undocumented in source.
findAdj_
template findAdj_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
findIf
template findIf(Buf, Pred)
Undocumented in source.
findIf_
template findIf_(Elem, Pred)
Undocumented in source.
find_
template find_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
includes
template includes(BufA, BufB)
Undocumented in source.
includes
template includes(BufA, BufB, Pred)
Undocumented in source.
includes_
template includes_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
intersectionOf
template intersectionOf(BufA, BufB)
Undocumented in source.
intersectionOf
template intersectionOf(BufA, BufB, Pred)
Undocumented in source.
intersectionOf_
template intersectionOf_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
kfind
template kfind(Buf, Pat, Pred)
Undocumented in source.
kfind
template kfind(Buf, Pat)
Undocumented in source.
kfind_
template kfind_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
krfind
template krfind(Buf, Pat, Pred)
Undocumented in source.
krfind
template krfind(Buf, Pat)
Undocumented in source.
krfind_
template krfind_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
lbound
template lbound(Buf, Pat)
Undocumented in source.
lbound
template lbound(Buf, Pat, Pred)
Undocumented in source.
lbound_
template lbound_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
makeHeap
template makeHeap(Buf)
Undocumented in source.
makeHeap
template makeHeap(Buf, Pred)
Undocumented in source.
makeHeap_
template makeHeap_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
map
template map(Func, Array)
Undocumented in source.
mismatch
template mismatch(BufA, BufB, Pred)
Undocumented in source.
mismatch
template mismatch(BufA, BufB)
Undocumented in source.
mismatch_
template mismatch_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
missingFrom
template missingFrom(BufA, BufB)
Undocumented in source.
missingFrom
template missingFrom(BufA, BufB, Pred)
Undocumented in source.
missingFrom_
template missingFrom_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
partition
template partition(Buf, Pred)
Undocumented in source.
partition_
template partition_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
popHeap
template popHeap(Buf)
Undocumented in source.
popHeap
template popHeap(Buf, Pred)
Undocumented in source.
popHeap_
template popHeap_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
pushHeap
template pushHeap(Buf, Val)
Undocumented in source.
pushHeap
template pushHeap(Buf, Val, Pred)
Undocumented in source.
pushHeap_
template pushHeap_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
reduce
template reduce(Array, Func)
Undocumented in source.
remove
template remove(Buf, Pat, Pred)
Undocumented in source.
remove
template remove(Buf, Pat)
Undocumented in source.
removeIf
template removeIf(Buf, Pred)
Undocumented in source.
removeIf_
template removeIf_(Elem, Pred)
Undocumented in source.
remove_
template remove_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
replace
template replace(Buf, Elem, Pred)
Undocumented in source.
replace
template replace(Buf, Elem)
Undocumented in source.
replaceIf
template replaceIf(Buf, Elem, Pred)
Undocumented in source.
replaceIf_
template replaceIf_(Elem, Pred)
Undocumented in source.
replace_
template replace_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
rfind
template rfind(Buf, Pat, Pred)
Undocumented in source.
rfind
template rfind(Buf, Pat)
Undocumented in source.
rfindIf
template rfindIf(Buf, Pred)
Undocumented in source.
rfindIf_
template rfindIf_(Elem, Pred)
Undocumented in source.
rfind_
template rfind_(Elem, Pred = IsEqual!(Elem))
Undocumented in source.
select
template select(Buf, Num)
Undocumented in source.
select
template select(Buf, Num, Pred)
Undocumented in source.
select_
template select_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
shuffle
template shuffle(Buf, Oper = RandOper!())
Undocumented in source.
shuffle_
template shuffle_(Elem, Oper)
Undocumented in source.
sort
template sort(Buf)
Undocumented in source.
sort
template sort(Buf, Pred)
Undocumented in source.
sortHeap
template sortHeap(Buf)
Undocumented in source.
sortHeap
template sortHeap(Buf, Pred)
Undocumented in source.
sortHeap_
template sortHeap_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
sort_
template sort_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
ubound
template ubound(Buf, Pat)
Undocumented in source.
ubound
template ubound(Buf, Pat, Pred)
Undocumented in source.
ubound_
template ubound_(Elem, Pred = IsLess!(Elem))
Undocumented in source.
unionOf
template unionOf(BufA, BufB)
Undocumented in source.
unionOf
template unionOf(BufA, BufB, Pred)
Undocumented in source.
unionOf_
template unionOf_(Elem, Pred = IsLess!(Elem))
Undocumented in source.

Meta

License

BSD style: $(LICENSE)

Authors

Sean Kelly