Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import swift algorithms #4497

Merged
merged 5 commits into from
Feb 1, 2021
Merged

Import swift algorithms #4497

merged 5 commits into from
Feb 1, 2021

Conversation

jjatie
Copy link
Collaborator

@jjatie jjatie commented Nov 6, 2020

Provides convenient algorithms written by the community, curated be the swift core team.

@codecov-io
Copy link

codecov-io commented Nov 6, 2020

Codecov Report

Merging #4497 (9bae784) into master (0aa2b76) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4497   +/-   ##
=======================================
  Coverage   58.96%   58.96%           
=======================================
  Files          50       50           
  Lines         290      290           
=======================================
  Hits          171      171           
  Misses        119      119           
Impacted Files Coverage Δ
...s/Data/Implementations/Standard/ChartDataSet.swift 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0aa2b76...9bae784. Read the comment docs.

@liuxuan30
Copy link
Member

sorry guys. been very busy in recent months

}

if closest != -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjatie I was trying to recall the imp here but I couldn't come up a case that closest could be -1. what's your thought here? As if closest could be -1, this function will return -1, and partitioningIndex would not return -1?

Copy link
Collaborator Author

@jjatie jjatie Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only case where closest == -1 in the old implementation is if the dataset is empty (low - high == -1). This should probably be checked immediately, rather than later on.

Returning -1 is very non-swift, which is why I've elected to drop that behaviour from everywhere I've found it in 4.0.

partitioningIndex returns endIndex if no index is found in startIndex..<endIndex which is the standard behaviour for binary search (since the correct insertion index would be at the end)


case .down:
// If rounding down, and found x-value is upper than specified x, and we can go lower...
if closestXValue > xValue && closest > startIndex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closest > startIndex is different than closest > 0 in old imp, I'm not sure if they are equivalent. are they?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case they are equivalent. I'm using startIndex as it is better to not assume the start is 0, as slices do not guarantee startIndex == 0. It also makes it easier to migrate the algorithm to a generalized extension in the future if desired.

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 29, 2021

the CI failed on tvOS very weird, don't understand why. It seems a carthage issue but iOS and macOS build pass.

Carthage/Carthage#3019 (comment) is the issue for carthage. It is super long and closed now. I have restarted again to see whether it's bound to different Xcode version and maybe we can find a better fix in the thread.

@liuxuan30
Copy link
Member

liuxuan30 commented Feb 1, 2021

filed Carthage/Carthage#3120 and waiting for some suggestions. Besides carthage seems made a major upgrade to support Xcode12 with complex steps to setup.

I'm kind of hesitating whether we should follow. Meanwhile, the iOS passed so I assume it's kind of safe to merge? @jjatie

@jjatie
Copy link
Collaborator Author

jjatie commented Feb 1, 2021

I believe it is.

@liuxuan30 liuxuan30 merged commit b8dba59 into master Feb 1, 2021
@jjatie jjatie deleted the import-swift-algorithms branch February 1, 2021 10:46
@StefaniOSApps
Copy link

@jjatie @liuxuan30 ...
import Algorithms can only be reached via SPM. This means that installation via CocoaPods is no longer possible for older projects. Can you fix that, please? Pull the repo, create a pod and add it to the Podfile by dependency.

@ariofrio
Copy link

ariofrio commented Feb 4, 2021

This seems to be causing a crash when the chart is tapped. To reproduce, run this code:

let chart = LineChartView()
chart.data = LineChartData(
  dataSet: LineChartDataSet(entries: [
    ChartDataEntry(x: 0, y: 0),
    ChartDataEntry(x: 10, y: 10),
    ChartDataEntry(x: 20, y: 20),
  ])
)

And tap on the chart (I tapped near the middle). The app crashes.

When I reverted back to the previous commit 857db24 this crash did not happen anymore.

@darbysauter
Copy link

@StefaniOSApps Did you figure out a solution for this? I have a fork that I use to add some data race protections but it keeps telling me that its missing Algorithms

@StefaniOSApps
Copy link

@darbysauter See #4572 ... I think that @liuxuan30 approved that PR too fast .. so wie lost cocoa pods in future

@darbysauter
Copy link

@StefaniOSApps I ended up using my fork of Charts with SPM instead of (Cocoapods and trying to import Algorithms with SPM) works fine now

@StefaniOSApps
Copy link

@darbysauter right, the best solution is a wrapper from swift to objc (only a workaround 😜)

abhiramvadlapatla pushed a commit to abhiramvadlapatla/Charts that referenced this pull request Dec 21, 2021
* Use Algorithms implementation of binary search

* Use `indexed()` where appropriate

* Update Package.swift to include SwiftAlgorithms

* Use lazy implementation of `prefix(while:)`

For better performance

* Revert "Use lazy implementation of `prefix(while:)`"

This reverts commit 69a303f.
@NachoSoto
Copy link

FYI as others have mentioned this has broken CocoaPods and Carthage support.

zebraciam added a commit to zebraciam/Charts that referenced this pull request Jul 6, 2022
* master:
  update changelog.
  Fixed incorrect guard return statement when rendering limit lines (ChartsOrg#4563)
  Fix bounds checks on binary search (ChartsOrg#4577)
  Added SPM build action (ChartsOrg#4576)
  Replace FBSnapshotTestCase with pointfree/swift-snapshot-testing (ChartsOrg#4574)
  Import swift algorithms (ChartsOrg#4497)
  ChartViewBase cleanup (ChartsOrg#4537)
  SPM GitHub Action (ChartsOrg#4553)
  Algorithm updates (ChartsOrg#3638)
  Added SPM Install section
  Update README.md
  Fix missing drawIconsEnabled parameter initialization in the copying constructor of the ChartBaseDataSet (ChartsOrg#4424)
  Resolve conflict for 4.0 branch and master (ChartsOrg#4456)
  Alternative for SPM dynamic linking (ChartsOrg#4478)
  3.6.0 changelog

# Conflicts:
#	Source/Charts/Renderers/LineChartRenderer.swift
leinhauplk added a commit to LukasHromadnik/Charts that referenced this pull request Oct 20, 2022
This reverts commit b8dba59.

# Conflicts:
#	Charts.xcodeproj/project.pbxproj
#	Charts.xcworkspace/xcshareddata/swiftpm/Package.resolved
#	Package.resolved
#	Package.swift
#	Source/Charts/Data/Implementations/Standard/ChartDataSet.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants