Skip to content

Commit b8f17e2

Browse files
committed
std.algorithms: document public methods
1 parent 80594b0 commit b8f17e2

File tree

5 files changed

+141
-94
lines changed

5 files changed

+141
-94
lines changed

std/algorithm/comparison.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ size_t levenshteinDistance(alias equals = (a,b) => a == b, Range1, Range2)
11681168
assert(levenshteinDistance("cat"d, "rat"d) == 1);
11691169
}
11701170

1171-
// compat overload for alias this strings
1171+
/// ditto
11721172
size_t levenshteinDistance(alias equals = (a,b) => a == b, Range1, Range2)
11731173
(auto ref Range1 s, auto ref Range2 t)
11741174
if (isConvertibleToString!Range1 || isConvertibleToString!Range2)
@@ -1240,7 +1240,7 @@ levenshteinDistanceAndPath(alias equals = (a,b) => a == b, Range1, Range2)
12401240
assert(levenshteinDistance("kitten", "sitting") == 3);
12411241
}
12421242

1243-
// compat overload for alias this strings
1243+
/// ditto
12441244
Tuple!(size_t, EditOp[])
12451245
levenshteinDistanceAndPath(alias equals = (a,b) => a == b, Range1, Range2)
12461246
(auto ref Range1 s, auto ref Range2 t)

std/algorithm/iteration.d

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,34 @@ private struct FilterBidiResult(alias pred, Range)
13191319
}
13201320
}
13211321

1322-
// group
1322+
/**
1323+
Groups consecutively equivalent elements into a single tuple of the element and
1324+
the number of its repetitions.
1325+
1326+
Similarly to $(D uniq), $(D group) produces a range that iterates over unique
1327+
consecutive elements of the given range. Each element of this range is a tuple
1328+
of the element and the number of times it is repeated in the original range.
1329+
Equivalence of elements is assessed by using the predicate $(D pred), which
1330+
defaults to $(D "a == b"). The predicate is passed to $(XREF functional,binaryFun),
1331+
and can either accept a string, or any callable that can be executed via
1332+
$(D pred(element, element)).
1333+
1334+
Params:
1335+
pred = Binary predicate for determining equivalence of two elements.
1336+
r = The $(XREF_PACK_NAMED range,primitives,isInputRange,input range) to
1337+
iterate over.
1338+
1339+
Returns: A range of elements of type $(D Tuple!(ElementType!R, uint)),
1340+
representing each consecutively unique element and its respective number of
1341+
occurrences in that run. This will be an input range if $(D R) is an input
1342+
range, and a forward range in all other cases.
1343+
*/
1344+
Group!(pred, Range) group(alias pred = "a == b", Range)(Range r)
1345+
{
1346+
return typeof(return)(r);
1347+
}
1348+
1349+
/// ditto
13231350
struct Group(alias pred, R) if (isInputRange!R)
13241351
{
13251352
import std.typecons : Rebindable, tuple, Tuple;
@@ -1344,12 +1371,14 @@ struct Group(alias pred, R) if (isInputRange!R)
13441371
private R _input;
13451372
private Tuple!(MutableE, uint) _current;
13461373

1374+
///
13471375
this(R input)
13481376
{
13491377
_input = input;
13501378
if (!_input.empty) popFront();
13511379
}
13521380

1381+
///
13531382
void popFront()
13541383
{
13551384
if (_input.empty)
@@ -1370,23 +1399,27 @@ struct Group(alias pred, R) if (isInputRange!R)
13701399

13711400
static if (isInfinite!R)
13721401
{
1402+
///
13731403
enum bool empty = false; // Propagate infiniteness.
13741404
}
13751405
else
13761406
{
1407+
///
13771408
@property bool empty()
13781409
{
13791410
return _current[1] == 0;
13801411
}
13811412
}
13821413

1414+
///
13831415
@property auto ref front()
13841416
{
13851417
assert(!empty);
13861418
return _current;
13871419
}
13881420

13891421
static if (isForwardRange!R) {
1422+
///
13901423
@property typeof(this) save() {
13911424
typeof(this) ret = this;
13921425
ret._input = this._input.save;
@@ -1396,33 +1429,6 @@ struct Group(alias pred, R) if (isInputRange!R)
13961429
}
13971430
}
13981431

1399-
/**
1400-
Groups consecutively equivalent elements into a single tuple of the element and
1401-
the number of its repetitions.
1402-
1403-
Similarly to $(D uniq), $(D group) produces a range that iterates over unique
1404-
consecutive elements of the given range. Each element of this range is a tuple
1405-
of the element and the number of times it is repeated in the original range.
1406-
Equivalence of elements is assessed by using the predicate $(D pred), which
1407-
defaults to $(D "a == b"). The predicate is passed to $(XREF functional,binaryFun),
1408-
and can either accept a string, or any callable that can be executed via
1409-
$(D pred(element, element)).
1410-
1411-
Params:
1412-
pred = Binary predicate for determining equivalence of two elements.
1413-
r = The $(XREF_PACK_NAMED range,primitives,isInputRange,input range) to
1414-
iterate over.
1415-
1416-
Returns: A range of elements of type $(D Tuple!(ElementType!R, uint)),
1417-
representing each consecutively unique element and its respective number of
1418-
occurrences in that run. This will be an input range if $(D R) is an input
1419-
range, and a forward range in all other cases.
1420-
*/
1421-
Group!(pred, Range) group(alias pred = "a == b", Range)(Range r)
1422-
{
1423-
return typeof(return)(r);
1424-
}
1425-
14261432
///
14271433
@safe unittest
14281434
{
@@ -4874,13 +4880,31 @@ private struct UniqResult(alias pred, Range)
48744880
}
48754881
}
48764882

4877-
// permutations
4883+
/**
4884+
Lazily computes all _permutations of $(D r) using $(WEB
4885+
en.wikipedia.org/wiki/Heap%27s_algorithm, Heap's algorithm).
4886+
4887+
Returns:
4888+
A forward range the elements of which are an $(XREF range,
4889+
indexed) view into $(D r).
4890+
4891+
See_Also:
4892+
$(XREF_PACK algorithm,sorting,nextPermutation).
4893+
*/
4894+
Permutations!Range permutations(Range)(Range r)
4895+
if (isRandomAccessRange!Range && hasLength!Range)
4896+
{
4897+
return typeof(return)(r);
4898+
}
4899+
4900+
/// ditto
48784901
struct Permutations(Range)
48794902
if (isRandomAccessRange!Range && hasLength!Range)
48804903
{
48814904
size_t[] indices, state;
48824905
Range r;
48834906

4907+
///
48844908
this(Range r)
48854909
{
48864910
import std.range : iota;
@@ -4892,14 +4916,17 @@ struct Permutations(Range)
48924916
empty = r.length == 0;
48934917
}
48944918

4919+
///
48954920
bool empty;
48964921

4922+
///
48974923
@property auto front()
48984924
{
48994925
import std.range : indexed;
49004926
return r.indexed(indices);
49014927
}
49024928

4929+
///
49034930
void popFront()
49044931
{
49054932
void next(int n)
@@ -4928,23 +4955,6 @@ struct Permutations(Range)
49284955
}
49294956
}
49304957

4931-
/**
4932-
Lazily computes all _permutations of $(D r) using $(WEB
4933-
en.wikipedia.org/wiki/Heap%27s_algorithm, Heap's algorithm).
4934-
4935-
Returns:
4936-
A forward range the elements of which are an $(XREF range,
4937-
indexed) view into $(D r).
4938-
4939-
See_Also:
4940-
$(XREF_PACK algorithm,sorting,nextPermutation).
4941-
*/
4942-
Permutations!Range permutations(Range)(Range r)
4943-
if (isRandomAccessRange!Range && hasLength!Range)
4944-
{
4945-
return typeof(return)(r);
4946-
}
4947-
49484958
///
49494959
unittest
49504960
{

std/algorithm/mutation.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ if (s != SwapStrategy.stable
16671667
return range;
16681668
}
16691669

1670-
// Ditto
1670+
/// Ditto
16711671
Range remove
16721672
(SwapStrategy s = SwapStrategy.stable, Range, Offset...)
16731673
(Range range, Offset offset)
@@ -2380,8 +2380,9 @@ unittest
23802380
swap(b1, b2);
23812381
}
23822382

2383-
// Not yet documented
2384-
void swap(T)(ref T lhs, ref T rhs) if (is(typeof(lhs.proxySwap(rhs))))
2383+
/// ditto
2384+
void swap(T)(ref T lhs, ref T rhs)
2385+
if (is(typeof(lhs.proxySwap(rhs))))
23852386
{
23862387
lhs.proxySwap(rhs);
23872388
}

0 commit comments

Comments
 (0)