No commit activity in last 3 years
No release in over 3 years
Sorted array using binary search
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2
>= 2.13

Runtime

~> 1.5
 Project Readme

sorted_array_binary

Build Status [![Coverage Status] (https://coveralls.io/repos/ledestin/sorted_array_binary/badge.png)] (https://coveralls.io/r/ledestin/sorted_array_binary) Code Climate

A sorted array using binary search

Why

  1. Neither of the existing sorted arrays gems use binary search (i.e. slow or very slow).
  2. I don't like their source code, so I decided to roll my own, instead of contributing.

Existing sorted array gems as of Jan 2014:

  • sorted_array (0.0.5)
  • array-sorted (1.1.2)

Example

require 'sorted_array_binary'

# Use standard sorting via <=>.
array = SortedArrayBinary.new
array.push 'b', 'a' #=> ['a', 'b']

# Use custom sorting block.
array = SortedArrayBinary.new { |a, b| b <=> a }
array.push 'a', 'b' #=> ['b', 'a']

# Take care to only add items that can be compared with <=>.
array.push nil, 1 #=> exception is raised

Performance

When #push'ing 1000 random numbers into an array:

sorted_array        (0.0.5)     1.179088
array-sorted        (1.1.2)     0.076348
sorted_array_binary (0.0.3)     0.005244

Installation

gem install sorted_array_binary