marisa 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e170b0442396b9de3d101da6814225bde4578e69
4
+ data.tar.gz: 65cd5189f8cd1016f08b306b3645479aa38c5c77
5
+ SHA512:
6
+ metadata.gz: 05861a4a70877a427d6eaf9aec34ed19c570581405cea027522c812274536a24a36cfda9f146145ab683b8dbda0a8b00519e64b1873c0ff4e0f512b8ed8b8bcc
7
+ data.tar.gz: dd8b614318c38bdd36a248408f1af98c15678ae64aeacf73b4d5ef94fe46f2afef52c5688d807704331c804fbc8baa2aae6e1186a7edd19589a3f16cad2410dc
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
11
+ /ext/marisa/*.o
12
+ /ext/marisa/*.so
13
+ /ext/marisa/*.bundle
14
+ /lib/marisa/*.so
15
+ /lib/marisa/*.bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in naare-core.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ The rubygem of "marisa" is licensed under The BSD 2-Clause License.
2
+ See also `ext/COPYING` about the license of bundled SWIG extension.
3
+
4
+ Copyright (c) 2016, Hidekazu Kobayashi
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/extensiontask'
3
+
4
+ Rake::ExtensionTask.new('marisa') do |ext|
5
+ ext.lib_dir = 'lib/marisa'
6
+ end
@@ -0,0 +1,32 @@
1
+ libmarisa and its command line tools are dual-licensed under the BSD 2-clause license and the LGPL.
2
+
3
+ * The BSD 2-clause license
4
+
5
+ Copyright (c) 2010-2013, Susumu Yata
6
+ All rights reserved.
7
+
8
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9
+
10
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
+
15
+ * The LGPL 2.1 or any later version
16
+
17
+ marisa-trie - A static and space-efficient trie data structure.
18
+ Copyright (C) 2010-2013 Susumu Yata
19
+
20
+ This library is free software; you can redistribute it and/or
21
+ modify it under the terms of the GNU Lesser General Public
22
+ License as published by the Free Software Foundation; either
23
+ version 2.1 of the License, or (at your option) any later version.
24
+
25
+ This library is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ Lesser General Public License for more details.
29
+
30
+ You should have received a copy of the GNU Lesser General Public
31
+ License along with this library; if not, write to the Free Software
32
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -0,0 +1,261 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@:)
9
+ ECHO = $(ECHO1:0=@echo)
10
+ NULLCMD = :
11
+
12
+ #### Start of system configuration section. ####
13
+
14
+ srcdir = .
15
+ topdir = /Users/koba789/.rbenv/versions/2.3.0/include/ruby-2.3.0
16
+ hdrdir = $(topdir)
17
+ arch_hdrdir = /Users/koba789/.rbenv/versions/2.3.0/include/ruby-2.3.0/x86_64-darwin15
18
+ PATH_SEPARATOR = :
19
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
20
+ prefix = $(DESTDIR)/Users/koba789/.rbenv/versions/2.3.0
21
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
22
+ rubyarchprefix = $(rubylibprefix)/$(arch)
23
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
24
+ exec_prefix = $(prefix)
25
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
26
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
27
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
28
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
29
+ sitehdrdir = $(rubyhdrdir)/site_ruby
30
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
31
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
32
+ vendorlibdir = $(vendordir)/$(ruby_version)
33
+ vendordir = $(rubylibprefix)/vendor_ruby
34
+ sitearchdir = $(sitelibdir)/$(sitearch)
35
+ sitelibdir = $(sitedir)/$(ruby_version)
36
+ sitedir = $(rubylibprefix)/site_ruby
37
+ rubyarchdir = $(rubylibdir)/$(arch)
38
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
39
+ sitearchincludedir = $(includedir)/$(sitearch)
40
+ archincludedir = $(includedir)/$(arch)
41
+ sitearchlibdir = $(libdir)/$(sitearch)
42
+ archlibdir = $(libdir)/$(arch)
43
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
44
+ mandir = $(datarootdir)/man
45
+ localedir = $(datarootdir)/locale
46
+ libdir = $(exec_prefix)/lib
47
+ psdir = $(docdir)
48
+ pdfdir = $(docdir)
49
+ dvidir = $(docdir)
50
+ htmldir = $(docdir)
51
+ infodir = $(datarootdir)/info
52
+ docdir = $(datarootdir)/doc/$(PACKAGE)
53
+ oldincludedir = $(DESTDIR)/usr/include
54
+ includedir = $(SDKROOT)$(prefix)/include
55
+ localstatedir = $(prefix)/var
56
+ sharedstatedir = $(prefix)/com
57
+ sysconfdir = $(prefix)/etc
58
+ datadir = $(datarootdir)
59
+ datarootdir = $(prefix)/share
60
+ libexecdir = $(exec_prefix)/libexec
61
+ sbindir = $(exec_prefix)/sbin
62
+ bindir = $(exec_prefix)/bin
63
+ archdir = $(rubyarchdir)
64
+
65
+
66
+ CC = clang
67
+ CXX = clang++
68
+ LIBRUBY = $(LIBRUBY_A)
69
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
70
+ LIBRUBYARG_SHARED =
71
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation
72
+ empty =
73
+ OUTFLAG = -o $(empty)
74
+ COUTFLAG = -o $(empty)
75
+
76
+ RUBY_EXTCONF_H =
77
+ cflags = $(optflags) $(debugflags) $(warnflags)
78
+ cxxflags = $(optflags) $(debugflags) $(warnflags)
79
+ optflags = -O3 -fno-fast-math
80
+ debugflags = -ggdb3
81
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens
82
+ CCDLFLAGS = -fno-common
83
+ CFLAGS = $(CCDLFLAGS) -O3 -Wno-error=shorten-64-to-32 -pipe $(ARCH_FLAG)
84
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
85
+ DEFS =
86
+ CPPFLAGS = -I/Users/koba789/.rbenv/versions/2.3.0/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
87
+ CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
88
+ ldflags = -L. -L/Users/koba789/.rbenv/versions/2.3.0/lib -fstack-protector
89
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
90
+ ARCH_FLAG =
91
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
92
+ LDSHARED = $(CC) -dynamic -bundle
93
+ LDSHAREDXX = $(CXX) -dynamic -bundle
94
+ AR = ar
95
+ EXEEXT =
96
+
97
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
98
+ RUBY_SO_NAME = ruby
99
+ RUBYW_INSTALL_NAME =
100
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
101
+ RUBYW_BASE_NAME = rubyw
102
+ RUBY_BASE_NAME = ruby
103
+
104
+ arch = x86_64-darwin15
105
+ sitearch = $(arch)
106
+ ruby_version = 2.3.0
107
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
108
+ RUBY = $(ruby)
109
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
110
+
111
+ RM = rm -f
112
+ RM_RF = $(RUBY) -run -e rm -- -rf
113
+ RMDIRS = rmdir --ignore-fail-on-non-empty -p
114
+ MAKEDIRS = /usr/local/opt/coreutils/libexec/gnubin/mkdir -p
115
+ INSTALL = /usr/local/opt/coreutils/libexec/gnubin/install -c
116
+ INSTALL_PROG = $(INSTALL) -m 0755
117
+ INSTALL_DATA = $(INSTALL) -m 644
118
+ COPY = cp
119
+ TOUCH = exit >
120
+
121
+ #### End of system configuration section. ####
122
+
123
+ preload =
124
+
125
+ libpath = . $(libdir)
126
+ LIBPATH = -L. -L$(libdir)
127
+ DEFFILE =
128
+
129
+ CLEANFILES = mkmf.log
130
+ DISTCLEANFILES =
131
+ DISTCLEANDIRS =
132
+
133
+ extout =
134
+ extout_prefix =
135
+ target_prefix =
136
+ LOCAL_LIBS =
137
+ LIBS = -lmarisa -lpthread -ldl -lobjc
138
+ ORIG_SRCS = marisa-swig.cxx marisa-swig_wrap.cxx
139
+ SRCS = $(ORIG_SRCS)
140
+ OBJS = marisa-swig.o marisa-swig_wrap.o
141
+ HDRS = $(srcdir)/marisa-swig.h
142
+ TARGET = marisa
143
+ TARGET_NAME = marisa
144
+ TARGET_ENTRY = Init_$(TARGET_NAME)
145
+ DLLIB = $(TARGET).bundle
146
+ EXTSTATIC =
147
+ STATIC_LIB =
148
+
149
+ TIMESTAMP_DIR = .
150
+ BINDIR = $(bindir)
151
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
152
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
153
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
154
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
155
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
156
+
157
+ TARGET_SO = $(DLLIB)
158
+ CLEANLIBS = $(TARGET).bundle
159
+ CLEANOBJS = *.o *.bak
160
+
161
+ all: $(DLLIB)
162
+ static: $(STATIC_LIB) install-rb
163
+ .PHONY: all install static install-so install-rb
164
+ .PHONY: clean clean-so clean-static clean-rb
165
+
166
+ clean-static::
167
+ clean-rb-default::
168
+ clean-rb::
169
+ clean-so::
170
+ clean: clean-so clean-static clean-rb-default clean-rb
171
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
172
+
173
+ distclean-rb-default::
174
+ distclean-rb::
175
+ distclean-so::
176
+ distclean-static::
177
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
178
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
179
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
180
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
181
+
182
+ realclean: distclean
183
+ install: install-so install-rb
184
+
185
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.time
186
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
187
+ clean-static::
188
+ -$(Q)$(RM) $(STATIC_LIB)
189
+ install-rb: pre-install-rb install-rb-default
190
+ install-rb-default: pre-install-rb-default
191
+ pre-install-rb: Makefile
192
+ pre-install-rb-default: Makefile
193
+ pre-install-rb-default:
194
+ @$(NULLCMD)
195
+ $(TIMESTAMP_DIR)/.RUBYARCHDIR.time:
196
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
197
+ $(Q) $(TOUCH) $@
198
+
199
+ site-install: site-install-so site-install-rb
200
+ site-install-so: install-so
201
+ site-install-rb: install-rb
202
+
203
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
204
+
205
+ .cc.o:
206
+ $(ECHO) compiling $(<)
207
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
208
+
209
+ .cc.S:
210
+ $(ECHO) translating $(<)
211
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
212
+
213
+ .mm.o:
214
+ $(ECHO) compiling $(<)
215
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
216
+
217
+ .mm.S:
218
+ $(ECHO) translating $(<)
219
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
220
+
221
+ .cxx.o:
222
+ $(ECHO) compiling $(<)
223
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
224
+
225
+ .cxx.S:
226
+ $(ECHO) translating $(<)
227
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
228
+
229
+ .cpp.o:
230
+ $(ECHO) compiling $(<)
231
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
232
+
233
+ .cpp.S:
234
+ $(ECHO) translating $(<)
235
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
236
+
237
+ .c.o:
238
+ $(ECHO) compiling $(<)
239
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
240
+
241
+ .c.S:
242
+ $(ECHO) translating $(<)
243
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
244
+
245
+ .m.o:
246
+ $(ECHO) compiling $(<)
247
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
248
+
249
+ .m.S:
250
+ $(ECHO) translating $(<)
251
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
252
+
253
+ $(DLLIB): $(OBJS) Makefile
254
+ $(ECHO) linking shared-object $(DLLIB)
255
+ -$(Q)$(RM) $(@)
256
+ $(Q) $(LDSHAREDXX) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
257
+ $(Q) $(POSTLINK)
258
+
259
+
260
+
261
+ $(OBJS): $(HDRS) $(ruby_headers)
@@ -0,0 +1,5 @@
1
+ require "mkmf"
2
+
3
+ have_library("marisa")
4
+
5
+ create_makefile("marisa/marisa")
@@ -0,0 +1,253 @@
1
+ #include <cstring>
2
+ #include <new>
3
+
4
+ #include "marisa-swig.h"
5
+
6
+ namespace marisa_swig {
7
+
8
+ void Key::str(const char **ptr_out, size_t *length_out) const {
9
+ *ptr_out = key_.ptr();
10
+ *length_out = key_.length();
11
+ }
12
+
13
+ size_t Key::id() const {
14
+ return key_.id();
15
+ }
16
+
17
+ float Key::weight() const {
18
+ return key_.weight();
19
+ }
20
+
21
+ void Query::str(const char **ptr_out, size_t *length_out) const {
22
+ *ptr_out = query_.ptr();
23
+ *length_out = query_.length();
24
+ }
25
+
26
+ size_t Query::id() const {
27
+ return query_.id();
28
+ }
29
+
30
+ Keyset::Keyset() : keyset_(new (std::nothrow) marisa::Keyset) {
31
+ MARISA_THROW_IF(keyset_ == NULL, ::MARISA_MEMORY_ERROR);
32
+ }
33
+
34
+ Keyset::~Keyset() {
35
+ delete keyset_;
36
+ }
37
+
38
+ void Keyset::push_back(const marisa::Key &key) {
39
+ keyset_->push_back(key);
40
+ }
41
+
42
+ void Keyset::push_back(const char *ptr, size_t length, float weight) {
43
+ keyset_->push_back(ptr, length, weight);
44
+ }
45
+
46
+ const Key &Keyset::key(size_t i) const {
47
+ return reinterpret_cast<const Key &>((*keyset_)[i]);
48
+ }
49
+
50
+ void Keyset::key_str(size_t i,
51
+ const char **ptr_out, size_t *length_out) const {
52
+ *ptr_out = (*keyset_)[i].ptr();
53
+ *length_out = (*keyset_)[i].length();
54
+ }
55
+
56
+ size_t Keyset::key_id(size_t i) const {
57
+ return (*keyset_)[i].id();
58
+ }
59
+
60
+ size_t Keyset::num_keys() const {
61
+ return keyset_->num_keys();
62
+ }
63
+
64
+ bool Keyset::empty() const {
65
+ return keyset_->empty();
66
+ }
67
+
68
+ size_t Keyset::size() const {
69
+ return keyset_->size();
70
+ }
71
+
72
+ size_t Keyset::total_length() const {
73
+ return keyset_->total_length();
74
+ }
75
+
76
+ void Keyset::reset() {
77
+ keyset_->reset();
78
+ }
79
+
80
+ void Keyset::clear() {
81
+ keyset_->clear();
82
+ }
83
+
84
+ Agent::Agent()
85
+ : agent_(new (std::nothrow) marisa::Agent), buf_(NULL), buf_size_(0) {
86
+ MARISA_THROW_IF(agent_ == NULL, ::MARISA_MEMORY_ERROR);
87
+ }
88
+
89
+ Agent::~Agent() {
90
+ delete agent_;
91
+ delete [] buf_;
92
+ }
93
+
94
+ void Agent::set_query(const char *ptr, size_t length) {
95
+ if (length > buf_size_) {
96
+ size_t new_buf_size = (buf_size_ != 0) ? buf_size_ : 1;
97
+ if (length >= (MARISA_SIZE_MAX / 2)) {
98
+ new_buf_size = MARISA_SIZE_MAX;
99
+ } else {
100
+ while (new_buf_size < length) {
101
+ new_buf_size *= 2;
102
+ }
103
+ }
104
+ char *new_buf = new (std::nothrow) char[new_buf_size];
105
+ MARISA_THROW_IF(new_buf == NULL, MARISA_MEMORY_ERROR);
106
+ delete [] buf_;
107
+ buf_ = new_buf;
108
+ buf_size_ = new_buf_size;
109
+ }
110
+ std::memcpy(buf_, ptr, length);
111
+ agent_->set_query(buf_, length);
112
+ }
113
+
114
+ void Agent::set_query(size_t id) {
115
+ agent_->set_query(id);
116
+ }
117
+
118
+ const Key &Agent::key() const {
119
+ return reinterpret_cast<const Key &>(agent_->key());
120
+ }
121
+
122
+ const Query &Agent::query() const {
123
+ return reinterpret_cast<const Query &>(agent_->query());
124
+ }
125
+
126
+ void Agent::key_str(const char **ptr_out, size_t *length_out) const {
127
+ *ptr_out = agent_->key().ptr();
128
+ *length_out = agent_->key().length();
129
+ }
130
+
131
+ size_t Agent::key_id() const {
132
+ return agent_->key().id();
133
+ }
134
+
135
+ void Agent::query_str(const char **ptr_out, size_t *length_out) const {
136
+ *ptr_out = agent_->query().ptr();
137
+ *length_out = agent_->query().length();
138
+ }
139
+
140
+ size_t Agent::query_id() const {
141
+ return agent_->query().id();
142
+ }
143
+
144
+ Trie::Trie() : trie_(new (std::nothrow) marisa::Trie) {
145
+ MARISA_THROW_IF(trie_ == NULL, ::MARISA_MEMORY_ERROR);
146
+ }
147
+
148
+ Trie::~Trie() {
149
+ delete trie_;
150
+ }
151
+
152
+ void Trie::build(Keyset &keyset, int config_flags) {
153
+ trie_->build(*keyset.keyset_, config_flags);
154
+ }
155
+
156
+ void Trie::mmap(const char *filename) {
157
+ trie_->mmap(filename);
158
+ }
159
+
160
+ void Trie::load(const char *filename) {
161
+ trie_->load(filename);
162
+ }
163
+
164
+ void Trie::save(const char *filename) const {
165
+ trie_->save(filename);
166
+ }
167
+
168
+ bool Trie::lookup(Agent &agent) const {
169
+ return trie_->lookup(*agent.agent_);
170
+ }
171
+
172
+ void Trie::reverse_lookup(Agent &agent) const {
173
+ trie_->reverse_lookup(*agent.agent_);
174
+ }
175
+
176
+ bool Trie::common_prefix_search(Agent &agent) const {
177
+ return trie_->common_prefix_search(*agent.agent_);
178
+ }
179
+
180
+ bool Trie::predictive_search(Agent &agent) const {
181
+ return trie_->predictive_search(*agent.agent_);
182
+ }
183
+
184
+ size_t Trie::lookup(const char *ptr, size_t length) const {
185
+ marisa::Agent agent;
186
+ agent.set_query(ptr, length);
187
+ if (!trie_->lookup(agent)) {
188
+ return MARISA_INVALID_KEY_ID;
189
+ }
190
+ return agent.key().id();
191
+ }
192
+
193
+ void Trie::reverse_lookup(size_t id,
194
+ const char **ptr_out_to_be_deleted, size_t *length_out) const {
195
+ marisa::Agent agent;
196
+ agent.set_query(id);
197
+ trie_->reverse_lookup(agent);
198
+ char * const buf = new (std::nothrow) char[agent.key().length()];
199
+ MARISA_THROW_IF(buf == NULL, MARISA_MEMORY_ERROR);
200
+ std::memcpy(buf, agent.key().ptr(), agent.key().length());
201
+ *ptr_out_to_be_deleted = buf;
202
+ *length_out = agent.key().length();
203
+ }
204
+
205
+ size_t Trie::num_tries() const {
206
+ return trie_->num_tries();
207
+ }
208
+
209
+ size_t Trie::num_keys() const {
210
+ return trie_->num_keys();
211
+ }
212
+
213
+ size_t Trie::num_nodes() const {
214
+ return trie_->num_nodes();
215
+ }
216
+
217
+ TailMode Trie::tail_mode() const {
218
+ if (trie_->tail_mode() == ::MARISA_TEXT_TAIL) {
219
+ return TEXT_TAIL;
220
+ } else {
221
+ return BINARY_TAIL;
222
+ }
223
+ }
224
+
225
+ NodeOrder Trie::node_order() const {
226
+ if (trie_->node_order() == ::MARISA_LABEL_ORDER) {
227
+ return LABEL_ORDER;
228
+ } else {
229
+ return WEIGHT_ORDER;
230
+ }
231
+ }
232
+
233
+ bool Trie::empty() const {
234
+ return trie_->empty();
235
+ }
236
+
237
+ size_t Trie::size() const {
238
+ return trie_->size();
239
+ }
240
+
241
+ size_t Trie::total_size() const {
242
+ return trie_->total_size();
243
+ }
244
+
245
+ size_t Trie::io_size() const {
246
+ return trie_->io_size();
247
+ }
248
+
249
+ void Trie::clear() {
250
+ trie_->clear();
251
+ }
252
+
253
+ } // namespace marisa_swig