NB: Special Image for Automated Tests only
1.1K
GTree - balanced binary tree from GLib library
In most cases it will behave same as Hash, but keys will be ordered by passed comparator.
pkg-config toolsudo apt-get install pkg-config cmake libglib2.0-dev
brew install pkg-config cmake glib
Check CMake tool version!
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
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
# ]
#]
new class method block.Enumerable module if additional methods are needed.Content type
Image
Digest
sha256:b5af3dd0f…
Size
303.5 MB
Last updated
over 3 years ago
docker pull unixs/ruby-btree-tests