native_btree 0.1.0.alpha1 → 0.1.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CMakeLists.txt +48 -0
- data/Gemfile +6 -0
- data/LICENSE +165 -0
- data/README.md +34 -0
- data/Rakefile +41 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ext/native_btree/CMakeLists.txt +21 -0
- data/ext/native_btree/extconf_cmake.rb +15 -0
- data/ext/native_btree/include/native_btree.h +5 -1
- data/ext/native_btree/native_btree.c +17 -20
- data/lib/native_btree/native_btree.so +0 -0
- data/lib/native_btree/version.rb +2 -2
- data/lib/native_btree.rb +2 -1
- data/native_btree.gemspec +46 -0
- data/spec/native_btree_spec.rb +17 -0
- data/spec/spec_helper.rb +15 -0
- metadata +177 -18
- data/ext/native_btree/btree.cc +0 -128
- data/ext/native_btree/extconf.h +0 -11
- data/ext/native_btree/extconf.rb +0 -35
- data/ext/native_btree/rb_methods.cc +0 -221
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc39abeab06b5ed3984afa9cda174d12556523df6926db05e2889274c0157305
|
4
|
+
data.tar.gz: 596a2b8af36be3da1ac5ebc2c64749f52e7ed5cb83d12280f11aa584f93e3fab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87faa333af87558b8a7600e680daf5367dce6f5393e524d467321409b0f1e5285aeedb2cfc6d2c3044c8a978f84d5b6135a628b6a3736df7b040b5312f04bd5c
|
7
|
+
data.tar.gz: 3aac04b9a2c1b14bff0db483c3075e164b6f7fe6fb9a9a45d4275fc9a66aa6a1cfa4f555a74c4680b821d12d8818985b0d10a2ca45fc69cd40a1f658c6401ab3
|
data/CHANGELOG.md
ADDED
data/CMakeLists.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
cmake_minimum_required(VERSION 3.18.0)
|
2
|
+
|
3
|
+
project(ruby-native-btree
|
4
|
+
LANGUAGES C
|
5
|
+
VERSION 0.1.0
|
6
|
+
HOMEPAGE_URL https://github.com/unixs/ruby-native-btree)
|
7
|
+
|
8
|
+
set(REQUIRED_RUBY_VERSION 2.7.0)
|
9
|
+
|
10
|
+
set(CMAKE_C_STANDARD 11)
|
11
|
+
set(CMAKE_C_EXTENSIONS ON)
|
12
|
+
set(CMAKE_C_STANDARD_REQUIRED ON)
|
13
|
+
|
14
|
+
set(CMAKE_C_FLAGS_DEBUG " -O0 -ggdb3 -Wall -Wextra -Wpedantic -Wno-unused-parameter")
|
15
|
+
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
16
|
+
set(CMAKE_C_FLAGS "-pipe -march=native")
|
17
|
+
|
18
|
+
if(NOT CMAKE_BUILD_TYPE)
|
19
|
+
set(CMAKE_BUILD_TYPE "Release")
|
20
|
+
endif()
|
21
|
+
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
22
|
+
|
23
|
+
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
24
|
+
|
25
|
+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
26
|
+
set(CMAKE_SHARED_LIBRARY_SUFFIX ".bundle")
|
27
|
+
set(CMAKE_FIND_FRAMEWORK LAST)
|
28
|
+
message(STATUS "CMAKE_FIND_FRAMEWORK='${CMAKE_FIND_FRAMEWORK}'")
|
29
|
+
endif()
|
30
|
+
|
31
|
+
find_package(PkgConfig REQUIRED)
|
32
|
+
|
33
|
+
# Find Ruby
|
34
|
+
find_package(Ruby ${REQUIRED_RUBY_VERSION} REQUIRED)
|
35
|
+
include_directories(${Ruby_INCLUDE_DIRS})
|
36
|
+
link_libraries(${Ruby_LIBRARIES})
|
37
|
+
message("Ruby_INCLUDE_DIRS: ${Ruby_INCLUDE_DIRS}")
|
38
|
+
|
39
|
+
message("Find Ruby deps.")
|
40
|
+
# Find jemalloc
|
41
|
+
pkg_check_modules(JEMALLOC jemalloc)
|
42
|
+
if(JEMALLOC_FOUND)
|
43
|
+
include_directories(${JEMALLOC_INCLUDE_DIRS})
|
44
|
+
# link_libraries(${JEMALLOC_LIBRARIES})
|
45
|
+
endif()
|
46
|
+
|
47
|
+
# Attach extension dir
|
48
|
+
add_subdirectory("ext/native_btree")
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Native Balanced binary tree for Ruby
|
2
|
+
|
3
|
+
Ruby bindings to [GTree - balanced binary tree from GLib library](https://developer.gnome.org/glib/stable/glib-Balanced-Binary-Trees.html) .
|
4
|
+
|
5
|
+
In most cases it is behave same as Hash, but keys will be ordered by passed comparator.
|
6
|
+
|
7
|
+
Basic usage:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'native_btree'
|
11
|
+
|
12
|
+
# Pass comparator for keys as block
|
13
|
+
tree = NativeBTree::BTree.new { |a, b| a <=> b }
|
14
|
+
|
15
|
+
tree[:a1] = '111'
|
16
|
+
tree[:c3] = '333'
|
17
|
+
tree[:b2] = '222'
|
18
|
+
|
19
|
+
tree.each { |k, v| puts "#{k} => #{v}" }
|
20
|
+
|
21
|
+
# a1 => 111
|
22
|
+
# b2 => 222
|
23
|
+
# c3 => 333
|
24
|
+
# nil
|
25
|
+
|
26
|
+
tree.size
|
27
|
+
# 3
|
28
|
+
|
29
|
+
tree.height
|
30
|
+
# 2
|
31
|
+
```
|
32
|
+
|
33
|
+
Trees is may comparable by `==` or `.eql?` operator.
|
34
|
+
Trees will be equal if all keys and all value is equal in both.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[rubocop spec]
|
13
|
+
|
14
|
+
BUILD_DIR = "build"
|
15
|
+
|
16
|
+
namespace :cmake do
|
17
|
+
desc "Remove build directory"
|
18
|
+
task :rmbuild do
|
19
|
+
sh "rm -rvf #{BUILD_DIR}"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Configure ext CMake project"
|
23
|
+
task configure: %i[cmake:rmbuild] do
|
24
|
+
sh "cmake . -B #{BUILD_DIR}"
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Build ext CMake project"
|
28
|
+
task build: %i[cmake:configure] do
|
29
|
+
sh "cmake --build #{BUILD_DIR}"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "`Rebuild ext CMake project"
|
33
|
+
task rebuild: %i[cmake:configure] do
|
34
|
+
sh "cmake --build #{BUILD_DIR} --clean-first"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Clean ext CMake project"
|
38
|
+
task :clean do
|
39
|
+
sh "cmake --build #{BUILD_DIR} --target clean"
|
40
|
+
end
|
41
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "ruby_btree"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
set(EXT_NAME "native_btree")
|
2
|
+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/${EXT_NAME})
|
3
|
+
|
4
|
+
include_directories(include)
|
5
|
+
|
6
|
+
message("Find ext deps.")
|
7
|
+
|
8
|
+
pkg_check_modules(GLIB2 REQUIRED glib-2.0)
|
9
|
+
|
10
|
+
# include_directories(include ${GLIB2_INCLUDE_DIRS})
|
11
|
+
add_library(${EXT_NAME}
|
12
|
+
SHARED
|
13
|
+
native_btree.c)
|
14
|
+
|
15
|
+
#set_target_properties(${EXT_NAME} PROPERTIES BUNDLE TRUE)
|
16
|
+
|
17
|
+
|
18
|
+
#target_link_libraries(${EXT_NAME}
|
19
|
+
# PRIVATE
|
20
|
+
# ${GLIB2_LDFLAGS})
|
21
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
require "rake"
|
3
|
+
|
4
|
+
abort "CMake build tool not found" unless find_executable('cmake')
|
5
|
+
|
6
|
+
File.open("Makefile", "wb") do |f|
|
7
|
+
dummy_makefile(".").each do |line|
|
8
|
+
f.puts(line)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
app = Rake.application
|
13
|
+
app.init
|
14
|
+
app.load_rakefile
|
15
|
+
app['cmake:rebuild'].invoke
|
@@ -1,5 +1,8 @@
|
|
1
1
|
#ifndef _NATIVE_BTREE_
|
2
|
-
|
2
|
+
|
3
|
+
#define NATIVE_BTREE "NativeBtree"
|
4
|
+
#define NATIVE_BTREE_CLASS "Btree"
|
5
|
+
|
3
6
|
|
4
7
|
#if defined(__cplusplus)
|
5
8
|
extern "C" {
|
@@ -7,6 +10,7 @@ extern "C" {
|
|
7
10
|
|
8
11
|
extern VALUE btree_class;
|
9
12
|
extern VALUE btree_module;
|
13
|
+
extern VALUE btree_class_from;
|
10
14
|
|
11
15
|
VALUE
|
12
16
|
btree_new(VALUE klass);
|
@@ -1,30 +1,27 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
1
3
|
#include <native_btree.h>
|
2
4
|
|
3
5
|
VALUE btree_class;
|
4
6
|
VALUE btree_module;
|
7
|
+
VALUE btree_class_from;
|
8
|
+
|
9
|
+
VALUE
|
10
|
+
btree_from(VALUE klass);
|
11
|
+
|
12
|
+
VALUE
|
13
|
+
btree_from(VALUE klass)
|
14
|
+
{
|
15
|
+
VALUE result = INT2NUM(10);
|
16
|
+
|
17
|
+
return result;
|
18
|
+
}
|
5
19
|
|
6
20
|
void
|
7
21
|
Init_native_btree()
|
8
22
|
{
|
9
|
-
btree_module = rb_define_module(
|
10
|
-
btree_class = rb_define_class_under(btree_module,
|
11
|
-
|
12
|
-
rb_define_singleton_method(btree_class, "new", btree_new, 0);
|
13
|
-
// rb_define_method(btree_class, "initialize", btree_init, 0);
|
14
|
-
rb_define_method(btree_class, "size", btree_size, 0);
|
15
|
-
rb_define_method(btree_class, "height", btree_height, 0);
|
16
|
-
rb_define_method(btree_class, "set", btree_set, 2);
|
17
|
-
rb_define_alias(btree_class, "[]=", "set");
|
18
|
-
rb_define_method(btree_class, "get", btree_get, 1);
|
19
|
-
rb_define_alias(btree_class, "[]", "get");
|
20
|
-
rb_define_method(btree_class, "delete", btree_delete, 1);
|
21
|
-
rb_define_method(btree_class, "clear", btree_clear, 0);
|
22
|
-
rb_define_method(btree_class, "has", btree_has, 1);
|
23
|
-
rb_define_method(btree_class, "each", btree_each, 0);
|
24
|
-
rb_define_method(btree_class, "<=>", btree_cmp, 1);
|
25
|
-
rb_define_method(btree_class, "eql?", btree_equal, 1);
|
26
|
-
rb_define_alias(btree_class, "==", "eql?");
|
27
|
-
// TODO: to_ary
|
28
|
-
// TODO: to_hash
|
23
|
+
btree_module = rb_define_module(NATIVE_BTREE);
|
24
|
+
btree_class = rb_define_class_under(btree_module, NATIVE_BTREE_CLASS, rb_cObject);
|
25
|
+
rb_define_singleton_method(btree_class, "from", btree_from, 0);
|
29
26
|
}
|
30
27
|
|
Binary file
|
data/lib/native_btree/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.1.0.
|
1
|
+
module NativeBtree
|
2
|
+
VERSION = "0.1.0.alpha2".freeze
|
3
3
|
end
|
data/lib/native_btree.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative "lib/native_btree/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'native_btree'
|
5
|
+
s.version = NativeBtree::VERSION
|
6
|
+
|
7
|
+
s.metadata = {
|
8
|
+
"bug_tracker_uri" => "https://github.com/unixs/ruby-native-btree/issues",
|
9
|
+
"changelog_uri" => "https://github.com/unixs/ruby-native-btree/blob/master/CHANGELOG.md",
|
10
|
+
"documentation_uri" => "https://github.com/unixs/ruby-native-btree/wiki",
|
11
|
+
"homepage_uri" => "https://github.com/unixs/ruby-native-btree",
|
12
|
+
"source_code_uri" => "https://github.com/unixs/ruby-native-btree",
|
13
|
+
"wiki_uri" => "https://github.com/unixs/ruby-native-btree/wiki",
|
14
|
+
"rubygems_mfa_required" => "true"
|
15
|
+
}
|
16
|
+
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.summary = 'Balanced binary tree from GLib.'
|
19
|
+
s.description = 'Ruby bindings to GTree balanced binary tree from GLib library.'
|
20
|
+
s.authors = ['Alexander Feodorov']
|
21
|
+
s.email = ['webmaster@unixcomp.org']
|
22
|
+
s.licenses = ['LGPL-3.0-or-later']
|
23
|
+
s.homepage = 'https://github.com/unixs/ruby-native-btree'
|
24
|
+
s.extensions = ["ext/#{s.name}/extconf_cmake.rb"]
|
25
|
+
|
26
|
+
s.files = Dir['{bin,ext,lib,spec}/**/*']
|
27
|
+
s.files += Dir['*.{md}']
|
28
|
+
s.files += %w[Rakefile Gemfile CMakeLists.txt native_btree.gemspec LICENSE]
|
29
|
+
|
30
|
+
s.bindir = "bin"
|
31
|
+
s.executables = s.files.grep(%r{\Abin/}) { |f| File.basename(f) }
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.required_ruby_version = '>= 2.6'
|
34
|
+
|
35
|
+
s.add_dependency 'rubocop', '~> 1.35.0'
|
36
|
+
s.add_dependency 'rubocop-rake', '~> 0.6.0'
|
37
|
+
s.add_dependency 'rubocop-rspec', '~> 2.12.1'
|
38
|
+
s.add_dependency 'rake', '~> 13.0.6'
|
39
|
+
s.add_dependency 'rspec', '~> 3.11.0'
|
40
|
+
|
41
|
+
s.add_development_dependency 'awesome_print', '~> 1.9'
|
42
|
+
s.add_development_dependency 'debase', '~> 0.2'
|
43
|
+
s.add_development_dependency 'pry', '~> 0.14'
|
44
|
+
s.add_development_dependency 'ruby-debug-ide', '~> 0.7'
|
45
|
+
s.add_development_dependency 'solargraph', '~> 0.46'
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe NativeBtree do
|
4
|
+
it "has a version number" do
|
5
|
+
expect(NativeBtree::VERSION).not_to be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "does something useful" do
|
9
|
+
expect((1 + 1)).to be(2)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe NativeBtree::Btree do
|
13
|
+
it "respond to from" do
|
14
|
+
expect(described_class.from).to be(10)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "native_btree"
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
# Enable flags like --only-failures and --next-failure
|
7
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
8
|
+
|
9
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
10
|
+
config.disable_monkey_patching!
|
11
|
+
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
c.syntax = :expect
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,37 +1,196 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: native_btree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Feodorov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2022-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.35.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.35.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.12.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.12.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 13.0.6
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 13.0.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.11.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.11.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: awesome_print
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: debase
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.14'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.14'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: ruby-debug-ide
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.7'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.7'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: solargraph
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.46'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.46'
|
153
|
+
description: Ruby bindings to GTree balanced binary tree from GLib library.
|
14
154
|
email:
|
15
155
|
- webmaster@unixcomp.org
|
16
|
-
executables:
|
156
|
+
executables:
|
157
|
+
- console
|
158
|
+
- setup
|
17
159
|
extensions:
|
18
|
-
- ext/native_btree/
|
160
|
+
- ext/native_btree/extconf_cmake.rb
|
19
161
|
extra_rdoc_files: []
|
20
162
|
files:
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
163
|
+
- CHANGELOG.md
|
164
|
+
- CMakeLists.txt
|
165
|
+
- Gemfile
|
166
|
+
- LICENSE
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- bin/console
|
170
|
+
- bin/setup
|
171
|
+
- ext/native_btree/CMakeLists.txt
|
172
|
+
- ext/native_btree/extconf_cmake.rb
|
24
173
|
- ext/native_btree/include/btree.h
|
25
174
|
- ext/native_btree/include/native_btree.h
|
26
175
|
- ext/native_btree/native_btree.c
|
27
|
-
- ext/native_btree/rb_methods.cc
|
28
176
|
- lib/native_btree.rb
|
177
|
+
- lib/native_btree/native_btree.so
|
29
178
|
- lib/native_btree/version.rb
|
179
|
+
- native_btree.gemspec
|
180
|
+
- spec/native_btree_spec.rb
|
181
|
+
- spec/spec_helper.rb
|
30
182
|
homepage: https://github.com/unixs/ruby-native-btree
|
31
183
|
licenses:
|
32
|
-
-
|
33
|
-
metadata:
|
34
|
-
|
184
|
+
- LGPL-3.0-or-later
|
185
|
+
metadata:
|
186
|
+
bug_tracker_uri: https://github.com/unixs/ruby-native-btree/issues
|
187
|
+
changelog_uri: https://github.com/unixs/ruby-native-btree/blob/master/CHANGELOG.md
|
188
|
+
documentation_uri: https://github.com/unixs/ruby-native-btree/wiki
|
189
|
+
homepage_uri: https://github.com/unixs/ruby-native-btree
|
190
|
+
source_code_uri: https://github.com/unixs/ruby-native-btree
|
191
|
+
wiki_uri: https://github.com/unixs/ruby-native-btree/wiki
|
192
|
+
rubygems_mfa_required: 'true'
|
193
|
+
post_install_message:
|
35
194
|
rdoc_options: []
|
36
195
|
require_paths:
|
37
196
|
- lib
|
@@ -39,15 +198,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
198
|
requirements:
|
40
199
|
- - ">="
|
41
200
|
- !ruby/object:Gem::Version
|
42
|
-
version: '2.
|
201
|
+
version: '2.6'
|
43
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
203
|
requirements:
|
45
204
|
- - ">"
|
46
205
|
- !ruby/object:Gem::Version
|
47
206
|
version: 1.3.1
|
48
207
|
requirements: []
|
49
|
-
rubygems_version: 3.1.
|
50
|
-
signing_key:
|
208
|
+
rubygems_version: 3.1.6
|
209
|
+
signing_key:
|
51
210
|
specification_version: 4
|
52
|
-
summary:
|
211
|
+
summary: Balanced binary tree from GLib.
|
53
212
|
test_files: []
|
data/ext/native_btree/btree.cc
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
#include "btree.h"
|
2
|
-
|
3
|
-
BTree::BTree(VALUE comnparator)
|
4
|
-
{
|
5
|
-
this->comparator = comnparator;
|
6
|
-
this->tree = g_tree_new_with_data(BTree::nativeComparator, this);
|
7
|
-
}
|
8
|
-
|
9
|
-
BTree::~BTree()
|
10
|
-
{
|
11
|
-
g_tree_destroy(this->tree);
|
12
|
-
}
|
13
|
-
|
14
|
-
void
|
15
|
-
BTree::mark()
|
16
|
-
{
|
17
|
-
rb_gc_mark(this->comparator);
|
18
|
-
this->markMyRValues();
|
19
|
-
}
|
20
|
-
|
21
|
-
void
|
22
|
-
BTree::markMyRValues()
|
23
|
-
{
|
24
|
-
g_tree_foreach(this->tree, BTree::markRValue, NULL);
|
25
|
-
}
|
26
|
-
|
27
|
-
gint
|
28
|
-
BTree::markRValue(gpointer k, gpointer v, gpointer not_used)
|
29
|
-
{
|
30
|
-
const VALUE key = reinterpret_cast<VALUE>(k);
|
31
|
-
const VALUE value = reinterpret_cast<VALUE>(v);
|
32
|
-
|
33
|
-
rb_gc_mark(key);
|
34
|
-
rb_gc_mark(value);
|
35
|
-
|
36
|
-
return false;
|
37
|
-
}
|
38
|
-
|
39
|
-
gint
|
40
|
-
BTree::nativeComparator(gconstpointer a, gconstpointer b, gpointer data)
|
41
|
-
{
|
42
|
-
const BTree *tree = static_cast<BTree *>(data);
|
43
|
-
const VALUE keyA = reinterpret_cast<VALUE>(a);
|
44
|
-
const VALUE keyB = reinterpret_cast<VALUE>(b);
|
45
|
-
|
46
|
-
VALUE ruby_result = rb_funcall(tree->comparator, rb_intern("call"), 2, keyA, keyB);
|
47
|
-
|
48
|
-
return NUM2INT(ruby_result);
|
49
|
-
}
|
50
|
-
|
51
|
-
gint
|
52
|
-
BTree::size()
|
53
|
-
{
|
54
|
-
return g_tree_nnodes(this->tree);
|
55
|
-
}
|
56
|
-
|
57
|
-
gint
|
58
|
-
BTree::height()
|
59
|
-
{
|
60
|
-
return g_tree_height(this->tree);
|
61
|
-
}
|
62
|
-
|
63
|
-
void
|
64
|
-
BTree::set(VALUE key, VALUE value)
|
65
|
-
{
|
66
|
-
g_tree_replace(this->tree, (gpointer) key, (gpointer) value);
|
67
|
-
}
|
68
|
-
|
69
|
-
VALUE
|
70
|
-
BTree::get(VALUE key)
|
71
|
-
{
|
72
|
-
gpointer result = g_tree_lookup(this->tree, reinterpret_cast<gconstpointer>(key));
|
73
|
-
|
74
|
-
if (!result) {
|
75
|
-
return Qnil;
|
76
|
-
}
|
77
|
-
|
78
|
-
return reinterpret_cast<VALUE>(result);
|
79
|
-
}
|
80
|
-
|
81
|
-
bool
|
82
|
-
BTree::del(VALUE key)
|
83
|
-
{
|
84
|
-
return g_tree_remove(this->tree, reinterpret_cast<gconstpointer>(key));
|
85
|
-
}
|
86
|
-
|
87
|
-
void
|
88
|
-
BTree::clear()
|
89
|
-
{
|
90
|
-
g_tree_unref(this->tree);
|
91
|
-
this->tree = g_tree_new_with_data(BTree::nativeComparator, this);
|
92
|
-
}
|
93
|
-
|
94
|
-
bool
|
95
|
-
BTree::has(VALUE key)
|
96
|
-
{
|
97
|
-
bool result = g_tree_lookup(this->tree, reinterpret_cast<gconstpointer>(key));
|
98
|
-
|
99
|
-
if (!result) {
|
100
|
-
return true;
|
101
|
-
}
|
102
|
-
|
103
|
-
return false;
|
104
|
-
}
|
105
|
-
|
106
|
-
gboolean
|
107
|
-
BTree::traverseFunc(gpointer k, gpointer v, gpointer b)
|
108
|
-
{
|
109
|
-
const VALUE key = reinterpret_cast<VALUE>(k);
|
110
|
-
const VALUE value = reinterpret_cast<VALUE>(v);
|
111
|
-
const VALUE block = reinterpret_cast<VALUE>(b);
|
112
|
-
|
113
|
-
rb_funcall(block, rb_intern("call"), 2, key, value);
|
114
|
-
|
115
|
-
return FALSE;
|
116
|
-
}
|
117
|
-
|
118
|
-
void
|
119
|
-
BTree::each(VALUE block)
|
120
|
-
{
|
121
|
-
g_tree_foreach(this->tree, BTree::traverseFunc, reinterpret_cast<gpointer>(block));
|
122
|
-
}
|
123
|
-
|
124
|
-
void
|
125
|
-
BTree::each(GTraverseFunc func, gpointer data)
|
126
|
-
{
|
127
|
-
g_tree_foreach(this->tree, func, data);
|
128
|
-
}
|
data/ext/native_btree/extconf.h
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
#ifndef EXTCONF_H
|
2
|
-
#define EXTCONF_H
|
3
|
-
#define HAVE_G_TREE_INSERT 1
|
4
|
-
#define HAVE_G_TREE_REPLACE 1
|
5
|
-
#define HAVE_G_TREE_NNODES 1
|
6
|
-
#define HAVE_G_TREE_LOOKUP 1
|
7
|
-
#define HAVE_G_TREE_FOREACH 1
|
8
|
-
#define HAVE_G_TREE_SEARCH 1
|
9
|
-
#define HAVE_G_TREE_DESTROY 1
|
10
|
-
#define HAVE_G_TREE_HEIGHT 1
|
11
|
-
#endif
|
data/ext/native_btree/extconf.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require "mkmf"
|
2
|
-
|
3
|
-
local_include = %w(
|
4
|
-
$(srcdir)/include
|
5
|
-
);
|
6
|
-
|
7
|
-
ldflags = cppflags = nil
|
8
|
-
|
9
|
-
pkg_config "glib-2.0"
|
10
|
-
dir_config 'glib', cppflags, ldflags
|
11
|
-
|
12
|
-
abort "Can't find the glib.h header" unless find_header 'glib.h'
|
13
|
-
abort "Can't find the glib libary'" unless find_library 'glib-2.0', 'g_tree_new_full'
|
14
|
-
abort "g_tree_insert() not found" unless have_func 'g_tree_insert'
|
15
|
-
abort "g_tree_replace() not found" unless have_func 'g_tree_replace'
|
16
|
-
abort "g_tree_nnodes() not found" unless have_func 'g_tree_nnodes'
|
17
|
-
abort "g_tree_lookup() not found" unless have_func 'g_tree_lookup'
|
18
|
-
abort "g_tree_foreach() not found" unless have_func 'g_tree_foreach'
|
19
|
-
abort "g_tree_search() not found" unless have_func 'g_tree_search'
|
20
|
-
abort "g_tree_destroy() not found" unless have_func 'g_tree_destroy'
|
21
|
-
abort "g_tree_height() not found" unless have_func 'g_tree_height'
|
22
|
-
|
23
|
-
$DEBUG = true
|
24
|
-
|
25
|
-
$VPATH.concat %w(
|
26
|
-
$(srcdir)/include
|
27
|
-
)
|
28
|
-
|
29
|
-
$INCFLAGS << local_include.map{|dir| " -I#{dir}" }.join("")
|
30
|
-
CONFIG["debugflags"] = "-ggdb3"
|
31
|
-
CONFIG["optflags"] = "-O0"
|
32
|
-
$CXXFLAGS = "-O0 -ggdb3 -pipe"
|
33
|
-
|
34
|
-
create_header
|
35
|
-
create_makefile "native_btree/native_btree"
|
@@ -1,221 +0,0 @@
|
|
1
|
-
#include <ruby.h>
|
2
|
-
#include <glib.h>
|
3
|
-
|
4
|
-
#include "native_btree.h"
|
5
|
-
#include "btree.h"
|
6
|
-
|
7
|
-
|
8
|
-
extern "C" {
|
9
|
-
|
10
|
-
class BTreeEQCtxt {
|
11
|
-
public:
|
12
|
-
VALUE eq = Qtrue;
|
13
|
-
BTree *tree2 = nullptr;
|
14
|
-
};
|
15
|
-
|
16
|
-
static void
|
17
|
-
btree_free(BTree *btree)
|
18
|
-
{
|
19
|
-
delete btree;
|
20
|
-
}
|
21
|
-
|
22
|
-
static void
|
23
|
-
btree_mark(gpointer obj)
|
24
|
-
{
|
25
|
-
reinterpret_cast<BTree *>(obj)->mark();
|
26
|
-
}
|
27
|
-
|
28
|
-
static VALUE
|
29
|
-
btree_enum_size(VALUE tree, VALUE args, VALUE eobj)
|
30
|
-
{
|
31
|
-
return btree_size(tree);
|
32
|
-
}
|
33
|
-
|
34
|
-
|
35
|
-
VALUE
|
36
|
-
btree_new(VALUE klass)
|
37
|
-
{
|
38
|
-
rb_need_block();
|
39
|
-
|
40
|
-
VALUE comparator = rb_block_lambda();
|
41
|
-
|
42
|
-
BTree *tree = new BTree(comparator);
|
43
|
-
|
44
|
-
VALUE instance = Data_Wrap_Struct(klass, btree_mark, btree_free, tree);
|
45
|
-
|
46
|
-
return instance;
|
47
|
-
}
|
48
|
-
|
49
|
-
VALUE
|
50
|
-
btree_init(VALUE self)
|
51
|
-
{
|
52
|
-
return self;
|
53
|
-
}
|
54
|
-
|
55
|
-
VALUE
|
56
|
-
btree_size(VALUE self)
|
57
|
-
{
|
58
|
-
BTree *tree;
|
59
|
-
Data_Get_Struct(self, BTree, tree);
|
60
|
-
|
61
|
-
VALUE result = INT2NUM(tree->size());
|
62
|
-
|
63
|
-
return result;
|
64
|
-
}
|
65
|
-
|
66
|
-
VALUE
|
67
|
-
btree_height(VALUE self)
|
68
|
-
{
|
69
|
-
BTree *tree;
|
70
|
-
Data_Get_Struct(self, BTree, tree);
|
71
|
-
|
72
|
-
VALUE result = INT2NUM(tree->height());
|
73
|
-
|
74
|
-
return result;
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
VALUE
|
79
|
-
btree_set(VALUE self, VALUE key, VALUE value)
|
80
|
-
{
|
81
|
-
BTree *tree;
|
82
|
-
Data_Get_Struct(self, BTree, tree);
|
83
|
-
|
84
|
-
tree->set(key, value);
|
85
|
-
|
86
|
-
return Qnil;
|
87
|
-
}
|
88
|
-
|
89
|
-
VALUE
|
90
|
-
btree_get(VALUE self, VALUE key)
|
91
|
-
{
|
92
|
-
BTree *tree;
|
93
|
-
Data_Get_Struct(self, BTree, tree);
|
94
|
-
|
95
|
-
return tree->get(key);
|
96
|
-
}
|
97
|
-
|
98
|
-
VALUE
|
99
|
-
btree_delete(VALUE self, VALUE key)
|
100
|
-
{
|
101
|
-
BTree *tree;
|
102
|
-
Data_Get_Struct(self, BTree, tree);
|
103
|
-
|
104
|
-
bool result = tree->del(key);
|
105
|
-
|
106
|
-
return result ? Qtrue : Qfalse;
|
107
|
-
}
|
108
|
-
|
109
|
-
VALUE
|
110
|
-
btree_clear(VALUE self)
|
111
|
-
{
|
112
|
-
BTree *tree;
|
113
|
-
Data_Get_Struct(self, BTree, tree);
|
114
|
-
|
115
|
-
tree->clear();
|
116
|
-
|
117
|
-
return Qnil;
|
118
|
-
}
|
119
|
-
|
120
|
-
VALUE
|
121
|
-
btree_has(VALUE self, VALUE key)
|
122
|
-
{
|
123
|
-
BTree *tree;
|
124
|
-
Data_Get_Struct(self, BTree, tree);
|
125
|
-
|
126
|
-
bool result = tree->has(key);
|
127
|
-
|
128
|
-
return result ? Qtrue : Qfalse;
|
129
|
-
}
|
130
|
-
|
131
|
-
VALUE
|
132
|
-
btree_each(VALUE self)
|
133
|
-
{
|
134
|
-
RETURN_SIZED_ENUMERATOR(self, 0, 0, btree_enum_size);
|
135
|
-
|
136
|
-
VALUE block = rb_block_lambda();
|
137
|
-
|
138
|
-
BTree *tree;
|
139
|
-
Data_Get_Struct(self, BTree, tree);
|
140
|
-
|
141
|
-
tree->each(block);
|
142
|
-
|
143
|
-
return Qnil;
|
144
|
-
}
|
145
|
-
|
146
|
-
// TODO: Need implementation
|
147
|
-
VALUE
|
148
|
-
btree_cmp(VALUE self, VALUE tree2)
|
149
|
-
{
|
150
|
-
return Qnil;
|
151
|
-
}
|
152
|
-
|
153
|
-
static gboolean
|
154
|
-
eql_comparator(gpointer k, gpointer v, gpointer data)
|
155
|
-
{
|
156
|
-
VALUE key = reinterpret_cast<VALUE>(k);
|
157
|
-
VALUE val = reinterpret_cast<VALUE>(v);
|
158
|
-
BTreeEQCtxt *context = reinterpret_cast<BTreeEQCtxt *>(data);
|
159
|
-
|
160
|
-
VALUE val2 = context->tree2->get(key);
|
161
|
-
|
162
|
-
// key not found
|
163
|
-
if (NIL_P(val2)) {
|
164
|
-
context->eq = Qfalse;
|
165
|
-
|
166
|
-
return TRUE;
|
167
|
-
}
|
168
|
-
|
169
|
-
// values !eql
|
170
|
-
if (!rb_eql(val, val2)) {
|
171
|
-
context->eq = Qfalse;
|
172
|
-
|
173
|
-
return TRUE;
|
174
|
-
}
|
175
|
-
|
176
|
-
return FALSE;
|
177
|
-
}
|
178
|
-
|
179
|
-
static VALUE// obj arg recur
|
180
|
-
recursive_eql(VALUE tree, VALUE tree2, int recur)
|
181
|
-
{
|
182
|
-
if (recur)
|
183
|
-
return Qtrue; /* Subtle! */
|
184
|
-
|
185
|
-
BTree *t, *t2;
|
186
|
-
Data_Get_Struct(tree, BTree, t);
|
187
|
-
Data_Get_Struct(tree2, BTree, t2);
|
188
|
-
|
189
|
-
BTreeEQCtxt context;
|
190
|
-
// context.eq == Qtrue;
|
191
|
-
|
192
|
-
context.tree2 = t2;
|
193
|
-
|
194
|
-
t->each(eql_comparator, reinterpret_cast<gpointer>(&context));
|
195
|
-
|
196
|
-
return context.eq;
|
197
|
-
}
|
198
|
-
|
199
|
-
VALUE
|
200
|
-
btree_equal(VALUE self, VALUE tree2)
|
201
|
-
{
|
202
|
-
BTree *t, *t2;
|
203
|
-
Data_Get_Struct(self, BTree, t);
|
204
|
-
Data_Get_Struct(tree2, BTree, t2);
|
205
|
-
|
206
|
-
if (self == tree2)
|
207
|
-
return Qtrue;
|
208
|
-
|
209
|
-
if (CLASS_OF(tree2) != btree_class)
|
210
|
-
return Qfalse;
|
211
|
-
|
212
|
-
if (t->size() != t2->size() || t->height() != t2->height())
|
213
|
-
return Qfalse;
|
214
|
-
|
215
|
-
if (t->size() == 0)
|
216
|
-
return Qtrue;
|
217
|
-
// func obj paired arg
|
218
|
-
return rb_exec_recursive_paired(recursive_eql, self, tree2, tree2);
|
219
|
-
}
|
220
|
-
|
221
|
-
}
|