def exists()

in cassovary-collections/src/main/scala/com/twitter/cassovary/collections/SortedCSeqOps.scala [10:31]


  def exists(cseq: CSeq[Int], elem: Int): Boolean = {
    if (cseq.isEmpty) return false

    def cSeqBinarySearch(a: CSeq[Int], key: Int): Int = {
      var low: Int = 0
      var high: Int = cseq.length - 1

      while (low <= high) {
        val mid: Int = (low + high) >>> 1
        val midVal: Int = a(mid)
        if (midVal < key) low = mid + 1
        else if (midVal > key) high = mid - 1
        else return mid
      }
      return -(low + 1)
    }

    cSeqBinarySearch(cseq, elem) match {
      case idx if idx < 0 => false
      case idx => true
    }
  }