native_btree 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4744529a22fe3d5cd3eb53cf258fa5440346df593e6d268d7af3d2e4b197addf
4
- data.tar.gz: 887db38cf3c3c23cd72984f6ec2bbdfce1ebce57e547c5cc2d96c81184a36833
3
+ metadata.gz: 48b0e894826a65be636d9e13813c6d084c69a306d0778caf3fc709511dc5d2f5
4
+ data.tar.gz: 18f2f200813df0762181ebb4e7d3cc32c1cd8ae337ab9a35547d9265fa91eaeb
5
5
  SHA512:
6
- metadata.gz: f46367c894c10a0ca5db645470228f08edafabe9010a5115d9c92008688eec29f9a0973ba462138483912a2bebe52660eb17828298ea69ebd1709d4811cfb470
7
- data.tar.gz: 9a342ae22e6ced29b02aa24917f1307fc0a0721885667185266eaa1b23f73fd37c90918126dd1ac6aa24cee08a3c838c25a951e3a84ea5f23cb93e2532d9549d
6
+ metadata.gz: 4c574719cc0366f86f8459e5e17c59739dab7886ae2cfe56450ed8696906fe4c13be6e90265756a195d04548a627018540c8d119e143d19e0b5cab378c166448
7
+ data.tar.gz: 8239197687c68a713da92c7d108b41acfe83c30dcbee888e7363e0842b2f6bdc7af30e584e96a5438c08bb5bd306399f986cb31d0dad86d2cf17c9ee65820638
data/CHANGELOG.md CHANGED
@@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
  * #<
15
15
  * #<=
16
16
 
17
+ ## [0.6.1] - 2023-05-05
18
+
19
+ ### Added
20
+
21
+ * api docs
22
+
17
23
  ## [0.6.0] - 2022-10-28
18
24
 
19
25
  ### Added
data/CMakeLists.txt CHANGED
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
2
2
 
3
3
  project(ruby-native-btree
4
4
  LANGUAGES C
5
- VERSION 0.6.0)
5
+ VERSION 0.6.1)
6
6
 
7
7
  include(CheckSymbolExists)
8
8
  include(CheckCCompilerFlag)
@@ -22,7 +22,7 @@ if(HAVE_CC_MARCH_NATIVE)
22
22
  string(APPEND CMAKE_C_FLAGS " -march=native")
23
23
  endif()
24
24
 
25
- set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb3 -Wall -Wextra -Wno-unused-parameter")
25
+ set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb3 -Wall -Wextra -Wno-unused-parameter --coverage")
26
26
  set(CMAKE_C_FLAGS_RELEASE "-O3 -fomit-frame-pointer")
27
27
 
28
28
  # Force -fPIC
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # GLib Balanced binary tree (GTree) bindings for Ruby
2
2
 
3
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
+ [![codecov](https://codecov.io/gh/unixs/ruby-native-btree/branch/master/graph/badge.svg?token=10JIVX89NG)](https://codecov.io/gh/unixs/ruby-native-btree)
4
5
  [![Gem Version](https://badge.fury.io/rb/native_btree.svg)](https://badge.fury.io/rb/native_btree)
5
6
  [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
6
7
 
@@ -87,38 +88,11 @@ tree.to_a
87
88
  #]
88
89
  ```
89
90
 
90
- ## API ref
91
+ ## API
91
92
 
92
- You must provide your own comparator for keys in `new` class method block.
93
+ * You must provide your own comparator for keys in `new` class method block.
94
+ * You can mix in the `Enumerable` module if additional methods are needed.
93
95
 
94
96
  ### API methods
95
97
 
96
- In general this class behave same as Hash
97
-
98
- Implemented methods:
99
-
100
- * `[]= (alias: set)`
101
- * `[] (alias: get)`
102
- * `==`
103
- * `delete`
104
- * `size`
105
- * `height`
106
- * `each`
107
- * `include?`
108
- * `clear`
109
- * `to_h`
110
- * `to_a`
111
- * `to_proc`
112
- * `to_s`
113
- * `inspect`
114
- * `filter` (alias: select)
115
- * `filter!` (alias: select!)
116
- * `each_value`
117
- * `each_key`
118
- * `search_before` (GLib version >= 2.68) - Select keys <= first arg, ret new Btree
119
- * `search_after` (GLib version >= 2.68) - Select keys >= first arg, ret new Btree
120
- * `empty?`
121
- * `reverse_each`
122
- * `delete_if`
123
-
124
- You can mix in the `Enumerable` module if additional methods are needed.
98
+ [YARD documentation](https://rubydoc.info/gems/native_btree)
data/Rakefile CHANGED
@@ -37,7 +37,7 @@ namespace :cmake do
37
37
  sh "cmake --build #{BUILD_DIR}"
38
38
  end
39
39
 
40
- desc "`Rebuild ext CMake project"
40
+ desc "Rebuild ext CMake project"
41
41
  task rebuild: %i[cmake:configure] do
42
42
  sh "cmake --build #{BUILD_DIR} --clean-first"
43
43
  end
@@ -27,6 +27,14 @@ init_rbtree(RBTree *rbtree, gushort flags)
27
27
  rbtree->flags = flags;
28
28
  }
29
29
 
30
+ /**
31
+ * Constructor
32
+ *
33
+ * Accepts block as "comparator" function.
34
+ * This function will recive two keys for comparison.
35
+ *
36
+ * @return [Btree] new instance
37
+ */
30
38
  VALUE
31
39
  rbtree_initialize(int argc, VALUE* argv, VALUE self)
32
40
  {
@@ -26,7 +26,11 @@ rbtree_to_a_callback(gpointer key, gpointer value, gpointer data)
26
26
  return FALSE;
27
27
  }
28
28
 
29
-
29
+ /**
30
+ * Converts tree to Hash
31
+ *
32
+ * @return [Hash] result
33
+ */
30
34
  VALUE
31
35
  rbtree_to_h(VALUE self)
32
36
  {
@@ -39,7 +43,13 @@ rbtree_to_h(VALUE self)
39
43
  return hash;
40
44
  }
41
45
 
42
-
46
+ /**
47
+ * Converts tree to array
48
+ *
49
+ * Coverts tree to array of arrays with key and value
50
+ *
51
+ * @return [Array] result
52
+ */
43
53
  VALUE
44
54
  rbtree_to_a(VALUE self)
45
55
  {
@@ -70,14 +80,24 @@ to_proc_proc(RB_BLOCK_CALL_FUNC_ARGLIST(key, callback_arg))
70
80
  return value;
71
81
  }
72
82
 
73
-
83
+ /**
84
+ * Returns a Proc object that maps a key to its value
85
+ *
86
+ * @return [Proc] block
87
+ */
74
88
  VALUE
75
89
  rbtree_to_proc(VALUE self)
76
90
  {
77
91
  return rb_proc_new(to_proc_proc, self);
78
92
  }
79
93
 
80
-
94
+ /**
95
+ * Converts tree to string.
96
+ *
97
+ * Under hood will convert tree to Hash.
98
+ *
99
+ * @return [String] result
100
+ */
81
101
  VALUE
82
102
  rbtree_to_s(VALUE self)
83
103
  {
@@ -110,7 +110,15 @@ legacy_rbtree_compare(const RBTree *a, const RBTree *b)
110
110
 
111
111
  #endif
112
112
 
113
-
113
+ /**
114
+ * Adds key/value pair in to tree.
115
+ *
116
+ * Key/value will be replaced if key already exists.
117
+ *
118
+ * @param key [Object]
119
+ * @param value [Object]
120
+ * @return [Btree] self
121
+ */
114
122
  VALUE
115
123
  rbtree_set(VALUE self, VALUE key, VALUE value)
116
124
  {
@@ -121,7 +129,14 @@ rbtree_set(VALUE self, VALUE key, VALUE value)
121
129
  return self;
122
130
  }
123
131
 
124
-
132
+ /**
133
+ * Gets value by key from tree.
134
+ *
135
+ * * Returns +nil+ if key does not exist.
136
+ *
137
+ * @param key [Object]
138
+ * @return [Object] result
139
+ */
125
140
  VALUE
126
141
  rbtree_get(VALUE self, VALUE key)
127
142
  {
@@ -138,7 +153,16 @@ rbtree_get(VALUE self, VALUE key)
138
153
  return result;
139
154
  }
140
155
 
141
-
156
+ /**
157
+ * Deletes key/value pair from tree.
158
+ *
159
+ * * Returns value if key exists
160
+ * * Returns +nil+ if key does not exists
161
+ * * Returns result of block if block was given
162
+ *
163
+ * @param key [Object] Key
164
+ * @return [Object] result
165
+ */
142
166
  VALUE
143
167
  rbtree_delete(VALUE self, VALUE key)
144
168
  {
@@ -166,7 +190,11 @@ rbtree_delete(VALUE self, VALUE key)
166
190
  }
167
191
  }
168
192
 
169
-
193
+ /**
194
+ * Returns tree height
195
+ *
196
+ * @return [Integer] maximum nodes in path from root to leaf
197
+ */
170
198
  VALUE
171
199
  rbtree_height(VALUE self)
172
200
  {
@@ -178,7 +206,11 @@ rbtree_height(VALUE self)
178
206
  return result;
179
207
  }
180
208
 
181
-
209
+ /**
210
+ * Returns number of nodes
211
+ *
212
+ * @return [Integer] number of nodes
213
+ */
182
214
  VALUE
183
215
  rbtree_size(VALUE self)
184
216
  {
@@ -190,7 +222,11 @@ rbtree_size(VALUE self)
190
222
  return result;
191
223
  }
192
224
 
193
-
225
+ /**
226
+ * Remove all nodes from tree.
227
+ *
228
+ * @return [Btree] self
229
+ */
194
230
  VALUE
195
231
  rbtree_clear(VALUE self)
196
232
  {
@@ -206,6 +242,12 @@ rbtree_clear(VALUE self)
206
242
  }
207
243
 
208
244
 
245
+ /**
246
+ * Checks that the given key is in the tree.
247
+ *
248
+ * @param key [Object]
249
+ * @return [Boolean] result
250
+ */
209
251
  VALUE
210
252
  rbtree_is_include(VALUE self, VALUE key)
211
253
  {
@@ -220,7 +262,11 @@ rbtree_is_include(VALUE self, VALUE key)
220
262
  return Qtrue;
221
263
  }
222
264
 
223
-
265
+ /**
266
+ * Checks that self tree is empty.
267
+ *
268
+ * @return [Boolean] result
269
+ */
224
270
  VALUE
225
271
  rbtree_is_empty(VALUE self)
226
272
  {
@@ -231,7 +277,18 @@ rbtree_is_empty(VALUE self)
231
277
  return size > 0 ? Qfalse : Qtrue;
232
278
  }
233
279
 
234
-
280
+ /**
281
+ * Checks if two trees are equal.
282
+ *
283
+ * Compares with +==+ method all keys and values from trees by order.
284
+ *
285
+ * * Returns +false+ if number of keys are not equal.
286
+ * * Returns +false+ if one keys or one values pair are not equal.
287
+ * * Returns +true+ if all keys and values are equal.
288
+ *
289
+ * @param second [Btree]
290
+ * @return [Boolean] result
291
+ */
235
292
  VALUE
236
293
  rbtree_equal(VALUE self, VALUE second)
237
294
  {
@@ -266,7 +323,11 @@ rbtree_equal(VALUE self, VALUE second)
266
323
  return result;
267
324
  }
268
325
 
269
-
326
+ /**
327
+ * Returns value from smallest key
328
+ *
329
+ * @return [Object] result
330
+ */
270
331
  VALUE
271
332
  rbtree_first(VALUE self)
272
333
  {
@@ -299,7 +360,11 @@ rbtree_first(VALUE self)
299
360
  #endif
300
361
  }
301
362
 
302
-
363
+ /**
364
+ * Returns value from largest key
365
+ *
366
+ * @return [Object] result
367
+ */
303
368
  VALUE
304
369
  rbtree_last(VALUE self)
305
370
  {
@@ -48,7 +48,11 @@ rbtree_enum_length(VALUE rbtree, VALUE args, VALUE eobj)
48
48
  return rbtree_size(rbtree);
49
49
  }
50
50
 
51
-
51
+ /**
52
+ * Execute block for each key/value pairs
53
+ *
54
+ * @return [Btree] self
55
+ */
52
56
  VALUE
53
57
  rbtree_each(VALUE self)
54
58
  {
@@ -63,7 +67,11 @@ rbtree_each(VALUE self)
63
67
  return self;
64
68
  }
65
69
 
66
-
70
+ /**
71
+ * Execute block for each key
72
+ *
73
+ * @return [Btree] self
74
+ */
67
75
  VALUE
68
76
  rbtree_each_key(VALUE self)
69
77
  {
@@ -78,7 +86,11 @@ rbtree_each_key(VALUE self)
78
86
  return self;
79
87
  }
80
88
 
81
-
89
+ /**
90
+ * Execute block for each value
91
+ *
92
+ * @return [Btree] self
93
+ */
82
94
  VALUE
83
95
  rbtree_each_value(VALUE self)
84
96
  {
@@ -93,7 +105,11 @@ rbtree_each_value(VALUE self)
93
105
  return self;
94
106
  }
95
107
 
96
-
108
+ /**
109
+ * Execute block for each key/value pairs in reverse order
110
+ *
111
+ * @return [Btree] self
112
+ */
97
113
  VALUE
98
114
  rbtree_reverse_each(VALUE self)
99
115
  {
@@ -149,7 +165,14 @@ rbtree_delete_if_cb(gpointer k, gpointer v, gpointer data)
149
165
  return FALSE;
150
166
  }
151
167
 
152
-
168
+ /**
169
+ * Deletes key/value pair from tree by result of block.
170
+ *
171
+ * Will execute block for each key/value pairs
172
+ * and delete them if block returns +true+
173
+ *
174
+ * @return [Btree] self
175
+ */
153
176
  VALUE
154
177
  rbtree_delete_if(VALUE self)
155
178
  {
@@ -2,29 +2,25 @@
2
2
  #include <rbtree_type.h>
3
3
  #include <glib_module.h>
4
4
 
5
- #define NATIVE_BTREE_MODULE "NativeBtree"
6
- #define NATIVE_BTREE_CLASS "Btree"
7
- #define NATIVE_BTREE_CONST_INT_COMPARATOR "INT_COMPARATOR"
8
-
9
-
10
5
  VALUE native_btree_class;
11
6
  VALUE native_btree_module;
12
7
 
13
8
  void
14
9
  Init_native_btree()
15
10
  {
16
- native_btree_module = rb_define_module(NATIVE_BTREE_MODULE);
17
- native_btree_class = rb_define_class_under(
18
- native_btree_module,
19
- NATIVE_BTREE_CLASS,
20
- rb_cObject
21
- );
11
+ native_btree_module = rb_define_module("NativeBtree");
12
+ native_btree_class = rb_define_class_under(native_btree_module, "Btree", rb_cObject);
22
13
 
23
14
  VALUE int_comparator = USHORT2NUM(RBTREE_FLAG_INT_COMPARATOR);
24
15
  OBJ_FREEZE(int_comparator);
16
+
17
+ /**
18
+ * Represents native comparator for integer keys
19
+ * @note Can be replaced with specific class in future releases
20
+ */
25
21
  rb_define_const(
26
22
  native_btree_class,
27
- NATIVE_BTREE_CONST_INT_COMPARATOR,
23
+ "INT_COMPARATOR",
28
24
  int_comparator
29
25
  );
30
26
 
@@ -43,6 +43,13 @@ filter_bang_callback(gpointer a, gpointer b, gpointer data)
43
43
  return FALSE;
44
44
  }
45
45
 
46
+ /**
47
+ * Filters btree by block call
48
+ *
49
+ * If block returns true, key/value will include in result tree
50
+ *
51
+ * @return [Btree] result
52
+ */
46
53
  VALUE
47
54
  rbtree_filter(VALUE self)
48
55
  {
@@ -68,6 +75,13 @@ rbtree_filter(VALUE self)
68
75
  return new_tree;
69
76
  }
70
77
 
78
+ /**
79
+ * Filters btree by block call
80
+ *
81
+ * Same as #filter but returns changed self.
82
+ *
83
+ * @return [Btree] result
84
+ */
71
85
  VALUE
72
86
  rbtree_filter_bang(VALUE self)
73
87
  {
@@ -0,0 +1,6 @@
1
+ module NativeBtree
2
+ # Main Btree class
3
+ class Btree # rubocop:disable Lint/EmptyClass
4
+ # all methods defined in native module
5
+ end
6
+ end
Binary file
@@ -1,3 +1,4 @@
1
1
  module NativeBtree
2
- VERSION = "0.6.0".freeze
2
+ # gem version
3
+ VERSION = "0.6.1".freeze
3
4
  end
data/lib/native_btree.rb CHANGED
@@ -1,4 +1,6 @@
1
- # Bindings to GLib-2.0 data structure BTree
1
+ # Bindings to GLib-2.0 BTree data structure
2
+ #
3
+ # gem root namespace
2
4
  module NativeBtree
3
5
  end
4
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: native_btree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Feodorov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby bindings to GTree balanced binary tree from GLib library.
14
14
  email:
@@ -48,6 +48,7 @@ files:
48
48
  - ext/native_btree/search.c
49
49
  - ext/native_btree/utils.c
50
50
  - lib/native_btree.rb
51
+ - lib/native_btree/btree.rb
51
52
  - lib/native_btree/native_btree.bundle
52
53
  - lib/native_btree/version.rb
53
54
  - native_btree.gemspec