Project

kibo-rb

0.0
No commit activity in last 3 years
No release in over 3 years
Kibo is a small library that implements classic algorithms like binary search, merge, sort, bubble sorts, etc..
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.11
~> 10.0
 Project Readme

Kibo

Build

Small API for sorting and finding elements in arrays and other data structures.

###What's so good about it?

Almost everything is O(logn) or O(nlogn).

Installation

Add this line to your application's Gemfile:

gem 'kibo-rb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kibo-rb

Usage

Kibo is really easy to use, you just have to:

require 'kibo' #not kibo-rb

Kibo::Search.bsearch(your_array, your_element)

Kibo also comes with a Native option

require 'kibo' #not kibo rb

a = (1..1_000_000).to_a
a.binsearch(563_321)

Kibo Native overrides the Array class to include the method binsearch so you don't have to make additional objects. Kibo will return true if the element exists in your array. Right now, .sbearch method only works wih integers, other data types will come later!

Benchmarks

This is the performance of kibo:

require 'benchmark'
require 'kibo'

a = (1..1000).to_a
b = (1..100_000).to_a
c = (1..1_0000_000).to_a
d = (1..2_000_000).to_a
e = (1..10_000_000).to_a
f = (1..20_000_000).to_a

#1000 elements
time1 = Benchmark.realtime do
  Kibo::Search.bsearch(a, 342)
end

#100_000 elements
time2 = Benchmark.realtime do
  Kibo::Search.bsearch(b, 56_321)
end

#1_000_000 elements
time3 = Benchmark.realtime do
  Kibo::Search.bsearch(c, 421_342)
end

#2_000_000 elements
time4 = Benchmark.realtime do
  Kibo::Search.bsearch(d, 1_321_123)
end

#10_000_000 elements
time5 = Benchmark.realtime do
  Kibo::Search.bsearch(e, 3_941_311)
end

#20_000_000 elements
time6 = Benchmark.realtime do
  Kibo::Search.bsearch(f, 12_321_125)
end

Which yielded: (respectively)

  Time elapsed: 0.012903001334052533 miliseconds
  Time elapsed: 0.00821600406197831 miliseconds
  Time elapsed: 0.01727400376694277 miliseconds
  Time elapsed: 0.013912998838350177 miliseconds
  Time elapsed: 0.018266997358296067 miliseconds
  Time elapsed: 0.025380999431945384 miliseconds

##TODO

  • Write benchmarks for all methods
  • Write tests for all methods
  • Implement sorts
  • Implement other search methods

License

The gem is available as open source under the terms of the MIT License.