Compare commits

...

101 Commits

Author SHA1 Message Date
Lukas Kubanek 06fd5ea31a Updated to Xcode 13.2 2021-11-25 20:58:08 +01:00
Lukas Kubanek 36f17aa442 Updated to Xcode 13.1 2021-10-19 11:11:29 +02:00
Lukas Kubanek 6c891952f4 Raised minimum macOS deployment target for test targets 2021-08-18 16:06:27 +02:00
Lukas Kubanek 3bac27b7a8 Added macOS 11 & Xcode 13 CI configuration 2021-08-18 15:39:28 +02:00
Lukas Kubanek 94d4b11aec Fixed compatibility issue with Swift 5.5 2021-08-18 15:23:00 +02:00
Lukas Kubanek 4be394e313 Updated to Xcode 13 β1 2021-06-08 09:44:17 +02:00
Lukas Kubanek 891ecf6e2d Bumped version numbers 2021-04-05 17:41:47 +02:00
Lukas Kubanek 736e0ea7da Removed Travis leftover 2021-04-05 17:39:28 +02:00
Lukas Kubanek c63ab5a3aa Merge pull request #69 from lukaskubanek/v4.0
v4.0
2021-04-05 17:36:11 +02:00
Lukas Kubanek f06553a74d Fixed links to releases in README 2021-04-05 17:22:40 +02:00
Lukas Kubanek 72f8248df1 Last tweaks to README 2021-04-05 17:06:38 +02:00
Lukas Kubanek 8ef9e9263f Edited README 2021-04-05 16:55:41 +02:00
Lukas Kubanek ab03176239 Updated README 2021-04-05 16:27:22 +02:00
Lukas Kubanek 4df7502e09 Removed obsolete Travis CI configuration 2021-04-05 16:02:55 +02:00
Lukas Kubanek 9bf57b0504 Removed playground that showcases the Codable API 2021-04-05 15:59:59 +02:00
Lukas Kubanek 92ae96cf2a Moved examples from playground to doc comments 2021-04-05 15:56:43 +02:00
Lukas Kubanek b120d60c55 update(_:at:) now returns a non-optional element 2021-04-05 15:48:37 +02:00
Lukas Kubanek cb4cb74a00 Added an invariant assertion 2021-04-05 12:27:37 +02:00
Lukas Kubanek 6bbbee5447 macOS 11 is apparently not yet ready for CI workflows… 2021-04-04 23:45:34 +02:00
Lukas Kubanek e5bc9eceae Fixed location of test files 2021-04-04 23:39:21 +02:00
Lukas Kubanek f153d5df84 Fixed invalid CI job name 2021-04-04 23:36:26 +02:00
Lukas Kubanek 1164a68fc8 Added missing steps section to macOS 11 CI job 2021-04-04 23:35:14 +02:00
Lukas Kubanek 596396a8e8 Tweaked name of macOS 11 CI job 2021-04-04 23:34:08 +02:00
Lukas Kubanek 027494878b Added macOS 11 to CI config file 2021-04-04 23:33:31 +02:00
Lukas Kubanek 74f50a4c71 Standardized path to source files 2021-04-04 23:24:55 +02:00
Lukas Kubanek ad37e7c91f Added conformance to Hashable 2021-04-04 23:10:46 +02:00
Lukas Kubanek 4c236e1b82 Fixed typos 2021-04-04 23:09:28 +02:00
Lukas Kubanek d78cc12e8d Updated to Xcode 12.5 2021-03-04 16:56:04 +01:00
Lukas Kubanek 8866b3e301 Updated to Xcode 12.4 2021-02-04 18:44:52 +01:00
Lukas Kubanek c3c5931187 2020 → 2021 2021-01-04 14:30:28 +01:00
Lukas Kubanek af7d973978 Updated CI configuration 2020-12-17 14:38:34 +01:00
Lukas Kubanek ab67e0fea8 Updated to Xcode 12.3 2020-12-09 21:49:18 +01:00
Lukas Kubanek 14e4501035 Fixed issues with slice-based mutations
- Introduced a dedicated slice type OrderedDictionarySlice
- Used new pattern for reordering methods with internal methods that take a range
- Included all reorderering methods from MutableCollection in both the base and slice types
- Added tests for access through slice
- Removed _unsafeValue(forKey:)
- Removed canUpdate(_:at:keyPresentAtIndex:)
- Refactored preconditions
- Regrouped code
2020-10-05 22:40:57 +02:00
Lukas Kubanek a569fc06f5 Added tests for subscript ambiguity
Refs #49
2020-10-05 13:54:42 +02:00
Lukas Kubanek 465ea731a3 Used Index type in swapAt(_:_:) 2020-10-05 13:39:37 +02:00
Lukas Kubanek 8a7247d9d4 Made XCTUnwrap shim internal 2020-10-05 12:14:48 +02:00
Lukas Kubanek 909bed0ada Added shim for XCTUnwrap 2020-10-05 12:07:32 +02:00
Lukas Kubanek 5a5a8cc62d Introduced OrderedDictionary.filter(_:)
Closes #66
2020-10-05 12:01:02 +02:00
Lukas Kubanek e44b3a7f4c Used Self wherever possible 2020-10-05 11:48:33 +02:00
Lukas Kubanek ecdc5f971b Revamped whole test suite
- Split tests into multiple files
- Added tests for functionality coming from MutableCollection
2020-10-05 11:44:47 +02:00
Lukas Kubanek efcb0db2e0 Reverted usage of key paths for map 2020-10-05 09:23:42 +02:00
Lukas Kubanek 1743d4dc3f Added initial conformance to MutableCollection
- Removed override subscript(bounds:) since it’s now inherited from MutableCollection
- Implemented getter for subscript(position:)
- Implemented override for swarAt(_:_:)
- Tweaked implementations of sort methods
2020-10-05 00:42:57 +02:00
Lukas Kubanek fb67bd25b0 Fixed typos in docs 2020-10-05 00:42:57 +02:00
Lukas Kubanek 69c8843b76 Moved canInsert(_:) to deprecations 2020-10-05 00:42:56 +02:00
Lukas Kubanek 36ff800650 Made backing storage private 2020-10-04 22:38:56 +02:00
Lukas Kubanek 13101672c2 Added conformance to RandomAccessCollection
Refs #64
2020-10-04 22:37:44 +02:00
Lukas Kubanek 7abeecbf58 Deprecated moveElement(forKey:to:) 2020-10-04 21:46:41 +02:00
Lukas Kubanek 13bf59d5bd Tweaked documentation comments 2020-10-04 21:11:06 +02:00
Lukas Kubanek 47f66b1abd Exposed direct access to key array
- Introduced type alias OrderedDictionary.LazyValues
- Removed OrderedDictionarySlice, OrderedDictionaryKeys & OrderedDictionaryValues

Closes #67
2020-10-04 20:55:50 +02:00
Lukas Kubanek 42bb82b87b Moved LinuxMain.swift
Closes #63
2020-10-04 20:27:01 +02:00
Lukas Kubanek 30c36e66fd Tweaked CI configuration 2020-10-04 20:26:52 +02:00
Lukas Kubanek 3f6f0750cf Dropped support for Swift 4.2 2020-10-04 19:31:25 +02:00
Lukas Kubanek ae2cc6dd55 Bumped macOS deployment target for tests to 10.15 2020-09-29 19:34:04 +02:00
Lukas Kubanek 0d48ec751a Updated to Xcode 12.2 β1 2020-09-20 21:22:09 +02:00
Lukas Kubanek d2dec8bba0 Activated „Build Active Scheme“ on playgrounds 2020-09-10 14:57:38 +02:00
Lukas Kubanek e8795b26df Updated to Xcode 12 β1 2020-06-23 09:21:53 +02:00
Lukas Kubanek ab7784b97f Removed obsolete file references 2020-06-23 09:21:19 +02:00
Lukas Kubanek 9adcc6f84c Bumped version to 3.0.1 2020-05-28 10:34:55 +02:00
Lukas Kubanek 4ccfd1b9a3 Re-added marketing version to Xcode project settings 2020-05-28 10:34:20 +02:00
Lukas Kubanek f08ff3e872 Updated version in README 2020-05-22 09:08:16 +02:00
Lukas Kubanek f0da8a43be Removed concrete version from Xcode project 2020-05-22 09:07:44 +02:00
Lukas Kubanek dbd6b816db Mentioned older Swift versions support in README 2020-05-22 09:04:56 +02:00
Lukas Kubanek 9818933b59 Dropped support for Swift <4.2 (#61) 2020-05-22 08:57:45 +02:00
Lukas Kubanek 88cc1ad101 Moved Travis scripts 2020-05-21 23:48:15 +02:00
Lukas Kubanek 4cd37bd207 Reduced Travis configuration to Swift 4.2 only 2020-05-21 23:44:40 +02:00
Lukas Kubanek 5e62daeff2 Added GitHub action for CI (#59) 2020-05-21 23:31:42 +02:00
Lukas Kubanek 52e42cd938 Refreshed README 2020-05-21 16:14:49 +02:00
Lukas Kubanek dbf4484048 Updated manifest files 2020-05-21 16:14:49 +02:00
Lukas Kubanek 804f2847b4 Updated .gitignore 2020-05-21 16:14:49 +02:00
Lukas Kubanek 46952da3c3 Updated to Xcode 11.4
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-03-26 10:29:23 +01:00
Lukas Kubanek acb62df760 Bumped version to 2.4.0
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-03-02 10:58:22 +00:00
Lukas Kubanek f303e02f63 Merge branch 'pr-capacity'
Closes #54

Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-03-02 10:38:54 +00:00
Lukas Kubanek 244d0128c9 Added basic tests for capacity reservation
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-03-02 10:32:41 +00:00
Lukas Kubanek 0d5e16fc4f Expose min reserved capacity of underlying types
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-03-02 10:32:24 +00:00
Lukas Kubanek ecd3f176e5 Introduced init(minimumCapacity:)
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-03-02 10:26:27 +00:00
Lukas Kubanek ac3f8fa5eb Tweaked documentation comments
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-03-02 10:26:26 +00:00
Gal Cohen 19046fb4a8 adds capacity getter and reserveCapacity method 2020-01-31 21:30:29 -05:00
Lukas Kubanek 005ef5c3ee 2019 → 2020
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2020-01-12 10:08:56 +01:00
Lukas Kubanek 68f2557694 Updated to Xcode 11.2
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-11-04 16:53:55 +01:00
Lukas Kubanek 72d4779e9b Concretized Swift version in the recent tweak
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-09-26 16:14:02 +02:00
Lukas Kubanek 8547583792 Another try to satisfy Swift 4.0
It turns out Swift <4.1 does not understand the rethrows keyword and thus sees the newly annotated initializer as failing. Resorted to a force unwrap in the deprecated initializer as its parameter is non-throwing.

Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-09-26 16:04:40 +02:00
Lukas Kubanek 3688348461 Another attempt on fixing the bug with missing try keyword
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-09-26 15:40:41 +02:00
Lukas Kubanek f875439709 Fixed a bug introduced in the last commit
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-09-26 15:32:43 +02:00
Lukas Kubanek 1920f07525 init(values:uniquelyKeyedBy:) now takes throwing closure
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-09-26 15:03:57 +02:00
Lukas Kubanek 69ed90dcfc Bumped version to 2.3.0
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-30 15:41:05 +02:00
Lukas Kubanek 33fa9622ce Removed irrelevant part of a playground
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-30 15:40:31 +02:00
Lukas Kubanek 468ad1c83a Attempted to fix type inference issue in Swift 4
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 13:00:43 +02:00
Lukas Kubanek 174c21d58f Fixed a warning for Swift 5.0
Fixes #52

Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 12:44:37 +02:00
Lukas Kubanek 5f076fccbb init(_:) → init(uniqueKeysWithValues:)
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 12:38:22 +02:00
Lukas Kubanek 642b5623b7 init(values:keyedBy:) → init(values:uniquelyKeyedBy:)
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 12:22:32 +02:00
Lukas Kubanek 03b5817530 Annotated Travis configuration with exact 4.1.X version
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 09:42:34 +02:00
Lukas Kubanek 7ba07fcef1 Re-added Travis configurations for different Swift versions
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 09:35:49 +02:00
Lukas Kubanek 0e1273e2ab Attempt to use specified Swift versions by Travis
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 09:25:32 +02:00
Lukas Kubanek 7b8b3c39a3 Simplified Travis setup
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 09:11:26 +02:00
Lukas Kubanek 1e5c2926a7 Made tests compatible with Swift 4
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 08:56:24 +02:00
Lukas Kubanek b678702e3d Introduced mapValues(_:) & compactMapValues(_:)
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-07-12 08:38:59 +02:00
Lukas Kubanek 4e4b205dcb Revert "Disabled automatic linking"
This reverts commit b345a3e8df.
2019-07-04 14:53:30 +02:00
Lukas Kubanek b345a3e8df Disabled automatic linking
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-06-05 16:56:17 +02:00
Lukas Kubanek 2cf9220874 Updated project file to Xcode 11
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-06-04 10:13:56 +02:00
Lukas Kubanek 08e9ff5371 Minor adjustment in README
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-04-29 14:01:50 +02:00
Lukas Kubanek e7adba0cb9 Fixed version numbers by bumped version to 2.2.2
Signed-off-by: Lukas Kubanek <lukas.kubanek@me.com>
2019-04-29 13:54:22 +02:00
42 changed files with 2764 additions and 1949 deletions
+61
View File
@@ -0,0 +1,61 @@
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
macos-11:
name: macOS 11 (Xcode ${{ matrix.xcode }})
runs-on: macos-11
strategy:
matrix:
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
xcode:
- "13.0" # Swift 5.5
- "12.5.1" # Swift 5.4.2
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: Build
run: swift build -v
- name: Test
run: swift test -v
macos-10_15:
name: macOS 10.15 (Xcode ${{ matrix.xcode }})
runs-on: macos-10.15
strategy:
matrix:
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md#xcode
xcode:
- "12.3" # Swift 5.3.2
- "12.2" # Swift 5.3.1
- "11.7" # Swift 5.2.4
- "11.3.1" # Swift 5.1.3
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: Build
run: swift build -v
- name: Test
run: swift test -v
linux:
name: Linux
runs-on: ubuntu-latest
container:
image: swift:5.3
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: swift build -v
- name: Test
run: swift test -v
+8 -29
View File
@@ -1,32 +1,11 @@
# OS X
# SPM
.build
.swiftpm
# Xcode
xcuserdata/
# macOS
.DS_Store
.AppleDouble
.LSOverride
# Ruby
.ruby-*
.rbenv-*
# Xcode
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
*.xctimeline
# Carthage
Carthage
# SPM
.build
-49
View File
@@ -1,49 +0,0 @@
# Git
branches:
only:
- master
# OS
os: osx
language: objective-c
# Xcode Project
xcode_project: OrderedDictionary.xcodeproj
# Build Matrix
matrix:
include:
# Swift 4.0 / macOS
- osx_image: xcode9.2
xcode_scheme: OrderedDictionary-Mac
env:
- XCODE_SDK=macosx
- XCODE_ACTION="build test"
- XCODE_DESTINATION="arch=x86_64"
- XCODE_PLAYGROUND_TARGET="x86_64-apple-macosx10.10"
# Swift 4.0 / iOS
- osx_image: xcode9.2
xcode_scheme: OrderedDictionary-iOS
env:
- XCODE_SDK=iphonesimulator
- XCODE_ACTION="build-for-testing test-without-building"
- XCODE_DESTINATION="platform=iOS Simulator,name=iPhone 6s,OS=10.1"
# Swift 4.1 / macOS
- osx_image: xcode9.3beta
xcode_scheme: OrderedDictionary-Mac
env:
- XCODE_SDK=macosx
- XCODE_ACTION="build test"
- XCODE_DESTINATION="arch=x86_64"
- XCODE_PLAYGROUND_TARGET="x86_64-apple-macosx10.10"
# Swift 4.1 / iOS
- osx_image: xcode9.3beta
xcode_scheme: OrderedDictionary-iOS
env:
- XCODE_SDK=iphonesimulator
- XCODE_ACTION="build-for-testing test-without-building"
- XCODE_DESTINATION="platform=iOS Simulator,name=iPhone 6s,OS=10.1"
# Build Script
script:
- Scripts/build.sh
+1 -1
View File
@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015-2019 Lukas Kubanek
Copyright © 2015-2021 Lukas Kubanek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+121 -35
View File
@@ -7,12 +7,42 @@
objects = {
/* Begin PBXBuildFile section */
8048C8AB22D8911B0086B88B /* OrderedDictionary+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8048C8AA22D8911B0086B88B /* OrderedDictionary+Deprecated.swift */; };
8048C8AC22D8911B0086B88B /* OrderedDictionary+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8048C8AA22D8911B0086B88B /* OrderedDictionary+Deprecated.swift */; };
8055B0421E201C5D009DC3EE /* OrderedDictionary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8055B0381E201C5D009DC3EE /* OrderedDictionary.framework */; };
8055B0591E201DF3009DC3EE /* OrderedDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8055B0581E201DF3009DC3EE /* OrderedDictionaryTests.swift */; };
80A203A11F3F483700622481 /* OrderedDictionary+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80A203A01F3F483700622481 /* OrderedDictionary+Codable.swift */; };
80A203A21F3F4C1F00622481 /* OrderedDictionary+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80A203A01F3F483700622481 /* OrderedDictionary+Codable.swift */; };
80B28EA01E201EC9007E3A77 /* OrderedDictionary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80B28E971E201EC8007E3A77 /* OrderedDictionary.framework */; };
80B28EB01E201F1C007E3A77 /* OrderedDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8055B0581E201DF3009DC3EE /* OrderedDictionaryTests.swift */; };
80BE579A252B278D00F85D45 /* XCTUnwrapShim.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE5799252B278D00F85D45 /* XCTUnwrapShim.swift */; };
80BE579B252B278D00F85D45 /* XCTUnwrapShim.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE5799252B278D00F85D45 /* XCTUnwrapShim.swift */; };
80BE57A5252B3F6000F85D45 /* SubscriptAmbiguityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE57A4252B3F6000F85D45 /* SubscriptAmbiguityTests.swift */; };
80BE57A6252B3F6000F85D45 /* SubscriptAmbiguityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE57A4252B3F6000F85D45 /* SubscriptAmbiguityTests.swift */; };
80BE57D4252BAB9400F85D45 /* OrderedDictionarySlice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE57D3252BAB9400F85D45 /* OrderedDictionarySlice.swift */; };
80BE57D5252BAB9400F85D45 /* OrderedDictionarySlice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE57D3252BAB9400F85D45 /* OrderedDictionarySlice.swift */; };
80BE57DF252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE57DE252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift */; };
80BE57E0252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BE57DE252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift */; };
80BFD01B252B049E002B3C05 /* InitializationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD01A252B049E002B3C05 /* InitializationTests.swift */; };
80BFD01C252B049E002B3C05 /* InitializationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD01A252B049E002B3C05 /* InitializationTests.swift */; };
80BFD02A252B069F002B3C05 /* SortingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD029252B069F002B3C05 /* SortingTests.swift */; };
80BFD02B252B069F002B3C05 /* SortingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD029252B069F002B3C05 /* SortingTests.swift */; };
80BFD031252B06EB002B3C05 /* DescriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD030252B06EB002B3C05 /* DescriptionTests.swift */; };
80BFD032252B06EB002B3C05 /* DescriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD030252B06EB002B3C05 /* DescriptionTests.swift */; };
80BFD040252B0740002B3C05 /* CodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD03F252B0740002B3C05 /* CodingTests.swift */; };
80BFD041252B0740002B3C05 /* CodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD03F252B0740002B3C05 /* CodingTests.swift */; };
80BFD04B252B0951002B3C05 /* CapacityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD04A252B0951002B3C05 /* CapacityTests.swift */; };
80BFD04C252B0951002B3C05 /* CapacityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD04A252B0951002B3C05 /* CapacityTests.swift */; };
80BFD052252B09DC002B3C05 /* ReorderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD051252B09DC002B3C05 /* ReorderingTests.swift */; };
80BFD053252B09DC002B3C05 /* ReorderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD051252B09DC002B3C05 /* ReorderingTests.swift */; };
80BFD061252B0A7F002B3C05 /* RemovalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD060252B0A7F002B3C05 /* RemovalTests.swift */; };
80BFD062252B0A7F002B3C05 /* RemovalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD060252B0A7F002B3C05 /* RemovalTests.swift */; };
80BFD070252B0C16002B3C05 /* AccessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD06F252B0C16002B3C05 /* AccessTests.swift */; };
80BFD071252B0C16002B3C05 /* AccessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD06F252B0C16002B3C05 /* AccessTests.swift */; };
80BFD077252B0D94002B3C05 /* MapFilterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD076252B0D94002B3C05 /* MapFilterTests.swift */; };
80BFD078252B0D94002B3C05 /* MapFilterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD076252B0D94002B3C05 /* MapFilterTests.swift */; };
80BFD07E252B0E19002B3C05 /* UpdatesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD07D252B0E19002B3C05 /* UpdatesTests.swift */; };
80BFD07F252B0E19002B3C05 /* UpdatesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD07D252B0E19002B3C05 /* UpdatesTests.swift */; };
80BFD0A8252B1C96002B3C05 /* InsertionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD0A7252B1C96002B3C05 /* InsertionsTests.swift */; };
80BFD0A9252B1C96002B3C05 /* InsertionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFD0A7252B1C96002B3C05 /* InsertionsTests.swift */; };
80E8E21D1E20301E00395E49 /* OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80E8E21C1E20301E00395E49 /* OrderedDictionary.swift */; };
80E8E21F1E20425B00395E49 /* OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80E8E21C1E20301E00395E49 /* OrderedDictionary.swift */; };
80E8E2301E2133D100395E49 /* OrderedDictionary+Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80E8E22F1E2133D100395E49 /* OrderedDictionary+Description.swift */; };
@@ -37,20 +67,29 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
8024947E2277123600AB44C7 /* Package@swift-4.2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Package@swift-4.2.swift"; sourceTree = "<group>"; };
8024947F2277136D00AB44C7 /* Package@swift-5.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Package@swift-5.swift"; sourceTree = "<group>"; };
804879371E217C7700AD31A3 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
804879381E217CA100AD31A3 /* validate-playgrounds.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "validate-playgrounds.sh"; sourceTree = "<group>"; };
8048C8AA22D8911B0086B88B /* OrderedDictionary+Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderedDictionary+Deprecated.swift"; sourceTree = "<group>"; };
8055B0381E201C5D009DC3EE /* OrderedDictionary.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OrderedDictionary.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8055B0411E201C5D009DC3EE /* OrderedDictionary_Mac_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OrderedDictionary_Mac_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
8055B0581E201DF3009DC3EE /* OrderedDictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderedDictionaryTests.swift; sourceTree = "<group>"; };
807AA68F1F1E587A00576474 /* OrderedDictionary+Codable.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = "OrderedDictionary+Codable.playground"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
80A203A01F3F483700622481 /* OrderedDictionary+Codable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderedDictionary+Codable.swift"; sourceTree = "<group>"; };
80B28E971E201EC8007E3A77 /* OrderedDictionary.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OrderedDictionary.framework; sourceTree = BUILT_PRODUCTS_DIR; };
80B28E9F1E201EC9007E3A77 /* OrderedDictionary_iOS_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OrderedDictionary_iOS_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
80B28EB41E201F81007E3A77 /* Info-Tests.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-Tests.plist"; sourceTree = "<group>"; };
80B28EB51E201F81007E3A77 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
80B28EB71E2020DD007E3A77 /* OrderedDictionary.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = OrderedDictionary.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
80BE5799252B278D00F85D45 /* XCTUnwrapShim.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTUnwrapShim.swift; sourceTree = "<group>"; };
80BE57A4252B3F6000F85D45 /* SubscriptAmbiguityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptAmbiguityTests.swift; sourceTree = "<group>"; };
80BE57D3252BAB9400F85D45 /* OrderedDictionarySlice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderedDictionarySlice.swift; sourceTree = "<group>"; };
80BE57DE252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+OrderedDictionary.swift"; sourceTree = "<group>"; };
80BFD01A252B049E002B3C05 /* InitializationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitializationTests.swift; sourceTree = "<group>"; };
80BFD029252B069F002B3C05 /* SortingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortingTests.swift; sourceTree = "<group>"; };
80BFD030252B06EB002B3C05 /* DescriptionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DescriptionTests.swift; sourceTree = "<group>"; };
80BFD03F252B0740002B3C05 /* CodingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodingTests.swift; sourceTree = "<group>"; };
80BFD04A252B0951002B3C05 /* CapacityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapacityTests.swift; sourceTree = "<group>"; };
80BFD051252B09DC002B3C05 /* ReorderingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReorderingTests.swift; sourceTree = "<group>"; };
80BFD060252B0A7F002B3C05 /* RemovalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemovalTests.swift; sourceTree = "<group>"; };
80BFD06F252B0C16002B3C05 /* AccessTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessTests.swift; sourceTree = "<group>"; };
80BFD076252B0D94002B3C05 /* MapFilterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFilterTests.swift; sourceTree = "<group>"; };
80BFD07D252B0E19002B3C05 /* UpdatesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdatesTests.swift; sourceTree = "<group>"; };
80BFD0A7252B1C96002B3C05 /* InsertionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsertionsTests.swift; sourceTree = "<group>"; };
80DE329220F4CAFA0053EDA7 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
80DE329320F4DD910053EDA7 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
80DE329420F4DD910053EDA7 /* LICENSE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = "<group>"; };
@@ -92,28 +131,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
804879361E217C7700AD31A3 /* Scripts */ = {
isa = PBXGroup;
children = (
804879371E217C7700AD31A3 /* build.sh */,
804879381E217CA100AD31A3 /* validate-playgrounds.sh */,
);
path = Scripts;
sourceTree = "<group>";
};
8055B02E1E201C5D009DC3EE = {
isa = PBXGroup;
children = (
80DE329320F4DD910053EDA7 /* README.md */,
80DE329420F4DD910053EDA7 /* LICENSE.md */,
80DE329220F4CAFA0053EDA7 /* Package.swift */,
8024947E2277123600AB44C7 /* Package@swift-4.2.swift */,
8024947F2277136D00AB44C7 /* Package@swift-5.swift */,
8055B0521E201D24009DC3EE /* Sources */,
80B28EB11E201F72007E3A77 /* Playgrounds */,
8055B0571E201DF3009DC3EE /* Tests */,
80B28EB31E201F81007E3A77 /* Supporting Files */,
804879361E217C7700AD31A3 /* Scripts */,
8055B0391E201C5D009DC3EE /* Products */,
);
sourceTree = "<group>";
@@ -132,9 +158,7 @@
8055B0521E201D24009DC3EE /* Sources */ = {
isa = PBXGroup;
children = (
80E8E21C1E20301E00395E49 /* OrderedDictionary.swift */,
80A203A01F3F483700622481 /* OrderedDictionary+Codable.swift */,
80E8E22F1E2133D100395E49 /* OrderedDictionary+Description.swift */,
80B7BC2B261A65C100EB2CA2 /* OrderedDictionary */,
);
path = Sources;
sourceTree = "<group>";
@@ -142,18 +166,29 @@
8055B0571E201DF3009DC3EE /* Tests */ = {
isa = PBXGroup;
children = (
8055B0581E201DF3009DC3EE /* OrderedDictionaryTests.swift */,
80AF1630252A48080065B656 /* OrderedDictionaryTests */,
);
path = Tests;
sourceTree = "<group>";
};
80B28EB11E201F72007E3A77 /* Playgrounds */ = {
80AF1630252A48080065B656 /* OrderedDictionaryTests */ = {
isa = PBXGroup;
children = (
80B28EB71E2020DD007E3A77 /* OrderedDictionary.playground */,
807AA68F1F1E587A00576474 /* OrderedDictionary+Codable.playground */,
80BFD01A252B049E002B3C05 /* InitializationTests.swift */,
80BFD06F252B0C16002B3C05 /* AccessTests.swift */,
80BFD0A7252B1C96002B3C05 /* InsertionsTests.swift */,
80BFD07D252B0E19002B3C05 /* UpdatesTests.swift */,
80BFD060252B0A7F002B3C05 /* RemovalTests.swift */,
80BE57A4252B3F6000F85D45 /* SubscriptAmbiguityTests.swift */,
80BFD076252B0D94002B3C05 /* MapFilterTests.swift */,
80BFD051252B09DC002B3C05 /* ReorderingTests.swift */,
80BFD029252B069F002B3C05 /* SortingTests.swift */,
80BFD04A252B0951002B3C05 /* CapacityTests.swift */,
80BFD03F252B0740002B3C05 /* CodingTests.swift */,
80BFD030252B06EB002B3C05 /* DescriptionTests.swift */,
80BE5799252B278D00F85D45 /* XCTUnwrapShim.swift */,
);
path = Playgrounds;
path = OrderedDictionaryTests;
sourceTree = "<group>";
};
80B28EB31E201F81007E3A77 /* Supporting Files */ = {
@@ -165,6 +200,19 @@
path = "Supporting Files";
sourceTree = "<group>";
};
80B7BC2B261A65C100EB2CA2 /* OrderedDictionary */ = {
isa = PBXGroup;
children = (
80E8E21C1E20301E00395E49 /* OrderedDictionary.swift */,
80A203A01F3F483700622481 /* OrderedDictionary+Codable.swift */,
80E8E22F1E2133D100395E49 /* OrderedDictionary+Description.swift */,
8048C8AA22D8911B0086B88B /* OrderedDictionary+Deprecated.swift */,
80BE57D3252BAB9400F85D45 /* OrderedDictionarySlice.swift */,
80BE57DE252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift */,
);
path = OrderedDictionary;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -264,7 +312,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1320;
ORGANIZATIONNAME = "Lukas Kubanek";
TargetAttributes = {
8055B0371E201C5D009DC3EE = {
@@ -346,9 +394,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8048C8AB22D8911B0086B88B /* OrderedDictionary+Deprecated.swift in Sources */,
80E8E2301E2133D100395E49 /* OrderedDictionary+Description.swift in Sources */,
80E8E21D1E20301E00395E49 /* OrderedDictionary.swift in Sources */,
80BE57D4252BAB9400F85D45 /* OrderedDictionarySlice.swift in Sources */,
80A203A11F3F483700622481 /* OrderedDictionary+Codable.swift in Sources */,
80BE57DF252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -356,7 +407,19 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8055B0591E201DF3009DC3EE /* OrderedDictionaryTests.swift in Sources */,
80BFD061252B0A7F002B3C05 /* RemovalTests.swift in Sources */,
80BFD031252B06EB002B3C05 /* DescriptionTests.swift in Sources */,
80BFD077252B0D94002B3C05 /* MapFilterTests.swift in Sources */,
80BFD070252B0C16002B3C05 /* AccessTests.swift in Sources */,
80BFD052252B09DC002B3C05 /* ReorderingTests.swift in Sources */,
80BFD04B252B0951002B3C05 /* CapacityTests.swift in Sources */,
80BFD02A252B069F002B3C05 /* SortingTests.swift in Sources */,
80BFD07E252B0E19002B3C05 /* UpdatesTests.swift in Sources */,
80BFD0A8252B1C96002B3C05 /* InsertionsTests.swift in Sources */,
80BFD040252B0740002B3C05 /* CodingTests.swift in Sources */,
80BE57A5252B3F6000F85D45 /* SubscriptAmbiguityTests.swift in Sources */,
80BFD01B252B049E002B3C05 /* InitializationTests.swift in Sources */,
80BE579A252B278D00F85D45 /* XCTUnwrapShim.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -364,9 +427,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8048C8AC22D8911B0086B88B /* OrderedDictionary+Deprecated.swift in Sources */,
80E8E2311E2133D100395E49 /* OrderedDictionary+Description.swift in Sources */,
80E8E21F1E20425B00395E49 /* OrderedDictionary.swift in Sources */,
80BE57D5252BAB9400F85D45 /* OrderedDictionarySlice.swift in Sources */,
80A203A21F3F4C1F00622481 /* OrderedDictionary+Codable.swift in Sources */,
80BE57E0252BADEE00F85D45 /* Dictionary+OrderedDictionary.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -374,7 +440,19 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
80B28EB01E201F1C007E3A77 /* OrderedDictionaryTests.swift in Sources */,
80BFD062252B0A7F002B3C05 /* RemovalTests.swift in Sources */,
80BFD032252B06EB002B3C05 /* DescriptionTests.swift in Sources */,
80BFD078252B0D94002B3C05 /* MapFilterTests.swift in Sources */,
80BFD071252B0C16002B3C05 /* AccessTests.swift in Sources */,
80BFD053252B09DC002B3C05 /* ReorderingTests.swift in Sources */,
80BFD04C252B0951002B3C05 /* CapacityTests.swift in Sources */,
80BFD02B252B069F002B3C05 /* SortingTests.swift in Sources */,
80BFD07F252B0E19002B3C05 /* UpdatesTests.swift in Sources */,
80BFD0A9252B1C96002B3C05 /* InsertionsTests.swift in Sources */,
80BFD041252B0740002B3C05 /* CodingTests.swift in Sources */,
80BE57A6252B3F6000F85D45 /* SubscriptAmbiguityTests.swift in Sources */,
80BFD01C252B049E002B3C05 /* InitializationTests.swift in Sources */,
80BE579B252B278D00F85D45 /* XCTUnwrapShim.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -419,6 +497,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -452,7 +531,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
@@ -483,6 +562,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -508,7 +588,7 @@
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
@@ -529,6 +609,7 @@
INFOPLIST_FILE = "Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionary;
PRODUCT_NAME = OrderedDictionary;
SKIP_INSTALL = YES;
@@ -550,6 +631,7 @@
INFOPLIST_FILE = "Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionary;
PRODUCT_NAME = OrderedDictionary;
SKIP_INSTALL = YES;
@@ -563,6 +645,7 @@
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "Supporting Files/Info-Tests.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 11.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionaryTests;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
};
@@ -575,6 +658,7 @@
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "Supporting Files/Info-Tests.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 11.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionaryTests;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
};
@@ -594,6 +678,7 @@
INFOPLIST_FILE = "Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionary;
PRODUCT_NAME = OrderedDictionary;
SDKROOT = iphoneos;
@@ -616,6 +701,7 @@
INFOPLIST_FILE = "Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lukaskubanek.OrderedDictionary;
PRODUCT_NAME = OrderedDictionary;
SDKROOT = iphoneos;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
@@ -39,17 +40,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8055B0371E201C5D009DC3EE"
BuildableName = "OrderedDictionary.framework"
BlueprintName = "OrderedDictionary-Mac"
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
@@ -70,8 +60,6 @@
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -39,17 +39,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "80B28E961E201EC8007E3A77"
BuildableName = "OrderedDictionary.framework"
BlueprintName = "OrderedDictionary-iOS"
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
@@ -70,8 +59,6 @@
ReferencedContainer = "container:OrderedDictionary.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
+4 -7
View File
@@ -1,4 +1,4 @@
// swift-tools-version:4
// swift-tools-version:5.0
import PackageDescription
@@ -14,14 +14,11 @@ let package = Package(
targets: [
.target(
name: "OrderedDictionary",
dependencies: [],
path: "Sources"
dependencies: []
),
.testTarget(
name: "OrderedDictionaryTests",
dependencies: ["OrderedDictionary"],
path: "Tests"
dependencies: ["OrderedDictionary"]
)
],
swiftLanguageVersions: [4]
]
)
-27
View File
@@ -1,27 +0,0 @@
// swift-tools-version:4.2
import PackageDescription
let package = Package(
name: "OrderedDictionary",
products: [
.library(
name: "OrderedDictionary",
targets: ["OrderedDictionary"]
)
],
dependencies: [],
targets: [
.target(
name: "OrderedDictionary",
dependencies: [],
path: "Sources"
),
.testTarget(
name: "OrderedDictionaryTests",
dependencies: ["OrderedDictionary"],
path: "Tests"
)
],
swiftLanguageVersions: [.v4, .v4_2]
)
-27
View File
@@ -1,27 +0,0 @@
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "OrderedDictionary",
products: [
.library(
name: "OrderedDictionary",
targets: ["OrderedDictionary"]
)
],
dependencies: [],
targets: [
.target(
name: "OrderedDictionary",
dependencies: [],
path: "Sources"
),
.testTarget(
name: "OrderedDictionaryTests",
dependencies: ["OrderedDictionary"],
path: "Tests"
)
],
swiftLanguageVersions: [.v5]
)
@@ -1,49 +0,0 @@
import Foundation
import OrderedDictionary
let orderedDictionary1: OrderedDictionary<String, Int> = [
"A": 42,
"B": 100,
"C": 11
]
// ======================================================= //
// MARK: - JSON Encoding & Decoding
// ======================================================= //
let jsonEncoder = JSONEncoder()
let jsonData = try! jsonEncoder.encode(orderedDictionary1)
let jsonString = String(data: jsonData, encoding: .utf8)
let jsonDecoder = JSONDecoder()
let orderedDictionary2 = try! jsonDecoder.decode(OrderedDictionary<String, Int>.self, from: jsonData)
orderedDictionary1 == orderedDictionary2
// ======================================================= //
// MARK: - Property List Encoding & Decoding
// ======================================================= //
let plistEncoder = PropertyListEncoder()
let plistData = try! plistEncoder.encode(orderedDictionary1)
let plistDecoder = PropertyListDecoder()
let orderedDictionary3 = try! plistDecoder.decode(OrderedDictionary<String, Int>.self, from: plistData)
orderedDictionary1 == orderedDictionary3
// ======================================================= //
// MARK: - Non-codable Type
// ======================================================= //
struct NonCodableType {
var string: String
}
let orderedDictionary4: OrderedDictionary<String, NonCodableType> = [
"A" : NonCodableType(string: "Foo"),
"B" : NonCodableType(string: "Bar"),
"C" : NonCodableType(string: "Baz")
]
//try? jsonEncoder.encode(x)
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos'>
<timeline fileName='timeline.xctimeline'/>
</playground>
@@ -1,134 +0,0 @@
import OrderedDictionary
// ======================================================= //
// Helpers
// ======================================================= //
func print(_ optional: Any?) {
print(optional as Any)
}
// ======================================================= //
// Construction
// ======================================================= //
// Construct an ordered dictionary using a dictionary literal
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
// Output the ordered dictionary
print(orderedDictionary) // => [A: 1, B: 2, C: 3, D: 4]
// ======================================================= //
// Enumeration
// ======================================================= //
// Loop through the ordered dictionary
for (key, value) in orderedDictionary {
print("[\(key): \(value)]") // => [A: 1], => [B: 2], => [C: 3], => [D: 4]
}
// Loop through the ordered dictionary with an additional index
for (index, element) in orderedDictionary.enumerated() {
print("(\(index): [\(element.key): \(element.value)])") // => (0: [A: 1]), => (1: [B: 2]), => (2: [C: 3]), => (3: [D: 4])
}
// ======================================================= //
// Acessing Content
// ======================================================= //
// Access the value for an existing key using the subscript
print(orderedDictionary["A"]) // => Optional(1)
// Access the value for a non-existent key using the subscript
print(orderedDictionary["X"]) // => nil
// Access the value for a key using the method
print(orderedDictionary.value(forKey: "A")) // => Optional(1)
// Access the value for a non-existent key using the method
print(orderedDictionary.value(forKey: "X")) // => nil
// Access the key-value pair (element) at an existing index
print(orderedDictionary[2]) // => ("C", 3)
// Access the key-value pair (element) at a non-existent index
//print(orderedDictionary[10]) // => fatal error
// Get the index for an existing key
print(orderedDictionary.index(forKey: "D")) // => Optional(3)
// ======================================================= //
// Modifying Content Using Keys
// ======================================================= //
// Modify the value for an existing key using the subscript
orderedDictionary["A"] = 100
print(orderedDictionary["A"]) // => Optional(100)
// Modify the value for an existing key using the method
orderedDictionary.updateValue(42, forKey: "D")
print(orderedDictionary["D"]) // => Optional(42)
// Append a new key-value pair by setting a value for an non-existent key
orderedDictionary["E"] = 5
print(orderedDictionary) // => [A: 100, B: 2, C: 3, D: 42, E: 5]
// Remove a key-value pair by setting `nil` value for an existing key
orderedDictionary["B"] = nil
print(orderedDictionary["B"]) // => nil
print(orderedDictionary) // => [A: 100, C: 3, D: 42, E: 5]
// ======================================================= //
// Modifying Content Using Indexes
// ======================================================= //
// Modify an element at an existing index
let replacedElement = orderedDictionary.update(("F", 235), at: 2)
print(orderedDictionary[2]) // => ("F", 235)
print(orderedDictionary) // => [A: 100, C: 3, F: 235, E: 5]
print(replacedElement) // => Optional("D", 42)
// Modify an element at a non-existent index
//orderedDictionary.update(("L", 0), at: 100) // => fatal error
// ======================================================= //
// Sorting
// ======================================================= //
// Sort the ordered dictionary using a closure
orderedDictionary.sort {
if $0.value == $1.value {
return $0.key < $1.key
} else {
return $0.value < $1.value
}
}
print(orderedDictionary) // => [C: 3, E: 5, A: 100, F: 235]
// ======================================================= //
// Removing Content
// ======================================================= //
// Remove value for an existing key
let removedValue = orderedDictionary.removeValue(forKey: "F")
print(removedValue) // => Optional(235)
print(orderedDictionary["F"]) // => nil
print(orderedDictionary) // => [C: 3, E: 5, A: 100]
// Remove value for a non-existent key
orderedDictionary.removeValue(forKey: "X")
print(orderedDictionary) // => [C: 3, E: 5, A: 100]
// Remove element at an existing index
let removedElement = orderedDictionary.remove(at: 1)
print(removedElement) // => Optional((E, 5))
print(orderedDictionary) // => [C: 3, A: 100]
// Remove element at a non-existent index
orderedDictionary.remove(at: 42)
print(orderedDictionary) // => [C: 3, A: 100]
// Remove all elements
orderedDictionary.removeAll()
print(orderedDictionary) // => [:]
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='osx'>
<timeline fileName='timeline.xctimeline'/>
</playground>
+54 -32
View File
@@ -1,64 +1,86 @@
# OrderedDictionary
[![](https://img.shields.io/travis/lukaskubanek/OrderedDictionary.svg?style=flat-square "Build")](https://travis-ci.org/lukaskubanek/OrderedDictionary) [![](https://img.shields.io/badge/release-v2.2.0-blue.svg?style=flat-square)](https://github.com/lukaskubanek/OrderedDictionary/releases) [![](https://img.shields.io/badge/Swift-4.0+-orange.svg?style=flat-square)](https://developer.apple.com/swift/ "Swift 4") ![](https://img.shields.io/badge/platform-macOS/iOS-yellowgreen.svg?style=flat-square "Platform: macOS/iOS") [![](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square "Carthage compatible")](https://github.com/Carthage/Carthage)
[![](https://img.shields.io/badge/SPM-compatible-brightgreen.svg?style=flat-square "SPM compatible")](https://github.com/Carthage/Carthage) [![](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat-square "License: MIT")](LICENSE.md)
<p align="left">
<a href="https://github.com/lukaskubanek/OrderedDictionary/releases">
<img src="https://img.shields.io/github/release/lukaskubanek/OrderedDictionary/all.svg?style=flat-square">
</a>
<a href="https://developer.apple.com/swift">
<img src="https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat-square" alt="Swift 5.0">
</a>
<a href="https://swift.org/package-manager">
<img src="https://img.shields.io/badge/SPM-compatible-brightgreen.svg?style=flat-square" alt="Swift Package Manager">
</a>
<a href="https://github.com/Carthage/Carthage">
<img src="https://img.shields.io/badge/Carthage-compatible-brightgreen.svg?style=flat-square" alt="Carthage">
</a>
<a href="LICENSE.md">
<img src="https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat-square" alt="License: MIT">
</a>
<a href="https://twitter.com/lukaskubanek">
<img src="https://img.shields.io/badge/contact-@lukaskubanek-olive.svg?style=flat-square" alt="Twitter: @lukaskubanek">
</a>
</p>
**OrderedDictionary** is a lightweight implementation of an ordered dictionary data structure in Swift.
OrderedDictionary is a lightweight implementation of an ordered dictionary data structure in Swift.
The `OrderedDictionary` struct is a generic collection which combines the features of `Dictionary` and `Array` from the Swift standard library. Like `Dictionary` it stores key-value pairs with each key being unique and maps each key to an associated value. Like `Array` it stores those pairs sorted and accessible by a zero-based integer index.
The `OrderedDictionary<Key: Hashable, Value>` struct is a generic collection that combines the features of the `Dictionary` and `Array` data structures from the Swift standard library. Like `Dictionary`, it stores key-value pairs with each key being unique and maps each key to an associated value. Like `Array`, it stores those pairs sorted and accessible by a zero-based integer index.
`OrderedDictionary` provides similar APIs like collections from the Swift standard library. This includes accessing contents by keys or indices, inserting and removing elements, iterating, sorting etc.
`OrderedDictionary` provides similar APIs to collections available in the Swift standard library like accessing contents by keys or indices, inserting and removing elements, iterating, sorting, transforming, filtering, etc.
Internally, `OrderedDictionary` uses a backing store composed of an instance of `Dictionary` for storing the key-value pairs and an instance of `Array` for managing the ordered keys. This means it is not the most performant implementation possible, but it gets its job done by reusing most functionality from the Swift standard library.
Internally, `OrderedDictionary` uses backing storage composed of a `Dictionary` for storing the key-value pairs and an `Array` for managing the ordered keys. This is certainly not the most performant implementation one can achieve, but it gets its job done while reusing most functionality from the Swift standard library.
## Requirements
- Swift 4.0, 4.2, 5.0
- Xcode 9.2+
- iOS 8.0+ / macOS 10.10+
- Swift 5.0 or later
- Xcode 11 or later
- iOS 8 or later / macOS 10.10 or later
*For support of older Swift versions, please refer to older versions of this library. For Swift 4.2, use version 3.x, and for Swift 4.0-4.1, use version 2.x.*
*The requirements for Xcode and OS versions only apply when the library is integrated as a framework or via the Xcode project.*
## Installation
The library is distributed as a Swift framework and can be integrated into your project in following ways:
### Swift Package Manager
#### Carthage
To install OrderedDictionary using the [Swift Package Manager](https://swift.org/package-manager/), add it as a dependency into your `Package.swift` file:
If you use [Carthage](https://github.com/Carthage/Carthage) for managing your dependencies, put OrderedDictionary into your `Cartfile`:
```plain
github "lukaskubanek/OrderedDictionary"
```swift
let package = Package(
...
dependencies: [
.package(url: "https://github.com/lukaskubanek/OrderedDictionary.git", from: "4.0.0")
],
...
)
```
Then, drag either the `OrderedDictionary.xcodeproj` or the `OrderedDictionary.framework` into your project/workspace and link your target against the `OrderedDictionary.framework`. Also make sure that the framework [gets copied](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to your application bundle.
### Carthage
#### Swift Package Manager
Another option is to use the [Swift Package Manager](https://swift.org/package-manager/). If you prefer this option, put OrderedDictionary as a dependency to your `Package.swift`:
To install OrderedDictionary using [Carthage](https://github.com/Carthage/Carthage), add it as a dependency into your `Cartfile`:
```plain
.package(url: "https://github.com/lukaskubanek/OrderedDictionary.git", from: "2.2.0")
github "lukaskubanek/OrderedDictionary" ~> 4.0
```
#### Git Submodules
Then drag either the `OrderedDictionary.xcodeproj` or the `OrderedDictionary.framework` into your Xcode project/workspace and link your target against the `OrderedDictionary.framework`. Make sure that the framework [gets copied](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to your application bundle.
Yet another option is using [Git submodules](http://git-scm.com/book/en/v2/Git-Tools-Submodules) and integrating the Xcode project `OrderedDictionary.xcodeproj` from the submodule directly to your Xcode workspace.
### Git Submodules
#### ⚠️ Note About CocoaPods
You can also install OrderedDictionary via [Git submodules](http://git-scm.com/book/en/v2/Git-Tools-Submodules) and integrate the project `OrderedDictionary.xcodeproj` from the submodule directly into your Xcode workspace.
Although there is high demand for [CocoaPods](https://cocoapods.org) support, this method won't be officially supported by this library. Since I'm not using CocoaPods myself and since I think this method will be once replaced by the Swift Package Manager, I don't want to put any effort in maintaining an official podspec. If you really want to include this library via CocoaPods, there is still a way by creating a custom podspec (see the last section of [this post](https://guides.cocoapods.org/syntax/podfile.html#pod)).
### Note About CocoaPods
Although there has been a high demand for [CocoaPods](https://cocoapods.org) support, this distribution method won't be officially supported by this library. If you really want to integrate this library via CocoaPods, you can create and maintain a custom podspec (see the last section of [this post](https://guides.cocoapods.org/syntax/podfile.html#pod)).
## Usage & Docs
For the usage of this library please refer to [the example playground](Playgrounds/OrderedDictionary.playground/Contents.swift). For documentation please refer to [the documentation comments](Sources/OrderedDictionary.swift).
For the explanation of the API of `OrderedDictionary` and examples on how to use this data structure, please refer to the [documentation comments](Sources/OrderedDictionary/OrderedDictionary.swift) or the [comprehensive test suite](Tests/OrderedDictionaryTests).
## Changelog
The changelog is managed on the [GitHub releases page](https://github.com/lukaskubanek/OrderedDictionary/releases).
To view the changelog, refer to GitHub's [releases page](https://github.com/lukaskubanek/OrderedDictionary/releases). If you're upgrading from version 3.x, you might want to check out the list of changes made in [version 4.0](https://github.com/lukaskubanek/OrderedDictionary/releases/tag/v4.0.0).
## Author
## Credits
Lukas Kubanek // [lukaskubanek.com](http://lukaskubanek.com) // [@kubanekl](https://twitter.com/kubanekl)
## License
**OrderedDictionary** is provided under the [MIT License](LICENSE.md).
OrderedDictionary was built by [@lukaskubanek](https://twitter.com/lukaskubanek), the founder and developer of [Diagrams](https://diagrams.app), a native diagram editor for Mac. This data structure is being used extensively for powering Diagrams' data model.
-54
View File
@@ -1,54 +0,0 @@
#!/bin/bash
# This script was taken from the ReactiveSwift repository.
# https://github.com/ReactiveCocoa/ReactiveSwift/blob/master/script/build
BUILD_DIRECTORY="build"
CONFIGURATION="Release"
if [[ -z $TRAVIS_XCODE_PROJECT ]]; then
echo "Error: \$TRAVIS_XCODE_PROJECT is not set."
exit 1
fi
if [[ -z $TRAVIS_XCODE_SCHEME ]]; then
echo "Error: \$TRAVIS_XCODE_SCHEME is not set."
exit 1
fi
if [[ -z $XCODE_ACTION ]]; then
echo "Error: \$XCODE_ACTION is not set."
exit 1
fi
if [[ -z $XCODE_SDK ]]; then
echo "Error: \$XCODE_SDK is not set."
exit 1
fi
if [[ -z $XCODE_DESTINATION ]]; then
echo "Error: \$XCODE_DESTINATION is not set."
exit 1
fi
set -o pipefail
xcodebuild $XCODE_ACTION \
-project "$TRAVIS_XCODE_PROJECT" \
-scheme "$TRAVIS_XCODE_SCHEME" \
-sdk "$XCODE_SDK" \
-destination "$XCODE_DESTINATION" \
-derivedDataPath "${BUILD_DIRECTORY}" \
-configuration $CONFIGURATION \
ENABLE_TESTABILITY=YES \
GCC_GENERATE_DEBUGGING_SYMBOLS=NO \
RUN_CLANG_STATIC_ANALYZER=NO | xcpretty
result=$?
if [ "$result" -ne 0 ]; then
exit $result
fi
if [[ $XCODE_SDK = "macosx" ]]; then
echo "SDK is ${XCODE_SDK}, validating playground..."
. Scripts/validate-playgrounds.sh
fi
-23
View File
@@ -1,23 +0,0 @@
#!/bin/bash
if [[ -z $BUILD_DIRECTORY ]]; then
echo "Error: \$BUILD_DIRECTORY is not set."
exit 1
fi
if [[ -z $XCODE_PLAYGROUND_TARGET ]]; then
echo "Error: \$XCODE_PLAYGROUND_TARGET is not set."
exit 1
fi
PAGES_PATH=Playgrounds/OrderedDictionary.playground/Contents.swift
swift -v -target ${XCODE_PLAYGROUND_TARGET} \
-D NOT_IN_PLAYGROUND \
-F ${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION} ${PAGES_PATH} > /dev/null
result=$?
rm -Rf ${BUILD_DIRECTORY}
exit $result
-136
View File
@@ -1,136 +0,0 @@
#if swift(>=4.1)
extension OrderedDictionary: Encodable where Key: Encodable, Value: Encodable {
/// __inheritdoc__
public func encode(to encoder: Encoder) throws {
// Encode the ordered dictionary as an array of alternating key-value pairs.
var container = encoder.unkeyedContainer()
for (key, value) in self {
try container.encode(key)
try container.encode(value)
}
}
}
extension OrderedDictionary: Decodable where Key: Decodable, Value: Decodable {
/// __inheritdoc__
public init(from decoder: Decoder) throws {
// Decode the ordered dictionary from an array of alternating key-value pairs.
self.init()
var container = try decoder.unkeyedContainer()
while !container.isAtEnd {
let key = try container.decode(Key.self)
guard !container.isAtEnd else { throw DecodingError.unkeyedContainerReachedEndBeforeValue(decoder.codingPath) }
let value = try container.decode(Value.self)
self[key] = value
}
}
}
#else
extension OrderedDictionary: Encodable {
/// __inheritdoc__
public func encode(to encoder: Encoder) throws {
// Since Swift 4.0 lacks the protocol conditional conformance support, we have to make the
// whole OrderedDictionary type conform to Encodable and assert that the key and value
// types conform to Encodable. Furthermore, we leverage a trick of super encoders to be
// able to encode objects without knowing their exact types. This trick was used in the
// standard library for encoding/decoding Dictionary before Swift 4.1.
_assertTypeIsEncodable(Key.self, in: type(of: self))
_assertTypeIsEncodable(Value.self, in: type(of: self))
var container = encoder.unkeyedContainer()
for (key, value) in self {
let keyEncoder = container.superEncoder()
try (key as! Encodable).encode(to: keyEncoder)
let valueEncoder = container.superEncoder()
try (value as! Encodable).encode(to: valueEncoder)
}
}
private func _assertTypeIsEncodable<T>(_ type: T.Type, in wrappingType: Any.Type) {
guard T.self is Encodable.Type else {
if T.self == Encodable.self || T.self == Codable.self {
preconditionFailure("\(wrappingType) does not conform to Encodable because Encodable does not conform to itself. You must use a concrete type to encode or decode.")
} else {
preconditionFailure("\(wrappingType) does not conform to Encodable because \(T.self) does not conform to Encodable.")
}
}
}
}
extension OrderedDictionary: Decodable {
/// __inheritdoc__
public init(from decoder: Decoder) throws {
// Since Swift 4.0 lacks the protocol conditional conformance support, we have to make the
// whole OrderedDictionary type conform to Decodable and assert that the key and value
// types conform to Decodable. Furthermore, we leverage a trick of super decoders to be
// able to decode objects without knowing their exact types. This trick was used in the
// standard library for encoding/decoding Dictionary before Swift 4.1.
self.init()
_assertTypeIsDecodable(Key.self, in: type(of: self))
_assertTypeIsDecodable(Value.self, in: type(of: self))
var container = try decoder.unkeyedContainer()
let keyMetaType = (Key.self as! Decodable.Type)
let valueMetaType = (Value.self as! Decodable.Type)
while !container.isAtEnd {
let keyDecoder = try container.superDecoder()
let key = try keyMetaType.init(from: keyDecoder) as! Key
guard !container.isAtEnd else { throw DecodingError.unkeyedContainerReachedEndBeforeValue(decoder.codingPath) }
let valueDecoder = try container.superDecoder()
let value = try valueMetaType.init(from: valueDecoder) as! Value
self[key] = value
}
}
private func _assertTypeIsDecodable<T>(_ type: T.Type, in wrappingType: Any.Type) {
guard T.self is Decodable.Type else {
if T.self == Decodable.self || T.self == Codable.self {
preconditionFailure("\(wrappingType) does not conform to Decodable because Decodable does not conform to itself. You must use a concrete type to encode or decode.")
} else {
preconditionFailure("\(wrappingType) does not conform to Decodable because \(T.self) does not conform to Decodable.")
}
}
}
}
#endif
extension DecodingError {
fileprivate static func unkeyedContainerReachedEndBeforeValue(
_ codingPath: [CodingKey]
) -> DecodingError {
return DecodingError.dataCorrupted(
DecodingError.Context(
codingPath: codingPath,
debugDescription: "Unkeyed container reached end before value in key-value pair."
)
)
}
}
-677
View File
@@ -1,677 +0,0 @@
/// A generic collection for storing key-value pairs in an ordered manner.
///
/// Same as in a dictionary all keys in the collection are unique and have an associated value.
/// Same as in an array, all key-value pairs (elements) are kept sorted and accessible by
/// a zero-based integer index.
public struct OrderedDictionary<Key: Hashable, Value>: BidirectionalCollection {
// ======================================================= //
// MARK: - Type Aliases
// ======================================================= //
/// The type of the key-value pair stored in the ordered dictionary.
public typealias Element = (key: Key, value: Value)
/// The type of the index.
public typealias Index = Int
/// The type of the indices collection.
public typealias Indices = CountableRange<Int>
/// The type of the contiguous subrange of the ordered dictionary's elements.
///
/// - SeeAlso: OrderedDictionarySlice
public typealias SubSequence = OrderedDictionarySlice<Key, Value>
// ======================================================= //
// MARK: - Initialization
// ======================================================= //
/// Creates an empty ordered dictionary.
public init() {}
/// Creates an ordered dictionary from a sequence of values keyed by a key which gets extracted
/// from the value in the provided closure.
///
/// - Parameter values: The sequence of values.
/// - Parameter getKey: The closure which provides a key for the given value from the values
/// sequence.
public init<Values: Sequence>(
values: Values,
keyedBy getKey: (Value) -> Key
) where Values.Element == Value {
self.init(values.map { (getKey($0), $0) })
}
/// Creates an ordered dictionary from a sequence of values keyed by a key loaded from the value
/// at the given key path.
///
/// - Parameter values: The sequence of values.
/// - Parameter keyPath: The key path for the value to locate its key at.
public init(values: [Value], keyedBy keyPath: KeyPath<Value, Key>) {
self.init(values.map { ($0[keyPath: keyPath], $0) })
}
/// Creates an ordered dictionary from a regular unsorted dictionary by sorting it using the
/// the given sort function.
///
/// - Parameter unsorted: The unsorted dictionary.
/// - Parameter areInIncreasingOrder: The sort function which compares the key-value pairs.
public init(
unsorted: Dictionary<Key, Value>,
areInIncreasingOrder: (Element, Element) throws -> Bool
) rethrows {
let elements = try unsorted
.map { (key: $0.key, value: $0.value) }
.sorted(by: areInIncreasingOrder)
self.init(elements)
}
/// Creates an ordered dictionary from a sequence of key-value pairs.
///
/// - Parameter elements: The key-value pairs that will make up the new ordered dictionary.
/// Each key in `elements` must be unique.
public init<S: Sequence>(_ elements: S) where S.Element == Element {
for (key, value) in elements {
precondition(!containsKey(key), "Elements sequence contains duplicate keys")
self[key] = value
}
}
// ======================================================= //
// MARK: - Ordered Keys & Values
// ======================================================= //
/// A collection containing just the keys of the ordered dictionary in the correct order.
public var orderedKeys: OrderedDictionaryKeys<Key, Value> {
return self.lazy.map { $0.key }
}
/// A collection containing just the values of the ordered dictionary in the correct order.
public var orderedValues: OrderedDictionaryValues<Key, Value> {
return self.lazy.map { $0.value }
}
// ======================================================= //
// MARK: - Dictionary
// ======================================================= //
/// Converts itself to a common unsorted dictionary.
public var unorderedDictionary: Dictionary<Key, Value> {
return _keysToValues
}
// ======================================================= //
// MARK: - Indices
// ======================================================= //
/// The indices that are valid for subscripting the ordered dictionary.
public var indices: Indices {
return _orderedKeys.indices
}
/// The position of the first key-value pair in a non-empty ordered dictionary.
public var startIndex: Index {
return _orderedKeys.startIndex
}
/// The position which is one greater than the position of the last valid key-value pair in the
/// ordered dictionary.
public var endIndex: Index {
return _orderedKeys.endIndex
}
/// Returns the position immediately after the given index.
public func index(after i: Index) -> Index {
return _orderedKeys.index(after: i)
}
/// Returns the position immediately before the given index.
public func index(before i: Index) -> Index {
return _orderedKeys.index(before: i)
}
// ======================================================= //
// MARK: - Slices
// ======================================================= //
/// Accesses a contiguous subrange of the ordered dictionary.
///
/// - Parameter bounds: A range of the ordered dictionary's indices. The bounds of the range
/// must be valid indices of the ordered dictionary.
/// - Returns: The slice view at the ordered dictionary in the specified subrange.
public subscript(bounds: Range<Index>) -> SubSequence {
return OrderedDictionarySlice(base: self, bounds: bounds)
}
// ======================================================= //
// MARK: - Key-based Access
// ======================================================= //
/// Accesses the value associated with the given key for reading and writing.
///
/// This key-based subscript returns the value for the given key if the key is found in the
/// ordered dictionary, or `nil` if the key is not found.
///
/// When you assign a value for a key and that key already exists, the ordered dictionary
/// overwrites the existing value and preservers the index of the key-value pair. If the ordered
/// dictionary does not contain the key, a new key-value pair is appended to the end of the
/// ordered dictionary.
///
/// If you assign `nil` as the value for the given key, the ordered dictionary removes that key
/// and its associated value if it exists.
///
/// - Parameter key: The key to find in the ordered dictionary.
/// - Returns: The value associated with `key` if `key` is in the ordered dictionary; otherwise,
/// `nil`.
public subscript(key: Key) -> Value? {
get {
return value(forKey: key)
}
set(newValue) {
if let newValue = newValue {
updateValue(newValue, forKey: key)
} else {
removeValue(forKey: key)
}
}
}
/// Returns a Boolean value indicating whether the ordered dictionary contains the given key.
///
/// - Parameter key: The key to be looked up.
/// - Returns: `true` if the ordered dictionary contains the given key; otherwise, `false`.
public func containsKey(_ key: Key) -> Bool {
return _keysToValues[key] != nil
}
/// Returns the value associated with the given key if the key is found in the ordered
/// dictionary, or `nil` if the key is not found.
///
/// - Parameter key: The key to find in the ordered dictionary.
/// - Returns: The value associated with `key` if `key` is in the ordered dictionary; otherwise,
/// `nil`.
public func value(forKey key: Key) -> Value? {
return _keysToValues[key]
}
/// Updates the value stored in the ordered dictionary for the given key, or appends a new
/// key-value pair if the key does not exist.
///
/// - Parameter value: The new value to add to the ordered dictionary.
/// - Parameter key: The key to associate with `value`. If `key` already exists in the ordered
/// dictionary, `value` replaces the existing associated value. If `key` is not already a key
/// of the ordered dictionary, the `(key, value)` pair is appended at the end of the ordered
/// dictionary.
@discardableResult
public mutating func updateValue(_ value: Value, forKey key: Key) -> Value? {
if containsKey(key) {
let currentValue = _unsafeValue(forKey: key)
_keysToValues[key] = value
return currentValue
} else {
_orderedKeys.append(key)
_keysToValues[key] = value
return nil
}
}
/// Removes the given key and its associated value from the ordered dictionary.
///
/// If the key is found in the ordered dictionary, this method returns the key's associated
/// value. On removal, the indices of the ordered dictionary are invalidated. If the key is
/// not found in the ordered dictionary, this method returns `nil`.
///
/// - Parameter key: The key to remove along with its associated value.
/// - Returns: The value that was removed, or `nil` if the key was not present in the
/// ordered dictionary.
///
/// - SeeAlso: remove(at:)
@discardableResult
public mutating func removeValue(forKey key: Key) -> Value? {
guard let index = index(forKey: key) else { return nil }
let currentValue = self[index].value
_orderedKeys.remove(at: index)
_keysToValues[key] = nil
return currentValue
}
/// Removes all key-value pairs from the ordered dictionary and invalidates all indices.
///
/// - Parameter keepCapacity: Whether the ordered dictionary should keep its underlying storage.
/// If you pass `true`, the operation preserves the storage capacity that the collection has,
/// otherwise the underlying storage is released. The default is `false`.
public mutating func removeAll(keepingCapacity keepCapacity: Bool = false) {
_orderedKeys.removeAll(keepingCapacity: keepCapacity)
_keysToValues.removeAll(keepingCapacity: keepCapacity)
}
private func _unsafeValue(forKey key: Key) -> Value {
let value = _keysToValues[key]
precondition(value != nil, "Inconsistency error occurred in OrderedDictionary")
return value!
}
// ======================================================= //
// MARK: - Index-based Access
// ======================================================= //
/// Accesses the key-value pair at the specified position.
///
/// The specified position has to be a valid index of the ordered dictionary. The index-base
/// subscript returns the key-value pair corresponding to the index.
///
/// - Parameter position: The position of the key-value pair to access. `position` must be
/// a valid index of the ordered dictionary and not equal to `endIndex`.
/// - Returns: A tuple containing the key-value pair corresponding to `position`.
///
/// - SeeAlso: update(:at:)
public subscript(position: Index) -> Element {
precondition(indices.contains(position), "OrderedDictionary index is out of range")
let key = _orderedKeys[position]
let value = _unsafeValue(forKey: key)
return (key, value)
}
/// Returns the index for the given key.
///
/// - Parameter key: The key to find in the ordered dictionary.
/// - Returns: The index for `key` and its associated value if `key` is in the ordered
/// dictionary; otherwise, `nil`.
public func index(forKey key: Key) -> Index? {
return _orderedKeys.index(of: key)
}
/// Returns the key-value pair at the specified index, or `nil` if there is no key-value pair
/// at that index.
///
/// - Parameter index: The index of the key-value pair to be looked up. `index` does not have to
/// be a valid index.
/// - Returns: A tuple containing the key-value pair corresponding to `index` if the index is
/// valid; otherwise, `nil`.
public func elementAt(_ index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
}
/// Checks whether the given key-value pair can be inserted into to ordered dictionary by
/// validating the presence of the key.
///
/// - Parameter newElement: The key-value pair to be inserted into the ordered dictionary.
/// - Returns: `true` if the key-value pair can be safely inserted; otherwise, `false`.
///
/// - SeeAlso: canInsert(key:)
/// - SeeAlso: canInsert(at:)
@available(*, deprecated, message: "Use canInsert(key:) with the element's key instead")
public func canInsert(_ newElement: Element) -> Bool {
return canInsert(key: newElement.key)
}
/// Checks whether a key-value pair with the given key can be inserted into the ordered
/// dictionary by validating its presence.
///
/// - Parameter key: The key to be inserted into the ordered dictionary.
/// - Returns: `true` if the key can safely be inserted; ortherwise, `false`.
///
/// - SeeAlso: canInsert(at:)
public func canInsert(key: Key) -> Bool {
return !containsKey(key)
}
/// Checks whether a new key-value pair can be inserted into the ordered dictionary at the
/// given index.
///
/// - Parameter index: The index the new key-value pair should be inserted at.
/// - Returns: `true` if a new key-value pair can be inserted at the specified index; otherwise,
/// `false`.
///
/// - SeeAlso: canInsert(key:)
public func canInsert(at index: Index) -> Bool {
return index >= startIndex && index <= endIndex
}
/// Inserts a new key-value pair at the specified position.
///
/// If the key of the inserted pair already exists in the ordered dictionary, a runtime error
/// is triggered. Use `canInsert(_:)` for performing a check first, so that this method can
/// be executed safely.
///
/// - Parameter newElement: The new key-value pair to insert into the ordered dictionary. The
/// key contained in the pair must not be already present in the ordered dictionary.
/// - Parameter index: The position at which to insert the new key-value pair. `index` must be
/// a valid index of the ordered dictionary or equal to `endIndex` property.
///
/// - SeeAlso: canInsert(key:)
/// - SeeAlso: canInsert(at:)
/// - SeeAlso: update(:at:)
public mutating func insert(_ newElement: Element, at index: Index) {
precondition(canInsert(key: newElement.key), "Cannot insert duplicate key in OrderedDictionary")
precondition(canInsert(at: index), "Cannot insert at invalid index in OrderedDictionary")
let (key, value) = newElement
_orderedKeys.insert(key, at: index)
_keysToValues[key] = value
}
/// Checks whether the key-value pair at the given index can be updated with the given key-value
/// pair. This is not the case if the key of the updated element is already present in the
/// ordered dictionary and located at another index than the updated one.
///
/// Although this is a checking method, a valid index has to be provided.
///
/// - Parameter newElement: The key-value pair to be set at the specified position.
/// - Parameter index: The position at which to set the key-value pair. `index` must be a valid
/// index of the ordered dictionary.
public func canUpdate(_ newElement: Element, at index: Index) -> Bool {
var keyPresentAtIndex = false
return _canUpdate(newElement, at: index, keyPresentAtIndex: &keyPresentAtIndex)
}
/// Updates the key-value pair located at the specified position.
///
/// If the key of the updated pair already exists in the ordered dictionary *and* is located at
/// a different position than the specified one, a runtime error is triggered. Use
/// `canUpdate(_:at:)` for performing a check first, so that this method can be executed safely.
///
/// - Parameter newElement: The key-value pair to be set at the specified position.
/// - Parameter index: The position at which to set the key-value pair. `index` must be a valid
/// index of the ordered dictionary.
///
/// - SeeAlso: canUpdate(_:at:)
/// - SeeAlso: insert(:at:)
@discardableResult
public mutating func update(_ newElement: Element, at index: Index) -> Element? {
// Store the flag indicating whether the key of the inserted element
// is present at the updated index
var keyPresentAtIndex = false
precondition(
_canUpdate(newElement, at: index, keyPresentAtIndex: &keyPresentAtIndex),
"OrderedDictionary update duplicates key"
)
// Decompose the element
let (key, value) = newElement
// Load the current element at the index
let replacedElement = self[index]
// If its key differs, remove its associated value
if (!keyPresentAtIndex) {
_keysToValues.removeValue(forKey: replacedElement.key)
}
// Store the new position of the key and the new value associated with the key
_orderedKeys[index] = key
_keysToValues[key] = value
return replacedElement
}
/// Removes and returns the key-value pair at the specified position if there is any key-value
/// pair, or `nil` if there is none.
///
/// - Parameter index: The position of the key-value pair to remove.
/// - Returns: The element at the specified index, or `nil` if the position is not taken.
///
/// - SeeAlso: removeValue(forKey:)
@discardableResult
public mutating func remove(at index: Index) -> Element? {
guard let element = elementAt(index) else { return nil }
_orderedKeys.remove(at: index)
_keysToValues.removeValue(forKey: element.key)
return element
}
private func _canUpdate(
_ newElement: Element,
at index: Index,
keyPresentAtIndex: inout Bool
) -> Bool {
precondition(indices.contains(index), "OrderedDictionary index is out of range")
let currentIndexOfKey = self.index(forKey: newElement.key)
let keyNotPresent = currentIndexOfKey == nil
keyPresentAtIndex = currentIndexOfKey == index
return keyNotPresent || keyPresentAtIndex
}
// ======================================================= //
// MARK: - Removing First & Last Elements
// ======================================================= //
/// Removes and returns the first key-value pair of the ordered dictionary if it is not empty.
public mutating func popFirst() -> Element? {
guard !isEmpty else { return nil }
return remove(at: startIndex)
}
/// Removes and returns the last key-value pair of the ordered dictionary if it is not empty.
public mutating func popLast() -> Element? {
guard !isEmpty else { return nil }
return remove(at: index(before: endIndex))
}
/// Removes and returns the first key-value pair of the ordered dictionary.
public mutating func removeFirst() -> Element {
precondition(!isEmpty, "Cannot remove key-value pairs from empty OrderedDictionary")
return remove(at: startIndex)!
}
/// Removes and returns the last key-value pair of the ordered dictionary.
public mutating func removeLast() -> Element {
precondition(!isEmpty, "Cannot remove key-value pairs from empty OrderedDictionary")
return remove(at: index(before: endIndex))!
}
// ======================================================= //
// MARK: - Moving Elements
// ======================================================= //
/// Moves an existing key-value pair specified by the given key to the new index by removing it
/// from its original index first and inserting it at the new index. If the movement is
/// actually performed, the previous index of the key-value pair is returned. Otherwise, `nil`
/// is returned.
///
/// - Parameter key: The key specifying the key-value pair to move.
/// - Parameter newIndex: The new index the key-value pair should be moved to.
/// - Returns: The previous index of the key-value pair if it was sucessfully moved.
@discardableResult
public mutating func moveElement(forKey key: Key, to newIndex: Index) -> Index? {
// Load the previous index and return nil if the index is not found.
guard let previousIndex = index(forKey: key) else { return nil }
// If the previous and new indices match, threat it as if the movement was already
// performed.
guard previousIndex != newIndex else { return previousIndex }
// Remove the value for the key at its original index.
let value = removeValue(forKey: key)!
// Validate the new index.
precondition(canInsert(at: newIndex), "Cannot move to invalid index in OrderedDictionary")
// Insert the element at the new index.
insert((key: key, value: value), at: newIndex)
return previousIndex
}
// ======================================================= //
// MARK: - Sorting Elements
// ======================================================= //
/// Sorts the ordered dictionary in place, using the given predicate as the comparison between
/// elements.
///
/// The predicate must be a *strict weak ordering* over the elements.
///
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its first argument
/// should be ordered before its second argument; otherwise, `false`.
///
/// - SeeAlso: MutableCollection.sort(by:), sorted(by:)
public mutating func sort(
by areInIncreasingOrder: (Element, Element) throws -> Bool
) rethrows {
_orderedKeys = try _sortedElements(by: areInIncreasingOrder).map { $0.key }
}
/// Returns a new ordered dictionary, sorted using the given predicate as the comparison between
/// elements.
///
/// The predicate must be a *strict weak ordering* over the elements.
///
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its first argument
/// should be ordered before its second argument; otherwise, `false`.
/// - Returns: A new ordered dictionary sorted according to the predicate.
///
/// - SeeAlso: MutableCollection.sorted(by:), sort(by:)
/// - MutatingVariant: sort
public func sorted(
by areInIncreasingOrder: (Element, Element) throws -> Bool
) rethrows -> OrderedDictionary<Key, Value> {
return OrderedDictionary(try _sortedElements(by: areInIncreasingOrder))
}
private func _sortedElements(
by areInIncreasingOrder: (Element, Element) throws -> Bool
) rethrows -> [Element] {
return try sorted(by: areInIncreasingOrder)
}
// ======================================================= //
// MARK: - Internal Storage
// ======================================================= //
/// The backing storage for the ordered keys.
fileprivate var _orderedKeys = [Key]()
/// The backing storage for the mapping of keys to values.
fileprivate var _keysToValues = [Key: Value]()
}
// ======================================================= //
// MARK: - Subtypes
// ======================================================= //
#if swift(>=4.1)
/// A view into an ordered dictionary whose indices are a subrange of the indices of the ordered
/// dictionary.
public typealias OrderedDictionarySlice<Key: Hashable, Value> = Slice<OrderedDictionary<Key, Value>>
/// A collection containing the keys of the ordered dictionary.
///
/// Under the hood this is a lazily evaluated bidirectional collection deriving the keys from
/// the base ordered dictionary on-the-fly.
public typealias OrderedDictionaryKeys<Key: Hashable, Value> = LazyMapCollection<OrderedDictionary<Key, Value>, Key>
/// A collection containing the values of the ordered dictionary.
///
/// Under the hood this is a lazily evaluated bidirectional collection deriving the values from
/// the base ordered dictionary on-the-fly.
public typealias OrderedDictionaryValues<Key: Hashable, Value> = LazyMapCollection<OrderedDictionary<Key, Value>, Value>
#else
/// A view into an ordered dictionary whose indices are a subrange of the indices of the ordered
/// dictionary.
public typealias OrderedDictionarySlice<Key: Hashable, Value> = BidirectionalSlice<OrderedDictionary<Key, Value>>
/// A collection containing the keys of the ordered dictionary.
///
/// Under the hood this is a lazily evaluated bidirectional collection deriving the keys from
/// the base ordered dictionary on-the-fly.
public typealias OrderedDictionaryKeys<Key: Hashable, Value> = LazyMapBidirectionalCollection<OrderedDictionary<Key, Value>, Key>
/// A collection containing the values of the ordered dictionary.
///
/// Under the hood this is a lazily evaluated bidirectional collection deriving the values from
/// the base ordered dictionary on-the-fly.
public typealias OrderedDictionaryValues<Key: Hashable, Value> = LazyMapBidirectionalCollection<OrderedDictionary<Key, Value>, Value>
#endif
// ======================================================= //
// MARK: - Literals
// ======================================================= //
extension OrderedDictionary: ExpressibleByArrayLiteral {
/// Creates an ordered dictionary initialized from an array literal containing a list of
/// key-value pairs.
public init(arrayLiteral elements: Element...) {
self.init(elements)
}
}
extension OrderedDictionary: ExpressibleByDictionaryLiteral {
/// Creates an ordered dictionary initialized from a dictionary literal.
public init(dictionaryLiteral elements: (Key, Value)...) {
self.init(elements.map { element in
let (key, value) = element
return (key: key, value: value)
})
}
}
// ======================================================= //
// MARK: - Equatable Conformance
// ======================================================= //
#if swift(>=4.1)
extension OrderedDictionary: Equatable where Value: Equatable {}
#endif
extension OrderedDictionary where Value: Equatable {
/// Returns a Boolean value that indicates whether the two given ordered dictionaries with
/// equatable values are equal.
public static func == (lhs: OrderedDictionary, rhs: OrderedDictionary) -> Bool {
return lhs._orderedKeys == rhs._orderedKeys
&& lhs._keysToValues == rhs._keysToValues
}
}
// ======================================================= //
// MARK: - Dictionary Extension
// ======================================================= //
extension Dictionary {
/// Returns an ordered dictionary containing the key-value pairs from the dictionary, sorted
/// using the given sort function.
///
/// - Parameter areInIncreasingOrder: The sort function which compares the key-value pairs.
/// - Returns: The ordered dictionary.
/// - SeeAlso: OrderedDictionary.init(unsorted:areInIncreasingOrder:)
public func sorted(
by areInIncreasingOrder: (Element, Element) throws -> Bool
) rethrows -> OrderedDictionary<Key, Value> {
return try OrderedDictionary(
unsorted: self,
areInIncreasingOrder: areInIncreasingOrder
)
}
}
@@ -0,0 +1,20 @@
extension Dictionary {
/// Returns an ordered dictionary containing the key-value pairs from the dictionary, sorted
/// using the given sort function.
///
/// - Parameters:
/// - areInIncreasingOrder: The sort function which compares the key-value pairs.
/// - Returns: The ordered dictionary.
///
/// - SeeAlso: `OrderedDictionary.init(unsorted:areInIncreasingOrder:)`
public func sorted(
by areInIncreasingOrder: (Element, Element) throws -> Bool
) rethrows -> OrderedDictionary<Key, Value> {
return try OrderedDictionary(
unsorted: self,
areInIncreasingOrder: areInIncreasingOrder
)
}
}
@@ -0,0 +1,49 @@
extension OrderedDictionary: Encodable where Key: Encodable, Value: Encodable {
/// Encodes the contents of this ordered dictionary into the given encoder.
public func encode(to encoder: Encoder) throws {
// Encode the ordered dictionary as an array of alternating key-value pairs.
var container = encoder.unkeyedContainer()
for (key, value) in self {
try container.encode(key)
try container.encode(value)
}
}
}
extension OrderedDictionary: Decodable where Key: Decodable, Value: Decodable {
/// Creates a new ordered dictionary by decoding from the given decoder.
public init(from decoder: Decoder) throws {
// Decode the ordered dictionary from an array of alternating key-value pairs.
self.init()
var container = try decoder.unkeyedContainer()
while !container.isAtEnd {
let key = try container.decode(Key.self)
guard !container.isAtEnd else { throw DecodingError.unkeyedContainerReachedEndBeforeValue(decoder.codingPath) }
let value = try container.decode(Value.self)
self[key] = value
}
}
}
extension DecodingError {
fileprivate static func unkeyedContainerReachedEndBeforeValue(
_ codingPath: [CodingKey]
) -> DecodingError {
return DecodingError.dataCorrupted(
DecodingError.Context(
codingPath: codingPath,
debugDescription: "Unkeyed container reached end before value in key-value pair."
)
)
}
}
@@ -0,0 +1,81 @@
extension OrderedDictionary {
// ============================================================================ //
// MARK: - Initialization
// ============================================================================ //
@available(*, deprecated, message: "Please use init(values:uniquelyKeyedBy:).", renamed: "init(values:uniquelyKeyedBy:)")
public init<S: Sequence>(
values: S,
keyedBy extractKey: (Value) -> Key
) where S.Element == Value {
self.init(values: values, uniquelyKeyedBy: extractKey)
}
@available(*, deprecated, message: "Please use init(values:uniquelyKeyedBy:).", renamed: "init(values:uniquelyKeyedBy:)")
public init(
values: [Value],
keyedBy keyPath: KeyPath<Value, Key>
) {
self.init(values: values, uniquelyKeyedBy: keyPath)
}
@available(*, deprecated, message: "Please use init(uniqueKeysWithValues:).", renamed: "init(uniqueKeysWithValues:)")
public init<S: Sequence>(_ elements: S) where S.Element == Element {
self.init(uniqueKeysWithValues: elements)
}
// ============================================================================ //
// MARK: - Insertion Checks
// ============================================================================ //
/// Checks whether the given key-value pair can be inserted into to ordered dictionary
/// by validating the presence of the key.
///
/// - Parameters:
/// - newElement: The key-value pair to be inserted into the ordered dictionary.
/// - Returns: `true` if the key-value pair can be safely inserted; otherwise, `false`.
///
/// - SeeAlso: `canInsert(key:)`
/// - SeeAlso: `canInsert(at:)`
@available(*, deprecated, message: "Use canInsert(key:) with the element's key instead.")
public func canInsert(_ newElement: Element) -> Bool {
return canInsert(key: newElement.key)
}
// ============================================================================ //
// MARK: - Moving Elements
// ============================================================================ //
/// Moves an existing key-value pair specified by the given key to the new index by removing
/// it from its original index first and inserting it at the new index. If the movement is
/// actually performed, the previous index of the key-value pair is returned. Otherwise, `nil`
/// is returned.
///
/// - Parameters:
/// - key: The key specifying the key-value pair to move.
/// - newIndex: The new index the key-value pair should be moved to.
/// - Returns: The previous index of the key-value pair if it was sucessfully moved.
@available(*, deprecated, message: "Since the concrete behavior of the element movement highly depends on concrete use cases, its official support will be dropped in the future. Please use the public API for modeling a move operation instead.")
@discardableResult
public mutating func moveElement(forKey key: Key, to newIndex: Index) -> Index? {
// Load the previous index and return nil if the index is not found.
guard let previousIndex = index(forKey: key) else { return nil }
// If the previous and new indices match, treat it as if the movement was already
// performed.
guard previousIndex != newIndex else { return previousIndex }
// Remove the value for the key at its original index.
let value = removeValue(forKey: key)!
// Validate the new index.
precondition(canInsert(at: newIndex), "Cannot move to invalid index in OrderedDictionary")
// Insert the element at the new index.
insert((key: key, value: value), at: newIndex)
return previousIndex
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,105 @@
public struct OrderedDictionarySlice<Key: Hashable, Value>: RandomAccessCollection, MutableCollection {
// ============================================================================ //
// MARK: - Type Aliases
// ============================================================================ //
/// The type of the underlying ordered dictionary.
public typealias Base = OrderedDictionary<Key, Value>
/// The type of the contiguous subrange of the ordered dictionary's elements.
public typealias SubSequence = Self
// ============================================================================ //
// MARK: - Initialization
// ============================================================================ //
public init(base: Base, bounds: Base.Indices) {
self.base = base
self.startIndex = bounds.lowerBound
self.endIndex = bounds.upperBound
}
// ============================================================================ //
// MARK: - Base
// ============================================================================ //
/// The underlying ordered dictionary.
public private(set) var base: Base
// ============================================================================ //
// MARK: - Indices
// ============================================================================ //
/// The start index.
public let startIndex: Base.Index
/// The end index.
public let endIndex: Base.Index
// ============================================================================ //
// MARK: - Subscripts
// ============================================================================ //
public subscript(
position: Base.Index
) -> Base.Element {
get {
base[position]
}
set(newElement) {
base[position] = newElement
}
}
public subscript(
bounds: Range<Int>
) -> OrderedDictionarySlice<Key, Value> {
get {
base[bounds]
}
set(newElements) {
base[bounds] = newElements
}
}
// ============================================================================ //
// MARK: - Reordering Methods Overloads
// ============================================================================ //
public mutating func sort(
by areInIncreasingOrder: (Base.Element, Base.Element) throws -> Bool
) rethrows {
try base._sort(
in: indices,
by: areInIncreasingOrder
)
}
public mutating func reverse() {
base._reverse(in: indices)
}
public mutating func shuffle<T>(
using generator: inout T
) where T: RandomNumberGenerator {
base._shuffle(
in: indices,
using: &generator
)
}
public mutating func partition(
by belongsInSecondPartition: (Base.Element) throws -> Bool
) rethrows -> Index {
return try base._partition(
in: indices,
by: belongsInSecondPartition
)
}
public mutating func swapAt(_ i: Base.Index, _ j: Base.Index) {
base.swapAt(i, j)
}
}
+2 -2
View File
@@ -15,13 +15,13 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.2.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015-2019 Lukas Kubanek. All rights reserved.</string>
<string>Copyright © 2015-2021 Lukas Kubanek. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
+8
View File
@@ -0,0 +1,8 @@
import XCTest
import OrderedDictionaryTests
var tests = [XCTestCaseEntry]()
tests += OrderedDictionaryTests.__allTests()
XCTMain(tests)
-630
View File
@@ -1,630 +0,0 @@
import OrderedDictionary
import Foundation
import XCTest
#if !swift(>=4.1)
/// This is a shim for testing the equality in Swift <4.1.
public func XCTAssertEqual<K, V: Equatable>(
_ expression1: OrderedDictionary<K, V>,
_ expression2: OrderedDictionary<K, V>,
_ message: @autoclosure () -> String = "",
file: StaticString = #file,
line: UInt = #line
) {
return XCTAssertTrue(
expression1 == expression2,
message,
file: file,
line: line
)
}
#endif
struct TestValue: Equatable {
var string: String
static func == (lhs: TestValue, rhs: TestValue) -> Bool {
return lhs.string == rhs.string
}
}
class OrderedDictionaryTests: XCTestCase {
// ======================================================= //
// MARK: - Initialization
// ======================================================= //
func testInitializationUsingArrayLiteral() {
let actual: OrderedDictionary<String, Int> = [
("A", 1),
("B", 2),
("C", 3)
]
let expected = OrderedDictionary<String, Int>([
(key: "A", value: 1),
(key: "B", value: 2),
(key: "C", value: 3)
])
XCTAssertEqual(actual, expected)
}
func testInitializationUsingDictionaryLiteral() {
let actual: OrderedDictionary<String, Int> = [
"A": 1,
"B": 2,
"C": 3
]
let expected = OrderedDictionary<String, Int>([
(key: "A", value: 1),
(key: "B", value: 2),
(key: "C", value: 3)
])
XCTAssertEqual(actual, expected)
}
func testInitializationUsingValuesAndKeyProviderClosure() {
let actual = OrderedDictionary(
values: [1, 2, 3],
keyedBy: { "\($0)" }
)
let expected = OrderedDictionary<String, Int>([
(key: "1", value: 1),
(key: "2", value: 2),
(key: "3", value: 3)
])
XCTAssertEqual(actual, expected)
}
func testInitializationUsingValuesAnyKeyPath() {
let actual = OrderedDictionary(
values: [
TestValue(string: "A"),
TestValue(string: "B"),
TestValue(string: "C")
],
keyedBy: \.string
)
let expected = OrderedDictionary<String, TestValue>([
(key: "A", value: TestValue(string: "A")),
(key: "B", value: TestValue(string: "B")),
(key: "C", value: TestValue(string: "C"))
])
XCTAssertEqual(actual, expected)
}
func testInitializationUsingUnsortedDictionaryAndSortFunction() {
let actual = OrderedDictionary(
unsorted: [
2: "foo",
1: "bar",
4: "baz",
5: "bat",
3: "bam"
],
areInIncreasingOrder: { $0.key < $1.key }
)
let expected = OrderedDictionary([
(key: 1, value: "bar"),
(key: 2, value: "foo"),
(key: 3, value: "bam"),
(key: 4, value: "baz"),
(key: 5, value: "bat")
])
XCTAssertEqual(actual, expected)
}
func testCreationFromDictionary() {
let actual = [
2: "foo",
1: "bar",
4: "baz",
5: "bat",
3: "bam"
].sorted(by: { $0.key < $1.key })
let expected = OrderedDictionary([
(key: 1, value: "bar"),
(key: 2, value: "foo"),
(key: 3, value: "bam"),
(key: 4, value: "baz"),
(key: 5, value: "bat")
])
XCTAssertEqual(actual, expected)
}
// ======================================================= //
// MARK: - Content Access
// ======================================================= //
func testAccessingContent() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
XCTAssertEqual(orderedDictionary.count, 3)
XCTAssertEqual(orderedDictionary["A"], 1)
XCTAssertEqual(orderedDictionary.value(forKey: "A"), 1)
XCTAssertEqual(orderedDictionary.index(forKey: "A"), 0)
XCTAssertTrue(orderedDictionary.containsKey("A"))
XCTAssertTrue(orderedDictionary[0] == ("A", 1))
XCTAssertEqual(orderedDictionary["B"], 2)
XCTAssertEqual(orderedDictionary.value(forKey: "B"), 2)
XCTAssertEqual(orderedDictionary.index(forKey: "B"), 1)
XCTAssertTrue(orderedDictionary.containsKey("B"))
XCTAssertTrue(orderedDictionary[1] == ("B", 2))
XCTAssertEqual(orderedDictionary["C"], 3)
XCTAssertEqual(orderedDictionary.value(forKey: "C"), 3)
XCTAssertEqual(orderedDictionary.index(forKey: "C"), 2)
XCTAssertTrue(orderedDictionary.containsKey("C"))
XCTAssertTrue(orderedDictionary[2] == ("C", 3))
}
func testCreatingIterator() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
var iterator = orderedDictionary.makeIterator()
let indexes = [0, 1, 2]
var indexesIterator = indexes.makeIterator()
while let (actualKey, actualValue) = iterator.next() {
let index = indexesIterator.next()
let (expectedKey, expectedValue) = orderedDictionary[index!]
XCTAssertEqual(actualKey, expectedKey)
XCTAssertEqual(actualValue, expectedValue)
}
XCTAssertNil(iterator.next())
XCTAssertNil(indexesIterator.next())
}
func testAccessingOrderedKeys() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let actual = Array(orderedDictionary.orderedKeys)
let expected = ["A", "B", "C"]
XCTAssertEqual(actual, expected)
}
func testAccessingOrderedValues() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let actual = Array(orderedDictionary.orderedValues)
let expected = [1, 2, 3]
XCTAssertEqual(actual, expected)
}
func testAccessingUnsortedDictionary() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let actual = orderedDictionary.unorderedDictionary
let expected = ["A": 1, "B": 2, "C": 3]
XCTAssertEqual(actual, expected)
}
// ======================================================= //
// MARK: - Key-based Modifications
// ======================================================= //
func testKeyBasedModifications() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
orderedDictionary["A"] = 5
orderedDictionary["D"] = 10
orderedDictionary["B"] = nil
XCTAssertEqual(orderedDictionary.count, 3)
XCTAssertEqual(orderedDictionary["A"], 5)
XCTAssertEqual(orderedDictionary.index(forKey: "A"), 0)
XCTAssertTrue(orderedDictionary.containsKey("A"))
XCTAssertNil(orderedDictionary["B"])
XCTAssertNil(orderedDictionary.index(forKey: "B"))
XCTAssertFalse(orderedDictionary.containsKey("B"))
XCTAssertEqual(orderedDictionary["C"], 3)
XCTAssertEqual(orderedDictionary.index(forKey: "C"), 1)
XCTAssertTrue(orderedDictionary.containsKey("C"))
XCTAssertEqual(orderedDictionary["D"], 10)
XCTAssertEqual(orderedDictionary.index(forKey: "D"), 2)
XCTAssertTrue(orderedDictionary.containsKey("D"))
}
// ======================================================= //
// MARK: - Index-based Insertions
// ======================================================= //
func testIndexBasedInsertionsWithUniqueKeys() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
orderedDictionary.insert((key: "T", value: 15), at: 0)
orderedDictionary.insert((key: "U", value: 16), at: 2)
orderedDictionary.insert((key: "V", value: 17), at: 5)
orderedDictionary.insert((key: "W", value: 18), at: 2)
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["T": 15, "A": 1, "W": 18, "U": 16, "B": 2, "C": 3, "V": 17]
XCTAssertEqual(actual, expected)
}
func testIndexBasedInsertionWithDuplicateKey() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let invalidKey = "A"
XCTAssertFalse(orderedDictionary.canInsert(key: invalidKey))
}
func testIndexBasedInsertionWithNegativeIndex() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let invalidIndex = -1
XCTAssertFalse(orderedDictionary.canInsert(at: invalidIndex))
}
func testIndexBasedInsertionWithIndexOutOfBounds() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let invalidIndex = 4
XCTAssertFalse(orderedDictionary.canInsert(at: invalidIndex))
}
// ======================================================= //
// MARK: - Index-based Updates
// ======================================================= //
func testIndexBasedUpdateMethodWithNewUniqueKey() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let previousElement = orderedDictionary.update((key: "D", value: 4), at: 1)
XCTAssertEqual(orderedDictionary.count, 3)
XCTAssertTrue(previousElement! == ("B", 2))
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["A": 1, "D": 4, "C": 3]
XCTAssertEqual(actual, expected)
}
func testIndexBasedUpdateMethodByReplacingSameKey() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let previousElement = orderedDictionary.update((key: "B", value: 42), at: 1)
XCTAssertEqual(orderedDictionary.count, 3)
XCTAssertTrue(previousElement! == ("B", 2))
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["A": 1, "B": 42, "C": 3]
XCTAssertEqual(actual, expected)
}
func testIndexBasedUpdateMethodByDuplicatingKey() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let element = (key: "A", value: 42)
XCTAssertTrue(orderedDictionary.canUpdate(element, at: 0))
XCTAssertFalse(orderedDictionary.canUpdate(element, at: 1))
XCTAssertFalse(orderedDictionary.canUpdate(element, at: 2))
}
func testRetrievingElementAtNonExistentIndex() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
XCTAssertNil(orderedDictionary.elementAt(42))
}
// ======================================================= //
// MARK: - Content Removal
// ======================================================= //
func testRemoveAll() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
orderedDictionary.removeAll()
XCTAssertEqual(orderedDictionary.count, 0)
}
func testKeyBasedRemoval() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
let removedValue1 = orderedDictionary.removeValue(forKey: "A")
let removedValue2 = orderedDictionary.removeValue(forKey: "K")
XCTAssertEqual(removedValue1, 1)
XCTAssertNil(removedValue2)
XCTAssertEqual(orderedDictionary.count, 2)
XCTAssertNil(orderedDictionary["A"])
XCTAssertNil(orderedDictionary.index(forKey: "A"))
XCTAssertEqual(orderedDictionary["B"], 2)
XCTAssertEqual(orderedDictionary.index(forKey: "B"), 0)
XCTAssertEqual(orderedDictionary["C"], 3)
XCTAssertEqual(orderedDictionary.index(forKey: "C"), 1)
}
func testIndexBasedRemoval() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
let (actualKey1, actualValue1) = orderedDictionary.remove(at: 0)!
let (expectedKey1, expectedValue1) = ("A", 1)
XCTAssertEqual(actualKey1, expectedKey1)
XCTAssertEqual(actualValue1, expectedValue1)
let (actualKey2, actualValue2) = orderedDictionary.remove(at: 2)!
let (expectedKey2, expectedValue2) = ("D", 4)
XCTAssertEqual(actualKey2, expectedKey2)
XCTAssertEqual(actualValue2, expectedValue2)
let nonExistentElement = orderedDictionary.remove(at: 42)
XCTAssertNil(nonExistentElement)
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["B": 2, "C": 3]
XCTAssertEqual(actual, expected)
}
func testPopFirstEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = []
let first = orderedDictionary.popFirst()
XCTAssertNil(first)
}
func testPopFirstNonEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
let (actualKey, actualValue) = orderedDictionary.popFirst()!
let (expectedKey, expectedValue) = ("A", 1)
XCTAssertEqual(actualKey, expectedKey)
XCTAssertEqual(actualValue, expectedValue)
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["B": 2, "C": 3, "D": 4]
XCTAssertEqual(actual, expected)
}
func testPopLastEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = []
let last = orderedDictionary.popLast()
XCTAssertNil(last)
}
func testPopLastNonEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
let (actualKey, actualValue) = orderedDictionary.popLast()!
let (expectedKey, expectedValue) = ("D", 4)
XCTAssertEqual(actualKey, expectedKey)
XCTAssertEqual(actualValue, expectedValue)
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
XCTAssertEqual(actual, expected)
}
func testRemoveFirstNonEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
let (actualKey, actualValue) = orderedDictionary.removeFirst()
let (expectedKey, expectedValue) = ("A", 1)
XCTAssertEqual(actualKey, expectedKey)
XCTAssertEqual(actualValue, expectedValue)
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["B": 2, "C": 3, "D": 4]
XCTAssertEqual(actual, expected)
}
func testRemoveLastNonEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
let (actualKey, actualValue) = orderedDictionary.removeLast()
let (expectedKey, expectedValue) = ("D", 4)
XCTAssertEqual(actualKey, expectedKey)
XCTAssertEqual(actualValue, expectedValue)
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3]
XCTAssertEqual(actual, expected)
}
// ======================================================= //
// MARK: - Moving Elements
// ======================================================= //
func testMovingElements() {
var orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
XCTAssertEqual(orderedDictionary.moveElement(forKey: "A", to: 2), 0) // B, C, A, D
XCTAssertEqual(orderedDictionary.moveElement(forKey: "D", to: 3), 3) // B, C, A, D
XCTAssertEqual(orderedDictionary.moveElement(forKey: "C", to: 0), 1) // C, B, A, D
XCTAssertEqual(orderedDictionary.moveElement(forKey: "B", to: 3), 1) // C, A, D, B
XCTAssertEqual(orderedDictionary.moveElement(forKey: "E", to: 0), nil)
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["C": 3, "A": 1, "D": 4, "B": 2]
XCTAssertEqual(actual, expected)
}
// ======================================================= //
// MARK: - Sorting Elements
// ======================================================= //
func testSortingWithMutation() {
var orderedDictionary: OrderedDictionary<String, Int> = ["E": 4, "G": 3, "A": 3, "D": 1, "B": 4]
orderedDictionary.sort { element1, element2 in
if element1.value != element2.value { return element1.value < element2.value }
return element1.key < element2.key
}
let actual = orderedDictionary
let expected: OrderedDictionary<String, Int> = ["D": 1, "A": 3, "G": 3, "B": 4, "E": 4]
XCTAssertEqual(actual, expected)
}
func testSortingWithoutMutation() {
let orderedDictionary: OrderedDictionary<String, Int> = ["E": 4, "G": 3, "A": 3, "D": 1, "B": 4]
let actual: OrderedDictionary<String, Int> = orderedDictionary.sorted { element1, element2 in
if element1.value != element2.value { return element1.value < element2.value }
return element1.key < element2.key
}
let expected: OrderedDictionary<String, Int> = ["D": 1, "A": 3, "G": 3, "B": 4, "E": 4]
XCTAssertEqual(actual, expected)
}
// ======================================================= //
// MARK: - Slices
// ======================================================= //
func testSliceAccess() {
let orderedDictionary: OrderedDictionary<String, Int> = ["A": 1, "B": 2, "C": 3, "D": 4]
let slice = orderedDictionary[2..<4]
XCTAssertEqual(slice.count, 2)
XCTAssertEqual(slice.startIndex, 2)
XCTAssertEqual(slice.endIndex, 4)
XCTAssertEqual(Array(slice.indices), [2, 3])
XCTAssert(slice[2] == (key: "C", value: 3))
XCTAssert(slice[3] == (key: "D", value: 4))
}
// ======================================================= //
// MARK: - Codable
// ======================================================= //
func testEncodingAndDecodingViaJSON() {
let orderedDictionary: OrderedDictionary<String, Int> = [
"A": 42,
"B": 100,
"C": 11
]
let jsonEncoder = JSONEncoder()
let data = try! jsonEncoder.encode(orderedDictionary)
let actualString = String(data: data, encoding: .utf8)
let expectedString = "[\"A\",42,\"B\",100,\"C\",11]"
XCTAssertEqual(actualString, expectedString)
let jsonDecoder = JSONDecoder()
let actual = try! jsonDecoder.decode(OrderedDictionary<String, Int>.self, from: data)
let expected = orderedDictionary
XCTAssertEqual(actual, expected)
}
func testEncodingAndDecodingViaPropertyList() {
let orderedDictionary: OrderedDictionary<String, Int> = [
"A": 42,
"B": 100,
"C": 11
]
let plistEncoder = PropertyListEncoder()
let data = try! plistEncoder.encode(orderedDictionary)
let plistDecoder = PropertyListDecoder()
let actual = try! plistDecoder.decode(OrderedDictionary<String, Int>.self, from: data)
let expected = orderedDictionary
XCTAssertEqual(actual, expected)
}
// ======================================================= //
// MARK: - Description
// ======================================================= //
struct DescribedValue: CustomStringConvertible, CustomDebugStringConvertible {
init(_ value: Int) { self.value = value }
let value: Int
var description: String { return "\(value)" }
var debugDescription: String { return "debug(\(value))" }
}
func testEmptyDescription() {
let orderedDictionary = OrderedDictionary<String, DescribedValue>()
let actual = orderedDictionary.description
let expected = "[:]"
XCTAssertEqual(actual, expected)
}
func testDescription() {
let orderedDictionary: OrderedDictionary<String, DescribedValue> = [
"A": DescribedValue(1),
"B": DescribedValue(2),
"C": DescribedValue(3)
]
let actual = orderedDictionary.description
let expected = "[A: 1, B: 2, C: 3]"
XCTAssertEqual(actual, expected)
}
func testEmptyDebugDescription() {
let orderedDictionary = OrderedDictionary<String, DescribedValue>()
let actual = orderedDictionary.debugDescription
let expected = "[:]"
XCTAssertEqual(actual, expected)
}
func testDebugDescription() {
let orderedDictionary: OrderedDictionary<String, DescribedValue> = [
"A": DescribedValue(1),
"B": DescribedValue(2),
"C": DescribedValue(3)
]
let actual = orderedDictionary.debugDescription
let expected = "[\"A\": debug(1), \"B\": debug(2), \"C\": debug(3)]"
XCTAssertEqual(actual, expected)
}
}
@@ -0,0 +1,106 @@
import Foundation
import OrderedDictionary
import XCTest
class AccessTests: XCTestCase {
func testAccessBasic() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
XCTAssertEqual(orderedDictionary.count, 3)
XCTAssertFalse(orderedDictionary.isEmpty)
XCTAssertEqual(orderedDictionary.indices, 0..<3)
XCTAssertEqual(orderedDictionary.startIndex, 0)
XCTAssertEqual(orderedDictionary.endIndex, 3)
XCTAssertEqual(orderedDictionary[0].key, "a")
XCTAssertEqual(orderedDictionary[1].key, "b")
XCTAssertEqual(orderedDictionary[2].key, "c")
XCTAssertTrue(orderedDictionary.containsKey("a"))
XCTAssertTrue(orderedDictionary.containsKey("b"))
XCTAssertTrue(orderedDictionary.containsKey("c"))
XCTAssertEqual(orderedDictionary["a"], 1)
XCTAssertEqual(orderedDictionary["b"], 2)
XCTAssertEqual(orderedDictionary["c"], 3)
XCTAssertEqual(orderedDictionary.value(forKey: "a"), 1)
XCTAssertEqual(orderedDictionary.value(forKey: "b"), 2)
XCTAssertEqual(orderedDictionary.value(forKey: "c"), 3)
XCTAssertEqual(orderedDictionary.index(forKey: "a"), 0)
XCTAssertEqual(orderedDictionary.index(forKey: "b"), 1)
XCTAssertEqual(orderedDictionary.index(forKey: "c"), 2)
XCTAssertNotNil(orderedDictionary.elementAt(0))
XCTAssertNotNil(orderedDictionary.elementAt(1))
XCTAssertNotNil(orderedDictionary.elementAt(2))
}
func testAccessSlice() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
let slice = orderedDictionary[2..<4]
XCTAssertEqual(slice.count, 2)
XCTAssertFalse(slice.isEmpty)
XCTAssertEqual(slice.indices, 2..<4)
XCTAssertEqual(slice.startIndex, 2)
XCTAssertEqual(slice.endIndex, 4)
XCTAssertEqual(orderedDictionary[2].key, "c")
XCTAssertEqual(orderedDictionary[3].key, "d")
}
func testAccessOrderedKeys() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
XCTAssertEqual(
orderedDictionary.orderedKeys,
["a", "b", "c"]
)
}
func testAccessOrderedValues() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
XCTAssertEqual(
Array(orderedDictionary.orderedValues),
[1, 2, 3]
)
}
func testAccessElementAtInvalidIndex() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
XCTAssertNil(orderedDictionary.elementAt(-1))
XCTAssertNil(orderedDictionary.elementAt(3))
}
func testAccessUnsortedDictionary() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
XCTAssertEqual(
orderedDictionary.unorderedDictionary,
["a": 1, "b": 2, "c": 3]
)
}
func testIteratorInForLoop() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
var keys = [String]()
var values = [Int]()
for (key, value) in orderedDictionary {
keys.append(key)
values.append(value)
}
XCTAssertEqual(keys, ["a", "b", "c"])
XCTAssertEqual(values, [1, 2, 3])
}
}
@@ -0,0 +1,43 @@
import Foundation
import OrderedDictionary
import XCTest
class CapacityTests: XCTestCase {
func testCapacityReservationViaInit() {
let orderedDictionary = OrderedDictionary<String, Int>(minimumCapacity: 10)
XCTAssertGreaterThanOrEqual(orderedDictionary.capacity, 10)
}
func testCapacityReservationViaMethod() {
var orderedDictionary = OrderedDictionary<String, Int>()
XCTAssertEqual(orderedDictionary.capacity, 0)
orderedDictionary.reserveCapacity(10)
XCTAssertGreaterThanOrEqual(orderedDictionary.capacity, 10)
XCTAssertLessThan(orderedDictionary.capacity, 20)
orderedDictionary.reserveCapacity(20)
XCTAssertGreaterThanOrEqual(orderedDictionary.capacity, 20)
}
func testCapacityGrowForElementInsertion() {
var orderedDictionary = OrderedDictionary<String, Int>()
XCTAssertEqual(orderedDictionary.capacity, 0)
orderedDictionary["a"] = 1
XCTAssertEqual(orderedDictionary.capacity, 1)
orderedDictionary["b"] = 2
orderedDictionary["a"] = 3
XCTAssertEqual(orderedDictionary.capacity, 2)
}
}
@@ -0,0 +1,40 @@
import Foundation
import OrderedDictionary
import XCTest
class CodingTests: XCTestCase {
func testEncodingAndDecodingViaJSON() throws {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let jsonEncoder = JSONEncoder()
let data = try jsonEncoder.encode(orderedDictionary)
let actualString = String(data: data, encoding: .utf8)
let expectedString = "[\"a\",1,\"b\",2,\"c\",3]"
XCTAssertEqual(actualString, expectedString)
let jsonDecoder = JSONDecoder()
let actual = try jsonDecoder.decode(OrderedDictionary<String, Int>.self, from: data)
let expected = orderedDictionary
XCTAssertEqual(actual, expected)
}
func testEncodingAndDecodingViaPropertyList() throws {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let plistEncoder = PropertyListEncoder()
let data = try plistEncoder.encode(orderedDictionary)
let plistDecoder = PropertyListDecoder()
let actual = try plistDecoder.decode(OrderedDictionary<String, Int>.self, from: data)
let expected = orderedDictionary
XCTAssertEqual(actual, expected)
}
}
@@ -0,0 +1,49 @@
import Foundation
import OrderedDictionary
import XCTest
struct DescribedValue: CustomStringConvertible, CustomDebugStringConvertible {
init(_ value: Int) { self.value = value }
let value: Int
var description: String { return "\(value)" }
var debugDescription: String { return "debug(\(value))" }
}
class DescriptionTests: XCTestCase {
func testEmptyDescription() {
let orderedDictionary = OrderedDictionary<String, DescribedValue>()
XCTAssertEqual(orderedDictionary.description, "[:]")
}
func testDescription() {
let orderedDictionary: OrderedDictionary = [
"a": DescribedValue(1),
"b": DescribedValue(2),
"c": DescribedValue(3)
]
XCTAssertEqual(orderedDictionary.description, "[a: 1, b: 2, c: 3]")
}
func testEmptyDebugDescription() {
let orderedDictionary = OrderedDictionary<String, DescribedValue>()
XCTAssertEqual(orderedDictionary.debugDescription, "[:]")
}
func testDebugDescription() {
let orderedDictionary: OrderedDictionary = [
"a": DescribedValue(1),
"b": DescribedValue(2),
"c": DescribedValue(3)
]
XCTAssertEqual(
orderedDictionary.debugDescription,
"[\"a\": debug(1), \"b\": debug(2), \"c\": debug(3)]"
)
}
}
@@ -0,0 +1,92 @@
import Foundation
import OrderedDictionary
import XCTest
class InitializationTests: XCTestCase {
func testInitializationFromArrayLiteral() {
let actual: OrderedDictionary = [
("a", 1),
("b", 2),
("c", 3)
]
let expected = OrderedDictionary(uniqueKeysWithValues: [
(key: "a", value: 1),
(key: "b", value: 2),
(key: "c", value: 3)
])
XCTAssertEqual(actual, expected)
}
func testInitializationFromDictionaryLiteral() {
let actual: OrderedDictionary = [
"a": 1,
"b": 2,
"c": 3
]
let expected = OrderedDictionary(uniqueKeysWithValues: [
(key: "a", value: 1),
(key: "b", value: 2),
(key: "c", value: 3)
])
XCTAssertEqual(actual, expected)
}
func testInitializationFromValuesAndKeyProviderClosure() {
let actual = OrderedDictionary(
values: [1, 2, 3],
uniquelyKeyedBy: { String($0) }
)
let expected = OrderedDictionary(uniqueKeysWithValues: [
(key: "1", value: 1),
(key: "2", value: 2),
(key: "3", value: 3)
])
XCTAssertEqual(actual, expected)
}
func testInitializationFromValuesAndKeyPath() {
let actual = OrderedDictionary(
values: ["a", "b", "c"],
uniquelyKeyedBy: \.self
)
let expected = OrderedDictionary(uniqueKeysWithValues: [
(key: "a", value: "a"),
(key: "b", value: "b"),
(key: "c", value: "c")
])
XCTAssertEqual(actual, expected)
}
func testInitializationFromUnsortedDictionaryAndSortFunction() {
let actual = OrderedDictionary(
unsorted: [
2: "foo",
1: "bar",
4: "baz",
5: "bat",
3: "bam"
],
areInIncreasingOrder: { $0.key < $1.key }
)
let expected = OrderedDictionary(uniqueKeysWithValues: [
(key: 1, value: "bar"),
(key: 2, value: "foo"),
(key: 3, value: "bam"),
(key: 4, value: "baz"),
(key: 5, value: "bat")
])
XCTAssertEqual(actual, expected)
}
}
@@ -0,0 +1,61 @@
import Foundation
import OrderedDictionary
import XCTest
class InsertionsTests: XCTestCase {
// ============================================================================ //
// MARK: - Index-based Insertion
// ============================================================================ //
func testIndexBasedInsertion_uniqueKey_startIndex() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let newElement = (key: "d", value: 4)
orderedDictionary.insert(newElement, at: 0)
XCTAssertEqual(orderedDictionary, ["d": 4, "a": 1, "b": 2, "c": 3])
}
func testIndexBasedInsertion_uniqueKey_middleIndex() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let newElement = (key: "d", value: 4)
orderedDictionary.insert(newElement, at: 2)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "d": 4, "c": 3])
}
func testIndexBasedInsertion_uniqueKey_endIndex() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let newElement = (key: "d", value: 4)
orderedDictionary.insert(newElement, at: 3)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3, "d": 4])
}
func testIndexBasedInsertion_duplicateKey() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
XCTAssertFalse(orderedDictionary.canInsert(key: "a"))
XCTAssertTrue(orderedDictionary.canInsert(key: "d"))
}
func testIndexBasedInsertion_invalidIndex() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
XCTAssertFalse(orderedDictionary.canInsert(at: -1))
XCTAssertFalse(orderedDictionary.canInsert(at: 4))
}
// ============================================================================ //
// MARK: - Key-based Insertion
// ============================================================================ //
func testKeyBasedInsertion() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
orderedDictionary["d"] = 4
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3, "d": 4])
}
}
@@ -0,0 +1,34 @@
import Foundation
import OrderedDictionary
import XCTest
class MapFilterTests: XCTestCase {
func testMapValues() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
XCTAssertEqual(
orderedDictionary.mapValues { String($0) },
["a": "1", "b": "2", "c": "3", "d": "4"]
)
}
func testCompactMapValues() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
XCTAssertEqual(
orderedDictionary.compactMapValues { $0.isMultiple(of: 2) ? String($0) : nil },
["b": "2", "d": "4"]
)
}
func testFilter() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
XCTAssertEqual(
orderedDictionary.filter { $0.value.isMultiple(of: 2) },
["b": 2, "d": 4]
)
}
}
@@ -0,0 +1,152 @@
import Foundation
import OrderedDictionary
import XCTest
class RemovalTests: XCTestCase {
// ============================================================================ //
// MARK: - Key-based Removal Via removeValue(forKey:)
// ============================================================================ //
func testKeyBasedRemoval_viaMethod_existingKey() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let value = orderedDictionary.removeValue(forKey: "b")
XCTAssertEqual(value, 2)
XCTAssertEqual(orderedDictionary, ["a": 1, "c": 3])
}
func testKeyBasedRemoval_viaMethod_invalidKey() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let value = orderedDictionary.removeValue(forKey: "d")
XCTAssertNil(value)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3])
}
// ============================================================================ //
// MARK: - Key-based Removal Via subscript(key:)
// ============================================================================ //
func testKeyBasedRemoval_viaSubscript_existingKey() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
orderedDictionary["b"] = nil
XCTAssertEqual(orderedDictionary, ["a": 1, "c": 3])
}
func testKeyBasedRemoval_viaSubscript_invalidKey() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
orderedDictionary["d"] = nil
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3])
}
// ============================================================================ //
// MARK: - Index-based Removal Via Method
// ============================================================================ //
func testIndexBasedRemoval_viaMethod_validIndex() throws {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let (key, value) = try XCTUnwrap(orderedDictionary.remove(at: 2))
XCTAssertEqual(key, "c")
XCTAssertEqual(value, 3)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2])
}
func testIndexBasedRemoval_viaMethod_invalidIndex() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let element = orderedDictionary.remove(at: 5)
XCTAssertNil(element)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3])
}
// ============================================================================ //
// MARK: - Remove All
// ============================================================================ //
func testRemoveAll() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
orderedDictionary.removeAll()
XCTAssertEqual(orderedDictionary, [])
}
// ============================================================================ //
// MARK: - Pop First & Last
// ============================================================================ //
func testPopFirstEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = []
let first = orderedDictionary.popFirst()
XCTAssertNil(first)
}
func testPopFirstNonEmpty() throws {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
let first = try XCTUnwrap(orderedDictionary.popFirst())
XCTAssertEqual(first.key, "a")
XCTAssertEqual(first.value, 1)
XCTAssertEqual(orderedDictionary, ["b": 2, "c": 3, "d": 4])
}
func testPopLastEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = []
let last = orderedDictionary.popLast()
XCTAssertNil(last)
}
func testPopLastNonEmpty() throws {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
let last = try XCTUnwrap(orderedDictionary.popLast())
XCTAssertEqual(last.key, "d")
XCTAssertEqual(last.value, 4)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3])
}
// ============================================================================ //
// MARK: - Removal First & Last
// ============================================================================ //
func testRemoveFirstNonEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
let first = orderedDictionary.removeFirst()
XCTAssertEqual(first.key, "a")
XCTAssertEqual(first.value, 1)
XCTAssertEqual(orderedDictionary, ["b": 2, "c": 3, "d": 4])
}
func testRemoveLastNonEmpty() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
let last = orderedDictionary.removeLast()
XCTAssertEqual(last.key, "d")
XCTAssertEqual(last.value, 4)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3])
}
}
@@ -0,0 +1,85 @@
import Foundation
import OrderedDictionary
import XCTest
class ReorderingTests: XCTestCase {
// ============================================================================ //
// MARK: - Reversal
// ============================================================================ //
func testReversal() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
orderedDictionary.reverse()
XCTAssertEqual(orderedDictionary, ["d": 4, "c": 3, "b": 2, "a": 1])
}
func testReversal_throughSlice() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
orderedDictionary[1..<3].reverse()
XCTAssertEqual(orderedDictionary, ["a": 1, "c": 3, "b": 2, "d": 4])
}
// ============================================================================ //
// MARK: - Partitioning
// ============================================================================ //
func testPartitioning() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
let index = orderedDictionary.partition(by: { $0.value.isMultiple(of: 2) })
XCTAssertEqual(index, 2)
XCTAssertEqual(orderedDictionary, ["a": 1, "c": 3, "b": 2, "d": 4])
}
func testPartitioning_throughSlice() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
let index = orderedDictionary[0..<3].partition(by: { !$0.value.isMultiple(of: 2) })
XCTAssertEqual(index, 1)
XCTAssertEqual(orderedDictionary, ["b": 2, "a": 1, "c": 3, "d": 4])
}
// ============================================================================ //
// MARK: - Swapping
// ============================================================================ //
func testSwapAtDifferentIndices() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
orderedDictionary.swapAt(1, 3)
XCTAssertEqual(orderedDictionary, ["a": 1, "d": 4, "c": 3, "b": 2])
}
func testSwapAtSameIndex() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
orderedDictionary.swapAt(0, 0)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3, "d": 4])
}
func testSwapAtDifferentIndices_throughSlice() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
orderedDictionary[1..<4].swapAt(1, 3)
XCTAssertEqual(orderedDictionary, ["a": 1, "d": 4, "c": 3, "b": 2])
}
func testSwapAtSameIndex_throughSlice() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3, "d": 4]
orderedDictionary[0..<1].swapAt(0, 0)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 2, "c": 3, "d": 4])
}
}
@@ -0,0 +1,83 @@
import Foundation
import OrderedDictionary
import XCTest
func sortByValuesAndKeys<Key: Comparable, Value: Comparable>(
element1: (key: Key, value: Value),
element2: (key: Key, value: Value)
) -> Bool {
if element1.value != element2.value {
return element1.value < element2.value
} else {
return element1.key < element2.key
}
}
class SortingTests: XCTestCase {
// ============================================================================ //
// MARK: - Mutating Sort
// ============================================================================ //
func testMutatingSort() {
var orderedDictionary: OrderedDictionary<String, Int> = ["e": 4, "g": 3, "a": 3, "d": 1, "b": 4]
orderedDictionary.sort(by: sortByValuesAndKeys)
XCTAssertEqual(
orderedDictionary,
["d": 1, "a": 3, "g": 3, "b": 4, "e": 4]
)
}
func testMutatingSort_throughSlice() {
var orderedDictionary: OrderedDictionary<String, Int> = ["e": 4, "g": 3, "a": 3, "d": 1, "b": 4]
orderedDictionary[2..<5].sort(by: sortByValuesAndKeys)
XCTAssertEqual(
orderedDictionary,
["e": 4, "g": 3, "d": 1, "a": 3, "b": 4]
)
}
// ============================================================================ //
// MARK: - Non-mutating Sort
// ============================================================================ //
func testSortingWithoutMutation() {
let orderedDictionary: OrderedDictionary<String, Int> = ["e": 4, "g": 3, "a": 3, "d": 1, "b": 4]
XCTAssertEqual(
orderedDictionary.sorted(by: sortByValuesAndKeys),
["d": 1, "a": 3, "g": 3, "b": 4, "e": 4]
)
}
// ============================================================================ //
// MARK: - Sorting Unsorted Dictionary
// ============================================================================ //
func testSortingUnsortedDictionary() {
let dictionary = [
2: "foo",
1: "bar",
4: "baz",
5: "bat",
3: "bam"
]
let actual = dictionary.sorted { $0.key < $1.key }
let expected: OrderedDictionary<Int, String> = [
1: "bar",
2: "foo",
3: "bam",
4: "baz",
5: "bat"
]
XCTAssertEqual(actual, expected)
}
}
@@ -0,0 +1,35 @@
import Foundation
import OrderedDictionary
import XCTest
// See #49
class SubscriptAmbiguityTests: XCTestCase {
func testAccess() {
let orderedDictionary: OrderedDictionary<Int, String> = [1: "a", 2: "b", 3: "c"]
let valueForKey = orderedDictionary[1] as String?
let elementAtIndex = orderedDictionary[1] as (key: Int, value: String)
XCTAssertEqual(valueForKey, "a")
XCTAssertEqual(elementAtIndex.key, 2)
XCTAssertEqual(elementAtIndex.value, "b")
}
func testIndexBasedUpdate() {
var orderedDictionary: OrderedDictionary<Int, String> = [1: "a", 2: "b", 3: "c"]
orderedDictionary[1] = (key: 2, value: "x")
XCTAssertEqual(orderedDictionary, [1: "a", 2: "x", 3: "c"])
}
func testKeyBasedUpdate() {
var orderedDictionary: OrderedDictionary<Int, String> = [1: "a", 2: "b", 3: "c"]
orderedDictionary[1] = "x"
XCTAssertEqual(orderedDictionary, [1: "x", 2: "b", 3: "c"])
}
}
@@ -0,0 +1,124 @@
import Foundation
import OrderedDictionary
import XCTest
class UpdatesTests: XCTestCase {
// ============================================================================ //
// MARK: - Index-based Updates Via update(_:at:)
// ============================================================================ //
func testIndexBasedUpdate_viaMethod_sameKey() throws {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let newElement = (key: "b", value: 0)
let previousElement = try XCTUnwrap(orderedDictionary.update(newElement, at: 1))
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 0, "c": 3])
XCTAssertEqual(previousElement.key, "b")
XCTAssertEqual(previousElement.value, 2)
}
func testIndexBasedUpdate_viaMethod_newUniqueKey() throws {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let newElement = (key: "d", value: 0)
let previousElement = try XCTUnwrap(orderedDictionary.update(newElement, at: 1))
XCTAssertEqual(orderedDictionary, ["a": 1, "d": 0, "c": 3])
XCTAssertEqual(previousElement.key, "b")
XCTAssertEqual(previousElement.value, 2)
}
func testIndexBasedUpdate_viaMethod_duplicateKey() {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let element = (key: "a", value: 42)
XCTAssertTrue(orderedDictionary.canUpdate(element, at: 0))
XCTAssertFalse(orderedDictionary.canUpdate(element, at: 1))
XCTAssertFalse(orderedDictionary.canUpdate(element, at: 2))
}
// ============================================================================ //
// MARK: - Index-based Updates Via subscript(position:)
// ============================================================================ //
func testIndexBasedUpdate_viaSubscriptSingle_sameKey() throws {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
orderedDictionary[1] = (key: "b", value: 0)
XCTAssertEqual(orderedDictionary, ["a": 1, "b": 0, "c": 3])
}
func testIndexBasedUpdate_viaSubscriptSingle_newUniqueKey() throws {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
orderedDictionary[1] = (key: "d", value: 0)
XCTAssertEqual(orderedDictionary, ["a": 1, "d": 0, "c": 3])
}
// ============================================================================ //
// MARK: - Index-based Updates Via subscript(bounds:)
// ============================================================================ //
func testIndexBasedUpdate_viaSubscriptMultiple_newUniqueKeys() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let sliceOrderedDictionary: OrderedDictionary<String, Int> = ["d": 0, "e": 0]
let slice = sliceOrderedDictionary[0..<2]
orderedDictionary[1..<3] = slice
XCTAssertEqual(orderedDictionary, ["a": 1, "d": 0, "e": 0])
}
func testIndexBasedUpdate_viaSubscriptMultiple_sameKeys() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let sliceOrderedDictionary: OrderedDictionary<String, Int> = ["c": 0, "b": 0]
let slice = sliceOrderedDictionary[0..<2]
orderedDictionary[1..<3] = slice
XCTAssertEqual(orderedDictionary, ["a": 1, "c": 0, "b": 0])
}
func testIndexBasedUpdate_viaSubscriptMultiple_mixedKeys() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let sliceOrderedDictionary: OrderedDictionary<String, Int> = ["d": 0, "c": 0]
let slice = sliceOrderedDictionary[0..<2]
orderedDictionary[1..<3] = slice
XCTAssertEqual(orderedDictionary, ["a": 1, "d": 0, "c": 0])
}
// ============================================================================ //
// MARK: - Key-based Updates
// ============================================================================ //
func testKeyBasedUpdate() {
var orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
// Update
orderedDictionary["a"] = 5
XCTAssertEqual(orderedDictionary, ["a": 5, "b": 2, "c": 3])
// Insertion
orderedDictionary["d"] = 10
XCTAssertEqual(orderedDictionary, ["a": 5, "b": 2, "c": 3, "d": 10])
XCTAssertTrue(orderedDictionary.containsKey("d"))
// Removal
orderedDictionary["b"] = nil
XCTAssertEqual(orderedDictionary, ["a": 5, "c": 3, "d": 10])
XCTAssertFalse(orderedDictionary.containsKey("b"))
}
}
@@ -0,0 +1,18 @@
// https://github.com/realm/SwiftLint/pull/2965
// https://bugs.swift.org/browse/SR-11501
#if compiler(<5.1) || (SWIFT_PACKAGE && os(macOS))
internal enum UnwrapError: Error {
case missingValue
}
internal func XCTUnwrap<T>(
_ expression: @autoclosure () throws -> T?,
_ message: @autoclosure () -> String = ""
) throws -> T {
if let value = try expression() {
return value
} else {
throw UnwrapError.missingValue
}
}
#endif
@@ -0,0 +1,183 @@
#if !canImport(ObjectiveC)
import XCTest
extension AccessTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__AccessTests = [
("testAccessBasic", testAccessBasic),
("testAccessElementAtInvalidIndex", testAccessElementAtInvalidIndex),
("testAccessOrderedKeys", testAccessOrderedKeys),
("testAccessOrderedValues", testAccessOrderedValues),
("testAccessSlice", testAccessSlice),
("testAccessUnsortedDictionary", testAccessUnsortedDictionary),
("testIteratorInForLoop", testIteratorInForLoop),
]
}
extension CapacityTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__CapacityTests = [
("testCapacityGrowForElementInsertion", testCapacityGrowForElementInsertion),
("testCapacityReservationViaInit", testCapacityReservationViaInit),
("testCapacityReservationViaMethod", testCapacityReservationViaMethod),
]
}
extension CodingTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__CodingTests = [
("testEncodingAndDecodingViaJSON", testEncodingAndDecodingViaJSON),
("testEncodingAndDecodingViaPropertyList", testEncodingAndDecodingViaPropertyList),
]
}
extension DescriptionTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__DescriptionTests = [
("testDebugDescription", testDebugDescription),
("testDescription", testDescription),
("testEmptyDebugDescription", testEmptyDebugDescription),
("testEmptyDescription", testEmptyDescription),
]
}
extension InitializationTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__InitializationTests = [
("testInitializationFromArrayLiteral", testInitializationFromArrayLiteral),
("testInitializationFromDictionaryLiteral", testInitializationFromDictionaryLiteral),
("testInitializationFromUnsortedDictionaryAndSortFunction", testInitializationFromUnsortedDictionaryAndSortFunction),
("testInitializationFromValuesAndKeyPath", testInitializationFromValuesAndKeyPath),
("testInitializationFromValuesAndKeyProviderClosure", testInitializationFromValuesAndKeyProviderClosure),
]
}
extension InsertionsTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__InsertionsTests = [
("testIndexBasedInsertion_duplicateKey", testIndexBasedInsertion_duplicateKey),
("testIndexBasedInsertion_invalidIndex", testIndexBasedInsertion_invalidIndex),
("testIndexBasedInsertion_uniqueKey_endIndex", testIndexBasedInsertion_uniqueKey_endIndex),
("testIndexBasedInsertion_uniqueKey_middleIndex", testIndexBasedInsertion_uniqueKey_middleIndex),
("testIndexBasedInsertion_uniqueKey_startIndex", testIndexBasedInsertion_uniqueKey_startIndex),
("testKeyBasedInsertion", testKeyBasedInsertion),
]
}
extension MapFilterTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__MapFilterTests = [
("testCompactMapValues", testCompactMapValues),
("testFilter", testFilter),
("testMapValues", testMapValues),
]
}
extension RemovalTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__RemovalTests = [
("testIndexBasedRemoval_viaMethod_invalidIndex", testIndexBasedRemoval_viaMethod_invalidIndex),
("testIndexBasedRemoval_viaMethod_validIndex", testIndexBasedRemoval_viaMethod_validIndex),
("testKeyBasedRemoval_viaMethod_existingKey", testKeyBasedRemoval_viaMethod_existingKey),
("testKeyBasedRemoval_viaMethod_invalidKey", testKeyBasedRemoval_viaMethod_invalidKey),
("testKeyBasedRemoval_viaSubscript_existingKey", testKeyBasedRemoval_viaSubscript_existingKey),
("testKeyBasedRemoval_viaSubscript_invalidKey", testKeyBasedRemoval_viaSubscript_invalidKey),
("testPopFirstEmpty", testPopFirstEmpty),
("testPopFirstNonEmpty", testPopFirstNonEmpty),
("testPopLastEmpty", testPopLastEmpty),
("testPopLastNonEmpty", testPopLastNonEmpty),
("testRemoveAll", testRemoveAll),
("testRemoveFirstNonEmpty", testRemoveFirstNonEmpty),
("testRemoveLastNonEmpty", testRemoveLastNonEmpty),
]
}
extension ReorderingTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__ReorderingTests = [
("testPartitioning", testPartitioning),
("testPartitioning_throughSlice", testPartitioning_throughSlice),
("testReversal", testReversal),
("testReversal_throughSlice", testReversal_throughSlice),
("testSwapAtDifferentIndices", testSwapAtDifferentIndices),
("testSwapAtDifferentIndices_throughSlice", testSwapAtDifferentIndices_throughSlice),
("testSwapAtSameIndex", testSwapAtSameIndex),
("testSwapAtSameIndex_throughSlice", testSwapAtSameIndex_throughSlice),
]
}
extension SortingTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__SortingTests = [
("testMutatingSort", testMutatingSort),
("testMutatingSort_throughSlice", testMutatingSort_throughSlice),
("testSortingUnsortedDictionary", testSortingUnsortedDictionary),
("testSortingWithoutMutation", testSortingWithoutMutation),
]
}
extension SubscriptAmbiguityTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__SubscriptAmbiguityTests = [
("testAccess", testAccess),
("testIndexBasedUpdate", testIndexBasedUpdate),
("testKeyBasedUpdate", testKeyBasedUpdate),
]
}
extension UpdatesTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__UpdatesTests = [
("testIndexBasedUpdate_viaMethod_duplicateKey", testIndexBasedUpdate_viaMethod_duplicateKey),
("testIndexBasedUpdate_viaMethod_newUniqueKey", testIndexBasedUpdate_viaMethod_newUniqueKey),
("testIndexBasedUpdate_viaMethod_sameKey", testIndexBasedUpdate_viaMethod_sameKey),
("testIndexBasedUpdate_viaSubscriptMultiple_mixedKeys", testIndexBasedUpdate_viaSubscriptMultiple_mixedKeys),
("testIndexBasedUpdate_viaSubscriptMultiple_newUniqueKeys", testIndexBasedUpdate_viaSubscriptMultiple_newUniqueKeys),
("testIndexBasedUpdate_viaSubscriptMultiple_sameKeys", testIndexBasedUpdate_viaSubscriptMultiple_sameKeys),
("testIndexBasedUpdate_viaSubscriptSingle_newUniqueKey", testIndexBasedUpdate_viaSubscriptSingle_newUniqueKey),
("testIndexBasedUpdate_viaSubscriptSingle_sameKey", testIndexBasedUpdate_viaSubscriptSingle_sameKey),
("testKeyBasedUpdate", testKeyBasedUpdate),
]
}
public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(AccessTests.__allTests__AccessTests),
testCase(CapacityTests.__allTests__CapacityTests),
testCase(CodingTests.__allTests__CodingTests),
testCase(DescriptionTests.__allTests__DescriptionTests),
testCase(InitializationTests.__allTests__InitializationTests),
testCase(InsertionsTests.__allTests__InsertionsTests),
testCase(MapFilterTests.__allTests__MapFilterTests),
testCase(RemovalTests.__allTests__RemovalTests),
testCase(ReorderingTests.__allTests__ReorderingTests),
testCase(SortingTests.__allTests__SortingTests),
testCase(SubscriptAmbiguityTests.__allTests__SubscriptAmbiguityTests),
testCase(UpdatesTests.__allTests__UpdatesTests),
]
}
#endif