Commit Graph

83 Commits

Author SHA1 Message Date
Nate Cook
3d7dfc232b [stdlib] Update complexity docs for seq/collection algorithms (#17254)
* [stdlib] Update complexity docs for seq/collection algorithms

This corrects and standardizes the complexity documentation for Sequence
and Collection methods. The use of constants is more consistent, with `n`
equal to the length of the target collection, `m` equal to the length of
a collection passed in as a parameter, and `k` equal to any other passed
or calculated constant.

* Apply notes from @brentdax about complexity nomenclature

* Change `n` to `distance` in `index(_:offsetBy:)`

* Use equivalency language more places; sync across array types

* Use k instead of n for parameter names

* Slight changes to index(_:offsetBy:) discussion.

* Update tests with new parameter names
2018-07-24 01:01:34 -05:00
Ben Cohen
a4230ab2ad [stdlib] Update stdlib to 4.0 and reorganize compatibility shims (#17580)
* Update stdlib to 4.0 and move all compatibility shims into a dedicated source file
2018-06-29 06:26:52 -07:00
Joe Groff
46cd1b786b stdlib: Make data structure protocols ready for future move-only types.
We would like to eventually extend Array, Dictionary, and Set to support move-only element types when the language does. To that end, we need to get the `consuming`-ness of protocol requirements on Sequence, Collection, and related protocols right for forward compatibility so that a future version of Swift that extends these types to support move-only data structures remains ABI- and API-compatible with older versions of the language. Mark requirements as `__consuming` where it would be necessary for a move-only implementation of one of these types.
2018-06-19 14:23:24 -07:00
Dave Abrahams
0c7a091390 Use _halfStablePartition to implement partition and removeAll(where:) 2018-06-07 08:43:08 -07:00
Nate Cook
7a4e0a32f6 [stdlib] Revise documentation
This includes various revisions to the APIs landing in Swift 4.2, including:
- Random and other randomness APIs
- Hashable changes
- MemoryLayout.offset(of:)
2018-05-18 11:31:54 -05:00
Dave Abrahams
ec9b402605 Slightly clarify removeAll(where:) (#16459)
* Slightly clarify removeAll(where:)

Improve parameter naming, use "guard" to reduce nesting
2018-05-09 07:57:28 -07:00
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05:00
Nate Cook
b6a0d9ed26 [stdlib] Documentation revisions
- Make RawRepresentable Codable abstracts distinguishable
- Make the UnboundedRange example a little more user friendly
- Correct the RangeReplaceableCollection example description
- Revise CaseIterable discussion
2018-04-11 11:34:51 -05:00
Slava Pestov
14654590dc stdlib: remove some @_inlineable that snuck in recently 2018-04-09 18:00:58 -07:00
swift-ci
3430f38563 Merge pull request #11576 from airspeedswift/remove-elements 2018-04-06 17:45:54 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Ben Cohen
ba11a23901 Add removeAll(where:) to RangeReplaceableCollection 2018-03-26 13:49:50 -07:00
Ben Cohen
898dce6f5b Add an ambiguity breaker for RRC.popLast 2018-03-02 13:11:59 -08:00
Ben Cohen
77e417f1d0 [stdlib] Hoist Array.popLast to RangeReplaceableCollection (#14392)
* Move Array.popLast to RangeReplaceableCollection

* Remove popLast from Array completion tests
2018-02-04 20:11:51 -08:00
Pavel Yaskevich
12980335cd [CSRanking] Fix self types to be unrelated when comparing operator decls
Such declarations should already have self bound as one of the parameters
which would enforce subtype relationship.

Resolves: rdar://problem/36333688
2018-01-05 23:24:24 -08:00
Max Moiseev
9bf8d773ab [stdlib] Rearrange + on RangeReplaceableCollection/Sequence once again 2018-01-04 13:58:45 -08:00
Max Moiseev
fe48e8c662 [stdlib] Free function + into static func + 2018-01-03 14:09:14 -08:00
Doug Gregor
a55adb2622 [Standard library] Remove extraneous associated type defaults.
These are no longer required by associated type inference.
2017-12-19 13:03:51 -08:00
Ben Cohen
4ddac3fbbd [stdlib] Eradicate IndexDistance associated type (#12641)
* Eradicate IndexDistance associated type, replacing with Int everywhere

* Consistently use Int for ExistentialCollection’s IndexDistance type.

* Fix test for IndexDistance removal

* Remove a handful of no-longer-needed explicit types

* Add compatibility shims for non-Int index distances

* Test compatibility shim

* Move IndexDistance typealias into the Collection protocol
2017-12-08 12:00:23 -08:00
Max Moiseev
42eb45347b [stdlib] Conditional gardening 2017-12-05 16:33:48 -08:00
Ben Cohen
c4f0b5fe94 [stdlib] Adopt conditional conformance for Indices, Slice, ReversedCollection (#12913)
* Refactor Indices and Slice to use conditional conformance

* Replace ReversedRandomAccessCollection with a conditional extension

* Refactor some types into struct+extensions

* Revise Slice documentation

* Fix test cases for adoption of conditional conformances.

* [RangeReplaceableCollection] Eliminate unnecessary slicing subscript operator.

* Add -enable-experimental-conditional-conformances to test.

* Gruesome workaround for crasher in MutableSlice tests
2017-11-30 09:10:22 -08:00
Dmitri Gribenko
8e886a3bdd stdlib: ranges: remove range protocols
The RangeProtocol was a very weak and fragile abstraction because it
didn't specify the interpretation of the endpoints.  To write a
non-trivial algorithm, one usually needed to consult that information.
The standard library code only actually worked correctly with half-open
and closed ranges (and didn't handle fully open ranges, for example).

The other two protocols, HalfOpenRangeProtocol and ClosedRangeProtocol,
were only used for code sharing, and present an ABI burden.  We can use
gyb instead.
2016-04-22 18:15:06 -07:00
Dave Abrahams
47a870cc50 [stdlib] Use location/formLocation for all index movement 2016-04-21 17:13:41 -07:00
Dave Abrahams
ab06cb0a12 [stdlib] Clean up some doc comments 2016-04-19 17:58:04 -07:00
Dave Abrahams
60c2fe08b0 [stdlib] fix 80-column violation 2016-04-19 17:58:04 -07:00
Dave Abrahams
ed91182959 [stdlib] fix RangeReplaceable dispatch insanity
Before,

* We had a generic implementation of replaceSubrange that would
satisfy the protocol's last non-defaulted requirement

* A generic removeSubrange was in the protocol requirements needlessly

* The default implementation of that generic removeSubrange dispatched
  to replaceSubrange instead of the non-generic removeSubrange, robbing
  the model of optimization opportunities.

Now,

* There's one non-generic replaceSubrange that models must implement.

* The default implementation of removeSubrange uses replaceSubrange to
  do its work.

* Models can implement the non-generic removeSubrange if they can
  implement it faster than the default implementation.

* The generic removeSubrange uses the non-generic removeSubrange to do
  its work.
2016-04-19 17:58:04 -07:00
Dave Abrahams
808d4af819 [stdlib] Spell "subrange" consistently
There's no excuse for

        removeSubrange(_ subRange: Range<Index>)

Either range is a separate word, or it isn't.
2016-04-19 17:12:09 -07:00
Dave Abrahams
9a3d51dd02 [stdlib] Copy doc comments onto RangeReplaceableIndexable 2016-04-19 16:21:15 -07:00
Dmitri Gribenko
3e708a9328 Merge commit '8e292daec1bc790c96b5ee39b8d55dadcac6ce1b' into swift-3-indexing-model 2016-04-14 15:10:26 -07:00
Dmitri Gribenko
10697f939f Merge commit '510f29abf77e202780c11d5f6c7449313c819030' into swift-3-indexing-model 2016-04-14 13:45:27 -07:00
Nate Cook
6b77c6a979 [New indexing model] Update documentation comments with new APIs
Most of these were successor() -> successor(of:).
2016-04-08 01:01:58 -05:00
Trent Nadeau
f96ad263a8 Added @discardableResult attr to mutating functions 2016-04-07 23:27:38 +00:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Dave Abrahams
5864117b1b [stdlib] De-underscore Range.init(uncheckedBounds:) 2016-04-06 09:20:30 -07:00
Dave Abrahams
db03708a3d [stdlib] De-underscore Range protocols
There's really no excuse for keeping these hidden; they appear in public
APIs.
2016-04-05 16:32:15 -07:00
Dmitri Gribenko
eb5c6bebc6 stdlib: indentation and coding style fixes 2016-04-04 14:26:38 -07:00
Dmitri Gribenko
e52b8d6f56 stdlib: underscore an internal function 2016-04-04 14:20:45 -07:00
Dave Abrahams
a5c3c63c3d [stdlib] Indexing model: nix RangeOfStrideable
Instead, use CountableRange which is constrained to have a Strideable
Bound whose Stride conforms to Integer.
2016-03-28 17:06:09 -07:00
Dave Abrahams
01127b32d5 index(n, stepsFrom: i)
M-x findr-query-replace

\<advance(\([^:]+?\),\([
]+\)by: *\([^(),]*\|[^(),]+([^()]*)[^(),]*\)\(,\(?:[
]+\)limit: *\(?:[^()]*\|[^()]+([^()]*)[^()]*\)\)?)

index(\3,\2stepsFrom: \1\4)
2016-03-25 17:54:39 -07:00
Dave Abrahams
8d9e62b274 [stdlib] indexing model: rename next/previous
I'm not too satisfied with the names for the updating: versions, but
this is a start.
2016-03-22 17:13:54 -07:00
Dmitri Gribenko
e7f5727751 stdlib: RangeReplaceableCollection: move a requirement to the derivable section 2016-03-18 23:03:19 -07:00
Dmitri Gribenko
37fb51aedd New indexing model: generate 12 Slice types
We need a slice type for every combination of collection protocols, so
that a collection's SubSequence preserves all operations available on
the collection itself.

We need three index types, one for each traversal kind.
2016-03-18 23:03:19 -07:00
Dave Abrahams
e65787f1fa [stdlib] indexing model: Generic removeSubrange 2016-03-18 14:07:13 -07:00
Dave Abrahams
88a9f2e628 [stdlib] indexing model: Complete Interval/Range merge
Down to 22 failures; only 5 in stdlib tests
2016-03-18 10:04:09 -07:00
Dave Abrahams
17f841430c Merge Range work 2016-03-16 15:59:39 -07:00
Dave Abrahams
f493b54e44 [stdlib] indexing model: Interval/Range merge
This is step 1; we still need to introduce ClosedRange.
2016-03-16 15:59:10 -07:00
Dmitri Gribenko
e2bd463f3c New indexing model: add ambiguity breakers for removeLast() 2016-03-15 20:55:20 -07:00
Dmitri Gribenko
3cde854287 Merge remote-tracking branch 'origin/master' into swift-3-indexing-model 2016-03-12 01:11:32 -08:00
Daniel Duan
276370b599 [stdlib] apply SE-0040 to stdlib 2016-03-11 16:01:41 -08:00
Dmitri Gribenko
e8bc77e5b8 Merge remote-tracking branch 'origin/master' into swift-3-indexing-model 2016-03-11 00:20:34 -08:00