Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lemire/SwiftBitset
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Sep 22, 2018
2 parents 6ba9057 + 1a4ee3d commit 027198c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: swift
os: osx
xcode_project: SwiftBitset
xcode_scheme: SwiftBitset-Package
osx_image:
- xcode9.4
- xcode10
before_install:
- brew update
script:
- swift package generate-xcodeproj
- set -o pipefail && xcodebuild -scheme SwiftBitset-Package -enableCodeCoverage YES clean build test
- swift build
- swift test
- swift test -Xswiftc -Ounchecked -s BitsetTests.BitsetTests/testForEachPerformance
11 changes: 9 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ let package = Package(
.library(name: "Bitset", targets: ["Bitset"]),
.library(name: "BitsetDynamic", type: .dynamic , targets: ["Bitset"]),
],
dependencies: [],
targets: [
.target(name: "Bitset", dependencies: []),
.testTarget(name: "BitsetTests", dependencies: ["Bitset"])
.target(
name: "Bitset",
dependencies: []
),
.testTarget(
name: "BitsetTests",
dependencies:["Bitset"]
)
]
)
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/Swift4-compatible-green.svg?style=flat" alt="Swift 4 compatible" /></a>
<a href="https://github.com/apple/swift-package-manager"><img src="https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg"/></a>

[![Build Status](https://travis-ci.org/lemire/SwiftBitset.svg?branch=master)](https://travis-ci.org/lemire/SwiftBitset)

A bitset class in Swift for fast and concise set operations over integers. Works under both Linux and MacOS.
It is engineered to be really fast, on par with portable C/C++ implementations.
Expand All @@ -14,7 +14,7 @@ $ git clone https://github.com/lemire/SwiftBitsetBenchmark.git
$ cd SwiftBitsetBenchmark
$ swift build -Xcc -march=native --configuration release
$(swift build --configuration release --show-bin-path)/SwiftBitsetBenchmark
$ $(swift build --configuration release --show-bin-path)/SwiftBitsetBenchmark
testAddPerformance 10.693318 ms
testIndexSetAddPerformance 231.737616 ms
Expand Down Expand Up @@ -101,11 +101,11 @@ for i in b1 {
b1.remove(4) // can remove values
let d1 = b1 & b2;// intersection
let d2 = b1 | b2;// union
let d3 = b1 &^ b2;// difference
let d3 = b1 - b2;// difference
let d4 = b1 ^ b2;// symmetric difference
b1 &= b2;// inplace intersection
b1 |= b2;// inplace union
b1 &^= b2;// inplace difference
b1 -= b2;// inplace difference
b1 ^= b2;// inplace symmetric difference
```

Expand Down Expand Up @@ -143,7 +143,7 @@ $ swift -I .build/release -L .build/release -lBitsetDynamic
```bash
$ swift package generate-xcodeproj
generated: ./Bitset.xcodeproj
$ open ./Bitset.xcodeproj
$ open ./SwiftBitset.xcodeproj
```

## Licensing
Expand Down
7 changes: 3 additions & 4 deletions Sources/Bitset/Bitset.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

infix operator &^;// andNot
infix operator &^=;// andNot

private extension Int64 {
func toUInt64() -> UInt64 { return UInt64(bitPattern:self) }
Expand Down Expand Up @@ -83,15 +81,16 @@ public final class Bitset: Sequence, Equatable, CustomStringConvertible,
lhs.union(rhs)
}


// difference between two bitsets, producing a new bitset
public static func &^ (lhs: Bitset, rhs: Bitset) -> Bitset {
public static func - (lhs: Bitset, rhs: Bitset) -> Bitset {
let mycopy = Bitset(lhs)
mycopy.difference(rhs)
return mycopy
}

// inplace difference between two bitsets
public static func &^= (lhs: Bitset, rhs: Bitset) {
public static func -= (lhs: Bitset, rhs: Bitset) {
lhs.difference(rhs)
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/BitsetTests/BitsetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class BitsetTests: XCTestCase {
let B1 = Bitset(b1)
let B2 = Bitset(b2)

b2 &^= b1
b2 -= b1
B2.difference(B1)
XCTAssertEqual(B2, b2, "Bad operator")
}
Expand All @@ -203,7 +203,7 @@ class BitsetTests: XCTestCase {
let B1 = Bitset(b1)
let B2 = Bitset(b2)

let b3 = b2 &^ b1
let b3 = b2 - b1
B2.difference(B1)
XCTAssertEqual(B2, b3, "Bad operator")
}
Expand Down Expand Up @@ -239,11 +239,11 @@ class BitsetTests: XCTestCase {
// will print 1 4 10 1000 10000
_ = b1 & b2;// intersection
_ = b1 | b2;// union
_ = b1 &^ b2;// difference
_ = b1 - b2;// difference
_ = b1 ^ b2;// symmetric difference
b1 &= b2;// inplace intersection
b1 |= b2;// inplace union
b1 &^= b2;// inplace difference
b1 -= b2;// inplace difference
b1 ^= b2;// inplace symmetric difference
}

Expand Down Expand Up @@ -271,7 +271,7 @@ class BitsetTests: XCTestCase {

#if os(Linux)
extension BitsetTests {
static var allTests: [(String, (BitsetTests) -> Void throws->Void)] {
static var allTests: [(String, (BitsetTests) -> () throws->())] {
return [
("testUnion", testUnion),
("testIterator", testIterator),
Expand Down

0 comments on commit 027198c

Please sign in to comment.