Skip to content

Commit

Permalink
Merged krisk#2
Browse files Browse the repository at this point in the history
  • Loading branch information
krisk committed Jun 1, 2017
1 parent c471380 commit d369a8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Fuse.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Fuse'
s.version = '0.2.0'
s.version = '1.0.0'
s.summary = 'Fuzzy searching.'
s.description = <<-DESC
A lightweight fuzzy-search library, with zero dependencies
Expand Down
18 changes: 9 additions & 9 deletions Fuse/Classes/FuseUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,30 @@ class FuseUtilities {
return mask
}

/// Returns an array of `CountableRange<Int>`, where each range represents a consecutive list of `1`s.
/// Returns an array of `CountableClosedRange<Int>`, where each range represents a consecutive list of `1`s.
///
/// let arr = [0, 1, 1, 0, 1, 1, 1 ]
/// let ranges = findRanges(arr)
/// // [{startIndex 1, endIndex 2}, {startIndex 4, endIndex 6}
///
/// - Parameter mask: A string representing the value to search for.
///
/// - Returns: `Range<Int>` array.
/// - Returns: `CountableClosedRange<Int>` array.
static func findRanges(_ mask: [Int]) -> [CountableClosedRange<Int>] {
var ranges = [CountableClosedRange<Int>]()
var start: Int?
var end: Int?
var start: Int = -1
var end: Int = -1
for (n, bit) in mask.enumerated() {
if bit == 1 && start == nil {
if bit == 1 && start == -1 {
start = n
} else if bit == 0 && start != nil {
} else if bit == 0 && start != -1 {
end = n - 1
ranges.append(CountableClosedRange<Int>(start!...end!))
start = nil
ranges.append(CountableClosedRange<Int>(start...end))
start = -1
}
}
if mask.last == 1 {
ranges.append(CountableClosedRange<Int>(start!...mask.count - 1))
ranges.append(CountableClosedRange<Int>(start...mask.count - 1))
}
return ranges
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let fuse = Fuse()
let result = fuse.search("od mn war", in: "Old Man's War")

print(result?.score) // 0.44444444444444442
print(result?.ranges) // [CountableRange(0..<0), CountableRange(2..<6), CountableRange(9..<12)]
print(result?.ranges) // [CountableClosedRange(0...0), CountableClosedRange(2...6), CountableClosedRange(9...12)]
```

#### Example 2
Expand Down Expand Up @@ -76,11 +76,11 @@ results.forEach { item in
//
// index: 1
// score: 0.015
// results: [(key: "author", score: 0.015000000000000003, ranges: [CountableRange(5..<7)])]
// results: [(key: "author", score: 0.015000000000000003, ranges: [CountableClosedRange(5...7)])]
// ---------------
// index: 0
// score: 0.028
// results: [(key: "title", score: 0.027999999999999997, ranges: [CountableRange(4..<6)])]
// results: [(key: "title", score: 0.027999999999999997, ranges: [CountableClosedRange(4...6)])]
```

### Options
Expand Down

0 comments on commit d369a8b

Please sign in to comment.