native_btree 0.1.0.alpha2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -2
- data/CMakeLists.txt +21 -8
- data/Gemfile +12 -0
- data/README.md +50 -13
- data/Rakefile +17 -9
- data/ext/native_btree/CMakeLists.txt +32 -10
- data/ext/native_btree/Makefile +456 -0
- data/ext/native_btree/comparator.c +13 -0
- data/ext/native_btree/constructor.c +19 -0
- data/ext/native_btree/conversion.c +54 -0
- data/ext/native_btree/include/common.h +21 -0
- data/ext/native_btree/include/comparator.h +4 -0
- data/ext/native_btree/include/constructor.h +11 -0
- data/ext/native_btree/include/conversion.h +8 -0
- data/ext/native_btree/include/instance.h +22 -0
- data/ext/native_btree/include/iterators.h +5 -0
- data/ext/native_btree/include/native_btree.h +5 -51
- data/ext/native_btree/include/rbtree_type.h +22 -0
- data/ext/native_btree/instance.c +126 -0
- data/ext/native_btree/iterators.c +26 -0
- data/ext/native_btree/native_btree.c +20 -19
- data/ext/native_btree/rbtree_type.c +102 -0
- data/lib/native_btree/native_btree.so +0 -0
- data/lib/native_btree/version.rb +1 -1
- data/native_btree.gemspec +0 -13
- data/spec/debug.rb +24 -0
- data/spec/native_btree_class_spec.rb +24 -0
- data/spec/native_btree_instance_spec.rb +283 -0
- data/spec/native_btree_module_spec.rb +15 -0
- metadata +25 -152
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/spec/native_btree_spec.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 398bae312c489bfe71fdee2f82499005e655097606a5537c38cfb122980b9f48
|
4
|
+
data.tar.gz: 492df9b7fc0585e0615da770a6c3fd3e2d02323d33c1d3cfecae46b882b881a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 634ac5f2eab6a8f9ebf9ed577d5cd2fcdca75fdb8e61f285b3e83e244204976bdef93981320ea101a621b2845cb9346099d61a94193eb5872d0f1480ad363f09
|
7
|
+
data.tar.gz: cf5f853401bdcab2d12088fe11c23cbde946e5a3542620d905e1acb59ede62522cbd293f65c7b10ca54f4a00737c9fe5485519c72358f185840fa8efbe81719b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,34 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
1
8
|
## [Unreleased]
|
2
9
|
|
3
|
-
|
10
|
+
* filter()
|
11
|
+
* filter!()
|
12
|
+
* each_key()
|
13
|
+
* each_value()
|
14
|
+
* select()
|
15
|
+
* select!
|
16
|
+
|
17
|
+
## [0.2.1] - 2022-09-08
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
|
21
|
+
* Legacy CMake versions support
|
22
|
+
|
23
|
+
## [0.2.0] - 2022-09-07
|
24
|
+
|
25
|
+
### Changed
|
26
|
+
|
27
|
+
* Small refactoring
|
28
|
+
|
29
|
+
### Added
|
4
30
|
|
5
|
-
|
31
|
+
* to_a()
|
32
|
+
* to_h()
|
33
|
+
* clear()
|
34
|
+
* include?()
|
data/CMakeLists.txt
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
cmake_minimum_required(VERSION 3.
|
1
|
+
cmake_minimum_required(VERSION 3.5)
|
2
2
|
|
3
3
|
project(ruby-native-btree
|
4
4
|
LANGUAGES C
|
5
|
-
VERSION 0.1
|
6
|
-
HOMEPAGE_URL https://github.com/unixs/ruby-native-btree)
|
5
|
+
VERSION 0.2.1)
|
7
6
|
|
8
|
-
|
7
|
+
include(CheckSymbolExists)
|
8
|
+
|
9
|
+
set(REQUIRED_RUBY_VERSION 2.6.0)
|
9
10
|
|
10
11
|
set(CMAKE_C_STANDARD 11)
|
11
12
|
set(CMAKE_C_EXTENSIONS ON)
|
@@ -15,6 +16,9 @@ set(CMAKE_C_FLAGS_DEBUG " -O0 -ggdb3 -Wall -Wextra -Wpedantic -Wno-unused-parame
|
|
15
16
|
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
16
17
|
set(CMAKE_C_FLAGS "-pipe -march=native")
|
17
18
|
|
19
|
+
# Force -fPIC
|
20
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
21
|
+
|
18
22
|
if(NOT CMAKE_BUILD_TYPE)
|
19
23
|
set(CMAKE_BUILD_TYPE "Release")
|
20
24
|
endif()
|
@@ -32,11 +36,20 @@ find_package(PkgConfig REQUIRED)
|
|
32
36
|
|
33
37
|
# Find Ruby
|
34
38
|
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
|
|
39
|
-
|
40
|
+
if(CMAKE_VERSION VERSION_GREATER "3.17.100")
|
41
|
+
include_directories(${Ruby_INCLUDE_DIRS})
|
42
|
+
link_libraries(${Ruby_LIBRARIES})
|
43
|
+
message(STATUS "Ruby_INCLUDE_DIRS: ${Ruby_INCLUDE_DIRS}")
|
44
|
+
else()
|
45
|
+
message(WARNING "Old CMake. Legacy FindRuby macro is used.")
|
46
|
+
include_directories(${RUBY_INCLUDE_DIRS})
|
47
|
+
link_libraries(${RUBY_LIBRARIES})
|
48
|
+
message(STATUS "RUBY_INCLUDE_DIRS: ${RUBY_INCLUDE_DIRS}")
|
49
|
+
endif()
|
50
|
+
|
51
|
+
message(STATUS "Find Ruby deps.")
|
52
|
+
|
40
53
|
# Find jemalloc
|
41
54
|
pkg_check_modules(JEMALLOC jemalloc)
|
42
55
|
if(JEMALLOC_FOUND)
|
data/Gemfile
CHANGED
@@ -4,3 +4,15 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in ruby_btree.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'awesome_print', '~> 1.9'
|
10
|
+
gem 'debase', '~> 0.2', platforms: [:mri_26, :mri_27]
|
11
|
+
gem 'pry', '~> 0.14'
|
12
|
+
gem 'rubocop', '~> 1.35.0'
|
13
|
+
gem 'rubocop-rake', '~> 0.6.0'
|
14
|
+
gem 'rubocop-rspec', '~> 2.12.1'
|
15
|
+
gem 'rspec', '~> 3.11.0'
|
16
|
+
gem 'ruby-debug-ide', '~> 0.7'
|
17
|
+
gem 'solargraph', '~> 0.46'
|
18
|
+
end
|
data/README.md
CHANGED
@@ -1,26 +1,49 @@
|
|
1
|
-
#
|
1
|
+
# GLib Balanced binary tree (GTree) bindings for Ruby
|
2
2
|
|
3
|
-
Ruby
|
3
|
+
[](https://github.com/unixs/ruby-native-btree/actions/workflows/main.yml)
|
4
|
+
[](https://badge.fury.io/rb/native_btree)
|
5
|
+
[](https://www.gnu.org/licenses/lgpl-3.0)
|
4
6
|
|
5
|
-
In most cases it is behave same as Hash, but keys will be ordered by passed comparator.
|
6
7
|
|
7
|
-
|
8
|
+
[GTree - balanced binary tree from GLib library](https://docs.gtk.org/glib/struct.Tree.html)
|
9
|
+
|
10
|
+
In most cases it will behave same as Hash, but keys will be ordered by passed comparator.
|
11
|
+
|
12
|
+
## Requirements
|
13
|
+
|
14
|
+
* **CMake** build tool version **>= 3.14.0**
|
15
|
+
* `pkg-config` tool
|
16
|
+
* **GLib** library
|
17
|
+
* On Ubuntu run:
|
18
|
+
```bash
|
19
|
+
sudo apt-get install pkg-config cmake libglib2.0-dev
|
20
|
+
```
|
21
|
+
* On MacOS run:
|
22
|
+
```
|
23
|
+
brew install pkg-config cmake glib
|
24
|
+
```
|
25
|
+
* On FreeBSD use pkg or ports.
|
26
|
+
* On windows use Google. I don't really know how it can work at this moment... But i think it's possible
|
27
|
+
|
28
|
+
**Check CMake tool version!**
|
29
|
+
|
30
|
+
## Basic usage
|
8
31
|
|
9
32
|
```ruby
|
10
33
|
require 'native_btree'
|
11
34
|
|
12
35
|
# Pass comparator for keys as block
|
13
|
-
tree =
|
36
|
+
tree = NativeBtree::Btree.new { |a, b| a - b }
|
14
37
|
|
15
|
-
tree[
|
16
|
-
tree[
|
17
|
-
tree[
|
38
|
+
tree[1] = '111'
|
39
|
+
tree[3] = '333'
|
40
|
+
tree[2] = '222'
|
18
41
|
|
19
42
|
tree.each { |k, v| puts "#{k} => #{v}" }
|
20
43
|
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
44
|
+
# 1 => 111
|
45
|
+
# 2 => 222
|
46
|
+
# 3 => 333
|
24
47
|
# nil
|
25
48
|
|
26
49
|
tree.size
|
@@ -30,5 +53,19 @@ tree.height
|
|
30
53
|
# 2
|
31
54
|
```
|
32
55
|
|
33
|
-
|
34
|
-
|
56
|
+
## API ref
|
57
|
+
|
58
|
+
You must provide your own comparator for keys in `new` class method block.
|
59
|
+
|
60
|
+
### Methods
|
61
|
+
|
62
|
+
* `[]= (alias: set)`
|
63
|
+
* `[] (alias: get)`
|
64
|
+
* `delete`
|
65
|
+
* `size`
|
66
|
+
* `height`
|
67
|
+
* `each`
|
68
|
+
* `include?`
|
69
|
+
* `clear`
|
70
|
+
* `to_h`
|
71
|
+
* `to_a`
|
data/Rakefile
CHANGED
@@ -1,27 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "rspec/core/rake_task"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
begin
|
6
|
+
require "rspec/core/rake_task"
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
rescue LoadError
|
9
|
+
warn "RSpec rake tasks was not loaded"
|
10
|
+
end
|
9
11
|
|
10
|
-
|
12
|
+
begin
|
13
|
+
require "rubocop/rake_task"
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
rescue LoadError
|
16
|
+
warn "Rubocop rake tasks was not loaded"
|
17
|
+
end
|
11
18
|
|
12
|
-
task default: %i[
|
19
|
+
task default: %i[cmake:build]
|
13
20
|
|
14
21
|
BUILD_DIR = "build"
|
15
22
|
|
16
23
|
namespace :cmake do
|
17
24
|
desc "Remove build directory"
|
18
25
|
task :rmbuild do
|
19
|
-
sh "rm -
|
26
|
+
sh "rm -rf #{BUILD_DIR}"
|
20
27
|
end
|
21
28
|
|
22
29
|
desc "Configure ext CMake project"
|
23
|
-
task configure
|
24
|
-
sh "
|
30
|
+
task :configure do
|
31
|
+
sh "mkdir #{BUILD_DIR} || true"
|
32
|
+
sh "cd #{BUILD_DIR} && cmake .."
|
25
33
|
end
|
26
34
|
|
27
35
|
desc "Build ext CMake project"
|
@@ -1,21 +1,43 @@
|
|
1
1
|
set(EXT_NAME "native_btree")
|
2
2
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/${EXT_NAME})
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
message("Find ext deps.")
|
4
|
+
message(STATUS "Find ext deps.")
|
7
5
|
|
8
6
|
pkg_check_modules(GLIB2 REQUIRED glib-2.0)
|
9
7
|
|
10
|
-
|
8
|
+
include_directories(include ${GLIB2_INCLUDE_DIRS})
|
9
|
+
|
10
|
+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${GLIB2_LDFLAGS})
|
11
|
+
list(APPEND CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS})
|
12
|
+
check_symbol_exists(g_tree_remove_all "glib.h" HAVE_GTREE_REMOVE_ALL)
|
13
|
+
|
14
|
+
if(HAVE_GTREE_REMOVE_ALL)
|
15
|
+
add_compile_definitions(HAVE_GTREE_REMOVE_ALL)
|
16
|
+
endif()
|
17
|
+
|
18
|
+
|
11
19
|
add_library(${EXT_NAME}
|
12
20
|
SHARED
|
13
21
|
native_btree.c)
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
add_library(rbtree_type OBJECT rbtree_type.c)
|
24
|
+
add_library(constructor OBJECT constructor.c)
|
25
|
+
add_library(instance OBJECT instance.c)
|
26
|
+
add_library(comparator OBJECT comparator.c)
|
27
|
+
add_library(iterators OBJECT iterators.c)
|
28
|
+
add_library(conversion OBJECT conversion.c)
|
29
|
+
|
30
|
+
add_library(native_btree_interface
|
31
|
+
STATIC
|
32
|
+
$<TARGET_OBJECTS:conversion>
|
33
|
+
$<TARGET_OBJECTS:iterators>
|
34
|
+
$<TARGET_OBJECTS:comparator>
|
35
|
+
$<TARGET_OBJECTS:instance>
|
36
|
+
$<TARGET_OBJECTS:constructor>
|
37
|
+
$<TARGET_OBJECTS:rbtree_type>)
|
38
|
+
|
39
|
+
target_link_libraries(${EXT_NAME}
|
40
|
+
PRIVATE
|
41
|
+
native_btree_interface
|
42
|
+
${GLIB2_LDFLAGS})
|
21
43
|
|