Skip to content

Swift 5, XCode 12 support #1

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
!*.xcodeproj/xcshareddata/

# CocoaPods
#
Expand Down
49 changes: 42 additions & 7 deletions VPTree/VPTree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@
isa = PBXGroup;
children = (
6FA8D7F11B23417E00821B73 /* VPTree.h */,
6FA8D7EF1B23417E00821B73 /* Supporting Files */,
6FA8D8151B2499B000821B73 /* Array.swift */,
6FA8D80E1B23449600821B73 /* PriorityQueue.swift */,
6FA8D8081B23419000821B73 /* VPNode.swift */,
6FA8D80A1B2341A200821B73 /* VPTree.swift */,
6FA8D80E1B23449600821B73 /* PriorityQueue.swift */,
6FA8D8151B2499B000821B73 /* Array.swift */,
6FA8D7EF1B23417E00821B73 /* Supporting Files */,
);
path = VPTree;
sourceTree = "<group>";
Expand Down Expand Up @@ -177,7 +177,7 @@
6FA8D7E31B23417E00821B73 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0640;
LastUpgradeCheck = 1230;
ORGANIZATIONNAME = Sunday;
TargetAttributes = {
6FA8D7EB1B23417E00821B73 = {
Expand All @@ -190,10 +190,11 @@
};
buildConfigurationList = 6FA8D7E61B23417E00821B73 /* Build configuration list for PBXProject "VPTree" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 6FA8D7E21B23417E00821B73;
productRefGroup = 6FA8D7ED1B23417E00821B73 /* Products */;
Expand Down Expand Up @@ -263,24 +264,37 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
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;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand All @@ -296,7 +310,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -311,17 +325,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
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;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -338,9 +364,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -359,9 +386,11 @@
INFOPLIST_FILE = VPTree/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sunday.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -376,8 +405,10 @@
INFOPLIST_FILE = VPTree/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sunday.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -394,6 +425,7 @@
);
INFOPLIST_FILE = VPTreeTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sunday.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -407,6 +439,7 @@
);
INFOPLIST_FILE = VPTreeTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sunday.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -430,6 +463,7 @@
6FA8D8041B23417E00821B73 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
6FA8D8051B23417E00821B73 /* Build configuration list for PBXNativeTarget "VPTreeTests" */ = {
isa = XCConfigurationList;
Expand All @@ -438,6 +472,7 @@
6FA8D8071B23417E00821B73 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
36 changes: 18 additions & 18 deletions VPTree/VPTree/Array.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
//
// Array.swift
// VPTree
//
// Created by Laurent CHENAY on 07/06/2015.
// Copyright (c) 2015 Sunday. All rights reserved.
//

import Foundation

private func split<T: Comparable>(inout array: [T], nbItemLeft: Int, nbItemRight: Int) -> (Array<T>, Array<T>) {
private func split<T: Comparable>(
_ array: inout [T],
_ nbItemLeft: Int,
_ nbItemRight: Int
) -> (Array<T>, Array<T>) {
var left: Array<T> = []
var right: Array<T> = []
var middle: Array<T> = []
Expand Down Expand Up @@ -52,20 +46,26 @@ private func split<T: Comparable>(inout array: [T], nbItemLeft: Int, nbItemRight
}

if left.count > nbItemLeft {
let (subLeft: [T], subRight: [T]) = split(&left, nbItemLeft, nbItemRight - right.count)
return (subLeft, right + subRight)
let sub: (left: [T], right: [T])
= split(&left, nbItemLeft, nbItemRight - right.count)
return (sub.left, right + sub.right)
} else if right.count > nbItemRight {
let (subLeft: [T], subRight: [T]) = split(&right, nbItemLeft - left.count, nbItemRight)
return (left + subLeft, subRight)
let sub: (left: [T], right: [T])
= split(&right, nbItemLeft - left.count, nbItemRight)
return (left + sub.left, sub.right)
} else {
return (left, right)
}
}

internal extension Array {
internal func splitByMedian<T where T: Comparable>() -> ([T], [T]) {

func splitByMedian<T>() -> ([T], [T]) where T: Comparable {
let mid = count / 2
var array: Array<T> = self.map {return $0 as! T}
return split(&array, count-mid, mid)
var array: Array<T> = self.map {
return $0 as! T
}
return VPTree.split(&array, count-mid, mid)
}

}
2 changes: 1 addition & 1 deletion VPTree/VPTree/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.sunday.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
14 changes: 6 additions & 8 deletions VPTree/VPTree/PriorityQueue.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Foundation

class PriorityQueue<T> {
struct PriorityQueue<T> {
private var _items: [(weight: Double, item: T)] = []
var limit: Int?

Expand All @@ -11,19 +9,19 @@ class PriorityQueue<T> {
init() {
}

func push(weight: Double, item: T) {
mutating func push(weight: Double, item: T) {
var index = 0

while (index < _items.count) {
if (weight < _items[index].weight) {
break
}
index++
index += 1
}

_items.insert((weight: weight, item: item), atIndex: index)
_items.insert((weight: weight, item: item), at: index)

if limit != nil && _items.count > limit {
if let limit = limit, _items.count > limit {
_items.removeLast()
}
}
Expand All @@ -38,4 +36,4 @@ class PriorityQueue<T> {
}
return Double.infinity
}
}
}
33 changes: 16 additions & 17 deletions VPTree/VPTree/VPNode.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Foundation

private func <<T>(left: Point<T>, right: Point<T>) -> Bool {
private func <<T>(left: VPoint<T>, right: VPoint<T>) -> Bool {
return left.d < right.d
}

private func ==<T>(left: Point<T>, right: Point<T>) -> Bool {
private func ==<T>(left: VPoint<T>, right: VPoint<T>) -> Bool {
return left.d == right.d
}

private class Point<T>: Comparable {
private final class VPoint<T>: Comparable {
var d: Double
let point: T

Expand All @@ -18,7 +16,7 @@ private class Point<T>: Comparable {
}
}

internal class VPNode<T: Distance> {
internal final class VPNode<T: Distance> {
var vpPoint: T!
var points: [T] = []
var mu: Double?
Expand All @@ -29,26 +27,26 @@ internal class VPNode<T: Distance> {
self.init(elements: [T](elements))
}

private func convertion (item: Point<T>) -> T {
private func convertion (item: VPoint<T>) -> T {
return item.point
}

convenience init?(elements: [T]) {
let array: [Point<T>] = elements.map {
(item: T) -> Point<T> in
return Point<T>(d: 0, point: item)
let array: [VPoint<T>] = elements.map {
(item: T) -> VPoint<T> in
return VPoint<T>(d: 0, point: item)
}

self.init(elements: array)
}

private init?(elements: [Point<T>]) {
private init?(elements: [VPoint<T>]) {
if elements.count == 0 {
return nil
}
var elements = elements
//Random get of the VP points
self.vpPoint = elements.removeAtIndex(0).point
self.vpPoint = elements.remove(at: 0).point

if elements.count == 0 {
return
Expand All @@ -58,14 +56,15 @@ internal class VPNode<T: Distance> {
item.d = item.point ~~ self.vpPoint
}

let (left: [Point<T>], right: [Point<T>]) = elements.splitByMedian()
let splitElements: (left: [VPoint<T>], right: [VPoint<T>])
= elements.splitByMedian()

mu = left.last!.d
leftChild = VPNode(elements: left)
rightChild = VPNode(elements: right)
mu = splitElements.left.last!.d
leftChild = VPNode(elements: splitElements.left)
rightChild = VPNode(elements: splitElements.right)
}

var isLeaf: Bool {
return leftChild == nil && rightChild == nil
}
}
}
Loading