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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc39abeab06b5ed3984afa9cda174d12556523df6926db05e2889274c0157305
4
- data.tar.gz: 596a2b8af36be3da1ac5ebc2c64749f52e7ed5cb83d12280f11aa584f93e3fab
3
+ metadata.gz: 398bae312c489bfe71fdee2f82499005e655097606a5537c38cfb122980b9f48
4
+ data.tar.gz: 492df9b7fc0585e0615da770a6c3fd3e2d02323d33c1d3cfecae46b882b881a3
5
5
  SHA512:
6
- metadata.gz: 87faa333af87558b8a7600e680daf5367dce6f5393e524d467321409b0f1e5285aeedb2cfc6d2c3044c8a978f84d5b6135a628b6a3736df7b040b5312f04bd5c
7
- data.tar.gz: 3aac04b9a2c1b14bff0db483c3075e164b6f7fe6fb9a9a45d4275fc9a66aa6a1cfa4f555a74c4680b821d12d8818985b0d10a2ca45fc69cd40a1f658c6401ab3
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
- ## [0.1.0.alpha1] - 2022-08-20
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
- - Initial release
31
+ * to_a()
32
+ * to_h()
33
+ * clear()
34
+ * include?()
data/CMakeLists.txt CHANGED
@@ -1,11 +1,12 @@
1
- cmake_minimum_required(VERSION 3.18.0)
1
+ cmake_minimum_required(VERSION 3.5)
2
2
 
3
3
  project(ruby-native-btree
4
4
  LANGUAGES C
5
- VERSION 0.1.0
6
- HOMEPAGE_URL https://github.com/unixs/ruby-native-btree)
5
+ VERSION 0.2.1)
7
6
 
8
- set(REQUIRED_RUBY_VERSION 2.7.0)
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
- message("Find Ruby deps.")
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
- # Native Balanced binary tree for Ruby
1
+ # GLib Balanced binary tree (GTree) bindings for Ruby
2
2
 
3
- Ruby bindings to [GTree - balanced binary tree from GLib library](https://developer.gnome.org/glib/stable/glib-Balanced-Binary-Trees.html) .
3
+ [![Ruby](https://github.com/unixs/ruby-native-btree/actions/workflows/main.yml/badge.svg)](https://github.com/unixs/ruby-native-btree/actions/workflows/main.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/native_btree.svg)](https://badge.fury.io/rb/native_btree)
5
+ [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](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
- Basic usage:
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 = NativeBTree::BTree.new { |a, b| a <=> b }
36
+ tree = NativeBtree::Btree.new { |a, b| a - b }
14
37
 
15
- tree[:a1] = '111'
16
- tree[:c3] = '333'
17
- tree[:b2] = '222'
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
- # a1 => 111
22
- # b2 => 222
23
- # c3 => 333
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
- Trees is may comparable by `==` or `.eql?` operator.
34
- Trees will be equal if all keys and all value is equal in both.
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
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
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
- RuboCop::RakeTask.new
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[rubocop spec]
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 -rvf #{BUILD_DIR}"
26
+ sh "rm -rf #{BUILD_DIR}"
20
27
  end
21
28
 
22
29
  desc "Configure ext CMake project"
23
- task configure: %i[cmake:rmbuild] do
24
- sh "cmake . -B #{BUILD_DIR}"
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
- include_directories(include)
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
- # include_directories(include ${GLIB2_INCLUDE_DIRS})
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
- #set_target_properties(${EXT_NAME} PROPERTIES BUNDLE TRUE)
16
-
17
-
18
- #target_link_libraries(${EXT_NAME}
19
- # PRIVATE
20
- # ${GLIB2_LDFLAGS})
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