2017년 1월 13일 금요일

Swift Study - Boyer-Moore String Search

swift-algorithm-club를 통한 swift 공부

Boyer-Moore String Search : String 사용방법을 알 수 있다.
  • String 에 extension으로 index 함수를 구현한다.
  • func index(of pattern: String) -> Index? { ... }
  • String의 length는 String.characters.count로 구할 수 있다.
  • let patternLength = pattern.characters.count
  • skip table은 dictionary type으로 저장하고 있는다.
  • var skipTable = [Character: Int]()
  • String으로부터 index와 Character를 뽑아낼 수 있다.
  • for (i, c) in pattern.characters.enumerated() { ... }
  • String에는 다음과 같은 property가 있다: startIndex, endIndex
  • String에는 index를 리턴하는 함수들이 있다: index(before: String.Index)
  • index(before: String.Index)
  • index(after: String.Index)
  • index(i: String.Index, offsetBy: String.IndexDistance)
  • index(i: String.Index, offsetBy: String.IndexDistance, limitedBy: String.Index)
  • index 값을 아는 경우 함수 안에서 self로 String의 character에 접근할 수 있다.(여기서 i는 Int값이 아니라 String.Index라는데 주의)
  • let c = self[i]

댓글 없음:

댓글 쓰기

Building asynchronous views in SwiftUI 정리

Handling loading states within SwiftUI views self loading views View model 사용하기 Combine을 사용한 AnyPublisher Making SwiftUI views refreshable r...