Skip to content

Commit 128bc7a

Browse files
committed
docstrings
1 parent 1d39550 commit 128bc7a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Init/Data/Slice/List/Basic.lean

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,44 @@ public import Init.Data.Slice.Basic
1010
public import Init.Data.Slice.Notation
1111
public import Init.Data.Range.Polymorphic.Nat
1212

13+
set_option linter.missingDocs true
14+
1315
/-!
1416
This module provides slice notation for list slices (a.k.a. `Sublist`) and implements an iterator
1517
for those slices.
1618
-/
1719

1820
open Std Std.Slice Std.PRange
1921

22+
/--
23+
Internal representation of `ListSlice`, which is an abbreviation for `Slice ListSliceData`.
24+
-/
2025
public class Std.Slice.Internal.ListSliceData (α : Type u) where
26+
/-- The relevant suffix of the underlying list. -/
2127
list : List α
28+
/-- The maximum length of the slice, starting at the beginning of `list`. -/
2229
stop : Nat
2330

31+
/--
32+
A region of some underlying list. List slices can be used to avoid copying or allocating space,
33+
while being more convenient than tracking the bounds by hand.
34+
35+
A list slice only stores the suffix of the underlying list, starting from the range's lower bound
36+
so that the cost of operations on the slice does not depend on the start position. However,
37+
the cost of creating a list slice is linear in the start position.
38+
-/
2439
public abbrev ListSlice (α : Type u) := Slice (Internal.ListSliceData α)
2540

2641
variable {α : Type u}
2742

43+
/--
44+
Returns a slice of a list with the given bounds.
45+
46+
If `start` or `stop` are not valid bounds for a subarray, then they are clamped to the list's length.
47+
Additionally, the starting index is clamped to the ending index.
48+
49+
This function is linear in `start` because it stores `as.drop start` in the slice.
50+
-/
2851
public def List.toSlice (as : List α) (start : Nat) (stop : Nat) : ListSlice α :=
2952
if start ≤ stop then
3053
⟨{ list := as.drop start, stop := stop - start }⟩

0 commit comments

Comments
 (0)