 }
 
 /**
+ Binary search.
+ - parameter key: Query.
+ - parameter sortedArray: Must be sorted in ascending order.
+ - parameter comparator: Comparator for each pair.
+ - returns: Result element among sortedArray and a number of execution of the compator. If no one is matched in the sortedArray, return nil.
+ */
+internal func bsearch<T, U>(with key: T, from sortedArray: [U], comparator: (T, U) -> Int) -> (U, Int)? {
+    var searchCount = 0
+    var startIndex = sortedArray.startIndex
+    var endIndex = sortedArray.endIndex
+    var range = startIndex..<endIndex
+    var middle = startIndex.advanced(by: range.count/2)
+    repeat {
+        range = startIndex..<endIndex
+        middle = startIndex.advanced(by: range.count/2)
+        searchCount += 1
+        let c = comparator(key, sortedArray[middle])
+        if c == 1 {
+            startIndex = middle
+        } else if c == -1 {
+            endIndex = middle
+        } else if c == 0 {
+            return (sortedArray[middle], searchCount)
+        } else {
+            return nil
+        }
+    } while range.count > 1
+    return nil
+}
+
+// MARK: - Unicode
+
+/**
  Decode, convert unicode scalar value to UTF16 code.
- - parameter unicode: 
- - returns:
- */
-private func decodeUnicodeScalar(unicode: UInt) -> [unichar] {
+ - parameter unicode: Unicode scalar value to be decoded.
+ - returns: Array of `unichar`, which contains UTF16 code.
+ */
+private func convertToSurrogatePair(unicodeScalar: UInt) -> [unichar] {
     // This convert algorithm is based on https://en.wikipedia.org/wiki/UTF-16
-    let w: UInt  = (unicode & 0b00000000000111110000000000000000) >> 16 - 1
-    let x1: UInt = (unicode & 0b00000000000000001111110000000000) >> 10
-    let x2: UInt = (unicode & 0b00000000000000000000001111111111) >> 0
+    let w: UInt  = (unicodeScalar & 0b00000000000111110000000000000000) >> 16 - 1
+    let x1: UInt = (unicodeScalar & 0b00000000000000001111110000000000) >> 10
+    let x2: UInt = (unicodeScalar & 0b00000000000000000000001111111111) >> 0
     let u1: UInt16 = UInt16((0b11011000 << 8) + (w << 6) + x1)
     let u2: UInt16 = UInt16(UInt(0b11011100 << 8) + x2)
     return [u1, u2]


/**
 Encode, convert UTF16 code to unicode scalar value.
 - parameter u1:
 - parameter u2:
 - returns:
 */
private func encodeUTF16(u1: unichar, u2: unichar) -> [UInt]? {
    // This convert algorithm is based on https://en.wikipedia.org/wiki/UTF-16
    guard u1 > (0b11011000 << 8) else { return nil }
    guard u1 < (0b11011100 << 8) else { return nil }

            return self
        }
    }
    
    /**
     Returns a String initialized by converting given ContiguousStorage of Unicode characters into Unicode characters.
     */
    private init<T>(utf16Storage: T) throws where T: ContiguousStorage, T.Iterator.Element == unichar {
        self = try utf16Storage.withUnsafeBufferPointer {
