0.0
There's a lot of open issues
No release in over a year
Ruby bindings to GTree balanced binary tree from GLib library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

GLib Balanced binary tree (GTree) bindings for Ruby

Ruby codecov Gem Version License: LGPL v3

GTree - balanced binary tree from GLib library

In most cases it will behave same as Hash, but keys will be ordered by passed comparator.

Requirements

  • CMake build tool version >= 3.5.0, >= 3.14.0 will be cool.
  • pkg-config tool
  • GLib library
    • On Ubuntu run:
    sudo apt-get install pkg-config cmake libglib2.0-dev
    • On MacOS run:
    brew install pkg-config cmake glib
    
    • On FreeBSD use pkg or ports.
    • On windows use Google. I don't really know how it can work at this moment... But i think it's possible

Check CMake tool version!

Basic usage

Example

require 'native_btree'

# Pass comparator for keys as block
tree = NativeBtree::Btree.new { |a, b|  a - b }

tree[1] = '111'
tree[3] = '333'
tree[2] = '222'

tree.each { |k, v| puts "#{k} => #{v}" }

# 1 => 111
# 2 => 222
# 3 => 333
# nil

tree.size
# 3

tree.height
# 2

Native int comparator

Will behave like an array with negative indexes)

# Pass comparator for keys as block
tree = NativeBtree::Btree.new(NativeBtree::Btree::INT_COMPARATOR)

tree[-2] = 22
tree[-1] = 1
tree[0] = 100
tree[5] = 55

tree.to_a

#[
#    [0] [
#        [0] -2,
#        [1] 22
#    ],
#    [1] [
#        [0] -1,
#        [1] 1
#    ],
#    [2] [
#        [0] 0,
#        [1] 100
#    ],
#    [3] [
#        [0] 5,
#        [1] 55
#    ]
#]

API

  • You must provide your own comparator for keys in new class method block.
  • You can mix in the Enumerable module if additional methods are needed.

API methods

YARD documentation