Commit Graph
86 Commits
Author SHA1 Message Date
Nate Cook 993b950250 Run swift-format with default settings 2021-04-15 15:04:29 -05:00
Tim Vermeulen 04d91803a2 Fix associated type inference error in release build (#130) 2021-04-14 16:32:47 -07:00
Tim Vermeulen 78dd4b5b93 Make the base property of UniquePermutations internal (#125) 2021-04-09 14:50:18 -05:00
Tim Vermeulen abc5559ef6 Remove collection conformances to Equatable and Hashable (#124) 2021-04-09 14:44:16 -05:00
Pranav Kasetti bcdbac800a Add new FiniteCycle type as the return type of Collection.cycled(times:) (#106) 2021-04-07 14:57:26 -05:00
Tim Vermeulen 718220d0f8 Make uniqued() lazy by default (#71)
* Make `uniqued()` lazy by default
2021-04-07 14:51:11 -05:00
Tim Vermeulen 551b4af927 Simplify Chain's index offsetting (#116)
* Use the offsetting structure from `Product2`

* Rename `convertIndex` to `normalizeIndex`
2021-04-07 19:52:49 +02:00
Tim Vermeulen dca25448e0 Rename the LazyChunked type to Chunked (#121)
* Rename LazyChunked -> Chunked
* Add deprecated typealias for `LazyChunked`
2021-04-07 09:43:37 -05:00
Luciano Almeida 1639c1e2c3 [tests] Ensure correct implementation of hash for ChunkedByCount (#123) 2021-04-07 09:42:28 -05:00
Luciano Almeida a61c3db4fb Making base properties on collection wrappers all internal (#85) 2021-04-06 13:38:55 -05:00
Luciano Almeida 198eee004e [Compacted] Adding compacted() method to remove all nils in a sequence or collection (#112) 2021-04-05 09:52:53 -05:00
Tim Vermeulen 001247f8a5 Expand the firstNonNil(_:) docs (#115)
* Fix indentation

* Improve documentation
2021-03-29 19:18:56 +02:00
Kyle Macomber 0065c60a22 Remove the inout on reductions(into:_:) to be consistent with the stdlib reduce(into:_) (#118) 2021-03-27 07:17:34 -07:00
Daniel Tull 5cde0b1b67 Inline all the reductions things! (#114) 2021-03-25 16:54:54 +01:00
Matt Zanchelli 220649e999 Correct typos (#113)
largets -> largest
2021-03-25 00:05:49 -07:00
Daniel Tull b171b81577 Add reductions(_:_:) (#46)
* Add scan function

* Add initial conditional conformances to Collection and BidirectionalCollection

* Rename scan to reductions

* Add information to the readme about the reductions name

* Add eager API

* Remove Reductions' conformance to BidirectionalCollection

* Implement Reductions subscript such that it occurs in constant time

* Add a variant which includes the given initial result

* Add a variant which takes no initial result value

* Add excluding label to show the initial result is not included

* Test lazy implementations

* Remove reductions(including:_:)

* Add conformance to LazySequenceProtocol and LazyCollectionProtocol when the base sequence conforms

* Fix implementation of lazy reductions

* Add test cases for sequences with one element

* Tidy up tests

* Improve ergonomics of no initial value eager reductions call and provide it as an extension on Sequence

* Add lazy InclusiveReductions sequence

* Rename Reductions to ExclusiveReductions

* Add Collection implementation for InclusiveReductions

* Update guide

* Add links for C++ implementations

* Add conformance to Collection for ExclusiveReductions

* Improve ergonomics of ExclusiveReductions' index representation

* Improve ergonomics of InclusiveReductions' index representation by sharing the Index implementation

* Tidy up internal function

* Add exclusive eager version of reductions(into:_:)

* Use new lazy assertion functions

* Correct the complexity claims for reductions

* Separate the index types

This will allow for future changes to either implementation without causing a breakage for the other.

* Update guide to reflect that arrays are returned directly

* Add scan as deprecated methods

* Add lazy overload of reductions(into:_:)

* Add the reductions(into:_:) functions

* More succinctly introduce reductions

* Add a note about the deprecated scan functions

* Update documentation

* Add @inlinable and @usableFromInline

* Copy documentation to all variants of reductions

* Test the value after the function is complete

* Just use the += operator

* Add an example for reductions(into:_:)

* Improve the documentation of the return value

* Update complexity note

* Use the reduce documentation for inspiration for the discussion of reductions
2021-03-24 17:10:09 +01:00
Nate CookandTim Vermeulen e652f01949 Add uniquePermutations as wrapper for nextPermutation (#91)
* Add uniquePermutations as wrapper for nextPermutation

* Implement uniquePermutations(ofCount:) variants

* Simplify UniquePermutations.Iterator.next()

* Add tests for uniquePermutations

* Move to a predicate-based uniquePermutations

* Add method documentation

* Convert to Hashable-based uniquing instead of Comparable

* Streamline tests, cover uniqueness

* Use optional count to collapse no-count method

* Update API documentation

* Remove leftover version of nextPermutation()

* Remove Hashable requirement from the UniquePermutations type

* Update documentation

* Apply Tim's great revisions

Co-authored-by: Tim Vermeulen <tvermeulen@apple.com>

* Add lazy conformance to UniquePermutations

Co-authored-by: Tim Vermeulen <tvermeulen@apple.com>
2021-03-24 15:17:27 +01:00
Karl 9783c1be91 Inline all the things! 🎨 (#109)
* Make suffix functions inlinable

* Inline all the things!
2021-03-23 15:00:09 -05:00
Charles Maria TorandXiaodi Wu e64cff7e1d Add Sequence.firstNonNil(_:) (#31)
* Add Sequence.firstNonNil(of:) and associated tests

* Rename First.swift to FirstTests.swift

* Address PR comments by adding guide and changing naming

* Address PR comments by changing name

* Update Guides/FirstNonNil.md

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>

* Update Sources/Algorithms/FirstNonNil.swift

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-03-23 19:55:33 +01:00
Oliver AtkinsonandTim Vermeulen 18ec8500b7 Improve the performance of Stride when Base isa Collection (#88)
* Implement StrideSequence so that the default implementation for collection uses IndexingIterator

* Update Sources/Algorithms/Stride.swift

Co-authored-by: Tim Vermeulen <tvermeulen@apple.com>

* reinstate documentation for Sequence and remove explicit Sequence conformance on Stride

* documentation

* rename Stride to StrideCollection

Co-authored-by: Tim Vermeulen <tvermeulen@apple.com>
2021-03-10 18:20:00 +01:00
Tim Vermeulen ab0ec2adf4 Internally add Collection.endOfPrefix(while:) and BidirectionalCollection.startOfSuffix(while:) (#92)
* Add endOfPrefix(while:) and startOfSuffix(while:) internally

* Add tests

* Use these methods throughout the package
2021-03-09 20:03:55 +01:00
Todd Thomas e7c6716499 Add lazy split implementation. (#78)
`split(maxSplits:omittingEmptySubsequences:whereSeparator:)`

and

`split(separator:maxSplits:omittingEmptySubsequences:)`

now operate lazily when called on `LazySequenceProtocol`- or
`LazyCollectionProtocol`-conforming values. In the latter case,
no additional storage is allocated on the heap.
2021-03-09 01:48:58 -06:00
Nate Cook bd64bef3d2 Rename sortedPrefix methods (#77)
This renames sortedPrefix to min(count:), adds max(count:),
and moves both methods down to Sequence.

In order to still provide the optimization when `count` is close to
a collection's length, we include a Collection-specific overload of
all methods. These won't be accessed when in a Sequence-generic context,
but it's the best we can do without adding these methods as protocol
requirements.
2021-02-26 13:57:55 -06:00
Ben Rimmington 32837b9ad6 Rename trimming(where:) to trimming(while:) 2021-02-26 10:38:50 -06:00
Luciano Almeida 914e626e23 Audit public functions and properties that could be inlinable (#83) 2021-02-23 11:48:57 -06:00
Nate Cook cc20b55cc6 Rename slidingWindows back to windows(ofCount:) 2021-02-18 12:31:58 -06:00
Matt Zanchelli 44d359b429 Use consistent variable names 2021-02-15 13:29:43 -08:00
Matt Zanchelli bdf36ad23d Avoid ambiguous single-letter variable names 2021-02-15 13:29:41 -08:00
Tim Vermeulen 7ca12bed60 Precompute LazyChunked's startIndex (#68) 2021-02-12 07:02:26 -08:00
Tim Vermeulen 4f7cd340cd Index offsetting for Product2 (#66) 2021-02-12 06:48:40 -08:00
Iceman 1a3c7061de Fix RandomSample crash when 0 was out from random. (#70) 2021-02-12 06:41:26 -08:00
Matt Zanchelli d8a11e0d51 All permutations (#56)
Adds the ability to easily get permutations of a range of sizes, like #51 did for Combinations.
2021-02-12 06:32:32 -08:00
Matt Zanchelli d2a1ca5f7b Lowercase suffix(while:) to match the case of the actual function name (#76) 2021-02-10 20:45:56 -06:00
Nate Cook 52e1e0e45a add suffix:while method (#65) 2021-02-09 13:00:17 -06:00
Nate Cook cda6fddada Merge pull request #61 from LucianoPAlmeida/normalizing-assert
[NFC] Using precondition instead of assert in calls that do not allow negative values
2021-01-28 10:08:09 -06:00
michibooandXiaodi Wu f9a4f79027 Update Sources/Algorithms/Suffix.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-01-28 15:22:18 +02:00
michibooandXiaodi Wu 2f8f798d0c Update Sources/Algorithms/Suffix.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-01-24 21:54:14 +08:00
michibooandXiaodi Wu 60bad3bbf4 Update Sources/Algorithms/Suffix.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-01-23 14:39:02 +08:00
michiboo 08e424ea07 add doc on suffix method 2021-01-23 08:38:12 +02:00
michiboo 813ea7905e add more test for suffix Tests 2021-01-22 16:17:28 +02:00
michiboo 9ef531f23f add suffix while method 2021-01-20 15:16:25 +02:00
Nate Cook 9836a4f80b [Chunked] Add chunks(of:) variant that divides a collection in chunks of a given size (#54) 2021-01-15 22:43:13 -06:00
Luciano Almeida 34d7a55d1a [NFC] Using precondition instead of assert in calls that do not allow negative values 2021-01-15 20:15:52 -03:00
Luciano Almeida 14f09e4228 [Chunked] Improving index(offset:limit:) to avoid distance call 2021-01-15 07:48:11 -03:00
Matt Zanchelli 5b7993ca8d All combinations (#51)
Add an overload of combinations(ofCount:) that accepts a range.
2021-01-14 13:32:47 -06:00
Luciano Almeida f89fe8fad1 [Chunked] Code review adjustments 2021-01-13 23:06:19 -03:00
Luciano Almeida 05df988369 [Chunked] Minor adjustments on tests 2021-01-10 17:18:49 -03:00
Luciano Almeida afac704540 [Chunked] Implemeting of ChunkedByCount index(offsetBy:) 2021-01-09 00:17:49 -03:00
Luciano Almeida 79aeb24e9d Fixing review comments 2021-01-08 08:21:01 -03:00
Luciano Almeida 505b57369f [Chunked] Implementing chunked collection by a given count 2021-01-08 00:07:46 -03:00