Struct std.range.SortedRange
Represents a sorted range. In addition to the regular range
primitives, supports additional operations that take advantage of the
ordering, such as merge and binary search. To obtain a SortedRange from an unsorted range r, use
sort which sorts r in place and returns the
corresponding SortedRange. To construct a SortedRange from a range
r that is known to be already sorted, use assumeSorted described
below.
						
				struct SortedRange(Range, alias pred)
				
				  
				
				if (isInputRange!Range);
						
					
				Properties
| Name | Type | Description | 
|---|---|---|
| back[get] | auto | Range primitives. | 
| empty[get] | bool | Range primitives. | 
| front[get] | auto | Range primitives. | 
| length[get] | size_t | Range primitives. | 
| save[get] | auto | Range primitives. | 
Methods
| Name | Description | 
|---|---|
| contains | Returns trueif and only ifvaluecan be found inrange, which is assumed to be sorted. Performs Ο(log(r)
evaluations ofpred. | 
| equalRange | Returns the subrange containing all elements efor which both   pred(e, value)andpred(value, e)evaluate tofalse(e.g.,
   ifpredis "less than", returns the portion of the range with
   elements equal tovalue). Uses a classic binary search with
   interval halving until it finds a value that satisfies the condition,
   then usesSearchPolicyto find the left boundary
   andSearchPolicyto find the right boundary. These
   policies are justified by the fact that the two boundaries are likely
   to be near the first found value (i.e., equal ranges are relatively
   small). Completes the entire search in Ο(log(n)) time. | 
| groupBy | Returns a range of subranges of elements that are equivalent according to the sorting relation. | 
| lowerBound | This function uses a search with policy spto find the
   largest left subrange on whichpred(x, value)istruefor
   allx(e.g., ifpredis "less than", returns the portion of
   the range with elements strictly smaller thanvalue). The search
   schedule and its complexity are documented inSearchPolicy. | 
| opBinaryRight | Like contains, but the value is specified before the range. | 
| opIndex | Range primitives. | 
| opSlice | Range primitives. | 
| popBack | Range primitives. | 
| popFront | Range primitives. | 
| release | Releases the controlled range and returns it. | 
| trisect | Returns a tuple rsuch thatr[0]is the same as the result
oflowerBound(value),r[1]is the same as the result ofequalRange(value), andr[2]is the same as the result ofupperBound(value). The call is faster than computing all three
separately. Uses a search schedule similar toequalRange. Completes the entire search in Ο(log(n)) time. | 
| upperBound | This function searches with policy spto find the largest right
subrange on whichpred(value, x)istruefor allx(e.g., ifpredis "less than", returns the portion of the range
with elements strictly greater thanvalue). The search schedule
and its complexity are documented inSearchPolicy. | 
Aliases
| Name | Description | 
|---|---|
| opDollar | Range primitives. | 
Example
import stdExample
SortedRange could accept ranges weaker than random-access, but it
is unable to provide interesting functionality for them. Therefore,
SortedRange is currently restricted to random-access ranges.
No copy of the original range is ever made. If the underlying range is
changed concurrently with its corresponding SortedRange in ways
that break its sorted-ness, SortedRange will work erratically.
import stdAuthors
Andrei Alexandrescu, David Simcha, Jonathan M Davis, and Jack Stouffer. Credit for some of the ideas in building this module goes to Leonardo Maffi.