dartsclone 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +6 -7
- data/CHANGELOG.md +12 -0
- data/Gemfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +5 -5
- data/Steepfile +20 -0
- data/dartsclone.gemspec +2 -2
- data/ext/dartsclone/dartscloneext.hpp +21 -4
- data/ext/dartsclone/dummy.rb +93 -0
- data/lib/dartsclone/version.rb +1 -1
- data/sig/dartsclone.rbs +20 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0de9241630b790fea0794afe5ec48d7ac7335faae7c9d563ce42cdfe47670f43
|
4
|
+
data.tar.gz: 66dd871d41f3ba849c949093c02b6ac4613541e8ad81e062255a771955ec0988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f696063913884d67ebdd20b51b4d49363537650c831b28d9a987d808d9cb3e239eeec95e2e0b4fed67ab94925ca37649383b4ff956e37141f9c12b3cd79ef33
|
7
|
+
data.tar.gz: f5ffe5cc13ee5560e258ecbb0ead2a14b0b96b09d7f286317d1514f5b01eb1dcca12fa1bd15dedb594bd5393eaa51c9e49ddc28ac2b4f87eba599fc8f181f505
|
data/.github/workflows/build.yml
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
name: build
|
2
2
|
|
3
|
-
on: [push]
|
3
|
+
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
build:
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
strategy:
|
9
|
+
fail-fast: false
|
9
10
|
matrix:
|
10
|
-
ruby: [ '2.
|
11
|
+
ruby: [ '2.6', '2.7', '3.0' ]
|
11
12
|
steps:
|
12
13
|
- uses: actions/checkout@v2
|
13
14
|
- name: Set up Ruby ${{ matrix.ruby }}
|
14
|
-
uses:
|
15
|
+
uses: ruby/setup-ruby@v1
|
15
16
|
with:
|
16
17
|
ruby-version: ${{ matrix.ruby }}
|
18
|
+
bundler-cache: true
|
17
19
|
- name: Build and test with Rake
|
18
|
-
run:
|
19
|
-
gem install bundler
|
20
|
-
bundle install --jobs 4 --retry 3
|
21
|
-
bundle exec rake
|
20
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 0.3.1
|
2
|
+
- Add dummy constructor call at memory allocation of binding class to prevent occuring segment fault on GC when initialize method is failed.
|
3
|
+
|
4
|
+
## 0.3.0
|
5
|
+
- Add type declaration file: sig/dartsclone.rbs
|
6
|
+
|
7
|
+
## 0.2.3
|
8
|
+
- Fix some codes and configulation files.
|
9
|
+
|
10
|
+
## 0.2.2
|
11
|
+
- Refactor native extension codes considering garbage collection.
|
12
|
+
|
1
13
|
## 0.2.1
|
2
14
|
- Replace Data_ functions to TypedData_ functions.
|
3
15
|
- Fix some config files.
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://github.com/yoshoku/darts-clone.rb/workflows/build/badge.svg)](https://github.com/yoshoku/darts-clone.rb/actions?query=workflow%3Abuild)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/dartsclone.svg)](https://badge.fury.io/rb/dartsclone)
|
5
|
-
[![BSD 2-Clause License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://github.com/yoshoku/darts-clone.rb/blob/
|
5
|
+
[![BSD 2-Clause License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://github.com/yoshoku/darts-clone.rb/blob/main/LICENSE.txt)
|
6
6
|
|
7
|
-
Darts-clone.rb
|
7
|
+
Darts-clone.rb provides Ruby bindings for the [Darts-clone](https://github.com/s-yata/darts-clone).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -51,14 +51,14 @@ da.open('foo.dat')
|
|
51
51
|
## Contributing
|
52
52
|
|
53
53
|
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/darts-clone.rb.
|
54
|
-
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yoshoku/darts-clone.rb/blob/
|
54
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yoshoku/darts-clone.rb/blob/main/CODE_OF_CONDUCT.md).
|
55
55
|
|
56
56
|
## License
|
57
57
|
|
58
58
|
The gem is available as open source under the terms of the [BSD 2-clause License](https://opensource.org/licenses/BSD-2-Clause).
|
59
59
|
Moreover, the gem includes the source code of Darts-clone.
|
60
|
-
The License of Darts-clone can be found in [COPYING.md](https://github.com/yoshoku/darts-clone.rb/blob/
|
60
|
+
The License of Darts-clone can be found in [COPYING.md](https://github.com/yoshoku/darts-clone.rb/blob/main/ext/dartsclone/src/COPYING.md).
|
61
61
|
|
62
62
|
## Code of Conduct
|
63
63
|
|
64
|
-
Everyone interacting in the Darts project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/darts-clone.rb/blob/
|
64
|
+
Everyone interacting in the Darts project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/darts-clone.rb/blob/main/CODE_OF_CONDUCT.md).
|
data/Steepfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
target :lib do
|
2
|
+
signature "sig"
|
3
|
+
#
|
4
|
+
check "lib" # Directory name
|
5
|
+
# check "Gemfile" # File name
|
6
|
+
# check "app/models/**/*.rb" # Glob
|
7
|
+
# # ignore "lib/templates/*.rb"
|
8
|
+
#
|
9
|
+
# # library "pathname", "set" # Standard libraries
|
10
|
+
# # library "strong_json" # Gems
|
11
|
+
end
|
12
|
+
|
13
|
+
# target :spec do
|
14
|
+
# signature "sig", "sig-private"
|
15
|
+
#
|
16
|
+
# check "spec"
|
17
|
+
#
|
18
|
+
# # library "pathname", "set" # Standard libraries
|
19
|
+
# # library "rspec"
|
20
|
+
# end
|
data/dartsclone.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ['yoshoku']
|
7
7
|
spec.email = ['yoshoku@outlook.com']
|
8
8
|
|
9
|
-
spec.summary = 'Ruby
|
10
|
-
spec.description = 'Darts-clone.rb
|
9
|
+
spec.summary = 'Ruby bindings for the Darts-clone.'
|
10
|
+
spec.description = 'Darts-clone.rb provides Ruby bindings for the Darts-clone.'
|
11
11
|
spec.homepage = 'https://github.com/yoshoku/darts-clone.rb'
|
12
12
|
spec.license = 'BSD-2-Clause'
|
13
13
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#ifndef DARTSCLONEEXT_HPP
|
2
2
|
#define DARTSCLONEEXT_HPP 1
|
3
3
|
|
4
|
+
#include <cstring>
|
5
|
+
|
4
6
|
#include <ruby.h>
|
5
7
|
#include <darts.h>
|
6
8
|
|
@@ -9,6 +11,7 @@ class RbDoubleArray
|
|
9
11
|
public:
|
10
12
|
static VALUE double_array_alloc(VALUE self) {
|
11
13
|
Darts::DoubleArray* ptr = (Darts::DoubleArray*)ruby_xmalloc(sizeof(Darts::DoubleArray));
|
14
|
+
new (ptr) Darts::DoubleArray(); // dummy call to constructor for GC.
|
12
15
|
return TypedData_Wrap_Struct(self, &double_array_type, ptr);
|
13
16
|
};
|
14
17
|
|
@@ -68,22 +71,26 @@ class RbDoubleArray
|
|
68
71
|
const int n_keys = RARRAY_LEN(_keys);
|
69
72
|
char** keys = (char**)ruby_xmalloc(n_keys * sizeof(char*));
|
70
73
|
int* values = _values == Qundef ? NULL : (int*)ruby_xmalloc(n_keys * sizeof(int));
|
74
|
+
VALUE key_str;
|
71
75
|
for (int i = 0; i < n_keys; i++) {
|
72
|
-
|
73
|
-
keys[i] = StringValueCStr(key_str);
|
76
|
+
key_str = rb_ary_entry(_keys, i);
|
77
|
+
keys[i] = strcpy((char*)ruby_xmalloc((RSTRING_LEN(key_str) + 1) * sizeof(char)), StringValueCStr(key_str));
|
74
78
|
if (_values != Qundef) values[i] = NUM2INT(rb_ary_entry(_values, i));
|
75
79
|
}
|
76
80
|
|
77
81
|
try {
|
78
82
|
get_double_array(self)->build(n_keys, keys, NULL, values);
|
79
83
|
} catch (Darts::Details::Exception e) {
|
84
|
+
for (int i = 0; i < n_keys; i++) ruby_xfree(keys[i]);
|
80
85
|
ruby_xfree(keys);
|
81
86
|
if (_values != Qundef) ruby_xfree(values);
|
82
87
|
rb_raise(rb_eRuntimeError, "%s", e.what());
|
83
88
|
return Qfalse;
|
84
89
|
}
|
90
|
+
for (int i = 0; i < n_keys; i++) ruby_xfree(keys[i]);
|
85
91
|
ruby_xfree(keys);
|
86
92
|
if (_values != Qundef) ruby_xfree(values);
|
93
|
+
RB_GC_GUARD(key_str);
|
87
94
|
return Qtrue;
|
88
95
|
}
|
89
96
|
|
@@ -97,13 +104,16 @@ class RbDoubleArray
|
|
97
104
|
rb_get_kwargs(kwargs, kwtable, 0, 3, kwvalues);
|
98
105
|
|
99
106
|
const char* filename = StringValueCStr(_filename);
|
100
|
-
|
107
|
+
VALUE _mode = kwvalues[0];
|
108
|
+
const char* mode = kwvalues[0] == Qundef ? "rb" : StringValueCStr(_mode);
|
101
109
|
const size_t offset = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
|
102
110
|
const size_t size = kwvalues[2] == Qundef ? 0 : NUM2SIZET(kwvalues[2]);
|
103
111
|
|
104
112
|
if (get_double_array(self)->open(filename, mode, offset, size) != 0) {
|
105
113
|
return Qfalse;
|
106
114
|
}
|
115
|
+
RB_GC_GUARD(_filename);
|
116
|
+
RB_GC_GUARD(_mode);
|
107
117
|
return Qtrue;
|
108
118
|
};
|
109
119
|
|
@@ -117,12 +127,15 @@ class RbDoubleArray
|
|
117
127
|
rb_get_kwargs(kwargs, kwtable, 0, 2, kwvalues);
|
118
128
|
|
119
129
|
const char* filename = StringValueCStr(_filename);
|
120
|
-
|
130
|
+
VALUE _mode = kwvalues[0];
|
131
|
+
const char* mode = kwvalues[0] == Qundef ? "wb" : StringValueCStr(_mode);
|
121
132
|
const size_t offset = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
|
122
133
|
|
123
134
|
if (get_double_array(self)->save(filename, mode, offset) != 0) {
|
124
135
|
return Qfalse;
|
125
136
|
}
|
137
|
+
RB_GC_GUARD(_filename);
|
138
|
+
RB_GC_GUARD(_mode);
|
126
139
|
return Qtrue;
|
127
140
|
};
|
128
141
|
|
@@ -137,6 +150,7 @@ class RbDoubleArray
|
|
137
150
|
const size_t total_sz = sz / get_double_array(self)->unit_size();
|
138
151
|
char* arr = StringValuePtr(bytes);
|
139
152
|
get_double_array(self)->set_array(arr, total_sz);
|
153
|
+
RB_GC_GUARD(bytes);
|
140
154
|
return Qnil;
|
141
155
|
};
|
142
156
|
|
@@ -160,6 +174,7 @@ class RbDoubleArray
|
|
160
174
|
|
161
175
|
Darts::DoubleArray::value_type value;
|
162
176
|
get_double_array(self)->exactMatchSearch(key, value, length, node_pos);
|
177
|
+
RB_GC_GUARD(_key);
|
163
178
|
return INT2NUM(value);
|
164
179
|
};
|
165
180
|
|
@@ -200,6 +215,7 @@ class RbDoubleArray
|
|
200
215
|
rb_ary_push(ret, values);
|
201
216
|
}
|
202
217
|
ruby_xfree(results);
|
218
|
+
RB_GC_GUARD(_key);
|
203
219
|
return ret;
|
204
220
|
};
|
205
221
|
|
@@ -223,6 +239,7 @@ class RbDoubleArray
|
|
223
239
|
rb_hash_aset(ret, ID2SYM(rb_intern("value")), INT2NUM(value));
|
224
240
|
rb_hash_aset(ret, ID2SYM(rb_intern("node_pos")), INT2NUM((int)node_pos));
|
225
241
|
rb_hash_aset(ret, ID2SYM(rb_intern("key_pos")), INT2NUM((int)key_pos));
|
242
|
+
RB_GC_GUARD(_key);
|
226
243
|
return ret;
|
227
244
|
};
|
228
245
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# This class is for yard.
|
2
|
+
|
3
|
+
# Darts-clone.rb is a Ruby binding for the Darts-clone.
|
4
|
+
module DartsClone
|
5
|
+
# The version of Darts-clone.rb you are using.
|
6
|
+
VERSION = '0.2.2'
|
7
|
+
|
8
|
+
# The version of Darts-clone that this gem is binding to.
|
9
|
+
DARTS_CLONE_VERSION = '0.32'
|
10
|
+
|
11
|
+
# DoubleArray is a class that implements double-array trie.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# require 'dartsclone'
|
15
|
+
#
|
16
|
+
# da = DartsClone::DoubleArray.new
|
17
|
+
#
|
18
|
+
# keys = ['abc', 'abcd', 'abcde', 'bcd', 'cde']
|
19
|
+
# da.build(keys)
|
20
|
+
#
|
21
|
+
# p da.common_prefix_search('abcde')
|
22
|
+
# # => [["abc", "abcd", "abcde"], [0, 1, 2]]
|
23
|
+
#
|
24
|
+
class DoubleArray
|
25
|
+
# Create a new double-array trie.
|
26
|
+
def initialize; end
|
27
|
+
|
28
|
+
# Build index of double-array trie
|
29
|
+
#
|
30
|
+
# @param keys [Array<String>]
|
31
|
+
# @param values [Array<Integer>]
|
32
|
+
# @return [Boolean]
|
33
|
+
def build(keys, values: nil); end
|
34
|
+
|
35
|
+
# Open saved index.
|
36
|
+
#
|
37
|
+
# @param filename [String]
|
38
|
+
# @return [Boolean]
|
39
|
+
def open(filename); end
|
40
|
+
|
41
|
+
# Save index.
|
42
|
+
#
|
43
|
+
# @param filename [String]
|
44
|
+
# @param mode [String]
|
45
|
+
# @param offset [Integer]
|
46
|
+
# @return [Boolean]
|
47
|
+
def save(filename, mode: 'wb', offset: 0); end
|
48
|
+
|
49
|
+
# Dump array data.
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
def get_array(); end
|
53
|
+
|
54
|
+
# Load array data.
|
55
|
+
#
|
56
|
+
# @param str [String]
|
57
|
+
def set_array(str); end
|
58
|
+
|
59
|
+
# Search with exact match
|
60
|
+
#
|
61
|
+
# @param key [String]
|
62
|
+
# @param length [Integer]
|
63
|
+
# @param node_pos [Integer]
|
64
|
+
def exact_match_search(key, length: 0, node_pos: 0); end
|
65
|
+
|
66
|
+
# Common prefix search.
|
67
|
+
#
|
68
|
+
# @param key [String]
|
69
|
+
def common_prefix_search(key, max_num_results: nil, length: 0, node_pos: 0); end
|
70
|
+
|
71
|
+
# Traverse trie.
|
72
|
+
#
|
73
|
+
# @param key [String]
|
74
|
+
def traverse(key, node_pos: nil, key_pos: nil, length: nil); end
|
75
|
+
|
76
|
+
# size
|
77
|
+
# @return [Integer]
|
78
|
+
def unit_size(); end
|
79
|
+
|
80
|
+
# unit size
|
81
|
+
# @return [Integer]
|
82
|
+
def size(); end
|
83
|
+
|
84
|
+
# total size
|
85
|
+
# @return [Integer]
|
86
|
+
def total_size(); end
|
87
|
+
|
88
|
+
# clear trie
|
89
|
+
# @return [Nil]
|
90
|
+
def clear(); end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/lib/dartsclone/version.rb
CHANGED
data/sig/dartsclone.rbs
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module DartsClone
|
2
|
+
VERSION: String
|
3
|
+
DARTS_CLONE_VERSION: String
|
4
|
+
|
5
|
+
class DoubleArray
|
6
|
+
def initialize: () -> void
|
7
|
+
def build: (Array[String] keys, ?values: Array[Integer]? values) -> bool
|
8
|
+
def open: (String filename) -> bool
|
9
|
+
def save: (String filename, ?mode: String mode, ?offset: Integer offset) -> bool
|
10
|
+
def get_array: () -> String
|
11
|
+
def set_array: (String str) -> nil
|
12
|
+
def exact_match_search: (String key, ?length: Integer length, ?node_pos: Integer node_pos) -> Integer
|
13
|
+
def common_prefix_search: (String key, ?max_num_results: Integer? max_num_results, ?length: Integer length, ?node_pos: Integer node_pos) -> [Array[String], Array[Integer]]
|
14
|
+
def traverse: (String key, ?node_pos: Integer? node_pos, ?key_pos: Integer? key_pos, ?length: Integer? length) -> { value: Integer, node_pos: Integer, key_pos: Integer }
|
15
|
+
def unit_size: () -> Integer
|
16
|
+
def size: () -> Integer
|
17
|
+
def total_size: () -> Integer
|
18
|
+
def clear: () -> nil
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dartsclone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Darts-clone.rb
|
13
|
+
description: Darts-clone.rb provides Ruby bindings for the Darts-clone.
|
14
14
|
email:
|
15
15
|
- yoshoku@outlook.com
|
16
16
|
executables: []
|
@@ -27,14 +27,17 @@ files:
|
|
27
27
|
- LICENSE.txt
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
|
+
- Steepfile
|
30
31
|
- dartsclone.gemspec
|
31
32
|
- ext/dartsclone/dartscloneext.cpp
|
32
33
|
- ext/dartsclone/dartscloneext.hpp
|
34
|
+
- ext/dartsclone/dummy.rb
|
33
35
|
- ext/dartsclone/extconf.rb
|
34
36
|
- ext/dartsclone/src/COPYING.md
|
35
37
|
- ext/dartsclone/src/darts.h
|
36
38
|
- lib/dartsclone.rb
|
37
39
|
- lib/dartsclone/version.rb
|
40
|
+
- sig/dartsclone.rbs
|
38
41
|
homepage: https://github.com/yoshoku/darts-clone.rb
|
39
42
|
licenses:
|
40
43
|
- BSD-2-Clause
|
@@ -58,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
61
|
- !ruby/object:Gem::Version
|
59
62
|
version: '0'
|
60
63
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
64
|
+
rubygems_version: 3.2.22
|
62
65
|
signing_key:
|
63
66
|
specification_version: 4
|
64
|
-
summary: Ruby
|
67
|
+
summary: Ruby bindings for the Darts-clone.
|
65
68
|
test_files: []
|