pax_global_header00006660000000000000000000000064150502726310014513gustar00rootroot0000000000000052 comment=4ef33cc5a2b6b4f5e147e4564a5236e163d67982 marisa-trie-master/000077500000000000000000000000001505027263100145655ustar00rootroot00000000000000marisa-trie-master/.clang-format000066400000000000000000000010231505027263100171340ustar00rootroot00000000000000--- BasedOnStyle: Google Language: Cpp # `AlignConsecutiveAssignments` controls all assignments. We would like to # align just enum declarations, but it doesn't look like it's possible. # `AlignConsecutiveDeclarations: true` is good for typedefs, but bad for # member functions and variables. Leave if off. AlignConsecutiveMacros: true AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: Empty IndentPPDirectives: BeforeHash PPIndentWidth: 1 PackConstructorInitializers: BinPack SpaceAfterCStyleCast: false ... marisa-trie-master/.clang-tidy000066400000000000000000000075361505027263100166340ustar00rootroot00000000000000--- # clang-tidy configuration # # clang-tidy can be run manually like this from CMake v3.26: # # cmake -S. -Bbuild -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_CXX_CLANG_TIDY_EXPORT_FIXES_DIR=clang-tidy-fixes # cmake --build build # # To export fixes suggested by clang-tidy, run: # # clang-apply-replacements build/clang-tidy-fixes # # To limit the run to certain checks, run: # # cmake -S. -Bbuild -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-checks='-*,modernize-use-nodiscard'" # # clang-tidy also has several IDE integrations listed here: # https://clang.llvm.org/extra/clang-tidy/Integrations.html HeaderFilterRegex: ".*" # Enable most checks. # # Built-in checks: # https://clang.llvm.org/extra/clang-tidy/checks/list.html # # Exclusions: # # -modernize-avoid-c-arrays # `std::array` is not always good replacement # because its length is not deduced. # # -modernize-use-constraints # C++17 does not have constraints. # # -modernize-use-trailing-return-type # -readability-function-cognitive-complexity # Subjective and/or stylistic checks. Checks: > -*, bugprone-*, cppcoreguidelines-pro-type-cstyle-cast, google-runtime-int, llvm-include-order, llvm-namespace-comment, misc-*, modernize-*, performance-*, portability-*, readability-*, -readability-function-cognitive-complexity, -readability-identifier-length, -bugprone-easily-swappable-parameters, -readability-magic-numbers, -misc-non-private-member-variables-in-classes, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, -modernize-use-constraints CheckOptions: - { key: readability-identifier-naming.NamespaceCase, value: lower_case } - { key: readability-identifier-naming.ClassCase, value: CamelCase } - { key: readability-identifier-naming.StructCase, value: CamelCase } - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase } - { key: readability-identifier-naming.MethodCase, value: lower_case } - { key: readability-identifier-naming.FunctionCase, value: aNy_CasE } - { key: readability-identifier-naming.ParameterCase, value: lower_case } - { key: readability-identifier-naming.MemberCase, value: lower_case } - { key: readability-identifier-naming.VariableCase, value: lower_case } - { key: readability-identifier-naming.ClassMemberCase, value: lower_case } - { key: readability-identifier-naming.GlobalVariableCase, value: aNy_CasE } - { key: readability-identifier-naming.GlobalFunctionCase, value: aNy_CasE } - { key: readability-identifier-naming.ClassMemberSuffix, value: _ } - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } - { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase } - { key: readability-identifier-naming.MemberConstantCase, value: CamelCase } - { key: readability-identifier-naming.StaticConstantCase, value: CamelCase } # Use fixed-width integer types instead of short, long and long long - { key: google-runtime-int.UnsignedTypePrefix, value: "uint" } - { key: google-runtime-int.SignedTypePrefix, value: "int" } - { key: google-runtime-int.TypeSuffix, value: "_t" } # `int8_t` aren't used as chars, disable misleading warning. - { key: bugprone-signed-char-misuse.CharTypdefsToIgnore, value: "int8_t" } # Single char loop counters are OK. - { key: readability-identifier-length.MinimumLoopCounterNameLength, value: 1 } marisa-trie-master/.github/000077500000000000000000000000001505027263100161255ustar00rootroot00000000000000marisa-trie-master/.github/dependabot.yml000066400000000000000000000003301505027263100207510ustar00rootroot00000000000000# Set update schedule for GitHub Actions version: 2 updates: - package-ecosystem: "github-actions" directory: "/" schedule: # Check for updates to GitHub Actions every week interval: "weekly" marisa-trie-master/.github/workflows/000077500000000000000000000000001505027263100201625ustar00rootroot00000000000000marisa-trie-master/.github/workflows/clang-format.yml000066400000000000000000000013061505027263100232570ustar00rootroot00000000000000name: clang-format on: push: branches: - master paths-ignore: - '*.md' - 'docs/**' pull_request: types: [ opened, synchronize ] paths-ignore: - '*.md' - 'docs/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: formatting-check: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: fetch-depth: 0 - name: Formatting Check uses: jidicula/clang-format-action@4726374d1aa3c6aecf132e5197e498979588ebc8 # v4.15.0 with: clang-format-version: '20' exclude-regex: '/bindings/' marisa-trie-master/.github/workflows/linux.yml000066400000000000000000000063731505027263100220550ustar00rootroot00000000000000name: Linux CI on: push: branches: [master, develop] paths-ignore: - '*.md' - 'docs/**' pull_request: types: [opened, synchronize] paths-ignore: - '*.md' - 'docs/**' workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: cmake: name: CMake - ${{ matrix.runs-on }} - ${{ matrix.name }} strategy: matrix: runs-on: - ubuntu-22.04 - ubuntu-latest include: - compiler: gcc name: GCC coverage: true - compiler: clang name: Clang coverage: false runs-on: ${{ matrix.runs-on }} steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: fetch-depth: 0 - name: Install Dependencies if: matrix.coverage run: sudo apt install lcov - name: Setup Compiler run: | if [ "${{ matrix.compiler }}" = "gcc" ]; then echo "CC=gcc" >> $GITHUB_ENV echo "CXX=g++" >> $GITHUB_ENV else echo "CC=clang" >> $GITHUB_ENV echo "CXX=clang++" >> $GITHUB_ENV fi - name: Build in Release Mode continue-on-error: true run: | cmake -S . -B build-release -DENABLE_NATIVE_CODE=ON cmake --build build-release -j $(getconf _NPROCESSORS_ONLN) - name: Build in Debug Mode run: | cmake -S. -B build-debug \ -DENABLE_NATIVE_CODE=ON \ -DENABLE_ASAN=ON \ -DENABLE_UBSAN=ON \ -DCMAKE_CXX_CLANG_TIDY=clang-tidy \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_POSITION_INDEPENDENT_CODE=On \ $([ "${{ matrix.coverage }}" = "true" ] && echo "-DENABLE_COVERAGE=ON") cmake --build build-debug -j $(getconf _NPROCESSORS_ONLN) - name: Build SWIG Bindings run: | make -C bindings - name: Build Python3 Binding run: | cd bindings/python3 CFLAGS="-std=c++17" python3 setup.py build_ext --include-dirs=../../include --library-dirs=../../build-debug python3 setup.py build - name: Build Perl Binding run: | cd bindings/perl perl Makefile.PL CC=$CC CCFLAGS="-std=c++17" INC=-I"../../include" LIBS=-L"../../build-debug" INSTALLDIRS=vendor make - name: Build Ruby Binding run: | cd bindings/ruby ruby extconf.rb --with-opt-include="../../include" --with-opt-lib="../../build-debug" --vendor make CC=$CC CXX=$CXX CXXFLAGS="-std=c++17" - name: Run Tests (Debug) run: ctest --test-dir build-debug --output-on-failure -j $(getconf _NPROCESSORS_ONLN) - name: Generate Coverage Report if: matrix.coverage run: | lcov --capture --directory . --output-file coverage.info lcov --remove coverage.info '/usr/*' --output-file coverage.info - name: Upload Code Coverage if: matrix.coverage uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6 with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: coverage.info marisa-trie-master/.github/workflows/macos.yml000066400000000000000000000033771505027263100220210ustar00rootroot00000000000000name: macOS CI on: push: branches: [master, develop] paths-ignore: - '*.md' - 'docs/**' pull_request: types: [opened, synchronize] paths-ignore: - '*.md' - 'docs/**' workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: cmake: name: CMake - ${{ matrix.runs-on }} - ${{ matrix.name }} strategy: matrix: runs-on: - macos-13 - macos-latest include: - compiler: gcc name: GCC coverage: true - compiler: clang name: Clang coverage: false runs-on: ${{ matrix.runs-on }} steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: fetch-depth: 0 - name: Setup Compiler run: | if [ "${{ matrix.compiler }}" = "gcc" ]; then echo "CC=gcc" >> $GITHUB_ENV echo "CXX=g++" >> $GITHUB_ENV else echo "CC=clang" >> $GITHUB_ENV echo "CXX=clang++" >> $GITHUB_ENV fi - name: Build in Release Mode continue-on-error: true run: | cmake -S . -B build-release -DENABLE_NATIVE_CODE=ON cmake --build build-release -j $(getconf _NPROCESSORS_ONLN) - name: Build in Debug Mode run: | cmake -S. -B build-debug \ -DENABLE_NATIVE_CODE=ON \ -DENABLE_ASAN=ON \ -DENABLE_UBSAN=ON \ -DCMAKE_BUILD_TYPE=Debug cmake --build build-debug -j $(getconf _NPROCESSORS_ONLN) - name: Run Tests (Debug) run: ctest --test-dir build-debug --output-on-failure -j $(getconf _NPROCESSORS_ONLN) marisa-trie-master/.github/workflows/windows.yml000066400000000000000000000021751505027263100224040ustar00rootroot00000000000000name: Windows CI on: push: branches: [master] paths-ignore: - '*.md' - 'docs/**' pull_request: types: [opened, synchronize] paths-ignore: - '*.md' - 'docs/**' workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: cmake: name: CMake - MSVC ${{ matrix.platform }} runs-on: windows-latest strategy: matrix: platform: [x64, Win32] steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: fetch-depth: 0 - name: Build in Release Mode continue-on-error: true run: | cmake -S . -B Release -A ${{ matrix.platform }} cmake --build Release --config Release - name: Build in Debug Mode run: | cmake -S. -B Debug ` -A ${{ matrix.platform }} ` -DENABLE_ASAN=ON ` -DENABLE_UBSAN=ON cmake --build Debug --config Debug - name: Run Tests (Debug) run: ctest --test-dir Debug --build-config Debug --output-on-failure marisa-trie-master/.gitignore000066400000000000000000000013741505027263100165620ustar00rootroot00000000000000.deps/ .libs/ .vscode/ *.a *.app *.dll *.dylib *.exe *.la *.lai *.lib *.lo *.log *.m4 *.o *.obj *.out *.slo *.so *~ Makefile Makefile.in aclocal.m4 autom4te.cache/ compile config.guess config.log config.status config.sub configure depcomp install-sh libtool ltmain.sh marisa.pc missing stamp-h1 test-driver tests/base-test tests/base-test.trs tests/io-test tests/io-test.dat tests/io-test.trs tests/marisa-test tests/marisa-test.dat tests/marisa-test.trs tests/trie-test tests/trie-test.dat tests/trie-test.trs tests/vector-test tests/vector-test.dat tests/vector-test.trs tools/marisa-benchmark tools/marisa-build tools/marisa-common-prefix-search tools/marisa-dump tools/marisa-lookup tools/marisa-predictive-search tools/marisa-reverse-lookup /build/ /build-*/ marisa-trie-master/AUTHORS000066400000000000000000000000441505027263100156330ustar00rootroot00000000000000Susumu Yata marisa-trie-master/CMakeLists.txt000066400000000000000000000243661505027263100173400ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.22) file(STRINGS "VERSION" VERSION_STR) project(Marisa VERSION "${VERSION_STR}" LANGUAGES C CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/finders") # Options option(ENABLE_NATIVE_CODE "Enable -march=native and supported instructions" OFF) option(ENABLE_TOOLS "Enables command-line tools" ON) option(ENABLE_ASAN "Enable address sanitizer" OFF) option(ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF) option(ENABLE_GPERFTOOLS_PROFILER "Find and link gperftools profiler" OFF) option(ENABLE_COVERAGE "Enable code coverage instrumentation (only enabled with BUILD_TESTING)" OFF) option(ENABLE_STATIC_STDLIB "Link C++ stdlib statically" OFF) include(GNUInstallDirs) set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "") if(CMAKE_INSTALL_LIBDIR MATCHES "lib64$") set(LIB_SUFFIX 64) endif() function(check_macro_defined MACRO OUTPUT_VAR) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) try_compile(result SOURCE_FROM_CONTENT "check_${OUTPUT_VAR}.cc" "#ifndef ${MACRO}\n#error \"${MACRO} is missing\"\n#endif\n" COMPILE_DEFINITIONS -march=native ) set("${OUTPUT_VAR}" "${result}" PARENT_SCOPE) message("${OUTPUT_VAR}: ${result}") endfunction() if(ENABLE_NATIVE_CODE) check_macro_defined(__SSE2__ HAVE_SSE2) check_macro_defined(__SSE3__ HAVE_SSE3) check_macro_defined(__SSSE3__ HAVE_SSSE3) check_macro_defined(__SSE4_1__ HAVE_SSE4_1) check_macro_defined(__SSE4_2__ HAVE_SSE4_2) check_macro_defined(__POPCNT__ HAVE_POPCNT) check_macro_defined(__BMI__ HAVE_BMI) check_macro_defined(__BMI2__ HAVE_BMI2) endif() include(CMakeDependentOption) cmake_dependent_option(ENABLE_SSE2 "Use SSE2 instructions" ON "ENABLE_NATIVE_CODE;HAVE_SSE2" OFF) cmake_dependent_option(ENABLE_SSE3 "Use SSE3 instructions" ON "ENABLE_NATIVE_CODE;HAVE_SSE3" OFF) cmake_dependent_option(ENABLE_SSSE3 "Use SSSE3 instructions" ON "ENABLE_NATIVE_CODE;HAVE_SSSE3" OFF) cmake_dependent_option(ENABLE_SSE4_1 "Use SSE4_1 instructions" ON "ENABLE_NATIVE_CODE;HAVE_SSE4_1" OFF) cmake_dependent_option(ENABLE_SSE4_2 "Use SSE4_2 instructions" ON "ENABLE_NATIVE_CODE;HAVE_SSE4_2" OFF) cmake_dependent_option(ENABLE_POPCNT "Use POPCNT instructions" ON "ENABLE_NATIVE_CODE;HAVE_POPCNT" OFF) cmake_dependent_option(ENABLE_BMI "Use BMI instructions" ON "ENABLE_NATIVE_CODE;HAVE_BMI" OFF) cmake_dependent_option(ENABLE_BMI2 "Use BMI2 instructions" ON "ENABLE_NATIVE_CODE;HAVE_BMI2" OFF) function(add_native_code TARGET) if(ENABLE_NATIVE_CODE) target_compile_options("${TARGET}" PRIVATE -march=native) if(ENABLE_BMI2) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_BMI2 -mbmi2 -msse4) elseif(ENABLE_BMI) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_BMI -mbmi -msse4) elseif(ENABLE_SSE4A) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_SSE4A -msse4a) elseif(ENABLE_SSE4_2 AND ENABLE_POPCNT) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_SSE4 -msse4) elseif(ENABLE_SSE4_2) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_SSE4_2 -msse4.2) elseif(ENABLE_SSE4_1) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_SSE4_1 -msse4.1) elseif(ENABLE_SSSE3) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_SSSE3 -mssse3) elseif(ENABLE_SSE3) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_SSE3 -msse3) elseif(ENABLE_SSE2) target_compile_options("${TARGET}" PRIVATE -DMARISA_USE_SSE2 -msse2) endif() endif() endfunction() include(CTest) # We allow C++20 features if the compiler supports them set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED OFF) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for clang-tidy # Target Windows 8 for PrefetchVirtualMemory if (MINGW) add_compile_definitions(_WIN32_WINNT=_WIN32_WINNT_WIN8) endif() # MSVC Configuration # https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170 # https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170 add_compile_options("$<$:/utf-8>") add_compile_options("$<$:/utf-8;/Zc:__cplusplus>") # Sanitizers support function(add_sanitizers TARGET) if(NOT MSVC) if(ENABLE_ASAN) target_compile_options(${TARGET} PUBLIC -fsanitize=address) target_link_libraries(${TARGET} PUBLIC -fsanitize=address) endif() if(ENABLE_UBSAN) target_compile_options(${TARGET} PUBLIC -fsanitize=undefined) target_link_libraries(${TARGET} PUBLIC -fsanitize=undefined) endif() endif() endfunction() # gperftools support (https://github.com/gperftools/gperftools) function(add_gperftools TARGET) if(ENABLE_GPERFTOOLS_PROFILER) if(NOT Gperftools_FOUND) find_package(Gperftools REQUIRED) set(ENABLE_STATIC_STDLIB OFF) endif() # Compile with information about file and line numbers for everything # even in non-Debug build types. if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(${TARGET} PRIVATE -g2) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Use the more size-efficient `-gmlt` option on clang. target_compile_options(${TARGET} PRIVATE -gmlt) endif() target_link_libraries(${TARGET} PUBLIC ${GPERFTOOLS_LIBRARIES}) endif() endfunction() # Applies configuration to the target based on options. function(configure_target_from_options TARGET) add_sanitizers(${TARGET}) add_gperftools(${TARGET}) target_compile_definitions(${TARGET} PRIVATE $<$:_DEBUG>) if(MARISA_ENABLE_STATIC_STDLIB) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_link_libraries(marisa PUBLIC -static-libgcc -static-libstdc++) endif() endif() endfunction() # Marisa Library set(MARISA_HEADERS include/marisa.h include/marisa/agent.h include/marisa/base.h include/marisa/iostream.h include/marisa/key.h include/marisa/keyset.h include/marisa/query.h include/marisa/stdio.h include/marisa/trie.h ) add_library(marisa ${MARISA_HEADERS} lib/marisa/agent.cc lib/marisa/grimoire/algorithm/sort.h lib/marisa/grimoire/intrin.h lib/marisa/grimoire/io.h lib/marisa/grimoire/io/mapper.cc lib/marisa/grimoire/io/mapper.h lib/marisa/grimoire/io/reader.cc lib/marisa/grimoire/io/reader.h lib/marisa/grimoire/io/writer.cc lib/marisa/grimoire/io/writer.h lib/marisa/grimoire/trie.h lib/marisa/grimoire/trie/cache.h lib/marisa/grimoire/trie/config.h lib/marisa/grimoire/trie/entry.h lib/marisa/grimoire/trie/header.h lib/marisa/grimoire/trie/history.h lib/marisa/grimoire/trie/key.h lib/marisa/grimoire/trie/louds-trie.cc lib/marisa/grimoire/trie/louds-trie.h lib/marisa/grimoire/trie/range.h lib/marisa/grimoire/trie/state.h lib/marisa/grimoire/trie/tail.cc lib/marisa/grimoire/trie/tail.h lib/marisa/grimoire/vector.h lib/marisa/grimoire/vector/bit-vector.cc lib/marisa/grimoire/vector/bit-vector.h lib/marisa/grimoire/vector/flat-vector.h lib/marisa/grimoire/vector/pop-count.h lib/marisa/grimoire/vector/rank-index.h lib/marisa/grimoire/vector/vector.h lib/marisa/keyset.cc lib/marisa/trie.cc ) target_include_directories(marisa PUBLIC $ $ PRIVATE lib ) set_target_properties(marisa PROPERTIES VERSION "${Marisa_VERSION}" SOVERSION "${Marisa_VERSION_MAJOR}" ) configure_target_from_options(marisa) add_native_code(marisa) add_library(Marisa::marisa ALIAS marisa) # Tools set(MARISA_TOOLS marisa-build marisa-lookup marisa-reverse-lookup marisa-common-prefix-search marisa-predictive-search marisa-dump marisa-benchmark ) if(ENABLE_TOOLS) add_library(cmdopt STATIC tools/cmdopt.h tools/cmdopt.cc) target_include_directories(cmdopt PUBLIC tools) foreach(_tool ${MARISA_TOOLS}) add_executable(${_tool} "tools/${_tool}.cc") target_link_libraries(${_tool} PRIVATE marisa cmdopt) configure_target_from_options(${_tool}) endforeach() endif() # Testing if(BUILD_TESTING) foreach(_test base-test io-test vector-test trie-test marisa-test ) add_executable(${_test} "tests/${_test}.cc") target_link_libraries(${_test} PRIVATE marisa) target_include_directories(${_test} PRIVATE tests lib) configure_target_from_options(${_test}) add_native_code(${_test}) add_test( NAME ${_test} COMMAND ${_test} ) endforeach() if(ENABLE_COVERAGE) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") message(WARNING "Code coverage is not supported with MSVC") else() target_compile_options(marisa PUBLIC --coverage) target_link_options(marisa PUBLIC --coverage) endif() endif() endif() # Install configuration if(NOT DEFINED LIB_INSTALL_DIR) set(LIB_INSTALL_DIR lib) endif() # We do not pass PUBLIC_HEADER because it doesn't respect subdirectories. # Instead, we install the headers manually via a second call to `install`. install( TARGETS marisa EXPORT MarisaTargets CONFIGURATIONS Release DESTINATION ${LIB_INSTALL_DIR} COMPONENT Library ) install( DIRECTORY include/ DESTINATION include COMPONENT Library FILES_MATCHING PATTERN "*.h" ) if(ENABLE_TOOLS) install( TARGETS ${MARISA_TOOLS} CONFIGURATIONS Release COMPONENT Binaries ) endif() set(ConfigPackageLocation "${LIB_INSTALL_DIR}/cmake/Marisa") include(CMakePackageConfigHelpers) configure_package_config_file(Marisa.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/Marisa/MarisaConfig.cmake" INSTALL_DESTINATION ${ConfigPackageLocation} ) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/Marisa/MarisaConfigVersion.cmake" VERSION ${Marisa_VERSION} COMPATIBILITY SameMajorVersion ) export(EXPORT MarisaTargets FILE "${CMAKE_CURRENT_BINARY_DIR}/Marisa/MarisaTargets.cmake" NAMESPACE Marisa:: ) install(EXPORT MarisaTargets FILE MarisaTargets.cmake NAMESPACE Marisa:: DESTINATION ${ConfigPackageLocation} COMPONENT Library ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/Marisa/MarisaConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/Marisa/MarisaConfigVersion.cmake" DESTINATION ${ConfigPackageLocation} COMPONENT Library ) configure_file(marisa.pc.in ${CMAKE_CURRENT_BINARY_DIR}/marisa.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/marisa.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) marisa-trie-master/COPYING.md000066400000000000000000000043431505027263100162230ustar00rootroot00000000000000### COPYING libmarisa and its command line tools are licensed under BSD-2-Clause OR LGPL-2.1-or-later. #### The BSD 2-clause license Copyright (c) 2010-2025, Susumu Yata All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - 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. 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. #### The LGPL 2.1 or any later version marisa-trie - A static and space-efficient trie data structure. Copyright (C) 2010-2025 Susumu Yata This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA marisa-trie-master/Marisa.cmake.in000066400000000000000000000001641505027263100174110ustar00rootroot00000000000000@PACKAGE_INIT@ check_required_components(Marisa) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") marisa-trie-master/README.md000066400000000000000000000046501505027263100160510ustar00rootroot00000000000000### README #### Project name marisa-trie #### Project summary MARISA: Matching Algorithm with Recursively Implemented StorAge #### Latest version 0.3.1 #### Description Matching Algorithm with Recursively Implemented StorAge (MARISA) is a static and space-efficient trie data structure. And libmarisa is a C++ library to provide an implementation of MARISA. Also, the package of libmarisa contains a set of command line tools for building and operating a MARISA-based dictionary. A MARISA-based dictionary supports not only lookup but also reverse lookup, common prefix search and predictive search. * Lookup is to check whether or not a given string exists in a dictionary. * Reverse lookup is to restore a key from its ID. * Common prefix search is to find keys from prefixes of a given string. * Predictive search is to find keys starting with a given string. The biggest advantage of libmarisa is that its dictionary size is considerably more compact than others. See below for the dictionary size of other implementations. * Input * Source: enwiki-20121101-all-titles-in-ns0.gz * Contents: all page titles of English Wikipedia (Nov. 2012) * Number of keys: 9,805,576 * Total size: 200,435,403 bytes (plain) / 54,933,690 bytes (gzipped) |Implementation|Size (bytes)|Remarks | |:-------------|-----------:|--------------------------:| |darts-clone | 376,613,888|Compacted double-array trie| |tx-trie | 127,727,058|LOUDS-based trie | |marisa-trie | 50,753,560|MARISA trie | #### Documentation * README (English): https://www.s-yata.jp/marisa-trie/docs/readme.en.html * README (Japanese): https://www.s-yata.jp/marisa-trie/docs/readme.ja.html #### Build instructions You can get the latest version via `git clone`. Then, you can build and install libmarisa and its command line tools via `cmake`. See also documentation for details. ``` $ git clone https://github.com/s-yata/marisa-trie.git $ cd marisa-trie $ cmake -S. -Bbuild-rel -DCMAKE_BUILD_TYPE=Release -DENABLE_NATIVE_CODE=ON -DBUILD_TESTING=OFF $ cmake --build build-rel $ sudo cmake --install build-rel ``` To install just the library without the binaries: ``` $ sudo cmake --install build-rel --component Library ``` To install just the binaries: ``` $ sudo cmake --install build-rel --component Binaries ``` #### Source code license Licensed under BSD-2-Clause OR LGPL-2.1-or-later. See [COPYING](COPYING.md) for details. marisa-trie-master/VERSION000066400000000000000000000000061505027263100156310ustar00rootroot000000000000000.3.1 marisa-trie-master/bindings/000077500000000000000000000000001505027263100163625ustar00rootroot00000000000000marisa-trie-master/bindings/.gitignore000066400000000000000000000002471505027263100203550ustar00rootroot00000000000000*/sample.dic perl/MYMETA.* perl/blib/ perl/marisa.bs perl/pm_to_blib python*/__pycache__/ python*/build/ python*/dist/ python*/marisa.egg-info/ ruby/.sitearchdir.time marisa-trie-master/bindings/Makefile000066400000000000000000000011521505027263100200210ustar00rootroot00000000000000ALL: swig-perl swig-python3 swig-ruby swig-perl: swig -Wall -c++ -perl -outdir perl marisa-swig.i mv marisa-swig_wrap.cxx perl cp marisa-swig.cxx marisa-swig.h perl swig-python: swig -Wall -c++ -python -outdir python marisa-swig.i mv marisa-swig_wrap.cxx python cp marisa-swig.cxx marisa-swig.h python swig-python3: swig -Wall -c++ -python -outdir python3 marisa-swig-python3.i mv marisa-swig-python3_wrap.cxx python3 cp marisa-swig-python3.cxx marisa-swig-python3.h python3 swig-ruby: swig -Wall -c++ -ruby -outdir ruby marisa-swig.i mv marisa-swig_wrap.cxx ruby cp marisa-swig.cxx marisa-swig.h ruby marisa-trie-master/bindings/marisa-swig-python3.cxx000066400000000000000000000116151505027263100227370ustar00rootroot00000000000000#include #include #include "marisa-swig-python3.h" namespace marisa_swig { void Key::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = key_.ptr(); *length_out = key_.length(); } size_t Key::key_id() const { return key_.id(); } float Key::weight() const { return key_.weight(); } void Query::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = query_.ptr(); *length_out = query_.length(); } size_t Query::query_id() const { return query_.id(); } Keyset::Keyset() : keyset_(new marisa::Keyset) { } Keyset::~Keyset() { delete keyset_; } void Keyset::push_back(const marisa::Key &key) { keyset_->push_back(key); } void Keyset::push_back(const char *ptr, size_t length, float weight) { keyset_->push_back(ptr, length, weight); } const Key &Keyset::key(size_t i) const { return reinterpret_cast((*keyset_)[i]); } void Keyset::key_str(size_t i, const char **ptr_out, size_t *length_out) const { *ptr_out = (*keyset_)[i].ptr(); *length_out = (*keyset_)[i].length(); } size_t Keyset::key_id(size_t i) const { return (*keyset_)[i].id(); } size_t Keyset::num_keys() const { return keyset_->num_keys(); } bool Keyset::empty() const { return keyset_->empty(); } size_t Keyset::size() const { return keyset_->size(); } size_t Keyset::total_length() const { return keyset_->total_length(); } void Keyset::reset() { keyset_->reset(); } void Keyset::clear() { keyset_->clear(); } Agent::Agent() : agent_(new marisa::Agent), buf_(NULL), buf_size_(0) { } Agent::~Agent() { delete agent_; delete [] buf_; } void Agent::set_query(const char *ptr, size_t length) { if (length > buf_size_) { size_t new_buf_size = (buf_size_ != 0) ? buf_size_ : 1; if (length >= (MARISA_SIZE_MAX / 2)) { new_buf_size = MARISA_SIZE_MAX; } else { while (new_buf_size < length) { new_buf_size *= 2; } } char *new_buf = new char[new_buf_size]; delete [] buf_; buf_ = new_buf; buf_size_ = new_buf_size; } std::memcpy(buf_, ptr, length); agent_->set_query(buf_, length); } void Agent::set_query(size_t id) { agent_->set_query(id); } const Key &Agent::key() const { return reinterpret_cast(agent_->key()); } const Query &Agent::query() const { return reinterpret_cast(agent_->query()); } void Agent::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->key().ptr(); *length_out = agent_->key().length(); } size_t Agent::key_id() const { return agent_->key().id(); } void Agent::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->query().ptr(); *length_out = agent_->query().length(); } size_t Agent::query_id() const { return agent_->query().id(); } Trie::Trie() : trie_(new marisa::Trie) { } Trie::~Trie() { delete trie_; } void Trie::build(Keyset &keyset, int config_flags) { trie_->build(*keyset.keyset_, config_flags); } void Trie::mmap(const char *filename, int flags) { trie_->mmap(filename, flags); } void Trie::load(const char *filename) { trie_->load(filename); } void Trie::save(const char *filename) const { trie_->save(filename); } bool Trie::lookup(Agent &agent) const { return trie_->lookup(*agent.agent_); } void Trie::reverse_lookup(Agent &agent) const { trie_->reverse_lookup(*agent.agent_); } bool Trie::common_prefix_search(Agent &agent) const { return trie_->common_prefix_search(*agent.agent_); } bool Trie::predictive_search(Agent &agent) const { return trie_->predictive_search(*agent.agent_); } size_t Trie::lookup(const char *ptr, size_t length) const { marisa::Agent agent; agent.set_query(ptr, length); if (!trie_->lookup(agent)) { return MARISA_INVALID_KEY_ID; } return agent.key().id(); } void Trie::reverse_lookup(size_t id, const char **ptr_out_to_be_deleted, size_t *length_out) const { marisa::Agent agent; agent.set_query(id); trie_->reverse_lookup(agent); char * const buf = new char[agent.key().length()]; std::memcpy(buf, agent.key().ptr(), agent.key().length()); *ptr_out_to_be_deleted = buf; *length_out = agent.key().length(); } size_t Trie::num_tries() const { return trie_->num_tries(); } size_t Trie::num_keys() const { return trie_->num_keys(); } size_t Trie::num_nodes() const { return trie_->num_nodes(); } TailMode Trie::tail_mode() const { if (trie_->tail_mode() == ::MARISA_TEXT_TAIL) { return TEXT_TAIL; } else { return BINARY_TAIL; } } NodeOrder Trie::node_order() const { if (trie_->node_order() == ::MARISA_LABEL_ORDER) { return LABEL_ORDER; } else { return WEIGHT_ORDER; } } bool Trie::empty() const { return trie_->empty(); } size_t Trie::size() const { return trie_->size(); } size_t Trie::total_size() const { return trie_->total_size(); } size_t Trie::io_size() const { return trie_->io_size(); } void Trie::clear() { trie_->clear(); } } // namespace marisa_swig marisa-trie-master/bindings/marisa-swig-python3.h000066400000000000000000000076661505027263100223770ustar00rootroot00000000000000#ifndef MARISA_SWIG_H_ #define MARISA_SWIG_H_ #include namespace marisa_swig { #define MARISA_SWIG_ENUM_COPY(name) name = MARISA_ ## name enum ErrorCode { MARISA_SWIG_ENUM_COPY(OK), MARISA_SWIG_ENUM_COPY(STATE_ERROR), MARISA_SWIG_ENUM_COPY(NULL_ERROR), MARISA_SWIG_ENUM_COPY(BOUND_ERROR), MARISA_SWIG_ENUM_COPY(RANGE_ERROR), MARISA_SWIG_ENUM_COPY(CODE_ERROR), MARISA_SWIG_ENUM_COPY(RESET_ERROR), MARISA_SWIG_ENUM_COPY(SIZE_ERROR), MARISA_SWIG_ENUM_COPY(MEMORY_ERROR), MARISA_SWIG_ENUM_COPY(IO_ERROR), MARISA_SWIG_ENUM_COPY(FORMAT_ERROR) }; enum MapFlags { MARISA_SWIG_ENUM_COPY(MAP_POPULATE), }; enum NumTries { MARISA_SWIG_ENUM_COPY(MIN_NUM_TRIES), MARISA_SWIG_ENUM_COPY(MAX_NUM_TRIES), MARISA_SWIG_ENUM_COPY(DEFAULT_NUM_TRIES) }; enum CacheLevel { MARISA_SWIG_ENUM_COPY(HUGE_CACHE), MARISA_SWIG_ENUM_COPY(LARGE_CACHE), MARISA_SWIG_ENUM_COPY(NORMAL_CACHE), MARISA_SWIG_ENUM_COPY(SMALL_CACHE), MARISA_SWIG_ENUM_COPY(TINY_CACHE), MARISA_SWIG_ENUM_COPY(DEFAULT_CACHE) }; enum TailMode { MARISA_SWIG_ENUM_COPY(TEXT_TAIL), MARISA_SWIG_ENUM_COPY(BINARY_TAIL), MARISA_SWIG_ENUM_COPY(DEFAULT_TAIL) }; enum NodeOrder { MARISA_SWIG_ENUM_COPY(LABEL_ORDER), MARISA_SWIG_ENUM_COPY(WEIGHT_ORDER), MARISA_SWIG_ENUM_COPY(DEFAULT_ORDER) }; #undef MARISA_SWIG_ENUM_COPY class Key { public: void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; float weight() const; private: const marisa::Key key_; Key(); Key(const Key &key); Key &operator=(const Key &); }; class Query { public: void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: const marisa::Query query_; Query(); Query(const Query &query); Query &operator=(const Query &); }; class Keyset { friend class Trie; public: Keyset(); ~Keyset(); void push_back(const marisa::Key &key); void push_back(const char *ptr, std::size_t length, float weight = 1.0); const Key &key(std::size_t i) const; void key_str(std::size_t i, const char **ptr_out, std::size_t *length_out) const; std::size_t key_id(std::size_t i) const; std::size_t num_keys() const; bool empty() const; std::size_t size() const; std::size_t total_length() const; void reset(); void clear(); private: marisa::Keyset *keyset_; Keyset(const Keyset &); Keyset &operator=(const Keyset &); }; class Agent { friend class Trie; public: Agent(); ~Agent(); void set_query(const char *ptr, std::size_t length); void set_query(std::size_t id); const Key &key() const; const Query &query() const; void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: marisa::Agent *agent_; char *buf_; std::size_t buf_size_; Agent(const Agent &); Agent &operator=(const Agent &); }; class Trie { public: Trie(); ~Trie(); void build(Keyset &keyset, int config_flags = 0); void mmap(const char *filename, int flags = 0); void load(const char *filename); void save(const char *filename) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t lookup(const char *ptr, std::size_t length) const; void reverse_lookup(std::size_t id, const char **ptr_out_to_be_deleted, std::size_t *length_out) const; std::size_t num_tries() const; std::size_t num_keys() const; std::size_t num_nodes() const; TailMode tail_mode() const; NodeOrder node_order() const; bool empty() const; std::size_t size() const; std::size_t total_size() const; std::size_t io_size() const; void clear(); private: marisa::Trie *trie_; Trie(const Trie &); Trie &operator=(const Trie &); }; } // namespace marisa_swig #endif // MARISA_SWIG_H_ marisa-trie-master/bindings/marisa-swig-python3.i000066400000000000000000000012411505027263100223570ustar00rootroot00000000000000%module marisa %include "cstring.i" %include "exception.i" %{ #include "marisa-swig-python3.h" %} %apply (char *STRING, int LENGTH) { (const char *ptr, std::size_t length) }; %cstring_output_allocate_size(const char **ptr_out, std::size_t *length_out, ); %cstring_output_allocate_size(const char **ptr_out_to_be_deleted, std::size_t *length_out, delete [] (*$1)); %exception { try { $action } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } %include "marisa-swig-python3.h" %constant size_t INVALID_KEY_ID = MARISA_INVALID_KEY_ID; marisa-trie-master/bindings/marisa-swig.cxx000066400000000000000000000115611505027263100213350ustar00rootroot00000000000000#include #include #include "marisa-swig.h" namespace marisa_swig { void Key::str(const char **ptr_out, size_t *length_out) const { *ptr_out = key_.ptr(); *length_out = key_.length(); } size_t Key::id() const { return key_.id(); } float Key::weight() const { return key_.weight(); } void Query::str(const char **ptr_out, size_t *length_out) const { *ptr_out = query_.ptr(); *length_out = query_.length(); } size_t Query::id() const { return query_.id(); } Keyset::Keyset() : keyset_(new marisa::Keyset) { } Keyset::~Keyset() { delete keyset_; } void Keyset::push_back(const marisa::Key &key) { keyset_->push_back(key); } void Keyset::push_back(const char *ptr, size_t length, float weight) { keyset_->push_back(ptr, length, weight); } const Key &Keyset::key(size_t i) const { return reinterpret_cast((*keyset_)[i]); } void Keyset::key_str(size_t i, const char **ptr_out, size_t *length_out) const { *ptr_out = (*keyset_)[i].ptr(); *length_out = (*keyset_)[i].length(); } size_t Keyset::key_id(size_t i) const { return (*keyset_)[i].id(); } size_t Keyset::num_keys() const { return keyset_->num_keys(); } bool Keyset::empty() const { return keyset_->empty(); } size_t Keyset::size() const { return keyset_->size(); } size_t Keyset::total_length() const { return keyset_->total_length(); } void Keyset::reset() { keyset_->reset(); } void Keyset::clear() { keyset_->clear(); } Agent::Agent() : agent_(new marisa::Agent), buf_(NULL), buf_size_(0) { } Agent::~Agent() { delete agent_; delete [] buf_; } void Agent::set_query(const char *ptr, size_t length) { if (length > buf_size_) { size_t new_buf_size = (buf_size_ != 0) ? buf_size_ : 1; if (length >= (MARISA_SIZE_MAX / 2)) { new_buf_size = MARISA_SIZE_MAX; } else { while (new_buf_size < length) { new_buf_size *= 2; } } char *new_buf = new char[new_buf_size]; delete [] buf_; buf_ = new_buf; buf_size_ = new_buf_size; } std::memcpy(buf_, ptr, length); agent_->set_query(buf_, length); } void Agent::set_query(size_t id) { agent_->set_query(id); } const Key &Agent::key() const { return reinterpret_cast(agent_->key()); } const Query &Agent::query() const { return reinterpret_cast(agent_->query()); } void Agent::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->key().ptr(); *length_out = agent_->key().length(); } size_t Agent::key_id() const { return agent_->key().id(); } void Agent::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->query().ptr(); *length_out = agent_->query().length(); } size_t Agent::query_id() const { return agent_->query().id(); } Trie::Trie() : trie_(new marisa::Trie) { } Trie::~Trie() { delete trie_; } void Trie::build(Keyset &keyset, int config_flags) { trie_->build(*keyset.keyset_, config_flags); } void Trie::mmap(const char *filename, int flags) { trie_->mmap(filename, flags); } void Trie::load(const char *filename) { trie_->load(filename); } void Trie::save(const char *filename) const { trie_->save(filename); } bool Trie::lookup(Agent &agent) const { return trie_->lookup(*agent.agent_); } void Trie::reverse_lookup(Agent &agent) const { trie_->reverse_lookup(*agent.agent_); } bool Trie::common_prefix_search(Agent &agent) const { return trie_->common_prefix_search(*agent.agent_); } bool Trie::predictive_search(Agent &agent) const { return trie_->predictive_search(*agent.agent_); } size_t Trie::lookup(const char *ptr, size_t length) const { marisa::Agent agent; agent.set_query(ptr, length); if (!trie_->lookup(agent)) { return MARISA_INVALID_KEY_ID; } return agent.key().id(); } void Trie::reverse_lookup(size_t id, const char **ptr_out_to_be_deleted, size_t *length_out) const { marisa::Agent agent; agent.set_query(id); trie_->reverse_lookup(agent); char * const buf = new char[agent.key().length()]; std::memcpy(buf, agent.key().ptr(), agent.key().length()); *ptr_out_to_be_deleted = buf; *length_out = agent.key().length(); } size_t Trie::num_tries() const { return trie_->num_tries(); } size_t Trie::num_keys() const { return trie_->num_keys(); } size_t Trie::num_nodes() const { return trie_->num_nodes(); } TailMode Trie::tail_mode() const { if (trie_->tail_mode() == ::MARISA_TEXT_TAIL) { return TEXT_TAIL; } else { return BINARY_TAIL; } } NodeOrder Trie::node_order() const { if (trie_->node_order() == ::MARISA_LABEL_ORDER) { return LABEL_ORDER; } else { return WEIGHT_ORDER; } } bool Trie::empty() const { return trie_->empty(); } size_t Trie::size() const { return trie_->size(); } size_t Trie::total_size() const { return trie_->total_size(); } size_t Trie::io_size() const { return trie_->io_size(); } void Trie::clear() { trie_->clear(); } } // namespace marisa_swig marisa-trie-master/bindings/marisa-swig.h000066400000000000000000000076421505027263100207670ustar00rootroot00000000000000#ifndef MARISA_SWIG_H_ #define MARISA_SWIG_H_ #include namespace marisa_swig { #define MARISA_SWIG_ENUM_COPY(name) name = MARISA_ ## name enum ErrorCode { MARISA_SWIG_ENUM_COPY(OK), MARISA_SWIG_ENUM_COPY(STATE_ERROR), MARISA_SWIG_ENUM_COPY(NULL_ERROR), MARISA_SWIG_ENUM_COPY(BOUND_ERROR), MARISA_SWIG_ENUM_COPY(RANGE_ERROR), MARISA_SWIG_ENUM_COPY(CODE_ERROR), MARISA_SWIG_ENUM_COPY(RESET_ERROR), MARISA_SWIG_ENUM_COPY(SIZE_ERROR), MARISA_SWIG_ENUM_COPY(MEMORY_ERROR), MARISA_SWIG_ENUM_COPY(IO_ERROR), MARISA_SWIG_ENUM_COPY(FORMAT_ERROR) }; enum MapFlags { MARISA_SWIG_ENUM_COPY(MAP_POPULATE), }; enum NumTries { MARISA_SWIG_ENUM_COPY(MIN_NUM_TRIES), MARISA_SWIG_ENUM_COPY(MAX_NUM_TRIES), MARISA_SWIG_ENUM_COPY(DEFAULT_NUM_TRIES) }; enum CacheLevel { MARISA_SWIG_ENUM_COPY(HUGE_CACHE), MARISA_SWIG_ENUM_COPY(LARGE_CACHE), MARISA_SWIG_ENUM_COPY(NORMAL_CACHE), MARISA_SWIG_ENUM_COPY(SMALL_CACHE), MARISA_SWIG_ENUM_COPY(TINY_CACHE), MARISA_SWIG_ENUM_COPY(DEFAULT_CACHE) }; enum TailMode { MARISA_SWIG_ENUM_COPY(TEXT_TAIL), MARISA_SWIG_ENUM_COPY(BINARY_TAIL), MARISA_SWIG_ENUM_COPY(DEFAULT_TAIL) }; enum NodeOrder { MARISA_SWIG_ENUM_COPY(LABEL_ORDER), MARISA_SWIG_ENUM_COPY(WEIGHT_ORDER), MARISA_SWIG_ENUM_COPY(DEFAULT_ORDER) }; #undef MARISA_SWIG_ENUM_COPY class Key { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; float weight() const; private: const marisa::Key key_; Key(); Key(const Key &key); Key &operator=(const Key &); }; class Query { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; private: const marisa::Query query_; Query(); Query(const Query &query); Query &operator=(const Query &); }; class Keyset { friend class Trie; public: Keyset(); ~Keyset(); void push_back(const marisa::Key &key); void push_back(const char *ptr, std::size_t length, float weight = 1.0); const Key &key(std::size_t i) const; void key_str(std::size_t i, const char **ptr_out, std::size_t *length_out) const; std::size_t key_id(std::size_t i) const; std::size_t num_keys() const; bool empty() const; std::size_t size() const; std::size_t total_length() const; void reset(); void clear(); private: marisa::Keyset *keyset_; Keyset(const Keyset &); Keyset &operator=(const Keyset &); }; class Agent { friend class Trie; public: Agent(); ~Agent(); void set_query(const char *ptr, std::size_t length); void set_query(std::size_t id); const Key &key() const; const Query &query() const; void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: marisa::Agent *agent_; char *buf_; std::size_t buf_size_; Agent(const Agent &); Agent &operator=(const Agent &); }; class Trie { public: Trie(); ~Trie(); void build(Keyset &keyset, int config_flags = 0); void mmap(const char *filename, int flags = 0); void load(const char *filename); void save(const char *filename) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t lookup(const char *ptr, std::size_t length) const; void reverse_lookup(std::size_t id, const char **ptr_out_to_be_deleted, std::size_t *length_out) const; std::size_t num_tries() const; std::size_t num_keys() const; std::size_t num_nodes() const; TailMode tail_mode() const; NodeOrder node_order() const; bool empty() const; std::size_t size() const; std::size_t total_size() const; std::size_t io_size() const; void clear(); private: marisa::Trie *trie_; Trie(const Trie &); Trie &operator=(const Trie &); }; } // namespace marisa_swig #endif // MARISA_SWIG_H_ marisa-trie-master/bindings/marisa-swig.i000066400000000000000000000012211505027263100207530ustar00rootroot00000000000000%module marisa %include "cstring.i" %include "exception.i" %{ #include "marisa-swig.h" %} %apply (char *STRING, int LENGTH) { (const char *ptr, std::size_t length) }; %cstring_output_allocate_size(const char **ptr_out, std::size_t *length_out, ); %cstring_output_allocate_size(const char **ptr_out_to_be_deleted, std::size_t *length_out, delete [] (*$1)); %exception { try { $action } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } %include "marisa-swig.h" %constant size_t INVALID_KEY_ID = MARISA_INVALID_KEY_ID; marisa-trie-master/bindings/perl/000077500000000000000000000000001505027263100173245ustar00rootroot00000000000000marisa-trie-master/bindings/perl/Makefile.PL000066400000000000000000000002271505027263100212770ustar00rootroot00000000000000use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'marisa', 'LIBS' => ['-lmarisa'], 'OBJECT' => 'marisa-swig.o marisa-swig_wrap.o' ); marisa-trie-master/bindings/perl/benchmark.pl000066400000000000000000000047731505027263100216260ustar00rootroot00000000000000use Time::HiRes; use marisa; my $time_begin = Time::HiRes::gettimeofday(); my @keys = ; foreach my $key (@keys) { chomp($key); } my $time_end = Time::HiRes::gettimeofday(); print "input: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); my %hash; foreach my $key (@keys) { $hash{$key} = 0; } $time_end = Time::HiRes::gettimeofday(); print "hash_build: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); foreach my $key (@keys) { $hash{$key}; } $time_end = Time::HiRes::gettimeofday(); print "hash_lookup: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); my $keyset = new marisa::Keyset; foreach my $key (@keys) { $keyset->push_back($key) } $time_end = Time::HiRes::gettimeofday(); print "keyset_build: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); $trie = new marisa::Trie; $trie->build($keyset); $time_end = Time::HiRes::gettimeofday(); print "trie_build: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); my $agent = new marisa::Agent; foreach my $key (@keys) { $agent->set_query($key); $trie->lookup($agent); $agent->key_id(); } $time_end = Time::HiRes::gettimeofday(); print "trie_agent_lookup: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); foreach my $key (@keys) { $trie->lookup($key); } $time_end = Time::HiRes::gettimeofday(); print "trie_lookup: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); my $max_key_id = $trie->size() - 1; for (0..$max_key_id) { $agent->set_query($_); $trie->reverse_lookup($agent); $agent->key_str(); } $time_end = Time::HiRes::gettimeofday(); print "trie_agent_reverse_lookup: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); for (0..$max_key_id) { $trie->reverse_lookup($_); } $time_end = Time::HiRes::gettimeofday(); print "trie_reverse_lookup: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); foreach my $key (@keys) { $agent->set_query($key); while ($trie->common_prefix_search($agent)) { $agent->key_str(); } } $time_end = Time::HiRes::gettimeofday(); print "trie_agent_common_prefix_search: ", $time_end - $time_begin, "\n"; $time_begin = Time::HiRes::gettimeofday(); foreach my $key (@keys) { $agent->set_query($key); while ($trie->predictive_search($agent)) { $agent->key_str(); } } $time_end = Time::HiRes::gettimeofday(); print "trie_agent_predictive_search: ", $time_end - $time_begin, "\n"; marisa-trie-master/bindings/perl/marisa-swig.cxx000066400000000000000000000115611505027263100222770ustar00rootroot00000000000000#include #include #include "marisa-swig.h" namespace marisa_swig { void Key::str(const char **ptr_out, size_t *length_out) const { *ptr_out = key_.ptr(); *length_out = key_.length(); } size_t Key::id() const { return key_.id(); } float Key::weight() const { return key_.weight(); } void Query::str(const char **ptr_out, size_t *length_out) const { *ptr_out = query_.ptr(); *length_out = query_.length(); } size_t Query::id() const { return query_.id(); } Keyset::Keyset() : keyset_(new marisa::Keyset) { } Keyset::~Keyset() { delete keyset_; } void Keyset::push_back(const marisa::Key &key) { keyset_->push_back(key); } void Keyset::push_back(const char *ptr, size_t length, float weight) { keyset_->push_back(ptr, length, weight); } const Key &Keyset::key(size_t i) const { return reinterpret_cast((*keyset_)[i]); } void Keyset::key_str(size_t i, const char **ptr_out, size_t *length_out) const { *ptr_out = (*keyset_)[i].ptr(); *length_out = (*keyset_)[i].length(); } size_t Keyset::key_id(size_t i) const { return (*keyset_)[i].id(); } size_t Keyset::num_keys() const { return keyset_->num_keys(); } bool Keyset::empty() const { return keyset_->empty(); } size_t Keyset::size() const { return keyset_->size(); } size_t Keyset::total_length() const { return keyset_->total_length(); } void Keyset::reset() { keyset_->reset(); } void Keyset::clear() { keyset_->clear(); } Agent::Agent() : agent_(new marisa::Agent), buf_(NULL), buf_size_(0) { } Agent::~Agent() { delete agent_; delete [] buf_; } void Agent::set_query(const char *ptr, size_t length) { if (length > buf_size_) { size_t new_buf_size = (buf_size_ != 0) ? buf_size_ : 1; if (length >= (MARISA_SIZE_MAX / 2)) { new_buf_size = MARISA_SIZE_MAX; } else { while (new_buf_size < length) { new_buf_size *= 2; } } char *new_buf = new char[new_buf_size]; delete [] buf_; buf_ = new_buf; buf_size_ = new_buf_size; } std::memcpy(buf_, ptr, length); agent_->set_query(buf_, length); } void Agent::set_query(size_t id) { agent_->set_query(id); } const Key &Agent::key() const { return reinterpret_cast(agent_->key()); } const Query &Agent::query() const { return reinterpret_cast(agent_->query()); } void Agent::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->key().ptr(); *length_out = agent_->key().length(); } size_t Agent::key_id() const { return agent_->key().id(); } void Agent::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->query().ptr(); *length_out = agent_->query().length(); } size_t Agent::query_id() const { return agent_->query().id(); } Trie::Trie() : trie_(new marisa::Trie) { } Trie::~Trie() { delete trie_; } void Trie::build(Keyset &keyset, int config_flags) { trie_->build(*keyset.keyset_, config_flags); } void Trie::mmap(const char *filename, int flags) { trie_->mmap(filename, flags); } void Trie::load(const char *filename) { trie_->load(filename); } void Trie::save(const char *filename) const { trie_->save(filename); } bool Trie::lookup(Agent &agent) const { return trie_->lookup(*agent.agent_); } void Trie::reverse_lookup(Agent &agent) const { trie_->reverse_lookup(*agent.agent_); } bool Trie::common_prefix_search(Agent &agent) const { return trie_->common_prefix_search(*agent.agent_); } bool Trie::predictive_search(Agent &agent) const { return trie_->predictive_search(*agent.agent_); } size_t Trie::lookup(const char *ptr, size_t length) const { marisa::Agent agent; agent.set_query(ptr, length); if (!trie_->lookup(agent)) { return MARISA_INVALID_KEY_ID; } return agent.key().id(); } void Trie::reverse_lookup(size_t id, const char **ptr_out_to_be_deleted, size_t *length_out) const { marisa::Agent agent; agent.set_query(id); trie_->reverse_lookup(agent); char * const buf = new char[agent.key().length()]; std::memcpy(buf, agent.key().ptr(), agent.key().length()); *ptr_out_to_be_deleted = buf; *length_out = agent.key().length(); } size_t Trie::num_tries() const { return trie_->num_tries(); } size_t Trie::num_keys() const { return trie_->num_keys(); } size_t Trie::num_nodes() const { return trie_->num_nodes(); } TailMode Trie::tail_mode() const { if (trie_->tail_mode() == ::MARISA_TEXT_TAIL) { return TEXT_TAIL; } else { return BINARY_TAIL; } } NodeOrder Trie::node_order() const { if (trie_->node_order() == ::MARISA_LABEL_ORDER) { return LABEL_ORDER; } else { return WEIGHT_ORDER; } } bool Trie::empty() const { return trie_->empty(); } size_t Trie::size() const { return trie_->size(); } size_t Trie::total_size() const { return trie_->total_size(); } size_t Trie::io_size() const { return trie_->io_size(); } void Trie::clear() { trie_->clear(); } } // namespace marisa_swig marisa-trie-master/bindings/perl/marisa-swig.h000066400000000000000000000076421505027263100217310ustar00rootroot00000000000000#ifndef MARISA_SWIG_H_ #define MARISA_SWIG_H_ #include namespace marisa_swig { #define MARISA_SWIG_ENUM_COPY(name) name = MARISA_ ## name enum ErrorCode { MARISA_SWIG_ENUM_COPY(OK), MARISA_SWIG_ENUM_COPY(STATE_ERROR), MARISA_SWIG_ENUM_COPY(NULL_ERROR), MARISA_SWIG_ENUM_COPY(BOUND_ERROR), MARISA_SWIG_ENUM_COPY(RANGE_ERROR), MARISA_SWIG_ENUM_COPY(CODE_ERROR), MARISA_SWIG_ENUM_COPY(RESET_ERROR), MARISA_SWIG_ENUM_COPY(SIZE_ERROR), MARISA_SWIG_ENUM_COPY(MEMORY_ERROR), MARISA_SWIG_ENUM_COPY(IO_ERROR), MARISA_SWIG_ENUM_COPY(FORMAT_ERROR) }; enum MapFlags { MARISA_SWIG_ENUM_COPY(MAP_POPULATE), }; enum NumTries { MARISA_SWIG_ENUM_COPY(MIN_NUM_TRIES), MARISA_SWIG_ENUM_COPY(MAX_NUM_TRIES), MARISA_SWIG_ENUM_COPY(DEFAULT_NUM_TRIES) }; enum CacheLevel { MARISA_SWIG_ENUM_COPY(HUGE_CACHE), MARISA_SWIG_ENUM_COPY(LARGE_CACHE), MARISA_SWIG_ENUM_COPY(NORMAL_CACHE), MARISA_SWIG_ENUM_COPY(SMALL_CACHE), MARISA_SWIG_ENUM_COPY(TINY_CACHE), MARISA_SWIG_ENUM_COPY(DEFAULT_CACHE) }; enum TailMode { MARISA_SWIG_ENUM_COPY(TEXT_TAIL), MARISA_SWIG_ENUM_COPY(BINARY_TAIL), MARISA_SWIG_ENUM_COPY(DEFAULT_TAIL) }; enum NodeOrder { MARISA_SWIG_ENUM_COPY(LABEL_ORDER), MARISA_SWIG_ENUM_COPY(WEIGHT_ORDER), MARISA_SWIG_ENUM_COPY(DEFAULT_ORDER) }; #undef MARISA_SWIG_ENUM_COPY class Key { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; float weight() const; private: const marisa::Key key_; Key(); Key(const Key &key); Key &operator=(const Key &); }; class Query { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; private: const marisa::Query query_; Query(); Query(const Query &query); Query &operator=(const Query &); }; class Keyset { friend class Trie; public: Keyset(); ~Keyset(); void push_back(const marisa::Key &key); void push_back(const char *ptr, std::size_t length, float weight = 1.0); const Key &key(std::size_t i) const; void key_str(std::size_t i, const char **ptr_out, std::size_t *length_out) const; std::size_t key_id(std::size_t i) const; std::size_t num_keys() const; bool empty() const; std::size_t size() const; std::size_t total_length() const; void reset(); void clear(); private: marisa::Keyset *keyset_; Keyset(const Keyset &); Keyset &operator=(const Keyset &); }; class Agent { friend class Trie; public: Agent(); ~Agent(); void set_query(const char *ptr, std::size_t length); void set_query(std::size_t id); const Key &key() const; const Query &query() const; void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: marisa::Agent *agent_; char *buf_; std::size_t buf_size_; Agent(const Agent &); Agent &operator=(const Agent &); }; class Trie { public: Trie(); ~Trie(); void build(Keyset &keyset, int config_flags = 0); void mmap(const char *filename, int flags = 0); void load(const char *filename); void save(const char *filename) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t lookup(const char *ptr, std::size_t length) const; void reverse_lookup(std::size_t id, const char **ptr_out_to_be_deleted, std::size_t *length_out) const; std::size_t num_tries() const; std::size_t num_keys() const; std::size_t num_nodes() const; TailMode tail_mode() const; NodeOrder node_order() const; bool empty() const; std::size_t size() const; std::size_t total_size() const; std::size_t io_size() const; void clear(); private: marisa::Trie *trie_; Trie(const Trie &); Trie &operator=(const Trie &); }; } // namespace marisa_swig #endif // MARISA_SWIG_H_ marisa-trie-master/bindings/perl/marisa-swig_wrap.cxx000066400000000000000000004760541505027263100233440ustar00rootroot00000000000000/* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (https://www.swig.org). * Version 4.2.0 * * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ #define SWIG_VERSION 0x040200 #define SWIGPERL #define SWIG_CASTRANK_MODE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. * ----------------------------------------------------------------------------- */ /* template workaround for compilers that cannot correctly implement the C++ standard */ #ifndef SWIGTEMPLATEDISAMBIGUATOR # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) # define SWIGTEMPLATEDISAMBIGUATOR template # elif defined(__HP_aCC) /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ # define SWIGTEMPLATEDISAMBIGUATOR template # else # define SWIGTEMPLATEDISAMBIGUATOR # endif #endif /* inline attribute */ #ifndef SWIGINLINE # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) # define SWIGINLINE inline # else # define SWIGINLINE # endif #endif /* attribute recognised by some compilers to avoid 'unused' warnings */ #ifndef SWIGUNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif # elif defined(__ICC) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif #endif #ifndef SWIG_MSC_UNSUPPRESS_4505 # if defined(_MSC_VER) # pragma warning(disable : 4505) /* unreferenced local function has been removed */ # endif #endif #ifndef SWIGUNUSEDPARM # ifdef __cplusplus # define SWIGUNUSEDPARM(p) # else # define SWIGUNUSEDPARM(p) p SWIGUNUSED # endif #endif /* internal SWIG method */ #ifndef SWIGINTERN # define SWIGINTERN static SWIGUNUSED #endif /* internal inline SWIG method */ #ifndef SWIGINTERNINLINE # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE #endif /* exporting methods */ #if defined(__GNUC__) # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) # ifndef GCC_HASCLASSVISIBILITY # define GCC_HASCLASSVISIBILITY # endif # endif #endif #ifndef SWIGEXPORT # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # if defined(STATIC_LINKED) # define SWIGEXPORT # else # define SWIGEXPORT __declspec(dllexport) # endif # else # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) # define SWIGEXPORT __attribute__ ((visibility("default"))) # else # define SWIGEXPORT # endif # endif #endif /* calling conventions for Windows */ #ifndef SWIGSTDCALL # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # define SWIGSTDCALL __stdcall # else # define SWIGSTDCALL # endif #endif /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) # define _CRT_SECURE_NO_DEPRECATE #endif /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) # define _SCL_SECURE_NO_DEPRECATE #endif /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 #endif /* Intel's compiler complains if a variable which was never initialised is * cast to void, which is a common idiom which we use to indicate that we * are aware a variable isn't used. So we just silence that warning. * See: https://github.com/swig/swig/issues/192 for more discussion. */ #ifdef __INTEL_COMPILER # pragma warning disable 592 #endif #if __cplusplus >=201103L # define SWIG_NULLPTR nullptr #else # define SWIG_NULLPTR NULL #endif /* ----------------------------------------------------------------------------- * swigrun.swg * * This file contains generic C API SWIG runtime support for pointer * type checking. * ----------------------------------------------------------------------------- */ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ #define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE # define SWIG_QUOTE_STRING(x) #x # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) #else # define SWIG_TYPE_TABLE_NAME #endif /* You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for creating a static or dynamic library from the SWIG runtime code. In 99.9% of the cases, SWIG just needs to declare them as 'static'. But only do this if strictly necessary, ie, if you have problems with your compiler or suchlike. */ #ifndef SWIGRUNTIME # define SWIGRUNTIME SWIGINTERN #endif #ifndef SWIGRUNTIMEINLINE # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE #endif /* Generic buffer size */ #ifndef SWIG_BUFFER_SIZE # define SWIG_BUFFER_SIZE 1024 #endif /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 #define SWIG_CAST_NEW_MEMORY 0x2 #define SWIG_POINTER_NO_NULL 0x4 #define SWIG_POINTER_CLEAR 0x8 #define SWIG_POINTER_RELEASE (SWIG_POINTER_CLEAR | SWIG_POINTER_DISOWN) /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 /* Flags/methods for returning states. The SWIG conversion methods, as ConvertPtr, return an integer that tells if the conversion was successful or not. And if not, an error code can be returned (see swigerrors.swg for the codes). Use the following macros/flags to set or process the returning states. In old versions of SWIG, code such as the following was usually written: if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { // success code } else { //fail code } Now you can be more explicit: int res = SWIG_ConvertPtr(obj,vptr,ty.flags); if (SWIG_IsOK(res)) { // success code } else { // fail code } which is the same really, but now you can also do Type *ptr; int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); if (SWIG_IsOK(res)) { // success code if (SWIG_IsNewObj(res) { ... delete *ptr; } else { ... } } else { // fail code } I.e., now SWIG_ConvertPtr can return new objects and you can identify the case and take care of the deallocation. Of course that also requires SWIG_ConvertPtr to return new result values, such as int SWIG_ConvertPtr(obj, ptr,...) { if () { if () { *ptr = ; return SWIG_NEWOBJ; } else { *ptr = ; return SWIG_OLDOBJ; } } else { return SWIG_BADOBJ; } } Of course, returning the plain '0(success)/-1(fail)' still works, but you can be more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the SWIG errors code. Finally, if the SWIG_CASTRANK_MODE is enabled, the result code allows returning the 'cast rank', for example, if you have this int food(double) int fooi(int); and you call food(1) // cast rank '1' (1 -> 1.0) fooi(1) // cast rank '0' just use the SWIG_AddCast()/SWIG_CheckState() */ #define SWIG_OK (0) /* Runtime errors are < 0 */ #define SWIG_ERROR (-1) /* Errors in range -1 to -99 are in swigerrors.swg (errors for all languages including those not using the runtime) */ /* Errors in range -100 to -199 are language specific errors defined in *errors.swg */ /* Errors < -200 are generic runtime specific errors */ #define SWIG_ERROR_RELEASE_NOT_OWNED (-200) #define SWIG_IsOK(r) (r >= 0) #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) /* The CastRankLimit says how many bits are used for the cast rank */ #define SWIG_CASTRANKLIMIT (1 << 8) /* The NewMask denotes the object was created (using new/malloc) */ #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) /* The TmpMask is for in/out typemaps that use temporary objects */ #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) /* Simple returning values */ #define SWIG_BADOBJ (SWIG_ERROR) #define SWIG_OLDOBJ (SWIG_OK) #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) /* Check, add and del object mask methods */ #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) /* Cast-Rank Mode */ #if defined(SWIG_CASTRANK_MODE) # ifndef SWIG_TypeRank # define SWIG_TypeRank unsigned long # endif # ifndef SWIG_MAXCASTRANK /* Default cast allowed */ # define SWIG_MAXCASTRANK (2) # endif # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) SWIGINTERNINLINE int SWIG_AddCast(int r) { return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; } SWIGINTERNINLINE int SWIG_CheckState(int r) { return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ # define SWIG_AddCast(r) (r) # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif /* C99 and C++11 should provide snprintf, but define SWIG_NO_SNPRINTF * if you're missing it. */ #if ((defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || \ (defined __cplusplus && __cplusplus >= 201103L) || \ defined SWIG_HAVE_SNPRINTF) && \ !defined SWIG_NO_SNPRINTF # define SWIG_snprintf(O,S,F,A) snprintf(O,S,F,A) # define SWIG_snprintf2(O,S,F,A,B) snprintf(O,S,F,A,B) #else /* Fallback versions ignore the buffer size, but most of our uses either have a * fixed maximum possible size or dynamically allocate a buffer that's large * enough. */ # define SWIG_snprintf(O,S,F,A) sprintf(O,F,A) # define SWIG_snprintf2(O,S,F,A,B) sprintf(O,F,A,B) #endif #include #ifdef __cplusplus extern "C" { #endif typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); /* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ struct swig_cast_info *cast; /* linked list of types that can cast into this type */ void *clientdata; /* language specific type data */ int owndata; /* flag if the structure owns the clientdata */ } swig_type_info; /* Structure to store a type and conversion function used for casting */ typedef struct swig_cast_info { swig_type_info *type; /* pointer to type that is equivalent to this type */ swig_converter_func converter; /* function to cast the void pointers */ struct swig_cast_info *next; /* pointer to next cast in linked list */ struct swig_cast_info *prev; /* pointer to the previous cast */ } swig_cast_info; /* Structure used to store module information * Each module generates one structure like this, and the runtime collects * all of these structures and stores them in a circularly linked list.*/ typedef struct swig_module_info { swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ size_t size; /* Number of types in this module */ struct swig_module_info *next; /* Pointer to next element in circularly linked list */ swig_type_info **type_initial; /* Array of initially generated type structures */ swig_cast_info **cast_initial; /* Array of initially generated casting structures */ void *clientdata; /* Language specific module data */ } swig_module_info; /* Compare two type names skipping the space characters, therefore "char*" == "char *" and "Class" == "Class", etc. Return 0 when the two name types are equivalent, as in strncmp, but skipping ' '. */ SWIGRUNTIME int SWIG_TypeNameComp(const char *f1, const char *l1, const char *f2, const char *l2) { for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { while ((*f1 == ' ') && (f1 != l1)) ++f1; while ((*f2 == ' ') && (f2 != l2)) ++f2; if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; } return (int)((l1 - f1) - (l2 - f2)); } /* Check type equivalence in a name list like ||... Return 0 if equal, -1 if nb < tb, 1 if nb > tb */ SWIGRUNTIME int SWIG_TypeCmp(const char *nb, const char *tb) { int equiv = 1; const char* te = tb + strlen(tb); const char* ne = nb; while (equiv != 0 && *ne) { for (nb = ne; *ne; ++ne) { if (*ne == '|') break; } equiv = SWIG_TypeNameComp(nb, ne, tb, te); if (*ne) ++ne; } return equiv; } /* Check type equivalence in a name list like ||... Return 0 if not equal, 1 if equal */ SWIGRUNTIME int SWIG_TypeEquiv(const char *nb, const char *tb) { return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; } /* Check the typename */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheck(const char *c, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (strcmp(iter->type->name, c) == 0) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheckStruct(const swig_type_info *from, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (iter->type == from) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* Dynamic pointer casting. Down an inheritance hierarchy */ SWIGRUNTIME swig_type_info * SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { swig_type_info *lastty = ty; if (!ty || !ty->dcast) return ty; while (ty && (ty->dcast)) { ty = (*ty->dcast)(ptr); if (ty) lastty = ty; } return lastty; } /* Return the name associated with this type */ SWIGRUNTIMEINLINE const char * SWIG_TypeName(const swig_type_info *ty) { return ty->name; } /* Return the pretty name associated with this type, that is an unmangled type name in a form presentable to the user. */ SWIGRUNTIME const char * SWIG_TypePrettyName(const swig_type_info *type) { /* The "str" field contains the equivalent pretty names of the type, separated by vertical-bar characters. Choose the last name. It should be the most specific; a fully resolved name but not necessarily with default template parameters expanded. */ if (!type) return NULL; if (type->str != NULL) { const char *last_name = type->str; const char *s; for (s = type->str; *s; s++) if (*s == '|') last_name = s+1; return last_name; } else return type->name; } /* Set the clientdata field for a type */ SWIGRUNTIME void SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { swig_cast_info *cast = ti->cast; /* if (ti->clientdata == clientdata) return; */ ti->clientdata = clientdata; while (cast) { if (!cast->converter) { swig_type_info *tc = cast->type; if (!tc->clientdata) { SWIG_TypeClientData(tc, clientdata); } } cast = cast->next; } } SWIGRUNTIME void SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { SWIG_TypeClientData(ti, clientdata); ti->owndata = 1; } /* Search for a swig_type_info structure only by mangled name Search is a O(log #types) We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_MangledTypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { swig_module_info *iter = start; do { if (iter->size) { size_t l = 0; size_t r = iter->size - 1; do { /* since l+r >= 0, we can (>> 1) instead (/ 2) */ size_t i = (l + r) >> 1; const char *iname = iter->types[i]->name; if (iname) { int compare = strcmp(name, iname); if (compare == 0) { return iter->types[i]; } else if (compare < 0) { if (i) { r = i - 1; } else { break; } } else if (compare > 0) { l = i + 1; } } else { break; /* should never happen */ } } while (l <= r); } iter = iter->next; } while (iter != end); return 0; } /* Search for a swig_type_info structure for either a mangled name or a human readable name. It first searches the mangled names of the types, which is a O(log #types) If a type is not found it then searches the human readable names, which is O(#types). We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_TypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { /* STEP 1: Search the name field using binary search */ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); if (ret) { return ret; } else { /* STEP 2: If the type hasn't been found, do a complete search of the str field (the human readable name) */ swig_module_info *iter = start; do { size_t i = 0; for (; i < iter->size; ++i) { if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) return iter->types[i]; } iter = iter->next; } while (iter != end); } /* neither found a match */ return 0; } /* Pack binary data into a string */ SWIGRUNTIME char * SWIG_PackData(char *c, void *ptr, size_t sz) { static const char hex[17] = "0123456789abcdef"; const unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { unsigned char uu = *u; *(c++) = hex[(uu & 0xf0) >> 4]; *(c++) = hex[uu & 0xf]; } return c; } /* Unpack binary data from a string */ SWIGRUNTIME const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { char d = *(c++); unsigned char uu; if ((d >= '0') && (d <= '9')) uu = (unsigned char)((d - '0') << 4); else if ((d >= 'a') && (d <= 'f')) uu = (unsigned char)((d - ('a'-10)) << 4); else return (char *) 0; d = *(c++); if ((d >= '0') && (d <= '9')) uu |= (unsigned char)(d - '0'); else if ((d >= 'a') && (d <= 'f')) uu |= (unsigned char)(d - ('a'-10)); else return (char *) 0; *u = uu; } return c; } /* Pack 'void *' into a string buffer. */ SWIGRUNTIME char * SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { char *r = buff; if ((2*sizeof(void *) + 2) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,&ptr,sizeof(void *)); if (strlen(name) + 1 > (bsz - (r - buff))) return 0; strcpy(r,name); return buff; } SWIGRUNTIME const char * SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { *ptr = (void *) 0; return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sizeof(void *)); } SWIGRUNTIME char * SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { char *r = buff; size_t lname = (name ? strlen(name) : 0); if ((2*sz + 2 + lname) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,ptr,sz); if (lname) { strncpy(r,name,lname+1); } else { *r = 0; } return buff; } SWIGRUNTIME const char * SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { memset(ptr,0,sz); return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sz); } #ifdef __cplusplus } #endif /* SWIG Errors applicable to all language modules, values are reserved from -1 to -99 */ #define SWIG_UnknownError -1 #define SWIG_IOError -2 #define SWIG_RuntimeError -3 #define SWIG_IndexError -4 #define SWIG_TypeError -5 #define SWIG_DivisionByZero -6 #define SWIG_OverflowError -7 #define SWIG_SyntaxError -8 #define SWIG_ValueError -9 #define SWIG_SystemError -10 #define SWIG_AttributeError -11 #define SWIG_MemoryError -12 #define SWIG_NullReferenceError -13 #ifdef __cplusplus /* Needed on some windows machines---since MS plays funny games with the header files under C++ */ #include #include extern "C" { #endif #if __GNUC__ >= 10 #if defined(__cplusplus) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wvolatile" #endif #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #if __GNUC__ >= 10 #if defined(__cplusplus) #pragma GCC diagnostic pop #endif #endif /* PERL_REVISION was added in Perl 5.6. */ #if !defined PERL_REVISION || (PERL_REVISION-0 == 5 && PERL_VERSION-0 < 8) # error SWIG requires Perl >= 5.8.0 #endif #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE) #define PerlIO_exportFILE(fh,fl) (FILE*)(fh) #endif #ifndef SvIOK_UV # define SvIOK_UV(sv) (SvIOK(sv) && (SvUVX(sv) == SvIVX(sv))) #endif #ifndef SvUOK # define SvUOK(sv) SvIOK_UV(sv) #endif #ifndef IVSIZE # ifdef LONGSIZE # define IVSIZE LONGSIZE # else # define IVSIZE 4 /* A bold guess, but the best we can make. */ # endif #endif #ifndef INT2PTR # if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE) # define PTRV UV # define INT2PTR(any,d) (any)(d) # else # if PTRSIZE == LONGSIZE # define PTRV unsigned long # else # define PTRV unsigned # endif # define INT2PTR(any,d) (any)(PTRV)(d) # endif # define NUM2PTR(any,d) (any)(PTRV)(d) # define PTR2IV(p) INT2PTR(IV,p) # define PTR2UV(p) INT2PTR(UV,p) # define PTR2NV(p) NUM2PTR(NV,p) # if PTRSIZE == LONGSIZE # define PTR2ul(p) (unsigned long)(p) # else # define PTR2ul(p) INT2PTR(unsigned long,p) # endif #endif /* !INT2PTR */ #ifndef SvPV_nolen # define SvPV_nolen(x) SvPV(x,PL_na) #endif #ifndef get_sv # define get_sv perl_get_sv #endif #ifndef ERRSV # define ERRSV get_sv("@",FALSE) #endif #ifndef pTHX_ #define pTHX_ #endif #include #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * error manipulation * ----------------------------------------------------------------------------- */ SWIGINTERN const char* SWIG_Perl_ErrorType(int code) { switch(code) { case SWIG_MemoryError: return "MemoryError"; case SWIG_IOError: return "IOError"; case SWIG_RuntimeError: return "RuntimeError"; case SWIG_IndexError: return "IndexError"; case SWIG_TypeError: return "TypeError"; case SWIG_DivisionByZero: return "ZeroDivisionError"; case SWIG_OverflowError: return "OverflowError"; case SWIG_SyntaxError: return "SyntaxError"; case SWIG_ValueError: return "ValueError"; case SWIG_SystemError: return "SystemError"; case SWIG_AttributeError: return "AttributeError"; default: return "RuntimeError"; } } /* ----------------------------------------------------------------------------- * perlrun.swg * * This file contains the runtime support for Perl modules * and includes code for managing global variables and pointer * type checking. * ----------------------------------------------------------------------------- */ #define SWIG_PERL_OBJECT_DECL #define SWIG_PERL_OBJECT_CALL /* Common SWIG API */ /* for raw pointers */ #define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags) #define SWIG_ConvertPtrAndOwn(obj, pp, type, flags,own) SWIG_Perl_ConvertPtrAndOwn(SWIG_PERL_OBJECT_CALL obj, pp, type, flags, own) #define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags) #define SWIG_AcquirePtr(ptr, src) SWIG_Perl_AcquirePtr(ptr, src) #define swig_owntype int /* for raw packed data */ #define SWIG_ConvertPacked(obj, p, s, type) SWIG_Perl_ConvertPacked(SWIG_PERL_OBJECT_CALL obj, p, s, type) #define SWIG_NewPackedObj(p, s, type) SWIG_Perl_NewPackedObj(SWIG_PERL_OBJECT_CALL p, s, type) /* for class or struct pointers */ #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) /* for C or C++ function pointers */ #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0) #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0) /* for C++ member pointers, ie, member methods */ #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_ConvertPacked(obj, ptr, sz, ty) #define SWIG_NewMemberObj(ptr, sz, type) SWIG_NewPackedObj(ptr, sz, type) /* Runtime API */ #define SWIG_GetModule(clientdata) SWIG_Perl_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Perl_SetModule(pointer) /* Error manipulation */ #define SWIG_ErrorType(code) SWIG_Perl_ErrorType(code) #define SWIG_Error(code, msg) sv_setpvf(get_sv("@", GV_ADD), "%s %s", SWIG_ErrorType(code), msg) #define SWIG_fail goto fail /* Perl-specific SWIG API */ #define SWIG_MakePtr(sv, ptr, type, flags) SWIG_Perl_MakePtr(SWIG_PERL_OBJECT_CALL sv, ptr, type, flags) #define SWIG_MakePackedObj(sv, p, s, type) SWIG_Perl_MakePackedObj(SWIG_PERL_OBJECT_CALL sv, p, s, type) #define SWIG_SetError(str) SWIG_Error(SWIG_RuntimeError, str) #define SWIG_PERL_DECL_ARGS_1(arg1) (SWIG_PERL_OBJECT_DECL arg1) #define SWIG_PERL_CALL_ARGS_1(arg1) (SWIG_PERL_OBJECT_CALL arg1) #define SWIG_PERL_DECL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_DECL arg1, arg2) #define SWIG_PERL_CALL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_CALL arg1, arg2) /* ----------------------------------------------------------------------------- * pointers/data manipulation * ----------------------------------------------------------------------------- */ /* For backward compatibility only */ #define SWIG_POINTER_EXCEPTION 0 #ifdef __cplusplus extern "C" { #endif #define SWIG_OWNER SWIG_POINTER_OWN #define SWIG_SHADOW SWIG_OWNER << 1 #define SWIG_MAYBE_PERL_OBJECT SWIG_PERL_OBJECT_DECL /* SWIG Perl macros */ /* Macro to declare an XS function */ #ifndef XSPROTO # define XSPROTO(name) void name(pTHX_ CV* cv) #endif /* Macro to call an XS function */ #ifndef MULTIPLICITY # define SWIG_CALLXS(_name) _name(cv) #else # define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv) #endif #define MAGIC_PPERL #define SWIGCLASS_STATIC static SWIGUNUSED #ifndef MULTIPLICITY #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) #ifdef __cplusplus extern "C" { #endif typedef int (*SwigMagicFunc)(SV *, MAGIC *); #ifdef __cplusplus } #endif #else /* MULTIPLICITY */ #define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b) #ifdef __cplusplus extern "C" { #endif typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *); #ifdef __cplusplus } #endif #endif /* MULTIPLICITY */ static void SWIGUNUSED SWIG_croak_null() { SV *err = get_sv("@", GV_ADD); if (sv_isobject(err)) croak(0); else croak("%s", SvPV_nolen(err)); } /* Define how strict is the cast between strings and integers/doubles when overloading between these types occurs. The default is making it as strict as possible by using SWIG_AddCast when needed. You can use -DSWIG_PERL_NO_STRICT_STR2NUM at compilation time to disable the SWIG_AddCast, making the casting between string and numbers less strict. In the end, we try to solve the overloading between strings and numerical types in the more natural way, but if you can avoid it, well, avoid it using %rename, for example. */ #ifndef SWIG_PERL_NO_STRICT_STR2NUM # ifndef SWIG_PERL_STRICT_STR2NUM # define SWIG_PERL_STRICT_STR2NUM # endif #endif #ifdef SWIG_PERL_STRICT_STR2NUM /* string takes precedence */ #define SWIG_Str2NumCast(x) SWIG_AddCast(x) #else /* number takes precedence */ #define SWIG_Str2NumCast(x) x #endif #include SWIGRUNTIME const char * SWIG_Perl_TypeProxyName(const swig_type_info *type) { if (!type) return NULL; if (type->clientdata != NULL) { return (const char*) type->clientdata; } else { return type->name; } } /* Identical to SWIG_TypeCheck, except for strcmp comparison */ SWIGRUNTIME swig_cast_info * SWIG_TypeProxyCheck(const char *c, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (strcmp(SWIG_Perl_TypeProxyName(iter->type), c) == 0) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Acquire a pointer value */ SWIGRUNTIME int SWIG_Perl_AcquirePtr(SWIG_MAYBE_PERL_OBJECT SV *SWIGUNUSEDPARM(sv), int SWIGUNUSEDPARM(own)) { /* TODO */ return 0; } /* Function for getting a pointer value */ SWIGRUNTIME int SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags, int *own) { swig_cast_info *tc; void *voidptr = (void *)0; SV *tsv = 0; int check_owned_pointer_release = (flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE; if (own) *own = 0; /* If magical, apply more magic */ if (SvGMAGICAL(sv)) mg_get(sv); /* Check to see if this is an object */ if (sv_isobject(sv)) { IV tmp = 0; tsv = (SV*) SvRV(sv); if ((SvTYPE(tsv) == SVt_PVHV)) { MAGIC *mg; if (SvMAGICAL(tsv)) { mg = mg_find(tsv,'P'); if (mg) { sv = mg->mg_obj; if (sv_isobject(sv)) { tsv = (SV*)SvRV(sv); tmp = SvIV(tsv); } } } else { return SWIG_ERROR; } } else { tmp = SvIV(tsv); } voidptr = INT2PTR(void *,tmp); } else if (! SvOK(sv)) { /* Check for undef */ *(ptr) = (void *) 0; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */ if (!SvROK(sv)) { /* In Perl 5.12 and later, SVt_RV == SVt_IV, so sv could be a valid integer value. */ if (SvIOK(sv)) { return SWIG_ERROR; } else { /* NULL pointer (reference to undef). */ *(ptr) = (void *) 0; return SWIG_OK; } } else { return SWIG_ERROR; } } else { /* Don't know what it is */ return SWIG_ERROR; } if (_t) { /* Now see if the types match */ char *_c = HvNAME(SvSTASH(SvRV(sv))); tc = SWIG_TypeProxyCheck(_c,_t); #ifdef SWIG_DIRECTORS if (!tc && !sv_derived_from(sv,SWIG_Perl_TypeProxyName(_t))) { #else if (!tc) { #endif return SWIG_ERROR; } { int newmemory = 0; *ptr = SWIG_TypeCast(tc,voidptr,&newmemory); if (newmemory == SWIG_CAST_NEW_MEMORY) { assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ if (own) *own = *own | SWIG_CAST_NEW_MEMORY; } } } else { *ptr = voidptr; } /* * DISOWN implementation: we need a perl guru to check this one. */ if (tsv && ((flags & SWIG_POINTER_DISOWN) || check_owned_pointer_release)) { /* * almost copy paste code from below SWIG_POINTER_OWN setting */ SV *obj = sv; HV *stash = SvSTASH(SvRV(obj)); GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE); int owned = 0; if (isGV(gv)) { HV *hv = GvHVn(gv); /* * To set ownership (see below), a newSViv(1) entry is added. * Hence, to remove ownership, we delete the entry. */ if (hv_exists_ent(hv, obj, 0)) { owned = 1; if (flags & SWIG_POINTER_DISOWN) { hv_delete_ent(hv, obj, 0, 0); } } } if (check_owned_pointer_release && !owned) { return SWIG_ERROR_RELEASE_NOT_OWNED; } } if (tsv && (flags & SWIG_POINTER_CLEAR)) { SvIV_set(tsv, 0); } return SWIG_OK; } SWIGRUNTIME int SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) { return SWIG_Perl_ConvertPtrAndOwn(sv, ptr, _t, flags, 0); } SWIGRUNTIME void SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) { if (ptr && (flags & (SWIG_SHADOW | SWIG_POINTER_OWN))) { SV *self; SV *obj=newSV(0); HV *hash=newHV(); HV *stash; sv_setref_pv(obj, SWIG_Perl_TypeProxyName(t), ptr); stash=SvSTASH(SvRV(obj)); if (flags & SWIG_POINTER_OWN) { HV *hv; GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE); if (!isGV(gv)) gv_init(gv, stash, "OWNER", 5, FALSE); hv=GvHVn(gv); hv_store_ent(hv, obj, newSViv(1), 0); } sv_magic((SV *)hash, (SV *)obj, 'P', Nullch, 0); SvREFCNT_dec(obj); self=newRV_noinc((SV *)hash); sv_setsv(sv, self); SvREFCNT_dec((SV *)self); sv_bless(sv, stash); } else { sv_setref_pv(sv, SWIG_Perl_TypeProxyName(t), ptr); } } SWIGRUNTIMEINLINE SV * SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) { SV *result = sv_newmortal(); SWIG_MakePtr(result, ptr, t, flags); return result; } SWIGRUNTIME void SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) { char result[1024]; char *r = result; if ((2*sz + 1 + strlen(SWIG_Perl_TypeProxyName(type))) > 1000) return; *(r++) = '_'; r = SWIG_PackData(r,ptr,sz); strcpy(r,SWIG_Perl_TypeProxyName(type)); sv_setpv(sv, result); } SWIGRUNTIME SV * SWIG_Perl_NewPackedObj(SWIG_MAYBE_PERL_OBJECT void *ptr, int sz, swig_type_info *type) { SV *result = sv_newmortal(); SWIG_Perl_MakePackedObj(result, ptr, sz, type); return result; } /* Convert a packed pointer value */ SWIGRUNTIME int SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty) { swig_cast_info *tc; const char *c = 0; if ((!obj) || (!SvOK(obj))) return SWIG_ERROR; c = SvPV_nolen(obj); /* Pointer values must start with leading underscore */ if (*c != '_') return SWIG_ERROR; c++; c = SWIG_UnpackData(c,ptr,sz); if (ty) { tc = SWIG_TypeCheck(c,ty); if (!tc) return SWIG_ERROR; } return SWIG_OK; } /* Macros for low-level exception handling */ #define SWIG_croak(x) { SWIG_Error(SWIG_RuntimeError, x); SWIG_fail; } typedef XSPROTO(SwigPerlWrapper); typedef SwigPerlWrapper *SwigPerlWrapperPtr; /* Structure for command table */ typedef struct { const char *name; SwigPerlWrapperPtr wrapper; } swig_command_info; /* Information for constant table */ #define SWIG_INT 1 #define SWIG_FLOAT 2 #define SWIG_STRING 3 #define SWIG_POINTER 4 #define SWIG_BINARY 5 /* Constant information structure */ typedef struct swig_constant_info { int type; const char *name; long lvalue; double dvalue; void *pvalue; swig_type_info **ptype; } swig_constant_info; /* Structure for variable table */ typedef struct { const char *name; SwigMagicFunc set; SwigMagicFunc get; swig_type_info **type; } swig_variable_info; /* Magic variable code */ #ifdef __cplusplus # define swig_create_magic(s,a,b,c) _swig_create_magic(s,const_cast(a),b,c) #else # define swig_create_magic(s,a,b,c) _swig_create_magic(s,(char*)(a),b,c) #endif #ifndef MULTIPLICITY SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) #else SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) #endif { MAGIC *mg; sv_magic(sv,sv,'U',name,(I32)strlen(name)); mg = mg_find(sv,'U'); mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL)); mg->mg_virtual->svt_get = (SwigMagicFunc) get; mg->mg_virtual->svt_set = (SwigMagicFunc) set; mg->mg_virtual->svt_len = 0; mg->mg_virtual->svt_clear = 0; mg->mg_virtual->svt_free = 0; } SWIGRUNTIME swig_module_info * SWIG_Perl_GetModule(void *SWIGUNUSEDPARM(clientdata)) { static void *type_pointer = (void *)0; SV *pointer; /* first check if pointer already created */ if (!type_pointer) { pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, FALSE | GV_ADDMULTI); if (pointer && SvOK(pointer)) { type_pointer = INT2PTR(swig_type_info **, SvIV(pointer)); } } return (swig_module_info *) type_pointer; } SWIGRUNTIME void SWIG_Perl_SetModule(swig_module_info *module) { SV *pointer; /* create a new pointer */ pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE | GV_ADDMULTI); sv_setiv(pointer, PTR2IV(module)); } #ifdef __cplusplus } #endif /* Workaround perl5 global namespace pollution. Note that undefining library * functions like fopen will not solve the problem on all platforms as fopen * might be a macro on Windows but not necessarily on other operating systems. */ #ifdef do_open #undef do_open #endif #ifdef do_close #undef do_close #endif #ifdef do_exec #undef do_exec #endif #ifdef scalar #undef scalar #endif #ifdef list #undef list #endif #ifdef apply #undef apply #endif #ifdef convert #undef convert #endif #ifdef Error #undef Error #endif #ifdef form #undef form #endif #ifdef vform #undef vform #endif #ifdef LABEL #undef LABEL #endif #ifdef METHOD #undef METHOD #endif #ifdef Move #undef Move #endif #ifdef yylex #undef yylex #endif #ifdef yyparse #undef yyparse #endif #ifdef yyerror #undef yyerror #endif #ifdef invert #undef invert #endif #ifdef ref #undef ref #endif #ifdef read #undef read #endif #ifdef write #undef write #endif #ifdef eof #undef eof #endif #ifdef close #undef close #endif #ifdef rewind #undef rewind #endif #ifdef free #undef free #endif #ifdef malloc #undef malloc #endif #ifdef calloc #undef calloc #endif #ifdef Stat #undef Stat #endif #ifdef check #undef check #endif #ifdef seekdir #undef seekdir #endif #ifdef open #undef open #endif #ifdef readdir #undef readdir #endif #ifdef bind #undef bind #endif #ifdef access #undef access #endif #ifdef stat #undef stat #endif #ifdef seed #undef seed #endif #ifdef bool /* Leave if macro is from C99 stdbool.h */ #ifndef __bool_true_false_are_defined #undef bool #endif #endif #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) #define SWIG_contract_assert(expr, msg) do { if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } } while (0) #define SWIG_exception(code, msg) do { SWIG_Error(code, msg); SWIG_fail;; } while(0) /* -------- TYPES TABLE (BEGIN) -------- */ #define SWIGTYPE_p_char swig_types[0] #define SWIGTYPE_p_marisa__Key swig_types[1] #define SWIGTYPE_p_marisa_swig__Agent swig_types[2] #define SWIGTYPE_p_marisa_swig__Key swig_types[3] #define SWIGTYPE_p_marisa_swig__Keyset swig_types[4] #define SWIGTYPE_p_marisa_swig__Query swig_types[5] #define SWIGTYPE_p_marisa_swig__Trie swig_types[6] #define SWIGTYPE_p_p_char swig_types[7] #define SWIGTYPE_p_std__size_t swig_types[8] static swig_type_info *swig_types[10]; static swig_module_info swig_module = {swig_types, 9, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) /* -------- TYPES TABLE (END) -------- */ #define SWIG_init boot_marisa #define SWIG_name "marisac::boot_marisa" #define SWIG_prefix "marisac::" #ifdef __cplusplus #include /* SwigValueWrapper is described in swig.swg */ template class SwigValueWrapper { struct SwigSmartPointer { T *ptr; SwigSmartPointer(T *p) : ptr(p) { } ~SwigSmartPointer() { delete ptr; } SwigSmartPointer& operator=(SwigSmartPointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } void reset(T *p) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = p; } } pointer; SwigValueWrapper& operator=(const SwigValueWrapper& rhs); SwigValueWrapper(const SwigValueWrapper& rhs); public: SwigValueWrapper() : pointer(0) { } SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; } #if __cplusplus >=201103L SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; } operator T&&() const { return std::move(*pointer.ptr); } #else operator T&() const { return *pointer.ptr; } #endif T *operator&() const { return pointer.ptr; } static void reset(SwigValueWrapper& t, T *p) { t.pointer.reset(p); } }; /* * SwigValueInit() is a generic initialisation solution as the following approach: * * T c_result = T(); * * doesn't compile for all types for example: * * unsigned int c_result = unsigned int(); */ template T SwigValueInit() { return T(); } #if __cplusplus >=201103L # define SWIG_STD_MOVE(OBJ) std::move(OBJ) #else # define SWIG_STD_MOVE(OBJ) OBJ #endif #endif #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) #include #ifdef __cplusplus extern "C" #endif #ifndef MULTIPLICITY SWIGEXPORT void SWIG_init (CV* cv); #else SWIGEXPORT void SWIG_init (pTHXo_ CV* cv); #endif #include "marisa-swig.h" SWIGINTERNINLINE SV * SWIG_From_long SWIG_PERL_DECL_ARGS_1(long value) { SV *sv; if (IVSIZE >= sizeof(value) || (value >= IV_MIN && value <= IV_MAX)) sv = newSViv(value); else sv = newSVpvf("%ld", value); return sv_2mortal(sv); } SWIGINTERNINLINE SV * SWIG_From_int SWIG_PERL_DECL_ARGS_1(int value) { return SWIG_From_long SWIG_PERL_CALL_ARGS_1(value); } SWIGINTERNINLINE SV * SWIG_FromCharPtrAndSize(const char* carray, size_t size) { SV *obj = sv_newmortal(); if (carray) { sv_setpvn(obj, carray, size); } else { sv_setsv(obj, &PL_sv_undef); } return obj; } SWIGINTERNINLINE SV * SWIG_From_unsigned_SS_long SWIG_PERL_DECL_ARGS_1(unsigned long value) { SV *sv; if (UVSIZE >= sizeof(value) || value <= UV_MAX) sv = newSVuv(value); else sv = newSVpvf("%lu", value); return sv_2mortal(sv); } #include #if !defined(SWIG_NO_LLONG_MAX) # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) # define LLONG_MAX __LONG_LONG_MAX__ # define LLONG_MIN (-LLONG_MAX - 1LL) # define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) # endif #endif #if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE) # define SWIG_LONG_LONG_AVAILABLE #endif #include #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf # define snprintf _snprintf # endif #endif #ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE SV * SWIG_From_unsigned_SS_long_SS_long SWIG_PERL_DECL_ARGS_1(unsigned long long value) { SV *sv; if (UVSIZE >= sizeof(value) || value <= UV_MAX) sv = newSVuv((UV)(value)); else { //sv = newSVpvf("%llu", value); doesn't work in non 64bit Perl char temp[256]; SWIG_snprintf(temp, sizeof(temp), "%llu", value); sv = newSVpv(temp, 0); } return sv_2mortal(sv); } #endif SWIGINTERNINLINE SV * SWIG_From_size_t SWIG_PERL_DECL_ARGS_1(size_t value) { #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif return SWIG_From_unsigned_SS_long SWIG_PERL_CALL_ARGS_1(static_cast< unsigned long >(value)); #ifdef SWIG_LONG_LONG_AVAILABLE } else { /* assume sizeof(size_t) <= sizeof(unsigned long long) */ return SWIG_From_unsigned_SS_long_SS_long SWIG_PERL_CALL_ARGS_1(static_cast< unsigned long long >(value)); } #endif } SWIGINTERNINLINE SV * SWIG_From_double SWIG_PERL_DECL_ARGS_1(double value) { return sv_2mortal(newSVnv(value)); } SWIGINTERNINLINE SV * SWIG_From_float SWIG_PERL_DECL_ARGS_1(float value) { return SWIG_From_double SWIG_PERL_CALL_ARGS_1(value); } SWIGINTERN swig_type_info* SWIG_pchar_descriptor(void) { static int init = 0; static swig_type_info* info = 0; if (!init) { info = SWIG_TypeQuery("_p_char"); init = 1; } return info; } SWIGINTERN int SWIG_AsCharPtrAndSize(SV *obj, char** cptr, size_t* psize, int *alloc) { if (SvMAGICAL(obj)) { SV *tmp = sv_newmortal(); SvSetSV(tmp, obj); obj = tmp; } if (SvPOK(obj)) { STRLEN len = 0; char *cstr = SvPV(obj, len); size_t size = len + 1; if (cptr) { if (alloc) { if (*alloc == SWIG_NEWOBJ) { *cptr = reinterpret_cast< char* >(memcpy(new char[size], cstr, sizeof(char)*(size))); } else { *cptr = cstr; *alloc = SWIG_OLDOBJ; } } } if (psize) *psize = size; return SWIG_OK; } else { swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); if (pchar_descriptor) { char* vptr = 0; if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_descriptor, 0) == SWIG_OK) { if (cptr) *cptr = vptr; if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0; if (alloc) *alloc = SWIG_OLDOBJ; return SWIG_OK; } } } return SWIG_TypeError; } #include #include /* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ #ifndef SWIG_isfinite /* isfinite() is a macro for C99 */ # if defined(isfinite) # define SWIG_isfinite(X) (isfinite(X)) # elif defined(__cplusplus) && __cplusplus >= 201103L /* Use a template so that this works whether isfinite() is std::isfinite() or * in the global namespace. The reality seems to vary between compiler * versions. * * Make sure namespace std exists to avoid compiler warnings. * * extern "C++" is required as this fragment can end up inside an extern "C" { } block */ namespace std { } extern "C++" template inline int SWIG_isfinite_func(T x) { using namespace std; return isfinite(x); } # define SWIG_isfinite(X) (SWIG_isfinite_func(X)) # elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) # define SWIG_isfinite(X) (__builtin_isfinite(X)) # elif defined(_MSC_VER) # define SWIG_isfinite(X) (_finite(X)) # elif defined(__sun) && defined(__SVR4) # include # define SWIG_isfinite(X) (finite(X)) # endif #endif /* Accept infinite as a valid float value unless we are unable to check if a value is finite */ #ifdef SWIG_isfinite # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX) && SWIG_isfinite(X)) #else # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX)) #endif SWIGINTERN int SWIG_AsVal_double SWIG_PERL_DECL_ARGS_2(SV *obj, double *val) { if (SvNIOK(obj)) { if (val) *val = SvNV(obj); return SWIG_OK; } else if (SvIOK(obj)) { if (val) *val = (double) SvIV(obj); return SWIG_AddCast(SWIG_OK); } else { const char *nptr = SvPV_nolen(obj); if (nptr) { char *endptr; double v; errno = 0; v = strtod(nptr, &endptr); if (errno == ERANGE) { errno = 0; return SWIG_OverflowError; } else { if (*endptr == '\0') { if (val) *val = v; return SWIG_Str2NumCast(SWIG_OK); } } } } return SWIG_TypeError; } SWIGINTERN int SWIG_AsVal_float SWIG_PERL_DECL_ARGS_2(SV * obj, float *val) { double v; int res = SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj, &v); if (SWIG_IsOK(res)) { if (SWIG_Float_Overflow_Check(v)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< float >(v); } } return res; } #include #ifdef _MSC_VER # ifndef strtoull # define strtoull _strtoui64 # endif # ifndef strtoll # define strtoll _strtoi64 # endif #endif SWIGINTERNINLINE int SWIG_CanCastAsInteger(double *d, double min, double max) { double x = *d; if ((min <= x && x <= max)) { double fx, cx, rd; errno = 0; fx = floor(x); cx = ceil(x); rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ if ((errno == EDOM) || (errno == ERANGE)) { errno = 0; } else { double summ, reps, diff; if (rd < x) { diff = x - rd; } else if (rd > x) { diff = rd - x; } else { return 1; } summ = rd + x; reps = diff/summ; if (reps < 8*DBL_EPSILON) { *d = rd; return 1; } } } return 0; } SWIGINTERN int SWIG_AsVal_unsigned_SS_long SWIG_PERL_DECL_ARGS_2(SV *obj, unsigned long *val) { if (SvUOK(obj)) { UV v = SvUV(obj); if (UVSIZE <= sizeof(*val) || v <= ULONG_MAX) { if (val) *val = v; return SWIG_OK; } return SWIG_OverflowError; } else if (SvIOK(obj)) { IV v = SvIV(obj); if (v >= 0 && (IVSIZE <= sizeof(*val) || v <= ULONG_MAX)) { if (val) *val = v; return SWIG_OK; } return SWIG_OverflowError; } else { int dispatch = 0; const char *nptr = SvPV_nolen(obj); if (nptr) { char *endptr; unsigned long v; errno = 0; v = strtoul(nptr, &endptr,0); if (errno == ERANGE) { errno = 0; return SWIG_OverflowError; } else { if (*endptr == '\0') { if (val) *val = v; return SWIG_Str2NumCast(SWIG_OK); } } } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj,&d)); if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) { if (val) *val = (unsigned long)(d); return res; } } } return SWIG_TypeError; } #ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_unsigned_SS_long_SS_long SWIG_PERL_DECL_ARGS_2(SV *obj, unsigned long long *val) { if (SvUOK(obj)) { /* pretty sure this should be conditional on * (UVSIZE <= sizeof(*val) || v <= ULLONG_MAX) */ if (val) *val = SvUV(obj); return SWIG_OK; } else if (SvIOK(obj)) { IV v = SvIV(obj); if (v >= 0 && (IVSIZE <= sizeof(*val) || v <= ULLONG_MAX)) { if (val) *val = v; return SWIG_OK; } else { return SWIG_OverflowError; } } else { int dispatch = 0; const char *nptr = SvPV_nolen(obj); if (nptr) { char *endptr; unsigned long long v; errno = 0; v = strtoull(nptr, &endptr,0); if (errno == ERANGE) { errno = 0; return SWIG_OverflowError; } else { if (*endptr == '\0') { if (val) *val = v; return SWIG_Str2NumCast(SWIG_OK); } } } if (!dispatch) { const double mant_max = 1LL << DBL_MANT_DIG; double d; int res = SWIG_AddCast(SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj,&d)); if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) { if (val) *val = (unsigned long long)(d); return res; } } } return SWIG_TypeError; } #endif SWIGINTERNINLINE int SWIG_AsVal_size_t SWIG_PERL_DECL_ARGS_2(SV * obj, size_t *val) { int res = SWIG_TypeError; #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif unsigned long v; res = SWIG_AsVal_unsigned_SS_long SWIG_PERL_CALL_ARGS_2(obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); #ifdef SWIG_LONG_LONG_AVAILABLE } else if (sizeof(size_t) <= sizeof(unsigned long long)) { unsigned long long v; res = SWIG_AsVal_unsigned_SS_long_SS_long SWIG_PERL_CALL_ARGS_2(obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); } #endif return res; } SWIGINTERNINLINE SV * SWIG_From_bool SWIG_PERL_DECL_ARGS_1(bool value) { return boolSV(value); } SWIGINTERN int SWIG_AsVal_long SWIG_PERL_DECL_ARGS_2(SV *obj, long* val) { if (SvUOK(obj)) { UV v = SvUV(obj); if (UVSIZE < sizeof(*val) || v <= LONG_MAX) { if (val) *val = v; return SWIG_OK; } return SWIG_OverflowError; } else if (SvIOK(obj)) { IV v = SvIV(obj); if (IVSIZE <= sizeof(*val) || (v >= LONG_MIN && v <= LONG_MAX)) { if(val) *val = v; return SWIG_OK; } return SWIG_OverflowError; } else { int dispatch = 0; const char *nptr = SvPV_nolen(obj); if (nptr) { char *endptr; long v; errno = 0; v = strtol(nptr, &endptr,0); if (errno == ERANGE) { errno = 0; return SWIG_OverflowError; } else { if (*endptr == '\0') { if (val) *val = v; return SWIG_Str2NumCast(SWIG_OK); } } } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj,&d)); if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { if (val) *val = (long)(d); return res; } } } return SWIG_TypeError; } SWIGINTERN int SWIG_AsVal_int SWIG_PERL_DECL_ARGS_2(SV * obj, int *val) { long v; int res = SWIG_AsVal_long SWIG_PERL_CALL_ARGS_2(obj, &v); if (SWIG_IsOK(res)) { if ((v < INT_MIN || v > INT_MAX)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< int >(v); } } return res; } #ifdef __cplusplus extern "C" { #endif #define MAGIC_CLASS SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV *SWIGUNUSEDPARM(sv), MAGIC *SWIGUNUSEDPARM(mg)) { MAGIC_PPERL croak("Value is read-only."); return 0; } #ifdef __cplusplus } #endif #ifdef __cplusplus extern "C" { #endif XS(_wrap_Key_str) { { marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; int argvi = 0; dXSARGS; arg2 = &temp2; arg3 = &tempn2; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Key_str(self,length_out);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_str" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { ((marisa_swig::Key const *)arg1)->str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (*arg2) { /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,59,%append_output@*/ if (argvi >= items) EXTEND(sp, argvi+1); ST(argvi) = SWIG_FromCharPtrAndSize(*arg2,*arg3); argvi++ /*@SWIG@*/; ; } XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Key_id) { { marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Key_id(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_id" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = ((marisa_swig::Key const *)arg1)->id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Key_weight) { { marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; float result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Key_weight(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_weight" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = (float)((marisa_swig::Key const *)arg1)->weight(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_float SWIG_PERL_CALL_ARGS_1(static_cast< float >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_delete_Key) { { marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: delete_Key(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Key, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Key" "', argument " "1"" of type '" "marisa_swig::Key *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Query_str) { { marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; int argvi = 0; dXSARGS; arg2 = &temp2; arg3 = &tempn2; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Query_str(self,length_out);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Query_str" "', argument " "1"" of type '" "marisa_swig::Query const *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { ((marisa_swig::Query const *)arg1)->str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (*arg2) { /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,59,%append_output@*/ if (argvi >= items) EXTEND(sp, argvi+1); ST(argvi) = SWIG_FromCharPtrAndSize(*arg2,*arg3); argvi++ /*@SWIG@*/; ; } XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Query_id) { { marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Query_id(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Query_id" "', argument " "1"" of type '" "marisa_swig::Query const *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { result = ((marisa_swig::Query const *)arg1)->id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_delete_Query) { { marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: delete_Query(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Query, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Query" "', argument " "1"" of type '" "marisa_swig::Query *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_new_Keyset) { { int argvi = 0; marisa_swig::Keyset *result = 0 ; dXSARGS; if ((items < 0) || (items > 0)) { SWIG_croak("Usage: new_Keyset();"); } { try { result = (marisa_swig::Keyset *)new marisa_swig::Keyset(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Keyset, SWIG_OWNER | SWIG_SHADOW); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_delete_Keyset) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: delete_Keyset(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Keyset" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_push_back__SWIG_0) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; marisa::Key *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Keyset_push_back(self,key);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_marisa__Key, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "marisa::Key const &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Keyset_push_back" "', argument " "2"" of type '" "marisa::Key const &""'"); } arg2 = reinterpret_cast< marisa::Key * >(argp2); { try { (arg1)->push_back((marisa::Key const &)*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_push_back__SWIG_1) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; float arg4 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; float val4 ; int ecode4 = 0 ; int argvi = 0; dXSARGS; if ((items < 3) || (items > 3)) { SWIG_croak("Usage: Keyset_push_back(self,ptr,length,weight);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); ecode4 = SWIG_AsVal_float SWIG_PERL_CALL_ARGS_2(ST(2), &val4); if (!SWIG_IsOK(ecode4)) { SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Keyset_push_back" "', argument " "4"" of type '" "float""'"); } arg4 = static_cast< float >(val4); { try { (arg1)->push_back((char const *)arg2,arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Keyset_push_back__SWIG_2) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Keyset_push_back(self,ptr,length);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->push_back((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Keyset_push_back) { dXSARGS; { unsigned long _index = 0; SWIG_TypeRank _rank = 0; if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(1), &vptr, SWIGTYPE_p_marisa__Key, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 1; if (_rank == _rankm) goto dispatch; } } check_1: if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (items > 2) { { { int res = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(2), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; } if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 2; if (_rank == _rankm) goto dispatch; } } check_2: if (items == 3) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_3; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_3; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_float SWIG_PERL_CALL_ARGS_2(ST(2), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_3; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 3; if (_rank == _rankm) goto dispatch; } } check_3: dispatch: switch(_index) { case 1: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Keyset_push_back__SWIG_0); return; case 2: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Keyset_push_back__SWIG_2); return; case 3: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Keyset_push_back__SWIG_1); return; } } croak("No matching function for overloaded 'Keyset_push_back'"); XSRETURN(0); } XS(_wrap_Keyset_key) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; int argvi = 0; marisa_swig::Key *result = 0 ; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Keyset_key(self,i);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(1), &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { result = (marisa_swig::Key *) &((marisa_swig::Keyset const *)arg1)->key(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | SWIG_SHADOW); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_key_str) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; int argvi = 0; dXSARGS; arg3 = &temp3; arg4 = &tempn3; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Keyset_key_str(self,i,length_out);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key_str" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(1), &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key_str" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Keyset const *)arg1)->key_str(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (*arg3) { /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,59,%append_output@*/ if (argvi >= items) EXTEND(sp, argvi+1); ST(argvi) = SWIG_FromCharPtrAndSize(*arg3,*arg4); argvi++ /*@SWIG@*/; ; } XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_key_id) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Keyset_key_id(self,i);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key_id" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(1), &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key_id" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { result = ((marisa_swig::Keyset const *)arg1)->key_id(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_num_keys) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Keyset_num_keys(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_num_keys" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_empty) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; bool result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Keyset_empty(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_empty" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = (bool)((marisa_swig::Keyset const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_size) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Keyset_size(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_size" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_total_length) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Keyset_total_length(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_total_length" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->total_length(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_reset) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Keyset_reset(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_reset" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->reset(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Keyset_clear) { { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Keyset_clear(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_clear" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_new_Agent) { { int argvi = 0; marisa_swig::Agent *result = 0 ; dXSARGS; if ((items < 0) || (items > 0)) { SWIG_croak("Usage: new_Agent();"); } { try { result = (marisa_swig::Agent *)new marisa_swig::Agent(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Agent, SWIG_OWNER | SWIG_SHADOW); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_delete_Agent) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: delete_Agent(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Agent" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Agent_set_query__SWIG_0) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Agent_set_query(self,ptr,length);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_set_query" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Agent_set_query" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->set_query((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Agent_set_query__SWIG_1) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Agent_set_query(self,id);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_set_query" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); ecode2 = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(1), &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Agent_set_query" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { (arg1)->set_query(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Agent_set_query) { dXSARGS; { unsigned long _index = 0; SWIG_TypeRank _rank = 0; if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(1), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 1; if (_rank == _rankm) goto dispatch; } } check_1: if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (items > 2) { { { int res = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(2), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; } if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 2; if (_rank == _rankm) goto dispatch; } } check_2: dispatch: switch(_index) { case 1: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Agent_set_query__SWIG_1); return; case 2: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Agent_set_query__SWIG_0); return; } } croak("No matching function for overloaded 'Agent_set_query'"); XSRETURN(0); } XS(_wrap_Agent_key) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; marisa_swig::Key *result = 0 ; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Agent_key(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Key *) &((marisa_swig::Agent const *)arg1)->key(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | SWIG_SHADOW); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Agent_query) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; marisa_swig::Query *result = 0 ; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Agent_query(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Query *) &((marisa_swig::Agent const *)arg1)->query(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Query, 0 | SWIG_SHADOW); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Agent_key_str) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; int argvi = 0; dXSARGS; arg2 = &temp2; arg3 = &tempn2; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Agent_key_str(self,length_out);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key_str" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->key_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (*arg2) { /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,59,%append_output@*/ if (argvi >= items) EXTEND(sp, argvi+1); ST(argvi) = SWIG_FromCharPtrAndSize(*arg2,*arg3); argvi++ /*@SWIG@*/; ; } XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Agent_key_id) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Agent_key_id(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key_id" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->key_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Agent_query_str) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; int argvi = 0; dXSARGS; arg2 = &temp2; arg3 = &tempn2; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Agent_query_str(self,length_out);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query_str" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->query_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (*arg2) { /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,59,%append_output@*/ if (argvi >= items) EXTEND(sp, argvi+1); ST(argvi) = SWIG_FromCharPtrAndSize(*arg2,*arg3); argvi++ /*@SWIG@*/; ; } XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Agent_query_id) { { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Agent_query_id(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query_id" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->query_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_new_Trie) { { int argvi = 0; marisa_swig::Trie *result = 0 ; dXSARGS; if ((items < 0) || (items > 0)) { SWIG_croak("Usage: new_Trie();"); } { try { result = (marisa_swig::Trie *)new marisa_swig::Trie(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Trie, SWIG_OWNER | SWIG_SHADOW); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_delete_Trie) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: delete_Trie(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Trie" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_build__SWIG_0) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int val3 ; int ecode3 = 0 ; int argvi = 0; dXSARGS; if ((items < 3) || (items > 3)) { SWIG_croak("Usage: Trie_build(self,keyset,config_flags);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_build" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Trie_build" "', argument " "3"" of type '" "int""'"); } arg3 = static_cast< int >(val3); { try { (arg1)->build(*arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_build__SWIG_1) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_build(self,keyset);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_build" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); { try { (arg1)->build(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_build) { dXSARGS; { unsigned long _index = 0; SWIG_TypeRank _rank = 0; if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(1), &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 1; if (_rank == _rankm) goto dispatch; } } check_1: if (items == 3) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(1), &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 2; if (_rank == _rankm) goto dispatch; } } check_2: dispatch: switch(_index) { case 1: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_build__SWIG_1); return; case 2: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_build__SWIG_0); return; } } croak("No matching function for overloaded 'Trie_build'"); XSRETURN(0); } XS(_wrap_Trie_mmap__SWIG_0) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; int val3 ; int ecode3 = 0 ; int argvi = 0; dXSARGS; if ((items < 3) || (items > 3)) { SWIG_croak("Usage: Trie_mmap(self,filename,flags);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_mmap" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_mmap" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Trie_mmap" "', argument " "3"" of type '" "int""'"); } arg3 = static_cast< int >(val3); { try { (arg1)->mmap((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Trie_mmap__SWIG_1) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_mmap(self,filename);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_mmap" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_mmap" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->mmap((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Trie_mmap) { dXSARGS; { unsigned long _index = 0; SWIG_TypeRank _rank = 0; if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 1; if (_rank == _rankm) goto dispatch; } } check_1: if (items == 3) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 2; if (_rank == _rankm) goto dispatch; } } check_2: dispatch: switch(_index) { case 1: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_mmap__SWIG_1); return; case 2: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_mmap__SWIG_0); return; } } croak("No matching function for overloaded 'Trie_mmap'"); XSRETURN(0); } XS(_wrap_Trie_load) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_load(self,filename);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_load" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_load" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->load((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Trie_save) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_save(self,filename);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_save" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_save" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { ((marisa_swig::Trie const *)arg1)->save((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Trie_lookup__SWIG_0) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int argvi = 0; bool result; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_lookup(self,agent);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_reverse_lookup__SWIG_0) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int argvi = 0; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_reverse_lookup(self,agent);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_reverse_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_common_prefix_search) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int argvi = 0; bool result; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_common_prefix_search(self,agent);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_common_prefix_search" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_common_prefix_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_common_prefix_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->common_prefix_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_predictive_search) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int argvi = 0; bool result; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_predictive_search(self,agent);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_predictive_search" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_predictive_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_predictive_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->predictive_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_lookup__SWIG_1) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_lookup(self,ptr,length);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_lookup" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { result = ((marisa_swig::Trie const *)arg1)->lookup((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; XSRETURN(argvi); fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; SWIG_croak_null(); } } XS(_wrap_Trie_lookup) { dXSARGS; { unsigned long _index = 0; SWIG_TypeRank _rank = 0; if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(1), &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 1; if (_rank == _rankm) goto dispatch; } } check_1: if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (items > 2) { { { int res = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(2), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; } if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 2; if (_rank == _rankm) goto dispatch; } } check_2: dispatch: switch(_index) { case 1: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_lookup__SWIG_0); return; case 2: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_lookup__SWIG_1); return; } } croak("No matching function for overloaded 'Trie_lookup'"); XSRETURN(0); } XS(_wrap_Trie_reverse_lookup__SWIG_1) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; int argvi = 0; dXSARGS; arg3 = &temp3; arg4 = &tempn3; if ((items < 2) || (items > 2)) { SWIG_croak("Usage: Trie_reverse_lookup(self,id,length_out);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_reverse_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); ecode2 = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(1), &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; if (*arg3) { /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,59,%append_output@*/ if (argvi >= items) EXTEND(sp, argvi+1); ST(argvi) = SWIG_FromCharPtrAndSize(*arg3,*arg4); argvi++ /*@SWIG@*/; delete [] (*arg3); } XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_reverse_lookup) { dXSARGS; { unsigned long _index = 0; SWIG_TypeRank _rank = 0; if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(1), &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 1; if (_rank == _rankm) goto dispatch; } } check_1: if (items == 2) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_size_t SWIG_PERL_CALL_ARGS_2(ST(1), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 2; if (_rank == _rankm) goto dispatch; } } check_2: dispatch: switch(_index) { case 1: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_reverse_lookup__SWIG_0); return; case 2: PUSHMARK(MARK); SWIG_CALLXS(_wrap_Trie_reverse_lookup__SWIG_1); return; } } croak("No matching function for overloaded 'Trie_reverse_lookup'"); XSRETURN(0); } XS(_wrap_Trie_num_tries) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_num_tries(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_tries" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_tries(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_num_keys) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_num_keys(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_keys" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_num_nodes) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_num_nodes(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_nodes" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_nodes(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_tail_mode) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; marisa_swig::TailMode result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_tail_mode(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_tail_mode" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::TailMode)((marisa_swig::Trie const *)arg1)->tail_mode(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_node_order) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; marisa_swig::NodeOrder result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_node_order(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_node_order" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::NodeOrder)((marisa_swig::Trie const *)arg1)->node_order(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_empty) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; bool result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_empty(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_empty" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (bool)((marisa_swig::Trie const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_size) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_size(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_total_size) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_total_size(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_total_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->total_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_io_size) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; std::size_t result; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_io_size(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_io_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->io_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(result)); argvi++ ; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_Trie_clear) { { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int argvi = 0; dXSARGS; if ((items < 1) || (items > 1)) { SWIG_croak("Usage: Trie_clear(self);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_clear" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } ST(argvi) = &PL_sv_undef; XSRETURN(argvi); fail: SWIG_croak_null(); } } /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa__Key = {"_p_marisa__Key", "marisa::Key *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Agent = {"_p_marisa_swig__Agent", "marisa_swig::Agent *", 0, 0, (void*)"marisa::Agent", 0}; static swig_type_info _swigt__p_marisa_swig__Key = {"_p_marisa_swig__Key", "marisa_swig::Key *", 0, 0, (void*)"marisa::Key", 0}; static swig_type_info _swigt__p_marisa_swig__Keyset = {"_p_marisa_swig__Keyset", "marisa_swig::Keyset *", 0, 0, (void*)"marisa::Keyset", 0}; static swig_type_info _swigt__p_marisa_swig__Query = {"_p_marisa_swig__Query", "marisa_swig::Query *", 0, 0, (void*)"marisa::Query", 0}; static swig_type_info _swigt__p_marisa_swig__Trie = {"_p_marisa_swig__Trie", "marisa_swig::Trie *", 0, 0, (void*)"marisa::Trie", 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_std__size_t = {"_p_std__size_t", "std::size_t *", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { &_swigt__p_char, &_swigt__p_marisa__Key, &_swigt__p_marisa_swig__Agent, &_swigt__p_marisa_swig__Key, &_swigt__p_marisa_swig__Keyset, &_swigt__p_marisa_swig__Query, &_swigt__p_marisa_swig__Trie, &_swigt__p_p_char, &_swigt__p_std__size_t, }; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa__Key[] = { {&_swigt__p_marisa__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Agent[] = { {&_swigt__p_marisa_swig__Agent, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Key[] = { {&_swigt__p_marisa_swig__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Keyset[] = { {&_swigt__p_marisa_swig__Keyset, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Query[] = { {&_swigt__p_marisa_swig__Query, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Trie[] = { {&_swigt__p_marisa_swig__Trie, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_std__size_t[] = { {&_swigt__p_std__size_t, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { _swigc__p_char, _swigc__p_marisa__Key, _swigc__p_marisa_swig__Agent, _swigc__p_marisa_swig__Key, _swigc__p_marisa_swig__Keyset, _swigc__p_marisa_swig__Query, _swigc__p_marisa_swig__Trie, _swigc__p_p_char, _swigc__p_std__size_t, }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ static swig_constant_info swig_constants[] = { {0,0,0,0,0,0} }; #ifdef __cplusplus } #endif static swig_variable_info swig_variables[] = { {0,0,0,0} }; static swig_command_info swig_commands[] = { {"marisac::Key_str", _wrap_Key_str}, {"marisac::Key_id", _wrap_Key_id}, {"marisac::Key_weight", _wrap_Key_weight}, {"marisac::delete_Key", _wrap_delete_Key}, {"marisac::Query_str", _wrap_Query_str}, {"marisac::Query_id", _wrap_Query_id}, {"marisac::delete_Query", _wrap_delete_Query}, {"marisac::new_Keyset", _wrap_new_Keyset}, {"marisac::delete_Keyset", _wrap_delete_Keyset}, {"marisac::Keyset_push_back", _wrap_Keyset_push_back}, {"marisac::Keyset_key", _wrap_Keyset_key}, {"marisac::Keyset_key_str", _wrap_Keyset_key_str}, {"marisac::Keyset_key_id", _wrap_Keyset_key_id}, {"marisac::Keyset_num_keys", _wrap_Keyset_num_keys}, {"marisac::Keyset_empty", _wrap_Keyset_empty}, {"marisac::Keyset_size", _wrap_Keyset_size}, {"marisac::Keyset_total_length", _wrap_Keyset_total_length}, {"marisac::Keyset_reset", _wrap_Keyset_reset}, {"marisac::Keyset_clear", _wrap_Keyset_clear}, {"marisac::new_Agent", _wrap_new_Agent}, {"marisac::delete_Agent", _wrap_delete_Agent}, {"marisac::Agent_set_query", _wrap_Agent_set_query}, {"marisac::Agent_key", _wrap_Agent_key}, {"marisac::Agent_query", _wrap_Agent_query}, {"marisac::Agent_key_str", _wrap_Agent_key_str}, {"marisac::Agent_key_id", _wrap_Agent_key_id}, {"marisac::Agent_query_str", _wrap_Agent_query_str}, {"marisac::Agent_query_id", _wrap_Agent_query_id}, {"marisac::new_Trie", _wrap_new_Trie}, {"marisac::delete_Trie", _wrap_delete_Trie}, {"marisac::Trie_build", _wrap_Trie_build}, {"marisac::Trie_mmap", _wrap_Trie_mmap}, {"marisac::Trie_load", _wrap_Trie_load}, {"marisac::Trie_save", _wrap_Trie_save}, {"marisac::Trie_common_prefix_search", _wrap_Trie_common_prefix_search}, {"marisac::Trie_predictive_search", _wrap_Trie_predictive_search}, {"marisac::Trie_lookup", _wrap_Trie_lookup}, {"marisac::Trie_reverse_lookup", _wrap_Trie_reverse_lookup}, {"marisac::Trie_num_tries", _wrap_Trie_num_tries}, {"marisac::Trie_num_keys", _wrap_Trie_num_keys}, {"marisac::Trie_num_nodes", _wrap_Trie_num_nodes}, {"marisac::Trie_tail_mode", _wrap_Trie_tail_mode}, {"marisac::Trie_node_order", _wrap_Trie_node_order}, {"marisac::Trie_empty", _wrap_Trie_empty}, {"marisac::Trie_size", _wrap_Trie_size}, {"marisac::Trie_total_size", _wrap_Trie_total_size}, {"marisac::Trie_io_size", _wrap_Trie_io_size}, {"marisac::Trie_clear", _wrap_Trie_clear}, {0,0} }; /* ----------------------------------------------------------------------------- * Type initialization: * This problem is tough by the requirement that no dynamic * memory is used. Also, since swig_type_info structures store pointers to * swig_cast_info structures and swig_cast_info structures store pointers back * to swig_type_info structures, we need some lookup code at initialization. * The idea is that swig generates all the structures that are needed. * The runtime then collects these partially filled structures. * The SWIG_InitializeModule function takes these initial arrays out of * swig_module, and does all the lookup, filling in the swig_module.types * array with the correct data and linking the correct swig_cast_info * structures together. * * The generated swig_type_info structures are assigned statically to an initial * array. We just loop through that array, and handle each type individually. * First we lookup if this type has been already loaded, and if so, use the * loaded structure instead of the generated one. Then we have to fill in the * cast linked list. The cast data is initially stored in something like a * two-dimensional array. Each row corresponds to a type (there are the same * number of rows as there are in the swig_type_initial array). Each entry in * a column is one of the swig_cast_info structures for that type. * The cast_initial array is actually an array of arrays, because each row has * a variable number of columns. So to actually build the cast linked list, * we find the array of casts associated with the type, and loop through it * adding the casts to the list. The one last trick we need to do is making * sure the type pointer in the swig_cast_info struct is correct. * * First off, we lookup the cast->type name to see if it is already loaded. * There are three cases to handle: * 1) If the cast->type has already been loaded AND the type we are adding * casting info to has not been loaded (it is in this module), THEN we * replace the cast->type pointer with the type pointer that has already * been loaded. * 2) If BOTH types (the one we are adding casting info to, and the * cast->type) are loaded, THEN the cast info has already been loaded by * the previous module so we just ignore it. * 3) Finally, if cast->type has not already been loaded, then we add that * swig_cast_info to the linked list (because the cast->type) pointer will * be correct. * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #if 0 } /* c-mode */ #endif #endif #if 0 #define SWIGRUNTIME_DEBUG #endif #ifndef SWIG_INIT_CLIENT_DATA_TYPE #define SWIG_INIT_CLIENT_DATA_TYPE void * #endif SWIGRUNTIME void SWIG_InitializeModule(SWIG_INIT_CLIENT_DATA_TYPE clientdata) { size_t i; swig_module_info *module_head, *iter; int init; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { /* Initialize the swig_module */ swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; init = 1; } else { init = 0; } /* Try and load any already created modules */ module_head = SWIG_GetModule(clientdata); if (!module_head) { /* This is the first module loaded for this interpreter */ /* so set the swig module into the interpreter */ SWIG_SetModule(clientdata, &swig_module); } else { /* the interpreter has loaded a SWIG module, but has it loaded this one? */ iter=module_head; do { if (iter==&swig_module) { /* Our module is already in the list, so there's nothing more to do. */ return; } iter=iter->next; } while (iter!= module_head); /* otherwise we must add our module into the list */ swig_module.next = module_head->next; module_head->next = &swig_module; } /* When multiple interpreters are used, a module could have already been initialized in a different interpreter, but not yet have a pointer in this interpreter. In this case, we do not want to continue adding types... everything should be set up already */ if (init == 0) return; /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); #endif for (i = 0; i < swig_module.size; ++i) { swig_type_info *type = 0; swig_type_info *ret; swig_cast_info *cast; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); #endif /* if there is another module already loaded */ if (swig_module.next != &swig_module) { type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); } if (type) { /* Overwrite clientdata field */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found type %s\n", type->name); #endif if (swig_module.type_initial[i]->clientdata) { type->clientdata = swig_module.type_initial[i]->clientdata; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); #endif } } else { type = swig_module.type_initial[i]; } /* Insert casting types */ cast = swig_module.cast_initial[i]; while (cast->type) { /* Don't need to add information already in the list */ ret = 0; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); #endif if (swig_module.next != &swig_module) { ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); #ifdef SWIGRUNTIME_DEBUG if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); #endif } if (ret) { if (type == swig_module.type_initial[i]) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: skip old type %s\n", ret->name); #endif cast->type = ret; ret = 0; } else { /* Check for casting already in the list */ swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); #ifdef SWIGRUNTIME_DEBUG if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); #endif if (!ocast) ret = 0; } } if (!ret) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); #endif if (type->cast) { type->cast->prev = cast; cast->next = type->cast; } type->cast = cast; } cast++; } /* Set entry in modules->types array equal to the type */ swig_module.types[i] = type; } swig_module.types[i] = 0; #ifdef SWIGRUNTIME_DEBUG printf("**** SWIG_InitializeModule: Cast List ******\n"); for (i = 0; i < swig_module.size; ++i) { int j = 0; swig_cast_info *cast = swig_module.cast_initial[i]; printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); while (cast->type) { printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); cast++; ++j; } printf("---- Total casts: %d\n",j); } printf("**** SWIG_InitializeModule: Cast List ******\n"); #endif } /* This function will propagate the clientdata field of type to * any new swig_type_info structures that have been added into the list * of equivalent types. It is like calling * SWIG_TypeClientData(type, clientdata) a second time. */ SWIGRUNTIME void SWIG_PropagateClientData(void) { size_t i; swig_cast_info *equiv; static int init_run = 0; if (init_run) return; init_run = 1; for (i = 0; i < swig_module.size; i++) { if (swig_module.types[i]->clientdata) { equiv = swig_module.types[i]->cast; while (equiv) { if (!equiv->converter) { if (equiv->type && !equiv->type->clientdata) SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); } equiv = equiv->next; } } } } #ifdef __cplusplus #if 0 { /* c-mode */ #endif } #endif #if defined(__cplusplus) && ! defined(XSPROTO) extern "C" #endif XS(SWIG_init) { dXSARGS; int i; (void)items; SWIG_InitializeModule(0); /* Install commands */ for (i = 0; swig_commands[i].name; i++) { /* Casts only needed for Perl < 5.10. */ #ifdef __cplusplus newXS(const_cast(swig_commands[i].name), swig_commands[i].wrapper, const_cast(__FILE__)); #else newXS((char*)swig_commands[i].name, swig_commands[i].wrapper, (char*)__FILE__); #endif } /* Install variables */ for (i = 0; swig_variables[i].name; i++) { SV *sv; sv = get_sv(swig_variables[i].name, TRUE | 0x2 | GV_ADDMULTI); if (swig_variables[i].type) { SWIG_MakePtr(sv,(void *)1, *swig_variables[i].type,0); } else { sv_setiv(sv,(IV) 0); } swig_create_magic(sv, swig_variables[i].name, swig_variables[i].set, swig_variables[i].get); } /* Install constant */ for (i = 0; swig_constants[i].type; i++) { SV *sv; sv = get_sv(swig_constants[i].name, TRUE | 0x2 | GV_ADDMULTI); switch(swig_constants[i].type) { case SWIG_INT: sv_setiv(sv, (IV) swig_constants[i].lvalue); break; case SWIG_FLOAT: sv_setnv(sv, (double) swig_constants[i].dvalue); break; case SWIG_STRING: sv_setpv(sv, (const char *) swig_constants[i].pvalue); break; case SWIG_POINTER: SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0); break; case SWIG_BINARY: SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype)); break; default: break; } SvREADONLY_on(sv); } /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "OK", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::OK))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "STATE_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::STATE_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "NULL_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::NULL_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "BOUND_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::BOUND_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "RANGE_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::RANGE_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "CODE_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::CODE_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "RESET_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::RESET_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "SIZE_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::SIZE_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "MEMORY_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::MEMORY_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "IO_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::IO_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "FORMAT_ERROR", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::FORMAT_ERROR))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "MAP_POPULATE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::MAP_POPULATE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "MIN_NUM_TRIES", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::MIN_NUM_TRIES))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "MAX_NUM_TRIES", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::MAX_NUM_TRIES))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "DEFAULT_NUM_TRIES", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::DEFAULT_NUM_TRIES))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "HUGE_CACHE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::HUGE_CACHE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "LARGE_CACHE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::LARGE_CACHE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "NORMAL_CACHE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::NORMAL_CACHE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "SMALL_CACHE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::SMALL_CACHE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "TINY_CACHE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::TINY_CACHE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "DEFAULT_CACHE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::DEFAULT_CACHE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "TEXT_TAIL", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::TEXT_TAIL))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "BINARY_TAIL", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::BINARY_TAIL))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "DEFAULT_TAIL", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::DEFAULT_TAIL))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "LABEL_ORDER", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::LABEL_ORDER))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "WEIGHT_ORDER", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::WEIGHT_ORDER))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "DEFAULT_ORDER", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(marisa_swig::DEFAULT_ORDER))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Key, (void*) "marisa::Key"); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Query, (void*) "marisa::Query"); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Keyset, (void*) "marisa::Keyset"); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Agent, (void*) "marisa::Agent"); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Trie, (void*) "marisa::Trie"); /*@SWIG:/usr/share/swig4.0/perl5/perltypemaps.swg,67,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "INVALID_KEY_ID", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_size_t SWIG_PERL_CALL_ARGS_1(static_cast< size_t >(MARISA_INVALID_KEY_ID))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; ST(0) = &PL_sv_yes; XSRETURN(1); } marisa-trie-master/bindings/perl/marisa.pm000066400000000000000000000152731505027263100211460ustar00rootroot00000000000000# This file was automatically generated by SWIG (https://www.swig.org). # Version 4.2.0 # # Do not make changes to this file unless you know what you are doing - modify # the SWIG interface file instead. package marisa; use base qw(Exporter); use base qw(DynaLoader); package marisac; bootstrap marisa; package marisa; @EXPORT = qw(); # ---------- BASE METHODS ------------- package marisa; sub TIEHASH { my ($classname,$obj) = @_; return bless $obj, $classname; } sub CLEAR { } sub FIRSTKEY { } sub NEXTKEY { } sub FETCH { my ($self,$field) = @_; my $member_func = "swig_${field}_get"; $self->$member_func(); } sub STORE { my ($self,$field,$newval) = @_; my $member_func = "swig_${field}_set"; $self->$member_func($newval); } sub this { my $ptr = shift; return tied(%$ptr); } # ------- FUNCTION WRAPPERS -------- package marisa; ############# Class : marisa::Key ############## package marisa::Key; use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); @ISA = qw( marisa ); %OWNER = (); %ITERATORS = (); *str = *marisac::Key_str; *id = *marisac::Key_id; *weight = *marisac::Key_weight; sub DESTROY { return unless $_[0]->isa('HASH'); my $self = tied(%{$_[0]}); return unless defined $self; delete $ITERATORS{$self}; if (exists $OWNER{$self}) { marisac::delete_Key($self); delete $OWNER{$self}; } } sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; } sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; } ############# Class : marisa::Query ############## package marisa::Query; use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); @ISA = qw( marisa ); %OWNER = (); %ITERATORS = (); *str = *marisac::Query_str; *id = *marisac::Query_id; sub DESTROY { return unless $_[0]->isa('HASH'); my $self = tied(%{$_[0]}); return unless defined $self; delete $ITERATORS{$self}; if (exists $OWNER{$self}) { marisac::delete_Query($self); delete $OWNER{$self}; } } sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; } sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; } ############# Class : marisa::Keyset ############## package marisa::Keyset; use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); @ISA = qw( marisa ); %OWNER = (); %ITERATORS = (); sub new { my $pkg = shift; my $self = marisac::new_Keyset(@_); bless $self, $pkg if defined($self); } sub DESTROY { return unless $_[0]->isa('HASH'); my $self = tied(%{$_[0]}); return unless defined $self; delete $ITERATORS{$self}; if (exists $OWNER{$self}) { marisac::delete_Keyset($self); delete $OWNER{$self}; } } *push_back = *marisac::Keyset_push_back; *key = *marisac::Keyset_key; *key_str = *marisac::Keyset_key_str; *key_id = *marisac::Keyset_key_id; *num_keys = *marisac::Keyset_num_keys; *empty = *marisac::Keyset_empty; *size = *marisac::Keyset_size; *total_length = *marisac::Keyset_total_length; *reset = *marisac::Keyset_reset; *clear = *marisac::Keyset_clear; sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; } sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; } ############# Class : marisa::Agent ############## package marisa::Agent; use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); @ISA = qw( marisa ); %OWNER = (); %ITERATORS = (); sub new { my $pkg = shift; my $self = marisac::new_Agent(@_); bless $self, $pkg if defined($self); } sub DESTROY { return unless $_[0]->isa('HASH'); my $self = tied(%{$_[0]}); return unless defined $self; delete $ITERATORS{$self}; if (exists $OWNER{$self}) { marisac::delete_Agent($self); delete $OWNER{$self}; } } *set_query = *marisac::Agent_set_query; *key = *marisac::Agent_key; *query = *marisac::Agent_query; *key_str = *marisac::Agent_key_str; *key_id = *marisac::Agent_key_id; *query_str = *marisac::Agent_query_str; *query_id = *marisac::Agent_query_id; sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; } sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; } ############# Class : marisa::Trie ############## package marisa::Trie; use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); @ISA = qw( marisa ); %OWNER = (); %ITERATORS = (); sub new { my $pkg = shift; my $self = marisac::new_Trie(@_); bless $self, $pkg if defined($self); } sub DESTROY { return unless $_[0]->isa('HASH'); my $self = tied(%{$_[0]}); return unless defined $self; delete $ITERATORS{$self}; if (exists $OWNER{$self}) { marisac::delete_Trie($self); delete $OWNER{$self}; } } *build = *marisac::Trie_build; *mmap = *marisac::Trie_mmap; *load = *marisac::Trie_load; *save = *marisac::Trie_save; *common_prefix_search = *marisac::Trie_common_prefix_search; *predictive_search = *marisac::Trie_predictive_search; *lookup = *marisac::Trie_lookup; *reverse_lookup = *marisac::Trie_reverse_lookup; *num_tries = *marisac::Trie_num_tries; *num_keys = *marisac::Trie_num_keys; *num_nodes = *marisac::Trie_num_nodes; *tail_mode = *marisac::Trie_tail_mode; *node_order = *marisac::Trie_node_order; *empty = *marisac::Trie_empty; *size = *marisac::Trie_size; *total_size = *marisac::Trie_total_size; *io_size = *marisac::Trie_io_size; *clear = *marisac::Trie_clear; sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; } sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; } # ------- VARIABLE STUBS -------- package marisa; *OK = *marisac::OK; *STATE_ERROR = *marisac::STATE_ERROR; *NULL_ERROR = *marisac::NULL_ERROR; *BOUND_ERROR = *marisac::BOUND_ERROR; *RANGE_ERROR = *marisac::RANGE_ERROR; *CODE_ERROR = *marisac::CODE_ERROR; *RESET_ERROR = *marisac::RESET_ERROR; *SIZE_ERROR = *marisac::SIZE_ERROR; *MEMORY_ERROR = *marisac::MEMORY_ERROR; *IO_ERROR = *marisac::IO_ERROR; *FORMAT_ERROR = *marisac::FORMAT_ERROR; *MAP_POPULATE = *marisac::MAP_POPULATE; *MIN_NUM_TRIES = *marisac::MIN_NUM_TRIES; *MAX_NUM_TRIES = *marisac::MAX_NUM_TRIES; *DEFAULT_NUM_TRIES = *marisac::DEFAULT_NUM_TRIES; *HUGE_CACHE = *marisac::HUGE_CACHE; *LARGE_CACHE = *marisac::LARGE_CACHE; *NORMAL_CACHE = *marisac::NORMAL_CACHE; *SMALL_CACHE = *marisac::SMALL_CACHE; *TINY_CACHE = *marisac::TINY_CACHE; *DEFAULT_CACHE = *marisac::DEFAULT_CACHE; *TEXT_TAIL = *marisac::TEXT_TAIL; *BINARY_TAIL = *marisac::BINARY_TAIL; *DEFAULT_TAIL = *marisac::DEFAULT_TAIL; *LABEL_ORDER = *marisac::LABEL_ORDER; *WEIGHT_ORDER = *marisac::WEIGHT_ORDER; *DEFAULT_ORDER = *marisac::DEFAULT_ORDER; *INVALID_KEY_ID = *marisac::INVALID_KEY_ID; 1; marisa-trie-master/bindings/perl/sample.pl000066400000000000000000000032311505027263100211410ustar00rootroot00000000000000use marisa; $keyset = new marisa::Keyset; $keyset->push_back("cake"); $keyset->push_back("cookie"); $keyset->push_back("ice"); $keyset->push_back("ice-cream"); $trie = new marisa::Trie; $trie->build($keyset); print("no. keys: ", $trie->num_keys(), "\n"); print("no. tries: ", $trie->num_tries(), "\n"); print("no. nodes: ", $trie->num_nodes(), "\n"); print("size: ", $trie->io_size(), "\n"); $agent = new marisa::Agent; $agent->set_query("cake"); $trie->lookup($agent); print($agent->query_str(), ": ", $agent->key_id(), "\n"); $agent->set_query("cookie"); $trie->lookup($agent); print($agent->query_str(), ": ", $agent->key_id(), "\n"); $agent->set_query("cockoo"); if ($trie->lookup(agent)) { print($agent->query_str(), ": not found\n"); } print("ice: ", $trie->lookup("ice"), "\n"); print("ice-cream: ", $trie->lookup("ice-cream"), "\n"); if ($trie->lookup("ice-age") == $marisa::INVALID_KEY_ID) { print("ice-age: not found\n"); } $trie->save("sample.dic"); $trie->load("sample.dic"); $agent->set_query(0); $trie->reverse_lookup($agent); print($agent->query_id(), ": ", $agent->key_str(), "\n"); $agent->set_query(1); $trie->reverse_lookup($agent); print($agent->query_id(), ": ", $agent->key_str(), "\n"); print("2: ", $trie->reverse_lookup(2), "\n"); print("3: ", $trie->reverse_lookup(3), "\n"); $trie->mmap("sample.dic"); $agent->set_query("ice-cream soda"); while ($trie->common_prefix_search($agent)) { print($agent->query_str(), ": ", $agent->key_str(), " (", $agent->key_id(), ")\n"); } $agent->set_query("ic"); while ($trie->predictive_search($agent)) { print($agent->query_str(), ": ", $agent->key_str(), " (", $agent->key_id(), ")\n"); } marisa-trie-master/bindings/python/000077500000000000000000000000001505027263100177035ustar00rootroot00000000000000marisa-trie-master/bindings/python/benchmark.py000066400000000000000000000041221505027263100222060ustar00rootroot00000000000000import datetime import marisa import sys time_begin = datetime.datetime.now() keys = [] for line in sys.stdin: keys.append(line.rstrip()) time_end = datetime.datetime.now() print "input:", time_end - time_begin time_begin = datetime.datetime.now() dic = dict() for i in range(len(keys)): dic[keys[i]] = i time_end = datetime.datetime.now() print "dict_build:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: dic.get(key) time_end = datetime.datetime.now() print "dict_lookup:", time_end - time_begin time_begin = datetime.datetime.now() keyset = marisa.Keyset() for key in keys: keyset.push_back(key) time_end = datetime.datetime.now() print "keyset_build:", time_end - time_begin time_begin = datetime.datetime.now() trie = marisa.Trie() trie.build(keyset) time_end = datetime.datetime.now() print "trie_build:", time_end - time_begin time_begin = datetime.datetime.now() agent = marisa.Agent() for key in keys: agent.set_query(key) trie.lookup(agent) agent.key_id() time_end = datetime.datetime.now() print "trie_agent_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: trie.lookup(key) time_end = datetime.datetime.now() print "trie_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for i in range(len(keys)): agent.set_query(i) trie.reverse_lookup(agent) agent.key_str() time_end = datetime.datetime.now() print "trie_agent_reverse_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for i in range(len(keys)): trie.reverse_lookup(i) time_end = datetime.datetime.now() print "trie_reverse_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: agent.set_query(key) while trie.common_prefix_search(agent): agent.key_str() time_end = datetime.datetime.now() print "trie_agent_common_prefix_search:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: agent.set_query(key) while trie.predictive_search(agent): agent.key_str() time_end = datetime.datetime.now() print "trie_agent_predictive_search:", time_end - time_begin marisa-trie-master/bindings/python/marisa-swig.cxx000066400000000000000000000115611505027263100226560ustar00rootroot00000000000000#include #include #include "marisa-swig.h" namespace marisa_swig { void Key::str(const char **ptr_out, size_t *length_out) const { *ptr_out = key_.ptr(); *length_out = key_.length(); } size_t Key::id() const { return key_.id(); } float Key::weight() const { return key_.weight(); } void Query::str(const char **ptr_out, size_t *length_out) const { *ptr_out = query_.ptr(); *length_out = query_.length(); } size_t Query::id() const { return query_.id(); } Keyset::Keyset() : keyset_(new marisa::Keyset) { } Keyset::~Keyset() { delete keyset_; } void Keyset::push_back(const marisa::Key &key) { keyset_->push_back(key); } void Keyset::push_back(const char *ptr, size_t length, float weight) { keyset_->push_back(ptr, length, weight); } const Key &Keyset::key(size_t i) const { return reinterpret_cast((*keyset_)[i]); } void Keyset::key_str(size_t i, const char **ptr_out, size_t *length_out) const { *ptr_out = (*keyset_)[i].ptr(); *length_out = (*keyset_)[i].length(); } size_t Keyset::key_id(size_t i) const { return (*keyset_)[i].id(); } size_t Keyset::num_keys() const { return keyset_->num_keys(); } bool Keyset::empty() const { return keyset_->empty(); } size_t Keyset::size() const { return keyset_->size(); } size_t Keyset::total_length() const { return keyset_->total_length(); } void Keyset::reset() { keyset_->reset(); } void Keyset::clear() { keyset_->clear(); } Agent::Agent() : agent_(new marisa::Agent), buf_(NULL), buf_size_(0) { } Agent::~Agent() { delete agent_; delete [] buf_; } void Agent::set_query(const char *ptr, size_t length) { if (length > buf_size_) { size_t new_buf_size = (buf_size_ != 0) ? buf_size_ : 1; if (length >= (MARISA_SIZE_MAX / 2)) { new_buf_size = MARISA_SIZE_MAX; } else { while (new_buf_size < length) { new_buf_size *= 2; } } char *new_buf = new char[new_buf_size]; delete [] buf_; buf_ = new_buf; buf_size_ = new_buf_size; } std::memcpy(buf_, ptr, length); agent_->set_query(buf_, length); } void Agent::set_query(size_t id) { agent_->set_query(id); } const Key &Agent::key() const { return reinterpret_cast(agent_->key()); } const Query &Agent::query() const { return reinterpret_cast(agent_->query()); } void Agent::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->key().ptr(); *length_out = agent_->key().length(); } size_t Agent::key_id() const { return agent_->key().id(); } void Agent::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->query().ptr(); *length_out = agent_->query().length(); } size_t Agent::query_id() const { return agent_->query().id(); } Trie::Trie() : trie_(new marisa::Trie) { } Trie::~Trie() { delete trie_; } void Trie::build(Keyset &keyset, int config_flags) { trie_->build(*keyset.keyset_, config_flags); } void Trie::mmap(const char *filename, int flags) { trie_->mmap(filename, flags); } void Trie::load(const char *filename) { trie_->load(filename); } void Trie::save(const char *filename) const { trie_->save(filename); } bool Trie::lookup(Agent &agent) const { return trie_->lookup(*agent.agent_); } void Trie::reverse_lookup(Agent &agent) const { trie_->reverse_lookup(*agent.agent_); } bool Trie::common_prefix_search(Agent &agent) const { return trie_->common_prefix_search(*agent.agent_); } bool Trie::predictive_search(Agent &agent) const { return trie_->predictive_search(*agent.agent_); } size_t Trie::lookup(const char *ptr, size_t length) const { marisa::Agent agent; agent.set_query(ptr, length); if (!trie_->lookup(agent)) { return MARISA_INVALID_KEY_ID; } return agent.key().id(); } void Trie::reverse_lookup(size_t id, const char **ptr_out_to_be_deleted, size_t *length_out) const { marisa::Agent agent; agent.set_query(id); trie_->reverse_lookup(agent); char * const buf = new char[agent.key().length()]; std::memcpy(buf, agent.key().ptr(), agent.key().length()); *ptr_out_to_be_deleted = buf; *length_out = agent.key().length(); } size_t Trie::num_tries() const { return trie_->num_tries(); } size_t Trie::num_keys() const { return trie_->num_keys(); } size_t Trie::num_nodes() const { return trie_->num_nodes(); } TailMode Trie::tail_mode() const { if (trie_->tail_mode() == ::MARISA_TEXT_TAIL) { return TEXT_TAIL; } else { return BINARY_TAIL; } } NodeOrder Trie::node_order() const { if (trie_->node_order() == ::MARISA_LABEL_ORDER) { return LABEL_ORDER; } else { return WEIGHT_ORDER; } } bool Trie::empty() const { return trie_->empty(); } size_t Trie::size() const { return trie_->size(); } size_t Trie::total_size() const { return trie_->total_size(); } size_t Trie::io_size() const { return trie_->io_size(); } void Trie::clear() { trie_->clear(); } } // namespace marisa_swig marisa-trie-master/bindings/python/marisa-swig.h000066400000000000000000000075471505027263100223140ustar00rootroot00000000000000#ifndef MARISA_SWIG_H_ #define MARISA_SWIG_H_ #include namespace marisa_swig { #define MARISA_SWIG_ENUM_COPY(name) name = MARISA_ ## name enum ErrorCode { MARISA_SWIG_ENUM_COPY(OK), MARISA_SWIG_ENUM_COPY(STATE_ERROR), MARISA_SWIG_ENUM_COPY(NULL_ERROR), MARISA_SWIG_ENUM_COPY(BOUND_ERROR), MARISA_SWIG_ENUM_COPY(RANGE_ERROR), MARISA_SWIG_ENUM_COPY(CODE_ERROR), MARISA_SWIG_ENUM_COPY(RESET_ERROR), MARISA_SWIG_ENUM_COPY(SIZE_ERROR), MARISA_SWIG_ENUM_COPY(MEMORY_ERROR), MARISA_SWIG_ENUM_COPY(IO_ERROR), MARISA_SWIG_ENUM_COPY(FORMAT_ERROR) }; enum NumTries { MARISA_SWIG_ENUM_COPY(MIN_NUM_TRIES), MARISA_SWIG_ENUM_COPY(MAX_NUM_TRIES), MARISA_SWIG_ENUM_COPY(DEFAULT_NUM_TRIES) }; enum CacheLevel { MARISA_SWIG_ENUM_COPY(HUGE_CACHE), MARISA_SWIG_ENUM_COPY(LARGE_CACHE), MARISA_SWIG_ENUM_COPY(NORMAL_CACHE), MARISA_SWIG_ENUM_COPY(SMALL_CACHE), MARISA_SWIG_ENUM_COPY(TINY_CACHE), MARISA_SWIG_ENUM_COPY(DEFAULT_CACHE) }; enum TailMode { MARISA_SWIG_ENUM_COPY(TEXT_TAIL), MARISA_SWIG_ENUM_COPY(BINARY_TAIL), MARISA_SWIG_ENUM_COPY(DEFAULT_TAIL) }; enum NodeOrder { MARISA_SWIG_ENUM_COPY(LABEL_ORDER), MARISA_SWIG_ENUM_COPY(WEIGHT_ORDER), MARISA_SWIG_ENUM_COPY(DEFAULT_ORDER) }; #undef MARISA_SWIG_ENUM_COPY class Key { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; float weight() const; private: const marisa::Key key_; Key(); Key(const Key &key); Key &operator=(const Key &); }; class Query { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; private: const marisa::Query query_; Query(); Query(const Query &query); Query &operator=(const Query &); }; class Keyset { friend class Trie; public: Keyset(); ~Keyset(); void push_back(const marisa::Key &key); void push_back(const char *ptr, std::size_t length, float weight = 1.0); const Key &key(std::size_t i) const; void key_str(std::size_t i, const char **ptr_out, std::size_t *length_out) const; std::size_t key_id(std::size_t i) const; std::size_t num_keys() const; bool empty() const; std::size_t size() const; std::size_t total_length() const; void reset(); void clear(); private: marisa::Keyset *keyset_; Keyset(const Keyset &); Keyset &operator=(const Keyset &); }; class Agent { friend class Trie; public: Agent(); ~Agent(); void set_query(const char *ptr, std::size_t length); void set_query(std::size_t id); const Key &key() const; const Query &query() const; void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: marisa::Agent *agent_; char *buf_; std::size_t buf_size_; Agent(const Agent &); Agent &operator=(const Agent &); }; class Trie { public: Trie(); ~Trie(); void build(Keyset &keyset, int config_flags = 0); void mmap(const char *filename, int flags = 0); void load(const char *filename); void save(const char *filename) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t lookup(const char *ptr, std::size_t length) const; void reverse_lookup(std::size_t id, const char **ptr_out_to_be_deleted, std::size_t *length_out) const; std::size_t num_tries() const; std::size_t num_keys() const; std::size_t num_nodes() const; TailMode tail_mode() const; NodeOrder node_order() const; bool empty() const; std::size_t size() const; std::size_t total_size() const; std::size_t io_size() const; void clear(); private: marisa::Trie *trie_; Trie(const Trie &); Trie &operator=(const Trie &); }; } // namespace marisa_swig #endif // MARISA_SWIG_H_ marisa-trie-master/bindings/python/marisa-swig_wrap.cxx000066400000000000000000006335341505027263100237210ustar00rootroot00000000000000/* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (https://www.swig.org). * Version 4.2.0 * * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ #define SWIG_VERSION 0x040200 #define SWIGPYTHON #define SWIG_PYTHON_DIRECTOR_NO_VTABLE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. * ----------------------------------------------------------------------------- */ /* template workaround for compilers that cannot correctly implement the C++ standard */ #ifndef SWIGTEMPLATEDISAMBIGUATOR # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) # define SWIGTEMPLATEDISAMBIGUATOR template # elif defined(__HP_aCC) /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ # define SWIGTEMPLATEDISAMBIGUATOR template # else # define SWIGTEMPLATEDISAMBIGUATOR # endif #endif /* inline attribute */ #ifndef SWIGINLINE # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) # define SWIGINLINE inline # else # define SWIGINLINE # endif #endif /* attribute recognised by some compilers to avoid 'unused' warnings */ #ifndef SWIGUNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif # elif defined(__ICC) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif #endif #ifndef SWIG_MSC_UNSUPPRESS_4505 # if defined(_MSC_VER) # pragma warning(disable : 4505) /* unreferenced local function has been removed */ # endif #endif #ifndef SWIGUNUSEDPARM # ifdef __cplusplus # define SWIGUNUSEDPARM(p) # else # define SWIGUNUSEDPARM(p) p SWIGUNUSED # endif #endif /* internal SWIG method */ #ifndef SWIGINTERN # define SWIGINTERN static SWIGUNUSED #endif /* internal inline SWIG method */ #ifndef SWIGINTERNINLINE # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE #endif /* exporting methods */ #if defined(__GNUC__) # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) # ifndef GCC_HASCLASSVISIBILITY # define GCC_HASCLASSVISIBILITY # endif # endif #endif #ifndef SWIGEXPORT # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # if defined(STATIC_LINKED) # define SWIGEXPORT # else # define SWIGEXPORT __declspec(dllexport) # endif # else # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) # define SWIGEXPORT __attribute__ ((visibility("default"))) # else # define SWIGEXPORT # endif # endif #endif /* calling conventions for Windows */ #ifndef SWIGSTDCALL # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # define SWIGSTDCALL __stdcall # else # define SWIGSTDCALL # endif #endif /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) # define _CRT_SECURE_NO_DEPRECATE #endif /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) # define _SCL_SECURE_NO_DEPRECATE #endif /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 #endif /* Intel's compiler complains if a variable which was never initialised is * cast to void, which is a common idiom which we use to indicate that we * are aware a variable isn't used. So we just silence that warning. * See: https://github.com/swig/swig/issues/192 for more discussion. */ #ifdef __INTEL_COMPILER # pragma warning disable 592 #endif #if __cplusplus >=201103L # define SWIG_NULLPTR nullptr #else # define SWIG_NULLPTR NULL #endif #if defined(__GNUC__) && defined(_WIN32) && !defined(SWIG_PYTHON_NO_HYPOT_WORKAROUND) /* Workaround for '::hypot' has not been declared', see https://bugs.python.org/issue11566 */ # include #endif #if !defined(PY_SSIZE_T_CLEAN) && !defined(SWIG_NO_PY_SSIZE_T_CLEAN) #define PY_SSIZE_T_CLEAN #endif #if __GNUC__ >= 7 #pragma GCC diagnostic push #if defined(__cplusplus) && __cplusplus >=201703L #pragma GCC diagnostic ignored "-Wregister" /* For python-2.7 headers that use register */ #endif #endif #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG) /* Use debug wrappers with the Python release dll */ #if defined(_MSC_VER) && _MSC_VER >= 1929 /* Workaround compilation errors when redefining _DEBUG in MSVC 2019 version 16.10 and later * See https://github.com/swig/swig/issues/2090 */ # include #endif # undef _DEBUG # include # define _DEBUG 1 #else # include #endif #if __GNUC__ >= 7 #pragma GCC diagnostic pop #endif #include /* ----------------------------------------------------------------------------- * swigrun.swg * * This file contains generic C API SWIG runtime support for pointer * type checking. * ----------------------------------------------------------------------------- */ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ #define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE # define SWIG_QUOTE_STRING(x) #x # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) #else # define SWIG_TYPE_TABLE_NAME #endif /* You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for creating a static or dynamic library from the SWIG runtime code. In 99.9% of the cases, SWIG just needs to declare them as 'static'. But only do this if strictly necessary, ie, if you have problems with your compiler or suchlike. */ #ifndef SWIGRUNTIME # define SWIGRUNTIME SWIGINTERN #endif #ifndef SWIGRUNTIMEINLINE # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE #endif /* Generic buffer size */ #ifndef SWIG_BUFFER_SIZE # define SWIG_BUFFER_SIZE 1024 #endif /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 #define SWIG_CAST_NEW_MEMORY 0x2 #define SWIG_POINTER_NO_NULL 0x4 #define SWIG_POINTER_CLEAR 0x8 #define SWIG_POINTER_RELEASE (SWIG_POINTER_CLEAR | SWIG_POINTER_DISOWN) /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 /* Flags/methods for returning states. The SWIG conversion methods, as ConvertPtr, return an integer that tells if the conversion was successful or not. And if not, an error code can be returned (see swigerrors.swg for the codes). Use the following macros/flags to set or process the returning states. In old versions of SWIG, code such as the following was usually written: if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { // success code } else { //fail code } Now you can be more explicit: int res = SWIG_ConvertPtr(obj,vptr,ty.flags); if (SWIG_IsOK(res)) { // success code } else { // fail code } which is the same really, but now you can also do Type *ptr; int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); if (SWIG_IsOK(res)) { // success code if (SWIG_IsNewObj(res) { ... delete *ptr; } else { ... } } else { // fail code } I.e., now SWIG_ConvertPtr can return new objects and you can identify the case and take care of the deallocation. Of course that also requires SWIG_ConvertPtr to return new result values, such as int SWIG_ConvertPtr(obj, ptr,...) { if () { if () { *ptr = ; return SWIG_NEWOBJ; } else { *ptr = ; return SWIG_OLDOBJ; } } else { return SWIG_BADOBJ; } } Of course, returning the plain '0(success)/-1(fail)' still works, but you can be more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the SWIG errors code. Finally, if the SWIG_CASTRANK_MODE is enabled, the result code allows returning the 'cast rank', for example, if you have this int food(double) int fooi(int); and you call food(1) // cast rank '1' (1 -> 1.0) fooi(1) // cast rank '0' just use the SWIG_AddCast()/SWIG_CheckState() */ #define SWIG_OK (0) /* Runtime errors are < 0 */ #define SWIG_ERROR (-1) /* Errors in range -1 to -99 are in swigerrors.swg (errors for all languages including those not using the runtime) */ /* Errors in range -100 to -199 are language specific errors defined in *errors.swg */ /* Errors < -200 are generic runtime specific errors */ #define SWIG_ERROR_RELEASE_NOT_OWNED (-200) #define SWIG_IsOK(r) (r >= 0) #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) /* The CastRankLimit says how many bits are used for the cast rank */ #define SWIG_CASTRANKLIMIT (1 << 8) /* The NewMask denotes the object was created (using new/malloc) */ #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) /* The TmpMask is for in/out typemaps that use temporary objects */ #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) /* Simple returning values */ #define SWIG_BADOBJ (SWIG_ERROR) #define SWIG_OLDOBJ (SWIG_OK) #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) /* Check, add and del object mask methods */ #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) /* Cast-Rank Mode */ #if defined(SWIG_CASTRANK_MODE) # ifndef SWIG_TypeRank # define SWIG_TypeRank unsigned long # endif # ifndef SWIG_MAXCASTRANK /* Default cast allowed */ # define SWIG_MAXCASTRANK (2) # endif # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) SWIGINTERNINLINE int SWIG_AddCast(int r) { return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; } SWIGINTERNINLINE int SWIG_CheckState(int r) { return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ # define SWIG_AddCast(r) (r) # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif /* C99 and C++11 should provide snprintf, but define SWIG_NO_SNPRINTF * if you're missing it. */ #if ((defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || \ (defined __cplusplus && __cplusplus >= 201103L) || \ defined SWIG_HAVE_SNPRINTF) && \ !defined SWIG_NO_SNPRINTF # define SWIG_snprintf(O,S,F,A) snprintf(O,S,F,A) # define SWIG_snprintf2(O,S,F,A,B) snprintf(O,S,F,A,B) #else /* Fallback versions ignore the buffer size, but most of our uses either have a * fixed maximum possible size or dynamically allocate a buffer that's large * enough. */ # define SWIG_snprintf(O,S,F,A) sprintf(O,F,A) # define SWIG_snprintf2(O,S,F,A,B) sprintf(O,F,A,B) #endif #include #ifdef __cplusplus extern "C" { #endif typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); /* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ struct swig_cast_info *cast; /* linked list of types that can cast into this type */ void *clientdata; /* language specific type data */ int owndata; /* flag if the structure owns the clientdata */ } swig_type_info; /* Structure to store a type and conversion function used for casting */ typedef struct swig_cast_info { swig_type_info *type; /* pointer to type that is equivalent to this type */ swig_converter_func converter; /* function to cast the void pointers */ struct swig_cast_info *next; /* pointer to next cast in linked list */ struct swig_cast_info *prev; /* pointer to the previous cast */ } swig_cast_info; /* Structure used to store module information * Each module generates one structure like this, and the runtime collects * all of these structures and stores them in a circularly linked list.*/ typedef struct swig_module_info { swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ size_t size; /* Number of types in this module */ struct swig_module_info *next; /* Pointer to next element in circularly linked list */ swig_type_info **type_initial; /* Array of initially generated type structures */ swig_cast_info **cast_initial; /* Array of initially generated casting structures */ void *clientdata; /* Language specific module data */ } swig_module_info; /* Compare two type names skipping the space characters, therefore "char*" == "char *" and "Class" == "Class", etc. Return 0 when the two name types are equivalent, as in strncmp, but skipping ' '. */ SWIGRUNTIME int SWIG_TypeNameComp(const char *f1, const char *l1, const char *f2, const char *l2) { for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { while ((*f1 == ' ') && (f1 != l1)) ++f1; while ((*f2 == ' ') && (f2 != l2)) ++f2; if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; } return (int)((l1 - f1) - (l2 - f2)); } /* Check type equivalence in a name list like ||... Return 0 if equal, -1 if nb < tb, 1 if nb > tb */ SWIGRUNTIME int SWIG_TypeCmp(const char *nb, const char *tb) { int equiv = 1; const char* te = tb + strlen(tb); const char* ne = nb; while (equiv != 0 && *ne) { for (nb = ne; *ne; ++ne) { if (*ne == '|') break; } equiv = SWIG_TypeNameComp(nb, ne, tb, te); if (*ne) ++ne; } return equiv; } /* Check type equivalence in a name list like ||... Return 0 if not equal, 1 if equal */ SWIGRUNTIME int SWIG_TypeEquiv(const char *nb, const char *tb) { return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; } /* Check the typename */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheck(const char *c, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (strcmp(iter->type->name, c) == 0) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheckStruct(const swig_type_info *from, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (iter->type == from) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* Dynamic pointer casting. Down an inheritance hierarchy */ SWIGRUNTIME swig_type_info * SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { swig_type_info *lastty = ty; if (!ty || !ty->dcast) return ty; while (ty && (ty->dcast)) { ty = (*ty->dcast)(ptr); if (ty) lastty = ty; } return lastty; } /* Return the name associated with this type */ SWIGRUNTIMEINLINE const char * SWIG_TypeName(const swig_type_info *ty) { return ty->name; } /* Return the pretty name associated with this type, that is an unmangled type name in a form presentable to the user. */ SWIGRUNTIME const char * SWIG_TypePrettyName(const swig_type_info *type) { /* The "str" field contains the equivalent pretty names of the type, separated by vertical-bar characters. Choose the last name. It should be the most specific; a fully resolved name but not necessarily with default template parameters expanded. */ if (!type) return NULL; if (type->str != NULL) { const char *last_name = type->str; const char *s; for (s = type->str; *s; s++) if (*s == '|') last_name = s+1; return last_name; } else return type->name; } /* Set the clientdata field for a type */ SWIGRUNTIME void SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { swig_cast_info *cast = ti->cast; /* if (ti->clientdata == clientdata) return; */ ti->clientdata = clientdata; while (cast) { if (!cast->converter) { swig_type_info *tc = cast->type; if (!tc->clientdata) { SWIG_TypeClientData(tc, clientdata); } } cast = cast->next; } } SWIGRUNTIME void SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { SWIG_TypeClientData(ti, clientdata); ti->owndata = 1; } /* Search for a swig_type_info structure only by mangled name Search is a O(log #types) We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_MangledTypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { swig_module_info *iter = start; do { if (iter->size) { size_t l = 0; size_t r = iter->size - 1; do { /* since l+r >= 0, we can (>> 1) instead (/ 2) */ size_t i = (l + r) >> 1; const char *iname = iter->types[i]->name; if (iname) { int compare = strcmp(name, iname); if (compare == 0) { return iter->types[i]; } else if (compare < 0) { if (i) { r = i - 1; } else { break; } } else if (compare > 0) { l = i + 1; } } else { break; /* should never happen */ } } while (l <= r); } iter = iter->next; } while (iter != end); return 0; } /* Search for a swig_type_info structure for either a mangled name or a human readable name. It first searches the mangled names of the types, which is a O(log #types) If a type is not found it then searches the human readable names, which is O(#types). We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_TypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { /* STEP 1: Search the name field using binary search */ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); if (ret) { return ret; } else { /* STEP 2: If the type hasn't been found, do a complete search of the str field (the human readable name) */ swig_module_info *iter = start; do { size_t i = 0; for (; i < iter->size; ++i) { if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) return iter->types[i]; } iter = iter->next; } while (iter != end); } /* neither found a match */ return 0; } /* Pack binary data into a string */ SWIGRUNTIME char * SWIG_PackData(char *c, void *ptr, size_t sz) { static const char hex[17] = "0123456789abcdef"; const unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { unsigned char uu = *u; *(c++) = hex[(uu & 0xf0) >> 4]; *(c++) = hex[uu & 0xf]; } return c; } /* Unpack binary data from a string */ SWIGRUNTIME const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { char d = *(c++); unsigned char uu; if ((d >= '0') && (d <= '9')) uu = (unsigned char)((d - '0') << 4); else if ((d >= 'a') && (d <= 'f')) uu = (unsigned char)((d - ('a'-10)) << 4); else return (char *) 0; d = *(c++); if ((d >= '0') && (d <= '9')) uu |= (unsigned char)(d - '0'); else if ((d >= 'a') && (d <= 'f')) uu |= (unsigned char)(d - ('a'-10)); else return (char *) 0; *u = uu; } return c; } /* Pack 'void *' into a string buffer. */ SWIGRUNTIME char * SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { char *r = buff; if ((2*sizeof(void *) + 2) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,&ptr,sizeof(void *)); if (strlen(name) + 1 > (bsz - (r - buff))) return 0; strcpy(r,name); return buff; } SWIGRUNTIME const char * SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { *ptr = (void *) 0; return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sizeof(void *)); } SWIGRUNTIME char * SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { char *r = buff; size_t lname = (name ? strlen(name) : 0); if ((2*sz + 2 + lname) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,ptr,sz); if (lname) { strncpy(r,name,lname+1); } else { *r = 0; } return buff; } SWIGRUNTIME const char * SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { memset(ptr,0,sz); return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sz); } #ifdef __cplusplus } #endif /* SWIG Errors applicable to all language modules, values are reserved from -1 to -99 */ #define SWIG_UnknownError -1 #define SWIG_IOError -2 #define SWIG_RuntimeError -3 #define SWIG_IndexError -4 #define SWIG_TypeError -5 #define SWIG_DivisionByZero -6 #define SWIG_OverflowError -7 #define SWIG_SyntaxError -8 #define SWIG_ValueError -9 #define SWIG_SystemError -10 #define SWIG_AttributeError -11 #define SWIG_MemoryError -12 #define SWIG_NullReferenceError -13 /* Compatibility macros for Python 3 */ #if PY_VERSION_HEX >= 0x03000000 #define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) #define PyInt_Check(x) PyLong_Check(x) #define PyInt_AsLong(x) PyLong_AsLong(x) #define PyInt_FromLong(x) PyLong_FromLong(x) #define PyInt_FromSize_t(x) PyLong_FromSize_t(x) #define PyString_Check(name) PyBytes_Check(name) #define PyString_FromString(x) PyUnicode_FromString(x) #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) #define PyString_AsString(str) PyBytes_AsString(str) #define PyString_Size(str) PyBytes_Size(str) #define PyString_InternFromString(key) PyUnicode_InternFromString(key) #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE #define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) #endif #ifndef Py_TYPE # define Py_TYPE(op) ((op)->ob_type) #endif /* SWIG APIs for compatibility of both Python 2 & 3 */ #if PY_VERSION_HEX >= 0x03000000 # define SWIG_Python_str_FromFormat PyUnicode_FromFormat #else # define SWIG_Python_str_FromFormat PyString_FromFormat #endif /* Wrapper around PyUnicode_AsUTF8AndSize - call Py_XDECREF on the returned pbytes when finished with the returned string */ SWIGINTERN const char * SWIG_PyUnicode_AsUTF8AndSize(PyObject *str, Py_ssize_t *psize, PyObject **pbytes) { #if PY_VERSION_HEX >= 0x03030000 # if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 *pbytes = NULL; return PyUnicode_AsUTF8AndSize(str, psize); # else *pbytes = PyUnicode_AsUTF8String(str); const char *chars = *pbytes ? PyBytes_AsString(*pbytes) : NULL; if (chars && psize) *psize = PyBytes_Size(*pbytes); return chars; # endif #else char *chars = NULL; *pbytes = NULL; PyString_AsStringAndSize(str, &chars, psize); return chars; #endif } SWIGINTERN PyObject* SWIG_Python_str_FromChar(const char *c) { #if PY_VERSION_HEX >= 0x03000000 return PyUnicode_FromString(c); #else return PyString_FromString(c); #endif } #ifndef PyObject_DEL # define PyObject_DEL PyObject_Del #endif /* SWIGPY_USE_CAPSULE is no longer used within SWIG itself, but some user interface files check for it. */ # define SWIGPY_USE_CAPSULE #ifdef SWIGPYTHON_BUILTIN # define SWIGPY_CAPSULE_ATTR_NAME "type_pointer_capsule_builtin" SWIG_TYPE_TABLE_NAME #else # define SWIGPY_CAPSULE_ATTR_NAME "type_pointer_capsule" SWIG_TYPE_TABLE_NAME #endif # define SWIGPY_CAPSULE_NAME ("swig_runtime_data" SWIG_RUNTIME_VERSION "." SWIGPY_CAPSULE_ATTR_NAME) #if PY_VERSION_HEX < 0x03020000 #define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type) #define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name) #define Py_hash_t long #endif #ifdef Py_LIMITED_API # define PyTuple_GET_ITEM PyTuple_GetItem /* Note that PyTuple_SetItem() has different semantics from PyTuple_SET_ITEM as it decref's the original tuple item, so in general they cannot be used interchangeably. However in SWIG-generated code PyTuple_SET_ITEM is only used with newly initialized tuples without any items and for them this does work. */ # define PyTuple_SET_ITEM PyTuple_SetItem # define PyTuple_GET_SIZE PyTuple_Size # define PyCFunction_GET_FLAGS PyCFunction_GetFlags # define PyCFunction_GET_FUNCTION PyCFunction_GetFunction # define PyCFunction_GET_SELF PyCFunction_GetSelf # define PyList_GET_ITEM PyList_GetItem # define PyList_SET_ITEM PyList_SetItem # define PySliceObject PyObject #endif /* ----------------------------------------------------------------------------- * error manipulation * ----------------------------------------------------------------------------- */ SWIGRUNTIME PyObject* SWIG_Python_ErrorType(int code) { PyObject* type = 0; switch(code) { case SWIG_MemoryError: type = PyExc_MemoryError; break; case SWIG_IOError: type = PyExc_IOError; break; case SWIG_RuntimeError: type = PyExc_RuntimeError; break; case SWIG_IndexError: type = PyExc_IndexError; break; case SWIG_TypeError: type = PyExc_TypeError; break; case SWIG_DivisionByZero: type = PyExc_ZeroDivisionError; break; case SWIG_OverflowError: type = PyExc_OverflowError; break; case SWIG_SyntaxError: type = PyExc_SyntaxError; break; case SWIG_ValueError: type = PyExc_ValueError; break; case SWIG_SystemError: type = PyExc_SystemError; break; case SWIG_AttributeError: type = PyExc_AttributeError; break; default: type = PyExc_RuntimeError; } return type; } SWIGRUNTIME void SWIG_Python_AddErrorMsg(const char* mesg) { PyObject *type = 0; PyObject *value = 0; PyObject *traceback = 0; if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); if (value) { PyObject *old_str = PyObject_Str(value); PyObject *bytes = NULL; const char *tmp = SWIG_PyUnicode_AsUTF8AndSize(old_str, NULL, &bytes); PyErr_Clear(); Py_XINCREF(type); if (tmp) PyErr_Format(type, "%s %s", tmp, mesg); else PyErr_Format(type, "%s", mesg); Py_XDECREF(bytes); Py_DECREF(old_str); Py_DECREF(value); } else { PyErr_SetString(PyExc_RuntimeError, mesg); } } SWIGRUNTIME int SWIG_Python_TypeErrorOccurred(PyObject *obj) { PyObject *error; if (obj) return 0; error = PyErr_Occurred(); return error && PyErr_GivenExceptionMatches(error, PyExc_TypeError); } SWIGRUNTIME void SWIG_Python_RaiseOrModifyTypeError(const char *message) { if (SWIG_Python_TypeErrorOccurred(NULL)) { /* Use existing TypeError to preserve stacktrace and enhance with given message */ PyObject *newvalue; PyObject *type = NULL, *value = NULL, *traceback = NULL; PyErr_Fetch(&type, &value, &traceback); #if PY_VERSION_HEX >= 0x03000000 newvalue = PyUnicode_FromFormat("%S\nAdditional information:\n%s", value, message); #else newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message); #endif if (newvalue) { Py_XDECREF(value); PyErr_Restore(type, newvalue, traceback); } else { PyErr_Restore(type, value, traceback); } } else { /* Raise TypeError using given message */ PyErr_SetString(PyExc_TypeError, message); } } #if defined(SWIG_PYTHON_NO_THREADS) # if defined(SWIG_PYTHON_THREADS) # undef SWIG_PYTHON_THREADS # endif #endif #if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ # if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) # define SWIG_PYTHON_USE_GIL # endif # if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ # if !defined(SWIG_PYTHON_INITIALIZE_THREADS) # if PY_VERSION_HEX < 0x03070000 # define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() # else # define SWIG_PYTHON_INITIALIZE_THREADS # endif # endif # ifdef __cplusplus /* C++ code */ class SWIG_Python_Thread_Block { bool status; PyGILState_STATE state; public: void end() { if (status) { PyGILState_Release(state); status = false;} } SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} ~SWIG_Python_Thread_Block() { end(); } }; class SWIG_Python_Thread_Allow { bool status; PyThreadState *save; public: void end() { if (status) { status = false; PyEval_RestoreThread(save); }} SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} ~SWIG_Python_Thread_Allow() { end(); } }; # define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block # define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() # define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow # define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() # else /* C code */ # define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() # define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) # define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() # define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) # endif # else /* Old thread way, not implemented, user must provide it */ # if !defined(SWIG_PYTHON_INITIALIZE_THREADS) # define SWIG_PYTHON_INITIALIZE_THREADS # endif # if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) # define SWIG_PYTHON_THREAD_BEGIN_BLOCK # endif # if !defined(SWIG_PYTHON_THREAD_END_BLOCK) # define SWIG_PYTHON_THREAD_END_BLOCK # endif # if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) # define SWIG_PYTHON_THREAD_BEGIN_ALLOW # endif # if !defined(SWIG_PYTHON_THREAD_END_ALLOW) # define SWIG_PYTHON_THREAD_END_ALLOW # endif # endif #else /* No thread support */ # define SWIG_PYTHON_INITIALIZE_THREADS # define SWIG_PYTHON_THREAD_BEGIN_BLOCK # define SWIG_PYTHON_THREAD_END_BLOCK # define SWIG_PYTHON_THREAD_BEGIN_ALLOW # define SWIG_PYTHON_THREAD_END_ALLOW #endif /* ----------------------------------------------------------------------------- * Python API portion that goes into the runtime * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #endif /* ----------------------------------------------------------------------------- * Constant declarations * ----------------------------------------------------------------------------- */ /* Constant Types */ #define SWIG_PY_POINTER 4 #define SWIG_PY_BINARY 5 /* Constant information structure */ typedef struct swig_const_info { int type; const char *name; long lvalue; double dvalue; void *pvalue; swig_type_info **ptype; } swig_const_info; #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * pyrun.swg * * This file contains the runtime support for Python modules * and includes code for managing global variables and pointer * type checking. * * ----------------------------------------------------------------------------- */ #if PY_VERSION_HEX < 0x02070000 /* 2.7.0 */ # error "This version of SWIG only supports Python >= 2.7" #endif #if PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03030000 # error "This version of SWIG only supports Python 3 >= 3.3" #endif /* Common SWIG API */ /* for raw pointers */ #define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) #ifdef SWIGPYTHON_BUILTIN #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(self, ptr, type, flags) #else #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) #endif #define SWIG_InternalNewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) #define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) #define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) #define swig_owntype int /* for raw packed data */ #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) /* for class or struct pointers */ #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) /* for C or C++ function pointers */ #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(NULL, ptr, type, 0) /* for C++ member pointers, ie, member methods */ #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) /* Runtime API */ #define SWIG_GetModule(clientdata) SWIG_Python_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) #define SWIG_NewClientData(obj) SwigPyClientData_New(obj) #define SWIG_SetErrorObj SWIG_Python_SetErrorObj #define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg #define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) #define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) #define SWIG_fail goto fail /* Runtime API implementation */ /* Error manipulation */ SWIGINTERN void SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetObject(errtype, obj); Py_DECREF(obj); SWIG_PYTHON_THREAD_END_BLOCK; } SWIGINTERN void SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetString(errtype, msg); SWIG_PYTHON_THREAD_END_BLOCK; } #define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) /* Set a constant value */ #if defined(SWIGPYTHON_BUILTIN) SWIGINTERN void SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) { PyObject *s = PyString_InternFromString(key); PyList_Append(seq, s); Py_DECREF(s); } SWIGINTERN void SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { PyDict_SetItemString(d, name, obj); Py_DECREF(obj); if (public_interface) SwigPyBuiltin_AddPublicSymbol(public_interface, name); } #else SWIGINTERN void SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { PyDict_SetItemString(d, name, obj); Py_DECREF(obj); } #endif /* Append a value to the result obj */ SWIGINTERN PyObject* SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { if (!result) { result = obj; } else if (result == Py_None) { Py_DECREF(result); result = obj; } else { if (!PyList_Check(result)) { PyObject *o2 = result; result = PyList_New(1); if (result) { PyList_SET_ITEM(result, 0, o2); } else { Py_DECREF(obj); return o2; } } PyList_Append(result,obj); Py_DECREF(obj); } return result; } /* Unpack the argument tuple */ SWIGINTERN Py_ssize_t SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) { if (!args) { if (!min && !max) { return 1; } else { PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", name, (min == max ? "" : "at least "), (int)min); return 0; } } if (!PyTuple_Check(args)) { if (min <= 1 && max >= 1) { Py_ssize_t i; objs[0] = args; for (i = 1; i < max; ++i) { objs[i] = 0; } return 2; } PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); return 0; } else { Py_ssize_t l = PyTuple_GET_SIZE(args); if (l < min) { PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", name, (min == max ? "" : "at least "), (int)min, (int)l); return 0; } else if (l > max) { PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", name, (min == max ? "" : "at most "), (int)max, (int)l); return 0; } else { Py_ssize_t i; for (i = 0; i < l; ++i) { objs[i] = PyTuple_GET_ITEM(args, i); } for (; l < max; ++l) { objs[l] = 0; } return i + 1; } } } SWIGINTERN int SWIG_Python_CheckNoKeywords(PyObject *kwargs, const char *name) { int no_kwargs = 1; if (kwargs) { assert(PyDict_Check(kwargs)); if (PyDict_Size(kwargs) > 0) { PyErr_Format(PyExc_TypeError, "%s() does not take keyword arguments", name); no_kwargs = 0; } } return no_kwargs; } /* A functor is a function object with one single object argument */ #define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); /* Helper for static pointer initialization for both C and C++ code, for example static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); */ #ifdef __cplusplus #define SWIG_STATIC_POINTER(var) var #else #define SWIG_STATIC_POINTER(var) var = 0; if (!var) var #endif #ifdef __cplusplus extern "C" { #endif /* Python-specific SWIG API */ #define SWIG_newvarlink() SWIG_Python_newvarlink() #define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) #define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) /* ----------------------------------------------------------------------------- * global variable support code. * ----------------------------------------------------------------------------- */ typedef struct swig_globalvar { char *name; /* Name of global variable */ PyObject *(*get_attr)(void); /* Return the current value */ int (*set_attr)(PyObject *); /* Set the value */ struct swig_globalvar *next; } swig_globalvar; typedef struct swig_varlinkobject { PyObject_HEAD swig_globalvar *vars; } swig_varlinkobject; SWIGINTERN PyObject * swig_varlink_repr(PyObject *SWIGUNUSEDPARM(v)) { #if PY_VERSION_HEX >= 0x03000000 return PyUnicode_InternFromString(""); #else return PyString_FromString(""); #endif } SWIGINTERN PyObject * swig_varlink_str(PyObject *o) { swig_varlinkobject *v = (swig_varlinkobject *) o; #if PY_VERSION_HEX >= 0x03000000 PyObject *str = PyUnicode_InternFromString("("); PyObject *tail; PyObject *joined; swig_globalvar *var; for (var = v->vars; var; var=var->next) { tail = PyUnicode_FromString(var->name); joined = PyUnicode_Concat(str, tail); Py_DecRef(str); Py_DecRef(tail); str = joined; if (var->next) { tail = PyUnicode_InternFromString(", "); joined = PyUnicode_Concat(str, tail); Py_DecRef(str); Py_DecRef(tail); str = joined; } } tail = PyUnicode_InternFromString(")"); joined = PyUnicode_Concat(str, tail); Py_DecRef(str); Py_DecRef(tail); str = joined; #else PyObject *str = PyString_FromString("("); swig_globalvar *var; for (var = v->vars; var; var=var->next) { PyString_ConcatAndDel(&str,PyString_FromString(var->name)); if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); } PyString_ConcatAndDel(&str,PyString_FromString(")")); #endif return str; } SWIGINTERN void swig_varlink_dealloc(PyObject *o) { swig_varlinkobject *v = (swig_varlinkobject *) o; swig_globalvar *var = v->vars; while (var) { swig_globalvar *n = var->next; free(var->name); free(var); var = n; } } SWIGINTERN PyObject * swig_varlink_getattr(PyObject *o, char *n) { swig_varlinkobject *v = (swig_varlinkobject *) o; PyObject *res = NULL; swig_globalvar *var = v->vars; while (var) { if (strcmp(var->name,n) == 0) { res = (*var->get_attr)(); break; } var = var->next; } if (res == NULL && !PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; } SWIGINTERN int swig_varlink_setattr(PyObject *o, char *n, PyObject *p) { swig_varlinkobject *v = (swig_varlinkobject *) o; int res = 1; swig_globalvar *var = v->vars; while (var) { if (strcmp(var->name,n) == 0) { res = (*var->set_attr)(p); break; } var = var->next; } if (res == 1 && !PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; } SWIGINTERN PyTypeObject* swig_varlink_type(void) { static char varlink__doc__[] = "Swig var link object"; #ifndef Py_LIMITED_API static PyTypeObject varlink_type; static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { #if PY_VERSION_HEX >= 0x03000000 PyVarObject_HEAD_INIT(NULL, 0) #else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif "swigvarlink", /* tp_name */ sizeof(swig_varlinkobject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor) swig_varlink_dealloc, /* tp_dealloc */ #if PY_VERSION_HEX < 0x030800b4 (printfunc)0, /*tp_print*/ #else (Py_ssize_t)0, /*tp_vectorcall_offset*/ #endif (getattrfunc) swig_varlink_getattr, /* tp_getattr */ (setattrfunc) swig_varlink_setattr, /* tp_setattr */ 0, /* tp_compare */ (reprfunc) swig_varlink_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ (reprfunc) swig_varlink_str, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ 0, /* tp_flags */ varlink__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ 0, /* tp_del */ 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif #if PY_VERSION_HEX >= 0x03080000 0, /* tp_vectorcall */ #endif #if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) 0, /* tp_print */ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /* tp_watched */ #endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ 0, /* tp_maxalloc */ 0, /* tp_prev */ 0 /* tp_next */ #endif }; varlink_type = tmp; type_init = 1; if (PyType_Ready(&varlink_type) < 0) return NULL; } return &varlink_type; #else PyType_Slot slots[] = { { Py_tp_dealloc, (void *)swig_varlink_dealloc }, { Py_tp_repr, (void *)swig_varlink_repr }, { Py_tp_getattr, (void *)swig_varlink_getattr }, { Py_tp_setattr, (void *)swig_varlink_setattr }, { Py_tp_str, (void *)swig_varlink_str }, { Py_tp_doc, (void *)varlink__doc__ }, { 0, NULL } }; PyType_Spec spec = { "swigvarlink", sizeof(swig_varlinkobject), 0, Py_TPFLAGS_DEFAULT, slots }; return (PyTypeObject *)PyType_FromSpec(&spec); #endif } /* Create a variable linking object for use later */ SWIGINTERN PyObject * SWIG_Python_newvarlink(void) { swig_varlinkobject *result = PyObject_New(swig_varlinkobject, swig_varlink_type()); if (result) { result->vars = 0; } return ((PyObject*) result); } SWIGINTERN void SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { swig_varlinkobject *v = (swig_varlinkobject *) p; swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); if (gv) { size_t size = strlen(name)+1; gv->name = (char *)malloc(size); if (gv->name) { memcpy(gv->name, name, size); gv->get_attr = get_attr; gv->set_attr = set_attr; gv->next = v->vars; } } v->vars = gv; } static PyObject *Swig_Globals_global = NULL; SWIGINTERN PyObject * SWIG_globals(void) { if (Swig_Globals_global == NULL) { Swig_Globals_global = SWIG_newvarlink(); } return Swig_Globals_global; } #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * Pointer declarations * ----------------------------------------------------------------------------- */ /* Flags for new pointer objects */ #define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) #define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) #define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) #define SWIG_BUILTIN_TP_INIT (SWIG_POINTER_OWN << 2) #define SWIG_BUILTIN_INIT (SWIG_BUILTIN_TP_INIT | SWIG_POINTER_OWN) #ifdef __cplusplus extern "C" { #endif /* The python void return value */ SWIGRUNTIMEINLINE PyObject * SWIG_Py_Void(void) { PyObject *none = Py_None; Py_INCREF(none); return none; } /* SwigPyClientData */ typedef struct { PyObject *klass; PyObject *newraw; PyObject *newargs; PyObject *destroy; int delargs; int implicitconv; PyTypeObject *pytype; } SwigPyClientData; SWIGRUNTIMEINLINE int SWIG_Python_CheckImplicit(swig_type_info *ty) { SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; int fail = data ? data->implicitconv : 0; if (fail) PyErr_SetString(PyExc_TypeError, "Implicit conversion is prohibited for explicit constructors."); return fail; } SWIGRUNTIMEINLINE PyObject * SWIG_Python_ExceptionType(swig_type_info *desc) { SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; PyObject *klass = data ? data->klass : 0; return (klass ? klass : PyExc_RuntimeError); } SWIGRUNTIME SwigPyClientData * SwigPyClientData_New(PyObject* obj) { if (!obj) { return 0; } else { SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); /* the klass element */ data->klass = obj; Py_INCREF(data->klass); /* the newraw method and newargs arguments used to create a new raw instance */ if (PyClass_Check(obj)) { data->newraw = 0; Py_INCREF(obj); data->newargs = obj; } else { data->newraw = PyObject_GetAttrString(data->klass, "__new__"); if (data->newraw) { data->newargs = PyTuple_New(1); if (data->newargs) { Py_INCREF(obj); PyTuple_SET_ITEM(data->newargs, 0, obj); } else { Py_DECREF(data->newraw); Py_DECREF(data->klass); free(data); return 0; } } else { Py_INCREF(obj); data->newargs = obj; } } /* the destroy method, aka as the C++ delete method */ data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__"); if (PyErr_Occurred()) { PyErr_Clear(); data->destroy = 0; } if (data->destroy) { data->delargs = !(PyCFunction_GET_FLAGS(data->destroy) & METH_O); } else { data->delargs = 0; } data->implicitconv = 0; data->pytype = 0; return data; } } SWIGRUNTIME void SwigPyClientData_Del(SwigPyClientData *data) { Py_XDECREF(data->klass); Py_XDECREF(data->newraw); Py_XDECREF(data->newargs); Py_XDECREF(data->destroy); free(data); } /* =============== SwigPyObject =====================*/ typedef struct { PyObject_HEAD void *ptr; swig_type_info *ty; int own; PyObject *next; #ifdef SWIGPYTHON_BUILTIN PyObject *dict; #endif } SwigPyObject; #ifdef SWIGPYTHON_BUILTIN SWIGRUNTIME PyObject * SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)v; if (!sobj->dict) sobj->dict = PyDict_New(); Py_XINCREF(sobj->dict); return sobj->dict; } #endif SWIGRUNTIME PyObject * SwigPyObject_long(SwigPyObject *v) { return PyLong_FromVoidPtr(v->ptr); } SWIGRUNTIME PyObject * SwigPyObject_format(const char* fmt, SwigPyObject *v) { PyObject *res = NULL; PyObject *args = PyTuple_New(1); if (args) { PyObject *val = SwigPyObject_long(v); if (val) { PyObject *ofmt; PyTuple_SET_ITEM(args, 0, val); ofmt = SWIG_Python_str_FromChar(fmt); if (ofmt) { #if PY_VERSION_HEX >= 0x03000000 res = PyUnicode_Format(ofmt,args); #else res = PyString_Format(ofmt,args); #endif Py_DECREF(ofmt); } } Py_DECREF(args); } return res; } SWIGRUNTIME PyObject * SwigPyObject_oct(SwigPyObject *v) { return SwigPyObject_format("%o",v); } SWIGRUNTIME PyObject * SwigPyObject_hex(SwigPyObject *v) { return SwigPyObject_format("%x",v); } SWIGRUNTIME PyObject * SwigPyObject_repr(SwigPyObject *v) { const char *name = SWIG_TypePrettyName(v->ty); PyObject *repr = SWIG_Python_str_FromFormat("", (name ? name : "unknown"), (void *)v); if (repr && v->next) { PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); if (nrep) { # if PY_VERSION_HEX >= 0x03000000 PyObject *joined = PyUnicode_Concat(repr, nrep); Py_DecRef(repr); Py_DecRef(nrep); repr = joined; # else PyString_ConcatAndDel(&repr,nrep); # endif } else { Py_DecRef(repr); repr = NULL; } } return repr; } /* We need a version taking two PyObject* parameters so it's a valid * PyCFunction to use in swigobject_methods[]. */ SWIGRUNTIME PyObject * SwigPyObject_repr2(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { return SwigPyObject_repr((SwigPyObject*)v); } SWIGRUNTIME int SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) { void *i = v->ptr; void *j = w->ptr; return (i < j) ? -1 : ((i > j) ? 1 : 0); } /* Added for Python 3.x, would it also be useful for Python 2.x? */ SWIGRUNTIME PyObject* SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) { PyObject* res = NULL; if (!PyErr_Occurred()) { if (op != Py_EQ && op != Py_NE) { Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0); } return res; } SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void); #ifdef SWIGPYTHON_BUILTIN static swig_type_info *SwigPyObject_stype = 0; SWIGRUNTIME PyTypeObject* SwigPyObject_type(void) { SwigPyClientData *cd; assert(SwigPyObject_stype); cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; assert(cd); assert(cd->pytype); return cd->pytype; } #else SWIGRUNTIME PyTypeObject* SwigPyObject_type(void) { static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce(); return type; } #endif SWIGRUNTIMEINLINE int SwigPyObject_Check(PyObject *op) { PyTypeObject *target_tp = SwigPyObject_type(); PyTypeObject *op_type = Py_TYPE(op); #ifdef SWIGPYTHON_BUILTIN if (PyType_IsSubtype(op_type, target_tp)) return 1; return (strcmp(op_type->tp_name, "SwigPyObject") == 0); #else if (op_type == target_tp) return 1; # ifdef Py_LIMITED_API int cmp; PyObject *tp_name = PyObject_GetAttrString((PyObject *)op_type, "__name__"); if (!tp_name) return 0; cmp = PyUnicode_CompareWithASCIIString(tp_name, "SwigPyObject"); Py_DECREF(tp_name); return cmp == 0; # else return (strcmp(op_type->tp_name, "SwigPyObject") == 0); # endif #endif } SWIGRUNTIME PyObject * SwigPyObject_New(void *ptr, swig_type_info *ty, int own); static PyObject* Swig_Capsule_global = NULL; SWIGRUNTIME void SwigPyObject_dealloc(PyObject *v) { SwigPyObject *sobj = (SwigPyObject *) v; PyObject *next = sobj->next; if (sobj->own == SWIG_POINTER_OWN) { swig_type_info *ty = sobj->ty; SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; PyObject *destroy = data ? data->destroy : 0; if (destroy) { /* destroy is always a VARARGS method */ PyObject *res; /* PyObject_CallFunction() has the potential to silently drop the active exception. In cases of unnamed temporary variable or where we just finished iterating over a generator StopIteration will be active right now, and this needs to remain true upon return from SwigPyObject_dealloc. So save and restore. */ PyObject *type = NULL, *value = NULL, *traceback = NULL; PyErr_Fetch(&type, &value, &traceback); if (data->delargs) { /* we need to create a temporary object to carry the destroy operation */ PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); if (tmp) { res = SWIG_Python_CallFunctor(destroy, tmp); } else { res = 0; } Py_XDECREF(tmp); } else { PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); PyObject *mself = PyCFunction_GET_SELF(destroy); res = ((*meth)(mself, v)); } if (!res) PyErr_WriteUnraisable(destroy); PyErr_Restore(type, value, traceback); Py_XDECREF(res); } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) else { const char *name = SWIG_TypePrettyName(ty); printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); } #endif Py_XDECREF(Swig_Capsule_global); } Py_XDECREF(next); #ifdef SWIGPYTHON_BUILTIN Py_XDECREF(sobj->dict); #endif PyObject_DEL(v); } SWIGRUNTIME PyObject* SwigPyObject_append(PyObject* v, PyObject* next) { SwigPyObject *sobj = (SwigPyObject *) v; if (!SwigPyObject_Check(next)) { PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject"); return NULL; } ((SwigPyObject *)next)->next = sobj->next; sobj->next = next; Py_INCREF(next); return SWIG_Py_Void(); } SWIGRUNTIME PyObject* SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *) v; if (sobj->next) { Py_INCREF(sobj->next); return sobj->next; } else { return SWIG_Py_Void(); } } SWIGINTERN PyObject* SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)v; sobj->own = 0; return SWIG_Py_Void(); } SWIGINTERN PyObject* SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)v; sobj->own = SWIG_POINTER_OWN; return SWIG_Py_Void(); } SWIGINTERN PyObject* SwigPyObject_own(PyObject *v, PyObject *args) { PyObject *val = 0; if (!PyArg_UnpackTuple(args, "own", 0, 1, &val)) { return NULL; } else { SwigPyObject *sobj = (SwigPyObject *)v; PyObject *obj = PyBool_FromLong(sobj->own); if (val) { if (PyObject_IsTrue(val)) { Py_DECREF(SwigPyObject_acquire(v,args)); } else { Py_DECREF(SwigPyObject_disown(v,args)); } } return obj; } } static PyMethodDef swigobject_methods[] = { {"disown", SwigPyObject_disown, METH_NOARGS, "releases ownership of the pointer"}, {"acquire", SwigPyObject_acquire, METH_NOARGS, "acquires ownership of the pointer"}, {"own", SwigPyObject_own, METH_VARARGS, "returns/sets ownership of the pointer"}, {"append", SwigPyObject_append, METH_O, "appends another 'this' object"}, {"next", SwigPyObject_next, METH_NOARGS, "returns the next 'this' object"}, {"__repr__",SwigPyObject_repr2, METH_NOARGS, "returns object representation"}, {0, 0, 0, 0} }; SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void) { static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; #ifndef Py_LIMITED_API static PyNumberMethods SwigPyObject_as_number = { (binaryfunc)0, /*nb_add*/ (binaryfunc)0, /*nb_subtract*/ (binaryfunc)0, /*nb_multiply*/ /* nb_divide removed in Python 3 */ #if PY_VERSION_HEX < 0x03000000 (binaryfunc)0, /*nb_divide*/ #endif (binaryfunc)0, /*nb_remainder*/ (binaryfunc)0, /*nb_divmod*/ (ternaryfunc)0,/*nb_power*/ (unaryfunc)0, /*nb_negative*/ (unaryfunc)0, /*nb_positive*/ (unaryfunc)0, /*nb_absolute*/ (inquiry)0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_VERSION_HEX < 0x03000000 0, /*nb_coerce*/ #endif (unaryfunc)SwigPyObject_long, /*nb_int*/ #if PY_VERSION_HEX < 0x03000000 (unaryfunc)SwigPyObject_long, /*nb_long*/ #else 0, /*nb_reserved*/ #endif (unaryfunc)0, /*nb_float*/ #if PY_VERSION_HEX < 0x03000000 (unaryfunc)SwigPyObject_oct, /*nb_oct*/ (unaryfunc)SwigPyObject_hex, /*nb_hex*/ #endif #if PY_VERSION_HEX >= 0x03050000 /* 3.5 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_matrix_multiply */ #elif PY_VERSION_HEX >= 0x03000000 /* 3.0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ #else 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ #endif }; static PyTypeObject swigpyobject_type; static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { #if PY_VERSION_HEX >= 0x03000000 PyVarObject_HEAD_INIT(NULL, 0) #else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif "SwigPyObject", /* tp_name */ sizeof(SwigPyObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)SwigPyObject_dealloc, /* tp_dealloc */ #if PY_VERSION_HEX < 0x030800b4 (printfunc)0, /*tp_print*/ #else (Py_ssize_t)0, /*tp_vectorcall_offset*/ #endif (getattrfunc)0, /* tp_getattr */ (setattrfunc)0, /* tp_setattr */ #if PY_VERSION_HEX >= 0x03000000 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ #else (cmpfunc)SwigPyObject_compare, /* tp_compare */ #endif (reprfunc)SwigPyObject_repr, /* tp_repr */ &SwigPyObject_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)0, /* tp_hash */ (ternaryfunc)0, /* tp_call */ 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ swigobject_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ (richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ swigobject_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ 0, /* tp_bases */ 0, /* tp_mro */ 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ 0, /* tp_del */ 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif #if PY_VERSION_HEX >= 0x03080000 0, /* tp_vectorcall */ #endif #if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) 0, /* tp_print */ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /* tp_watched */ #endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ 0, /* tp_maxalloc */ 0, /* tp_prev */ 0 /* tp_next */ #endif }; swigpyobject_type = tmp; type_init = 1; if (PyType_Ready(&swigpyobject_type) != 0) return NULL; } return &swigpyobject_type; #else PyType_Slot slots[] = { { Py_tp_dealloc, (void *)SwigPyObject_dealloc }, { Py_tp_repr, (void *)SwigPyObject_repr }, { Py_tp_getattro, (void *)PyObject_GenericGetAttr }, { Py_tp_doc, (void *)swigobject_doc }, { Py_tp_richcompare, (void *)SwigPyObject_richcompare }, { Py_tp_methods, (void *)swigobject_methods }, { Py_nb_int, (void *)SwigPyObject_long }, { 0, NULL } }; PyType_Spec spec = { "SwigPyObject", sizeof(SwigPyObject), 0, Py_TPFLAGS_DEFAULT, slots }; return (PyTypeObject *)PyType_FromSpec(&spec); #endif } SWIGRUNTIME PyObject * SwigPyObject_New(void *ptr, swig_type_info *ty, int own) { SwigPyObject *sobj = PyObject_New(SwigPyObject, SwigPyObject_type()); if (sobj) { sobj->ptr = ptr; sobj->ty = ty; sobj->own = own; sobj->next = 0; #ifdef SWIGPYTHON_BUILTIN sobj->dict = 0; #endif if (own == SWIG_POINTER_OWN) { /* Obtain a reference to the Python capsule wrapping the module information, so that the * module information is correctly destroyed after all SWIG python objects have been freed * by the GC (and corresponding destructors invoked) */ Py_XINCREF(Swig_Capsule_global); } } return (PyObject *)sobj; } /* ----------------------------------------------------------------------------- * Implements a simple Swig Packed type, and use it instead of string * ----------------------------------------------------------------------------- */ typedef struct { PyObject_HEAD void *pack; swig_type_info *ty; size_t size; } SwigPyPacked; SWIGRUNTIME PyObject * SwigPyPacked_repr(SwigPyPacked *v) { char result[SWIG_BUFFER_SIZE]; if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { return SWIG_Python_str_FromFormat("", result, v->ty->name); } else { return SWIG_Python_str_FromFormat("", v->ty->name); } } SWIGRUNTIME PyObject * SwigPyPacked_str(SwigPyPacked *v) { char result[SWIG_BUFFER_SIZE]; if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); } else { return SWIG_Python_str_FromChar(v->ty->name); } } SWIGRUNTIME int SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) { size_t i = v->size; size_t j = w->size; int s = (i < j) ? -1 : ((i > j) ? 1 : 0); return s ? s : strncmp((const char *)v->pack, (const char *)w->pack, 2*v->size); } SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void); SWIGRUNTIME PyTypeObject* SwigPyPacked_type(void) { static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce(); return type; } SWIGRUNTIMEINLINE int SwigPyPacked_Check(PyObject *op) { PyTypeObject* op_type = Py_TYPE(op); if (op_type == SwigPyPacked_TypeOnce()) return 1; #ifdef Py_LIMITED_API int cmp; PyObject *tp_name = PyObject_GetAttrString((PyObject *)op_type, "__name__"); if (!tp_name) return 0; cmp = PyUnicode_CompareWithASCIIString(tp_name, "SwigPyPacked"); Py_DECREF(tp_name); return cmp == 0; #else return (strcmp(op_type->tp_name, "SwigPyPacked") == 0); #endif } SWIGRUNTIME void SwigPyPacked_dealloc(PyObject *v) { if (SwigPyPacked_Check(v)) { SwigPyPacked *sobj = (SwigPyPacked *) v; free(sobj->pack); } PyObject_DEL(v); } SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void) { static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; #ifndef Py_LIMITED_API static PyTypeObject swigpypacked_type; static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { #if PY_VERSION_HEX>=0x03000000 PyVarObject_HEAD_INIT(NULL, 0) #else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif "SwigPyPacked", /* tp_name */ sizeof(SwigPyPacked), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ #if PY_VERSION_HEX < 0x030800b4 (printfunc)0, /*tp_print*/ #else (Py_ssize_t)0, /*tp_vectorcall_offset*/ #endif (getattrfunc)0, /* tp_getattr */ (setattrfunc)0, /* tp_setattr */ #if PY_VERSION_HEX>=0x03000000 0, /* tp_reserved in 3.0.1 */ #else (cmpfunc)SwigPyPacked_compare, /* tp_compare */ #endif (reprfunc)SwigPyPacked_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)0, /* tp_hash */ (ternaryfunc)0, /* tp_call */ (reprfunc)SwigPyPacked_str, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ swigpacked_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ 0, /* tp_bases */ 0, /* tp_mro */ 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ 0, /* tp_del */ 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif #if PY_VERSION_HEX >= 0x03080000 0, /* tp_vectorcall */ #endif #if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) 0, /* tp_print */ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /* tp_watched */ #endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ 0, /* tp_maxalloc */ 0, /* tp_prev */ 0 /* tp_next */ #endif }; swigpypacked_type = tmp; type_init = 1; if (PyType_Ready(&swigpypacked_type) != 0) return NULL; } return &swigpypacked_type; #else PyType_Slot slots[] = { { Py_tp_dealloc, (void *)SwigPyPacked_dealloc }, { Py_tp_repr, (void *)SwigPyPacked_repr }, { Py_tp_str, (void *)SwigPyPacked_str }, { Py_tp_getattro, (void *)PyObject_GenericGetAttr }, { Py_tp_doc, (void *)swigpacked_doc }, { 0, NULL } }; PyType_Spec spec = { "SwigPyPacked", sizeof(SwigPyPacked), 0, Py_TPFLAGS_DEFAULT, slots }; return (PyTypeObject *)PyType_FromSpec(&spec); #endif } SWIGRUNTIME PyObject * SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) { SwigPyPacked *sobj = PyObject_New(SwigPyPacked, SwigPyPacked_type()); if (sobj) { void *pack = malloc(size); if (pack) { memcpy(pack, ptr, size); sobj->pack = pack; sobj->ty = ty; sobj->size = size; } else { PyObject_DEL((PyObject *) sobj); sobj = 0; } } return (PyObject *) sobj; } SWIGRUNTIME swig_type_info * SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) { if (SwigPyPacked_Check(obj)) { SwigPyPacked *sobj = (SwigPyPacked *)obj; if (sobj->size != size) return 0; memcpy(ptr, sobj->pack, size); return sobj->ty; } else { return 0; } } /* ----------------------------------------------------------------------------- * pointers/data manipulation * ----------------------------------------------------------------------------- */ static PyObject *Swig_This_global = NULL; SWIGRUNTIME PyObject * SWIG_This(void) { if (Swig_This_global == NULL) Swig_This_global = SWIG_Python_str_FromChar("this"); return Swig_This_global; } /* #define SWIG_PYTHON_SLOW_GETSET_THIS */ /* TODO: I don't know how to implement the fast getset in Python 3 right now */ #if PY_VERSION_HEX>=0x03000000 #define SWIG_PYTHON_SLOW_GETSET_THIS #endif SWIGRUNTIME SwigPyObject * SWIG_Python_GetSwigThis(PyObject *pyobj) { PyObject *obj; if (SwigPyObject_Check(pyobj)) return (SwigPyObject *) pyobj; #ifdef SWIGPYTHON_BUILTIN (void)obj; # ifdef PyWeakref_CheckProxy if (PyWeakref_CheckProxy(pyobj)) { pyobj = PyWeakref_GET_OBJECT(pyobj); if (pyobj && SwigPyObject_Check(pyobj)) return (SwigPyObject*) pyobj; } # endif return NULL; #else obj = 0; #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) if (PyInstance_Check(pyobj)) { obj = _PyInstance_Lookup(pyobj, SWIG_This()); } else { PyObject **dictptr = _PyObject_GetDictPtr(pyobj); if (dictptr != NULL) { PyObject *dict = *dictptr; obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; } else { #ifdef PyWeakref_CheckProxy if (PyWeakref_CheckProxy(pyobj)) { PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; } #endif obj = PyObject_GetAttr(pyobj,SWIG_This()); if (obj) { Py_DECREF(obj); } else { if (PyErr_Occurred()) PyErr_Clear(); return 0; } } } #else obj = PyObject_GetAttr(pyobj,SWIG_This()); if (obj) { Py_DECREF(obj); } else { if (PyErr_Occurred()) PyErr_Clear(); return 0; } #endif if (obj && !SwigPyObject_Check(obj)) { /* a PyObject is called 'this', try to get the 'real this' SwigPyObject from it */ return SWIG_Python_GetSwigThis(obj); } return (SwigPyObject *)obj; #endif } /* Acquire a pointer value */ SWIGRUNTIME int SWIG_Python_AcquirePtr(PyObject *obj, int own) { if (own == SWIG_POINTER_OWN) { SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); if (sobj) { int oldown = sobj->own; sobj->own = own; return oldown; } } return 0; } /* Convert a pointer value */ SWIGRUNTIME int SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { int res; SwigPyObject *sobj; int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0; if (!obj) return SWIG_ERROR; if (obj == Py_None && !implicit_conv) { if (ptr) *ptr = 0; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } res = SWIG_ERROR; sobj = SWIG_Python_GetSwigThis(obj); if (own) *own = 0; while (sobj) { void *vptr = sobj->ptr; if (ty) { swig_type_info *to = sobj->ty; if (to == ty) { /* no type cast needed */ if (ptr) *ptr = vptr; break; } else { swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); if (!tc) { sobj = (SwigPyObject *)sobj->next; } else { if (ptr) { int newmemory = 0; *ptr = SWIG_TypeCast(tc,vptr,&newmemory); if (newmemory == SWIG_CAST_NEW_MEMORY) { assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ if (own) *own = *own | SWIG_CAST_NEW_MEMORY; } } break; } } } else { if (ptr) *ptr = vptr; break; } } if (sobj) { if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !sobj->own) { res = SWIG_ERROR_RELEASE_NOT_OWNED; } else { if (own) *own = *own | sobj->own; if (flags & SWIG_POINTER_DISOWN) { sobj->own = 0; } if (flags & SWIG_POINTER_CLEAR) { sobj->ptr = 0; } res = SWIG_OK; } } else { if (implicit_conv) { SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; if (data && !data->implicitconv) { PyObject *klass = data->klass; if (klass) { PyObject *impconv; data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ impconv = SWIG_Python_CallFunctor(klass, obj); data->implicitconv = 0; if (PyErr_Occurred()) { PyErr_Clear(); impconv = 0; } if (impconv) { SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); if (iobj) { void *vptr; res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); if (SWIG_IsOK(res)) { if (ptr) { *ptr = vptr; /* transfer the ownership to 'ptr' */ iobj->own = 0; res = SWIG_AddCast(res); res = SWIG_AddNewMask(res); } else { res = SWIG_AddCast(res); } } } Py_DECREF(impconv); } } } if (!SWIG_IsOK(res) && obj == Py_None) { if (ptr) *ptr = 0; if (PyErr_Occurred()) PyErr_Clear(); res = SWIG_OK; } } } return res; } /* Convert a function ptr value */ SWIGRUNTIME int SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { if (!PyCFunction_Check(obj)) { return SWIG_ConvertPtr(obj, ptr, ty, 0); } else { void *vptr = 0; swig_cast_info *tc; /* here we get the method pointer for callbacks */ #ifndef Py_LIMITED_API const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); #else PyObject* pystr_doc = PyObject_GetAttrString(obj, "__doc__"); PyObject *bytes = NULL; const char *doc = pystr_doc ? SWIG_PyUnicode_AsUTF8AndSize(pystr_doc, NULL, &bytes) : 0; #endif const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; if (desc) desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; #ifdef Py_LIMITED_API Py_XDECREF(bytes); Py_XDECREF(pystr_doc); #endif if (!desc) return SWIG_ERROR; tc = SWIG_TypeCheck(desc,ty); if (tc) { int newmemory = 0; *ptr = SWIG_TypeCast(tc,vptr,&newmemory); assert(!newmemory); /* newmemory handling not yet implemented */ } else { return SWIG_ERROR; } return SWIG_OK; } } /* Convert a packed pointer value */ SWIGRUNTIME int SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); if (!to) return SWIG_ERROR; if (ty) { if (to != ty) { /* check type cast? */ swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); if (!tc) return SWIG_ERROR; } } return SWIG_OK; } /* ----------------------------------------------------------------------------- * Create a new pointer object * ----------------------------------------------------------------------------- */ /* Create a new instance object, without calling __init__, and set the 'this' attribute. */ SWIGRUNTIME PyObject* SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) { PyObject *inst = 0; PyObject *newraw = data->newraw; if (newraw) { inst = PyObject_Call(newraw, data->newargs, NULL); if (inst) { #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) PyObject **dictptr = _PyObject_GetDictPtr(inst); if (dictptr != NULL) { PyObject *dict = *dictptr; if (dict == NULL) { dict = PyDict_New(); *dictptr = dict; } if (dict) { PyDict_SetItem(dict, SWIG_This(), swig_this); } else{ Py_DECREF(inst); inst = 0; } } #else if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) { Py_DECREF(inst); inst = 0; } #endif } } else { #if PY_VERSION_HEX >= 0x03000000 PyObject *empty_args = PyTuple_New(0); if (empty_args) { PyObject *empty_kwargs = PyDict_New(); if (empty_kwargs) { #ifndef Py_LIMITED_API newfunc newfn = ((PyTypeObject *)data->newargs)->tp_new; #else newfunc newfn = (newfunc)PyType_GetSlot((PyTypeObject *)data->newargs, Py_tp_new); #endif inst = newfn((PyTypeObject *)data->newargs, empty_args, empty_kwargs); Py_DECREF(empty_kwargs); if (inst) { if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) { Py_DECREF(inst); inst = 0; } else { PyType_Modified(Py_TYPE(inst)); } } } Py_DECREF(empty_args); } #else PyObject *dict = PyDict_New(); if (dict) { PyDict_SetItem(dict, SWIG_This(), swig_this); inst = PyInstance_NewRaw(data->newargs, dict); Py_DECREF(dict); } #endif } return inst; } SWIGRUNTIME int SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) { #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) PyObject **dictptr = _PyObject_GetDictPtr(inst); if (dictptr != NULL) { PyObject *dict = *dictptr; if (dict == NULL) { dict = PyDict_New(); *dictptr = dict; } if (dict) { return PyDict_SetItem(dict, SWIG_This(), swig_this); } else{ return -1; } } #endif return PyObject_SetAttr(inst, SWIG_This(), swig_this); } SWIGINTERN PyObject * SWIG_Python_InitShadowInstance(PyObject *args) { PyObject *obj[2]; if (!SWIG_Python_UnpackTuple(args, "swiginit", 2, 2, obj)) { return NULL; } else { SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); if (sthis) { Py_DECREF(SwigPyObject_append((PyObject*) sthis, obj[1])); } else { if (SWIG_Python_SetSwigThis(obj[0], obj[1]) != 0) return NULL; } return SWIG_Py_Void(); } } /* Create a new pointer object */ SWIGRUNTIME PyObject * SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { SwigPyClientData *clientdata; PyObject * robj; int own; if (!ptr) return SWIG_Py_Void(); clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; if (clientdata && clientdata->pytype) { SwigPyObject *newobj; if (flags & SWIG_BUILTIN_TP_INIT) { newobj = (SwigPyObject*) self; if (newobj->ptr) { #ifndef Py_LIMITED_API allocfunc alloc = clientdata->pytype->tp_alloc; #else allocfunc alloc = (allocfunc)PyType_GetSlot(clientdata->pytype, Py_tp_alloc); #endif PyObject *next_self = alloc(clientdata->pytype, 0); while (newobj->next) newobj = (SwigPyObject *) newobj->next; newobj->next = next_self; newobj = (SwigPyObject *)next_self; #ifdef SWIGPYTHON_BUILTIN newobj->dict = 0; #endif } } else { newobj = PyObject_New(SwigPyObject, clientdata->pytype); #ifdef SWIGPYTHON_BUILTIN if (newobj) { newobj->dict = 0; } #endif } if (newobj) { newobj->ptr = ptr; newobj->ty = type; newobj->own = own; newobj->next = 0; return (PyObject*) newobj; } return SWIG_Py_Void(); } assert(!(flags & SWIG_BUILTIN_TP_INIT)); robj = SwigPyObject_New(ptr, type, own); if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); Py_DECREF(robj); robj = inst; } return robj; } /* Create a new packed object */ SWIGRUNTIMEINLINE PyObject * SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); } /* -----------------------------------------------------------------------------* * Get type list * -----------------------------------------------------------------------------*/ #ifdef SWIG_LINK_RUNTIME void *SWIG_ReturnGlobalTypeList(void *); #endif static PyObject *Swig_TypeCache_global = NULL; /* The python cached type query */ SWIGRUNTIME PyObject * SWIG_Python_TypeCache(void) { if (Swig_TypeCache_global == NULL) { Swig_TypeCache_global = PyDict_New(); } return Swig_TypeCache_global; } SWIGRUNTIME swig_module_info * SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { #ifdef SWIG_LINK_RUNTIME static void *type_pointer = (void *)0; /* first check if module already created */ if (!type_pointer) { type_pointer = SWIG_ReturnGlobalTypeList((void *)0); } #else void *type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); if (PyErr_Occurred()) { PyErr_Clear(); type_pointer = (void *)0; } #endif return (swig_module_info *) type_pointer; } static int interpreter_counter = 0; /* how many (sub-)interpreters are using swig_module's types */ SWIGRUNTIME void SWIG_Python_DestroyModule(PyObject *obj) { swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME); swig_type_info **types = swig_module->types; size_t i; if (--interpreter_counter != 0) /* another sub-interpreter may still be using the swig_module's types */ return; for (i =0; i < swig_module->size; ++i) { swig_type_info *ty = types[i]; if (ty->owndata) { SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; ty->clientdata = 0; if (data) SwigPyClientData_Del(data); } } Py_DECREF(SWIG_This()); Swig_This_global = NULL; Py_DECREF(SWIG_globals()); Swig_Globals_global = NULL; Py_DECREF(SWIG_Python_TypeCache()); Swig_TypeCache_global = NULL; Swig_Capsule_global = NULL; } SWIGRUNTIME void SWIG_Python_SetModule(swig_module_info *swig_module) { #if PY_VERSION_HEX >= 0x03000000 /* Add a dummy module object into sys.modules */ PyObject *module = PyImport_AddModule("swig_runtime_data" SWIG_RUNTIME_VERSION); #else static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */ PyObject *module = Py_InitModule("swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table); #endif PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); if (pointer && module) { if (PyModule_AddObject(module, SWIGPY_CAPSULE_ATTR_NAME, pointer) == 0) { ++interpreter_counter; Swig_Capsule_global = pointer; } else { Py_DECREF(pointer); } } else { Py_XDECREF(pointer); } } SWIGRUNTIME swig_type_info * SWIG_Python_TypeQuery(const char *type) { PyObject *cache = SWIG_Python_TypeCache(); PyObject *key = SWIG_Python_str_FromChar(type); PyObject *obj = PyDict_GetItem(cache, key); swig_type_info *descriptor; if (obj) { descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, NULL); } else { swig_module_info *swig_module = SWIG_GetModule(0); descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); if (descriptor) { obj = PyCapsule_New((void*) descriptor, NULL, NULL); if (obj) { PyDict_SetItem(cache, key, obj); Py_DECREF(obj); } } } Py_DECREF(key); return descriptor; } /* For backward compatibility only */ #define SWIG_POINTER_EXCEPTION 0 #define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) #define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) SWIGRUNTIME int SWIG_Python_AddErrMesg(const char* mesg, int infront) { if (PyErr_Occurred()) { PyObject *type = 0; PyObject *value = 0; PyObject *traceback = 0; PyErr_Fetch(&type, &value, &traceback); if (value) { PyObject *old_str = PyObject_Str(value); PyObject *bytes = NULL; const char *tmp = SWIG_PyUnicode_AsUTF8AndSize(old_str, NULL, &bytes); const char *errmesg = tmp ? tmp : "Invalid error message"; Py_XINCREF(type); PyErr_Clear(); if (infront) { PyErr_Format(type, "%s %s", mesg, errmesg); } else { PyErr_Format(type, "%s %s", errmesg, mesg); } Py_XDECREF(bytes); Py_DECREF(old_str); } return 1; } else { return 0; } } SWIGRUNTIME int SWIG_Python_ArgFail(int argnum) { if (PyErr_Occurred()) { /* add information about failing argument */ char mesg[256]; PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); return SWIG_Python_AddErrMesg(mesg, 1); } else { return 0; } } SWIGRUNTIMEINLINE const char * SwigPyObject_GetDesc(PyObject *self) { SwigPyObject *v = (SwigPyObject *)self; swig_type_info *ty = v ? v->ty : 0; return ty ? ty->str : ""; } SWIGRUNTIME void SWIG_Python_TypeError(const char *type, PyObject *obj) { if (type) { #if defined(SWIG_COBJECT_TYPES) if (obj && SwigPyObject_Check(obj)) { const char *otype = (const char *) SwigPyObject_GetDesc(obj); if (otype) { PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", type, otype); return; } } else #endif { #ifndef Py_LIMITED_API /* tp_name is not accessible */ const char *otype = (obj ? obj->ob_type->tp_name : 0); if (otype) { PyObject *str = PyObject_Str(obj); PyObject *bytes = NULL; const char *cstr = str ? SWIG_PyUnicode_AsUTF8AndSize(str, NULL, &bytes) : 0; if (cstr) { PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", type, otype, cstr); } else { PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", type, otype); } Py_XDECREF(bytes); Py_XDECREF(str); return; } #endif } PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); } else { PyErr_Format(PyExc_TypeError, "unexpected type is received"); } } /* Convert a pointer value, signal an exception on a type mismatch */ SWIGRUNTIME void * SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) { void *result; if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { PyErr_Clear(); } return result; } #ifdef SWIGPYTHON_BUILTIN SWIGRUNTIME int SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyTypeObject *tp = obj->ob_type; PyObject *descr; PyObject *encoded_name; descrsetfunc f; int res = -1; # ifdef Py_USING_UNICODE if (PyString_Check(name)) { name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); if (!name) return -1; } else if (!PyUnicode_Check(name)) # else if (!PyString_Check(name)) # endif { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); return -1; } else { Py_INCREF(name); } if (!tp->tp_dict) { if (PyType_Ready(tp) != 0) goto done; } descr = _PyType_Lookup(tp, name); f = NULL; if (descr != NULL) f = descr->ob_type->tp_descr_set; if (!f) { if (PyString_Check(name)) { encoded_name = name; Py_INCREF(name); } else { encoded_name = PyUnicode_AsUTF8String(name); if (!encoded_name) goto done; } PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); Py_DECREF(encoded_name); } else { res = f(descr, obj, value); } done: Py_DECREF(name); return res; } #endif #ifdef __cplusplus } #endif #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) #define SWIG_contract_assert(expr, msg) do { if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } } while (0) #define SWIG_exception(code, msg) do { SWIG_Error(code, msg); SWIG_fail;; } while(0) /* -------- TYPES TABLE (BEGIN) -------- */ #define SWIGTYPE_p_char swig_types[0] #define SWIGTYPE_p_marisa__Key swig_types[1] #define SWIGTYPE_p_marisa_swig__Agent swig_types[2] #define SWIGTYPE_p_marisa_swig__Key swig_types[3] #define SWIGTYPE_p_marisa_swig__Keyset swig_types[4] #define SWIGTYPE_p_marisa_swig__Query swig_types[5] #define SWIGTYPE_p_marisa_swig__Trie swig_types[6] #define SWIGTYPE_p_p_char swig_types[7] #define SWIGTYPE_p_std__size_t swig_types[8] static swig_type_info *swig_types[10]; static swig_module_info swig_module = {swig_types, 9, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) /* -------- TYPES TABLE (END) -------- */ #ifdef SWIG_TypeQuery # undef SWIG_TypeQuery #endif #define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _marisa.so ------------------------------------------------*/ #if PY_VERSION_HEX >= 0x03000000 # define SWIG_init PyInit__marisa #else # define SWIG_init init_marisa #endif #define SWIG_name "_marisa" #ifdef __cplusplus #include /* SwigValueWrapper is described in swig.swg */ template class SwigValueWrapper { struct SwigSmartPointer { T *ptr; SwigSmartPointer(T *p) : ptr(p) { } ~SwigSmartPointer() { delete ptr; } SwigSmartPointer& operator=(SwigSmartPointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } void reset(T *p) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = p; } } pointer; SwigValueWrapper& operator=(const SwigValueWrapper& rhs); SwigValueWrapper(const SwigValueWrapper& rhs); public: SwigValueWrapper() : pointer(0) { } SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; } #if __cplusplus >=201103L SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; } operator T&&() const { return std::move(*pointer.ptr); } #else operator T&() const { return *pointer.ptr; } #endif T *operator&() const { return pointer.ptr; } static void reset(SwigValueWrapper& t, T *p) { t.pointer.reset(p); } }; /* * SwigValueInit() is a generic initialisation solution as the following approach: * * T c_result = T(); * * doesn't compile for all types for example: * * unsigned int c_result = unsigned int(); */ template T SwigValueInit() { return T(); } #if __cplusplus >=201103L # define SWIG_STD_MOVE(OBJ) std::move(OBJ) #else # define SWIG_STD_MOVE(OBJ) OBJ #endif #endif #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) #include namespace swig { class SwigPtr_PyObject { protected: PyObject *_obj; public: SwigPtr_PyObject() :_obj(0) { } SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); SWIG_PYTHON_THREAD_END_BLOCK; } SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) { if (initial_ref) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); SWIG_PYTHON_THREAD_END_BLOCK; } } SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(item._obj); Py_XDECREF(_obj); _obj = item._obj; SWIG_PYTHON_THREAD_END_BLOCK; return *this; } ~SwigPtr_PyObject() { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XDECREF(_obj); SWIG_PYTHON_THREAD_END_BLOCK; } operator PyObject *() const { return _obj; } PyObject *operator->() const { return _obj; } }; } namespace swig { struct SwigVar_PyObject : SwigPtr_PyObject { SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { } SwigVar_PyObject & operator = (PyObject* obj) { Py_XDECREF(_obj); _obj = obj; return *this; } }; } #include "marisa-swig.h" SWIGINTERNINLINE PyObject* SWIG_From_int (int value) { return PyInt_FromLong((long) value); } SWIGINTERN swig_type_info* SWIG_pchar_descriptor(void) { static int init = 0; static swig_type_info* info = 0; if (!init) { info = SWIG_TypeQuery("_p_char"); init = 1; } return info; } SWIGINTERNINLINE PyObject * SWIG_FromCharPtrAndSize(const char* carray, size_t size) { if (carray) { if (size > INT_MAX) { swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); return pchar_descriptor ? SWIG_InternalNewPointerObj(const_cast< char * >(carray), pchar_descriptor, 0) : SWIG_Py_Void(); } else { #if PY_VERSION_HEX >= 0x03000000 #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) return PyBytes_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); #else return PyUnicode_DecodeUTF8(carray, static_cast< Py_ssize_t >(size), "surrogateescape"); #endif #else return PyString_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); #endif } } else { return SWIG_Py_Void(); } } #define SWIG_From_long PyInt_FromLong SWIGINTERNINLINE PyObject* SWIG_From_unsigned_SS_long (unsigned long value) { return (value > LONG_MAX) ? PyLong_FromUnsignedLong(value) : PyInt_FromLong(static_cast< long >(value)); } #include #if !defined(SWIG_NO_LLONG_MAX) # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) # define LLONG_MAX __LONG_LONG_MAX__ # define LLONG_MIN (-LLONG_MAX - 1LL) # define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) # endif #endif #if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE) # define SWIG_LONG_LONG_AVAILABLE #endif #ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE PyObject* SWIG_From_unsigned_SS_long_SS_long (unsigned long long value) { return (value > LONG_MAX) ? PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(static_cast< long >(value)); } #endif SWIGINTERNINLINE PyObject * SWIG_From_size_t (size_t value) { #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif return SWIG_From_unsigned_SS_long (static_cast< unsigned long >(value)); #ifdef SWIG_LONG_LONG_AVAILABLE } else { /* assume sizeof(size_t) <= sizeof(unsigned long long) */ return SWIG_From_unsigned_SS_long_SS_long (static_cast< unsigned long long >(value)); } #endif } #define SWIG_From_double PyFloat_FromDouble SWIGINTERNINLINE PyObject * SWIG_From_float (float value) { return SWIG_From_double (value); } /* Return string from Python obj. NOTE: obj must remain in scope in order to use the returned cptr (but only when alloc is set to SWIG_OLDOBJ) */ SWIGINTERN int SWIG_AsCharPtrAndSize(PyObject *obj, char **cptr, size_t *psize, int *alloc) { #if PY_VERSION_HEX>=0x03000000 #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) if (PyBytes_Check(obj)) #else if (PyUnicode_Check(obj)) #endif #else if (PyString_Check(obj)) #endif { char *cstr; Py_ssize_t len; PyObject *bytes = NULL; int ret = SWIG_OK; if (alloc) *alloc = SWIG_OLDOBJ; #if PY_VERSION_HEX>=0x03000000 && defined(SWIG_PYTHON_STRICT_BYTE_CHAR) if (PyBytes_AsStringAndSize(obj, &cstr, &len) == -1) return SWIG_TypeError; #else cstr = (char *)SWIG_PyUnicode_AsUTF8AndSize(obj, &len, &bytes); if (!cstr) return SWIG_TypeError; /* The returned string is only duplicated if the char * returned is not owned and memory managed by obj */ if (bytes && cptr) { if (alloc) { cstr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); *alloc = SWIG_NEWOBJ; } else { /* alloc must be set in order to clean up allocated memory */ return SWIG_RuntimeError; } } #endif if (cptr) *cptr = cstr; if (psize) *psize = len + 1; Py_XDECREF(bytes); return ret; } else { #if defined(SWIG_PYTHON_2_UNICODE) #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) #error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once" #endif #if PY_VERSION_HEX<0x03000000 if (PyUnicode_Check(obj)) { char *cstr; Py_ssize_t len; if (!alloc && cptr) { return SWIG_RuntimeError; } obj = PyUnicode_AsUTF8String(obj); if (!obj) return SWIG_TypeError; if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) { if (cptr) { if (alloc) *alloc = SWIG_NEWOBJ; *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); } if (psize) *psize = len + 1; Py_XDECREF(obj); return SWIG_OK; } else { Py_XDECREF(obj); } } #endif #endif swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); if (pchar_descriptor) { void* vptr = 0; if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { if (cptr) *cptr = (char *) vptr; if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; if (alloc) *alloc = SWIG_OLDOBJ; return SWIG_OK; } } } return SWIG_TypeError; } #include #include /* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ #ifndef SWIG_isfinite /* isfinite() is a macro for C99 */ # if defined(isfinite) # define SWIG_isfinite(X) (isfinite(X)) # elif defined(__cplusplus) && __cplusplus >= 201103L /* Use a template so that this works whether isfinite() is std::isfinite() or * in the global namespace. The reality seems to vary between compiler * versions. * * Make sure namespace std exists to avoid compiler warnings. * * extern "C++" is required as this fragment can end up inside an extern "C" { } block */ namespace std { } extern "C++" template inline int SWIG_isfinite_func(T x) { using namespace std; return isfinite(x); } # define SWIG_isfinite(X) (SWIG_isfinite_func(X)) # elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) # define SWIG_isfinite(X) (__builtin_isfinite(X)) # elif defined(_MSC_VER) # define SWIG_isfinite(X) (_finite(X)) # elif defined(__sun) && defined(__SVR4) # include # define SWIG_isfinite(X) (finite(X)) # endif #endif /* Accept infinite as a valid float value unless we are unable to check if a value is finite */ #ifdef SWIG_isfinite # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX) && SWIG_isfinite(X)) #else # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX)) #endif SWIGINTERN int SWIG_AsVal_double (PyObject *obj, double *val) { int res = SWIG_TypeError; if (PyFloat_Check(obj)) { if (val) *val = PyFloat_AsDouble(obj); return SWIG_OK; #if PY_VERSION_HEX < 0x03000000 } else if (PyInt_Check(obj)) { if (val) *val = (double) PyInt_AsLong(obj); return SWIG_OK; #endif } else if (PyLong_Check(obj)) { double v = PyLong_AsDouble(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); } } #ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; double d = PyFloat_AsDouble(obj); if (!PyErr_Occurred()) { if (val) *val = d; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { long v = PyLong_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); } else { PyErr_Clear(); } } } #endif return res; } SWIGINTERN int SWIG_AsVal_float (PyObject * obj, float *val) { double v; int res = SWIG_AsVal_double (obj, &v); if (SWIG_IsOK(res)) { if (SWIG_Float_Overflow_Check(v)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< float >(v); } } return res; } SWIGINTERNINLINE int SWIG_CanCastAsInteger(double *d, double min, double max) { double x = *d; if ((min <= x && x <= max)) { double fx, cx, rd; errno = 0; fx = floor(x); cx = ceil(x); rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ if ((errno == EDOM) || (errno == ERANGE)) { errno = 0; } else { double summ, reps, diff; if (rd < x) { diff = x - rd; } else if (rd > x) { diff = rd - x; } else { return 1; } summ = rd + x; reps = diff/summ; if (reps < 8*DBL_EPSILON) { *d = rd; return 1; } } } return 0; } SWIGINTERN int SWIG_AsVal_unsigned_SS_long (PyObject *obj, unsigned long *val) { #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { long v = PyInt_AsLong(obj); if (v >= 0) { if (val) *val = v; return SWIG_OK; } else { return SWIG_OverflowError; } } else #endif if (PyLong_Check(obj)) { unsigned long v = PyLong_AsUnsignedLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); return SWIG_OverflowError; } } #ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; unsigned long v = PyLong_AsUnsignedLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); // Largest double not larger than ULONG_MAX (not portably calculated easily) // Note that double(ULONG_MAX) is stored in a double rounded up by one (for 64-bit unsigned long) // 0xfffffffffffff800ULL == (uint64_t)std::nextafter(double(__uint128_t(ULONG_MAX)+1), double(0)) const double ulong_max = sizeof(unsigned long) == 8 ? 0xfffffffffffff800ULL : ULONG_MAX; if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ulong_max)) { if (val) *val = (unsigned long)(d); return res; } } } #endif return SWIG_TypeError; } #ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_unsigned_SS_long_SS_long (PyObject *obj, unsigned long long *val) { int res = SWIG_TypeError; if (PyLong_Check(obj)) { unsigned long long v = PyLong_AsUnsignedLongLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); res = SWIG_OverflowError; } } else { unsigned long v; res = SWIG_AsVal_unsigned_SS_long (obj,&v); if (SWIG_IsOK(res)) { if (val) *val = v; return res; } } #ifdef SWIG_PYTHON_CAST_MODE { const double mant_max = 1LL << DBL_MANT_DIG; double d; res = SWIG_AsVal_double (obj,&d); if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, 0, mant_max)) return SWIG_OverflowError; if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) { if (val) *val = (unsigned long long)(d); return SWIG_AddCast(res); } res = SWIG_TypeError; } #endif return res; } #endif SWIGINTERNINLINE int SWIG_AsVal_size_t (PyObject * obj, size_t *val) { int res = SWIG_TypeError; #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif unsigned long v; res = SWIG_AsVal_unsigned_SS_long (obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); #ifdef SWIG_LONG_LONG_AVAILABLE } else if (sizeof(size_t) <= sizeof(unsigned long long)) { unsigned long long v; res = SWIG_AsVal_unsigned_SS_long_SS_long (obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); } #endif return res; } SWIGINTERNINLINE PyObject* SWIG_From_bool (bool value) { return PyBool_FromLong(value ? 1 : 0); } SWIGINTERN int SWIG_AsVal_long (PyObject *obj, long* val) { #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { if (val) *val = PyInt_AsLong(obj); return SWIG_OK; } else #endif if (PyLong_Check(obj)) { long v = PyLong_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); return SWIG_OverflowError; } } #ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; long v = PyInt_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); // Largest double not larger than LONG_MAX (not portably calculated easily) // Note that double(LONG_MAX) is stored in a double rounded up by one (for 64-bit long) // 0x7ffffffffffffc00LL == (int64_t)std::nextafter(double(__uint128_t(LONG_MAX)+1), double(0)) const double long_max = sizeof(long) == 8 ? 0x7ffffffffffffc00LL : LONG_MAX; // No equivalent needed for 64-bit double(LONG_MIN) is exactly LONG_MIN if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, long_max)) { if (val) *val = (long)(d); return res; } } } #endif return SWIG_TypeError; } SWIGINTERN int SWIG_AsVal_int (PyObject * obj, int *val) { long v; int res = SWIG_AsVal_long (obj, &v); if (SWIG_IsOK(res)) { if ((v < INT_MIN || v > INT_MAX)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< int >(v); } } return res; } #ifdef __cplusplus extern "C" { #endif SWIGINTERN PyObject *_wrap_Key_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_str" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { ((marisa_swig::Key const *)arg1)->str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Key_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_id" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = ((marisa_swig::Key const *)arg1)->id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Key_weight(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; float result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_weight" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = (float)((marisa_swig::Key const *)arg1)->weight(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_float(static_cast< float >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Key(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Key" "', argument " "1"" of type '" "marisa_swig::Key *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Key_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Key, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *_wrap_Query_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Query_str" "', argument " "1"" of type '" "marisa_swig::Query const *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { ((marisa_swig::Query const *)arg1)->str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Query_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Query_id" "', argument " "1"" of type '" "marisa_swig::Query const *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { result = ((marisa_swig::Query const *)arg1)->id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Query(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Query, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Query" "', argument " "1"" of type '" "marisa_swig::Query *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Query_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Query, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *_wrap_new_Keyset(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "new_Keyset", 0, 0, 0)) SWIG_fail; { try { result = (marisa_swig::Keyset *)new marisa_swig::Keyset(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NEW | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Keyset(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Keyset" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; marisa::Key *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa__Key, 0 | 0); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "marisa::Key const &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Keyset_push_back" "', argument " "2"" of type '" "marisa::Key const &""'"); } arg2 = reinterpret_cast< marisa::Key * >(argp2); { try { (arg1)->push_back((marisa::Key const &)*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; float arg4 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; float val4 ; int ecode4 = 0 ; (void)self; if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); ecode4 = SWIG_AsVal_float(swig_obj[2], &val4); if (!SWIG_IsOK(ecode4)) { SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Keyset_push_back" "', argument " "4"" of type '" "float""'"); } arg4 = static_cast< float >(val4); { try { (arg1)->push_back((char const *)arg2,arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back__SWIG_2(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->push_back((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[4] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Keyset_push_back", 0, 3, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_ConvertPtr(argv[1], 0, SWIGTYPE_p_marisa__Key, SWIG_POINTER_NO_NULL | 0); _v = SWIG_CheckState(res); if (_v) { return _wrap_Keyset_push_back__SWIG_0(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Keyset_push_back__SWIG_2(self, argc, argv); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Keyset_push_back__SWIG_2(self, argc, argv); } } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_float(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Keyset_push_back__SWIG_1(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Keyset_push_back'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Keyset::push_back(marisa::Key const &)\n" " marisa_swig::Keyset::push_back(char const *,std::size_t,float)\n" " marisa_swig::Keyset::push_back(char const *,std::size_t)\n"); return 0; } SWIGINTERN PyObject *_wrap_Keyset_key(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; PyObject *swig_obj[2] ; marisa_swig::Key *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "Keyset_key", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { result = (marisa_swig::Key *) &((marisa_swig::Keyset const *)arg1)->key(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_key_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; PyObject *swig_obj[2] ; arg3 = &temp3; arg4 = &tempn3; (void)self; if (!SWIG_Python_UnpackTuple(args, "Keyset_key_str", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key_str" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key_str" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Keyset const *)arg1)->key_str(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg3) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg3,*arg4)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_key_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; PyObject *swig_obj[2] ; std::size_t result; (void)self; if (!SWIG_Python_UnpackTuple(args, "Keyset_key_id", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key_id" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key_id" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { result = ((marisa_swig::Keyset const *)arg1)->key_id(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_num_keys(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_num_keys" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_empty(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; bool result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_empty" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = (bool)((marisa_swig::Keyset const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_size" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_total_length(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_total_length" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->total_length(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_reset(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_reset" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->reset(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_clear(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_clear" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Keyset_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Keyset, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *Keyset_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { return SWIG_Python_InitShadowInstance(args); } SWIGINTERN PyObject *_wrap_new_Agent(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "new_Agent", 0, 0, 0)) SWIG_fail; { try { result = (marisa_swig::Agent *)new marisa_swig::Agent(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NEW | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Agent(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Agent" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_set_query__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_set_query" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Agent_set_query" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->set_query((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Agent_set_query__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_set_query" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Agent_set_query" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { (arg1)->set_query(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_set_query(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[3] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Agent_set_query", 0, 2, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_size_t(argv[1], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Agent_set_query__SWIG_1(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Agent_set_query__SWIG_0(self, argc, argv); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Agent_set_query__SWIG_0(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Agent_set_query'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Agent::set_query(char const *,std::size_t)\n" " marisa_swig::Agent::set_query(std::size_t)\n"); return 0; } SWIGINTERN PyObject *_wrap_Agent_key(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::Key *result = 0 ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Key *) &((marisa_swig::Agent const *)arg1)->key(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_query(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::Query *result = 0 ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Query *) &((marisa_swig::Agent const *)arg1)->query(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_key_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key_str" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->key_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_key_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key_id" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->key_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_query_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query_str" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->query_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_query_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query_id" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->query_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Agent_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Agent, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *Agent_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { return SWIG_Python_InitShadowInstance(args); } SWIGINTERN PyObject *_wrap_new_Trie(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "new_Trie", 0, 0, 0)) SWIG_fail; { try { result = (marisa_swig::Trie *)new marisa_swig::Trie(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Trie, SWIG_POINTER_NEW | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Trie(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Trie" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_build__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int val3 ; int ecode3 = 0 ; (void)self; if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_build" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); ecode3 = SWIG_AsVal_int(swig_obj[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Trie_build" "', argument " "3"" of type '" "int""'"); } arg3 = static_cast< int >(val3); { try { (arg1)->build(*arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_build__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_build" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); { try { (arg1)->build(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_build(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[4] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_build", 0, 3, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_build__SWIG_1(self, argc, argv); } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_int(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_build__SWIG_0(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_build'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::build(marisa_swig::Keyset &,int)\n" " marisa_swig::Trie::build(marisa_swig::Keyset &)\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_mmap__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; int val3 ; int ecode3 = 0 ; (void)self; if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_mmap" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_mmap" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); ecode3 = SWIG_AsVal_int(swig_obj[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Trie_mmap" "', argument " "3"" of type '" "int""'"); } arg3 = static_cast< int >(val3); { try { (arg1)->mmap((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_mmap__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_mmap" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_mmap" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->mmap((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_mmap(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[4] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_mmap", 0, 3, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_mmap__SWIG_1(self, argc, argv); } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_int(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_mmap__SWIG_0(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_mmap'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::mmap(char const *,int)\n" " marisa_swig::Trie::mmap(char const *)\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_load(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; PyObject *swig_obj[2] ; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_load", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_load" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_load" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->load((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_save(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; PyObject *swig_obj[2] ; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_save", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_save" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_save" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { ((marisa_swig::Trie const *)arg1)->save((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_lookup__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; bool result; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_reverse_lookup__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_reverse_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_common_prefix_search(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; PyObject *swig_obj[2] ; bool result; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_common_prefix_search", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_common_prefix_search" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_common_prefix_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_common_prefix_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->common_prefix_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_predictive_search(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; PyObject *swig_obj[2] ; bool result; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_predictive_search", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_predictive_search" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_predictive_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_predictive_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->predictive_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_lookup__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; std::size_t result; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_lookup" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { result = ((marisa_swig::Trie const *)arg1)->lookup((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_lookup(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[3] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_lookup", 0, 2, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_lookup__SWIG_0(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Trie_lookup__SWIG_1(self, argc, argv); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_lookup__SWIG_1(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_lookup'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::lookup(marisa_swig::Agent &) const\n" " marisa_swig::Trie::lookup(char const *,std::size_t) const\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_reverse_lookup__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; arg3 = &temp3; arg4 = &tempn3; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_reverse_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg3) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg3,*arg4)); delete [] (*arg3); } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_reverse_lookup(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[3] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_reverse_lookup", 0, 2, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_reverse_lookup__SWIG_0(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_size_t(argv[1], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_reverse_lookup__SWIG_1(self, argc, argv); } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_reverse_lookup'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::reverse_lookup(marisa_swig::Agent &) const\n" " marisa_swig::Trie::reverse_lookup(std::size_t,char const **,std::size_t *) const\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_num_tries(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_tries" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_tries(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_num_keys(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_keys" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_num_nodes(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_nodes" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_nodes(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_tail_mode(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::TailMode result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_tail_mode" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::TailMode)((marisa_swig::Trie const *)arg1)->tail_mode(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_int(static_cast< int >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_node_order(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::NodeOrder result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_node_order" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::NodeOrder)((marisa_swig::Trie const *)arg1)->node_order(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_int(static_cast< int >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_empty(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; bool result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_empty" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (bool)((marisa_swig::Trie const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_total_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_total_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->total_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_io_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_io_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->io_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_clear(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_clear" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Trie_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Trie, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *Trie_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { return SWIG_Python_InitShadowInstance(args); } static PyMethodDef SwigMethods[] = { { "Key_str", _wrap_Key_str, METH_O, NULL}, { "Key_id", _wrap_Key_id, METH_O, NULL}, { "Key_weight", _wrap_Key_weight, METH_O, NULL}, { "delete_Key", _wrap_delete_Key, METH_O, NULL}, { "Key_swigregister", Key_swigregister, METH_O, NULL}, { "Query_str", _wrap_Query_str, METH_O, NULL}, { "Query_id", _wrap_Query_id, METH_O, NULL}, { "delete_Query", _wrap_delete_Query, METH_O, NULL}, { "Query_swigregister", Query_swigregister, METH_O, NULL}, { "new_Keyset", _wrap_new_Keyset, METH_NOARGS, NULL}, { "delete_Keyset", _wrap_delete_Keyset, METH_O, NULL}, { "Keyset_push_back", _wrap_Keyset_push_back, METH_VARARGS, NULL}, { "Keyset_key", _wrap_Keyset_key, METH_VARARGS, NULL}, { "Keyset_key_str", _wrap_Keyset_key_str, METH_VARARGS, NULL}, { "Keyset_key_id", _wrap_Keyset_key_id, METH_VARARGS, NULL}, { "Keyset_num_keys", _wrap_Keyset_num_keys, METH_O, NULL}, { "Keyset_empty", _wrap_Keyset_empty, METH_O, NULL}, { "Keyset_size", _wrap_Keyset_size, METH_O, NULL}, { "Keyset_total_length", _wrap_Keyset_total_length, METH_O, NULL}, { "Keyset_reset", _wrap_Keyset_reset, METH_O, NULL}, { "Keyset_clear", _wrap_Keyset_clear, METH_O, NULL}, { "Keyset_swigregister", Keyset_swigregister, METH_O, NULL}, { "Keyset_swiginit", Keyset_swiginit, METH_VARARGS, NULL}, { "new_Agent", _wrap_new_Agent, METH_NOARGS, NULL}, { "delete_Agent", _wrap_delete_Agent, METH_O, NULL}, { "Agent_set_query", _wrap_Agent_set_query, METH_VARARGS, NULL}, { "Agent_key", _wrap_Agent_key, METH_O, NULL}, { "Agent_query", _wrap_Agent_query, METH_O, NULL}, { "Agent_key_str", _wrap_Agent_key_str, METH_O, NULL}, { "Agent_key_id", _wrap_Agent_key_id, METH_O, NULL}, { "Agent_query_str", _wrap_Agent_query_str, METH_O, NULL}, { "Agent_query_id", _wrap_Agent_query_id, METH_O, NULL}, { "Agent_swigregister", Agent_swigregister, METH_O, NULL}, { "Agent_swiginit", Agent_swiginit, METH_VARARGS, NULL}, { "new_Trie", _wrap_new_Trie, METH_NOARGS, NULL}, { "delete_Trie", _wrap_delete_Trie, METH_O, NULL}, { "Trie_build", _wrap_Trie_build, METH_VARARGS, NULL}, { "Trie_mmap", _wrap_Trie_mmap, METH_VARARGS, NULL}, { "Trie_load", _wrap_Trie_load, METH_VARARGS, NULL}, { "Trie_save", _wrap_Trie_save, METH_VARARGS, NULL}, { "Trie_common_prefix_search", _wrap_Trie_common_prefix_search, METH_VARARGS, NULL}, { "Trie_predictive_search", _wrap_Trie_predictive_search, METH_VARARGS, NULL}, { "Trie_lookup", _wrap_Trie_lookup, METH_VARARGS, NULL}, { "Trie_reverse_lookup", _wrap_Trie_reverse_lookup, METH_VARARGS, NULL}, { "Trie_num_tries", _wrap_Trie_num_tries, METH_O, NULL}, { "Trie_num_keys", _wrap_Trie_num_keys, METH_O, NULL}, { "Trie_num_nodes", _wrap_Trie_num_nodes, METH_O, NULL}, { "Trie_tail_mode", _wrap_Trie_tail_mode, METH_O, NULL}, { "Trie_node_order", _wrap_Trie_node_order, METH_O, NULL}, { "Trie_empty", _wrap_Trie_empty, METH_O, NULL}, { "Trie_size", _wrap_Trie_size, METH_O, NULL}, { "Trie_total_size", _wrap_Trie_total_size, METH_O, NULL}, { "Trie_io_size", _wrap_Trie_io_size, METH_O, NULL}, { "Trie_clear", _wrap_Trie_clear, METH_O, NULL}, { "Trie_swigregister", Trie_swigregister, METH_O, NULL}, { "Trie_swiginit", Trie_swiginit, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa__Key = {"_p_marisa__Key", "marisa::Key *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Agent = {"_p_marisa_swig__Agent", "marisa_swig::Agent *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Key = {"_p_marisa_swig__Key", "marisa_swig::Key *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Keyset = {"_p_marisa_swig__Keyset", "marisa_swig::Keyset *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Query = {"_p_marisa_swig__Query", "marisa_swig::Query *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Trie = {"_p_marisa_swig__Trie", "marisa_swig::Trie *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_std__size_t = {"_p_std__size_t", "std::size_t *", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { &_swigt__p_char, &_swigt__p_marisa__Key, &_swigt__p_marisa_swig__Agent, &_swigt__p_marisa_swig__Key, &_swigt__p_marisa_swig__Keyset, &_swigt__p_marisa_swig__Query, &_swigt__p_marisa_swig__Trie, &_swigt__p_p_char, &_swigt__p_std__size_t, }; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa__Key[] = { {&_swigt__p_marisa__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Agent[] = { {&_swigt__p_marisa_swig__Agent, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Key[] = { {&_swigt__p_marisa_swig__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Keyset[] = { {&_swigt__p_marisa_swig__Keyset, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Query[] = { {&_swigt__p_marisa_swig__Query, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Trie[] = { {&_swigt__p_marisa_swig__Trie, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_std__size_t[] = { {&_swigt__p_std__size_t, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { _swigc__p_char, _swigc__p_marisa__Key, _swigc__p_marisa_swig__Agent, _swigc__p_marisa_swig__Key, _swigc__p_marisa_swig__Keyset, _swigc__p_marisa_swig__Query, _swigc__p_marisa_swig__Trie, _swigc__p_p_char, _swigc__p_std__size_t, }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ static swig_const_info swig_const_table[] = { {0, 0, 0, 0.0, 0, 0}}; #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * Type initialization: * This problem is tough by the requirement that no dynamic * memory is used. Also, since swig_type_info structures store pointers to * swig_cast_info structures and swig_cast_info structures store pointers back * to swig_type_info structures, we need some lookup code at initialization. * The idea is that swig generates all the structures that are needed. * The runtime then collects these partially filled structures. * The SWIG_InitializeModule function takes these initial arrays out of * swig_module, and does all the lookup, filling in the swig_module.types * array with the correct data and linking the correct swig_cast_info * structures together. * * The generated swig_type_info structures are assigned statically to an initial * array. We just loop through that array, and handle each type individually. * First we lookup if this type has been already loaded, and if so, use the * loaded structure instead of the generated one. Then we have to fill in the * cast linked list. The cast data is initially stored in something like a * two-dimensional array. Each row corresponds to a type (there are the same * number of rows as there are in the swig_type_initial array). Each entry in * a column is one of the swig_cast_info structures for that type. * The cast_initial array is actually an array of arrays, because each row has * a variable number of columns. So to actually build the cast linked list, * we find the array of casts associated with the type, and loop through it * adding the casts to the list. The one last trick we need to do is making * sure the type pointer in the swig_cast_info struct is correct. * * First off, we lookup the cast->type name to see if it is already loaded. * There are three cases to handle: * 1) If the cast->type has already been loaded AND the type we are adding * casting info to has not been loaded (it is in this module), THEN we * replace the cast->type pointer with the type pointer that has already * been loaded. * 2) If BOTH types (the one we are adding casting info to, and the * cast->type) are loaded, THEN the cast info has already been loaded by * the previous module so we just ignore it. * 3) Finally, if cast->type has not already been loaded, then we add that * swig_cast_info to the linked list (because the cast->type) pointer will * be correct. * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #if 0 } /* c-mode */ #endif #endif #if 0 #define SWIGRUNTIME_DEBUG #endif #ifndef SWIG_INIT_CLIENT_DATA_TYPE #define SWIG_INIT_CLIENT_DATA_TYPE void * #endif SWIGRUNTIME void SWIG_InitializeModule(SWIG_INIT_CLIENT_DATA_TYPE clientdata) { size_t i; swig_module_info *module_head, *iter; int init; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { /* Initialize the swig_module */ swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; init = 1; } else { init = 0; } /* Try and load any already created modules */ module_head = SWIG_GetModule(clientdata); if (!module_head) { /* This is the first module loaded for this interpreter */ /* so set the swig module into the interpreter */ SWIG_SetModule(clientdata, &swig_module); } else { /* the interpreter has loaded a SWIG module, but has it loaded this one? */ iter=module_head; do { if (iter==&swig_module) { /* Our module is already in the list, so there's nothing more to do. */ return; } iter=iter->next; } while (iter!= module_head); /* otherwise we must add our module into the list */ swig_module.next = module_head->next; module_head->next = &swig_module; } /* When multiple interpreters are used, a module could have already been initialized in a different interpreter, but not yet have a pointer in this interpreter. In this case, we do not want to continue adding types... everything should be set up already */ if (init == 0) return; /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); #endif for (i = 0; i < swig_module.size; ++i) { swig_type_info *type = 0; swig_type_info *ret; swig_cast_info *cast; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); #endif /* if there is another module already loaded */ if (swig_module.next != &swig_module) { type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); } if (type) { /* Overwrite clientdata field */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found type %s\n", type->name); #endif if (swig_module.type_initial[i]->clientdata) { type->clientdata = swig_module.type_initial[i]->clientdata; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); #endif } } else { type = swig_module.type_initial[i]; } /* Insert casting types */ cast = swig_module.cast_initial[i]; while (cast->type) { /* Don't need to add information already in the list */ ret = 0; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); #endif if (swig_module.next != &swig_module) { ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); #ifdef SWIGRUNTIME_DEBUG if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); #endif } if (ret) { if (type == swig_module.type_initial[i]) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: skip old type %s\n", ret->name); #endif cast->type = ret; ret = 0; } else { /* Check for casting already in the list */ swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); #ifdef SWIGRUNTIME_DEBUG if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); #endif if (!ocast) ret = 0; } } if (!ret) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); #endif if (type->cast) { type->cast->prev = cast; cast->next = type->cast; } type->cast = cast; } cast++; } /* Set entry in modules->types array equal to the type */ swig_module.types[i] = type; } swig_module.types[i] = 0; #ifdef SWIGRUNTIME_DEBUG printf("**** SWIG_InitializeModule: Cast List ******\n"); for (i = 0; i < swig_module.size; ++i) { int j = 0; swig_cast_info *cast = swig_module.cast_initial[i]; printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); while (cast->type) { printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); cast++; ++j; } printf("---- Total casts: %d\n",j); } printf("**** SWIG_InitializeModule: Cast List ******\n"); #endif } /* This function will propagate the clientdata field of type to * any new swig_type_info structures that have been added into the list * of equivalent types. It is like calling * SWIG_TypeClientData(type, clientdata) a second time. */ SWIGRUNTIME void SWIG_PropagateClientData(void) { size_t i; swig_cast_info *equiv; static int init_run = 0; if (init_run) return; init_run = 1; for (i = 0; i < swig_module.size; i++) { if (swig_module.types[i]->clientdata) { equiv = swig_module.types[i]->cast; while (equiv) { if (!equiv->converter) { if (equiv->type && !equiv->type->clientdata) SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); } equiv = equiv->next; } } } } #ifdef __cplusplus #if 0 { /* c-mode */ #endif } #endif #ifdef __cplusplus extern "C" { #endif /* ----------------------------------------------------------------------------- * constants/methods manipulation * ----------------------------------------------------------------------------- */ /* Install Constants */ SWIGINTERN void SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { PyObject *obj = 0; size_t i; for (i = 0; constants[i].type; ++i) { switch(constants[i].type) { case SWIG_PY_POINTER: obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); break; case SWIG_PY_BINARY: obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); break; default: obj = 0; break; } if (obj) { PyDict_SetItemString(d, constants[i].name, obj); Py_DECREF(obj); } } } /* ----------------------------------------------------------------------------- * Patch %callback methods' docstrings to hold the callback ptrs * -----------------------------------------------------------------------------*/ SWIGINTERN void SWIG_Python_FixMethods(PyMethodDef *methods, const swig_const_info *const_table, swig_type_info **types, swig_type_info **types_initial) { size_t i; for (i = 0; methods[i].ml_name; ++i) { const char *c = methods[i].ml_doc; if (!c) continue; c = strstr(c, "swig_ptr: "); if (c) { int j; const swig_const_info *ci = 0; const char *name = c + 10; for (j = 0; const_table[j].type; ++j) { if (strncmp(const_table[j].name, name, strlen(const_table[j].name)) == 0) { ci = &(const_table[j]); break; } } if (ci) { void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; if (ptr) { size_t shift = (ci->ptype) - types; swig_type_info *ty = types_initial[shift]; size_t ldoc = (c - methods[i].ml_doc); size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; char *ndoc = (char*)malloc(ldoc + lptr + 10); if (ndoc) { char *buff = ndoc; memcpy(buff, methods[i].ml_doc, ldoc); buff += ldoc; memcpy(buff, "swig_ptr: ", 10); buff += 10; SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); methods[i].ml_doc = ndoc; } } } } } } #ifdef __cplusplus } #endif /* -----------------------------------------------------------------------------* * Partial Init method * -----------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" #endif SWIGEXPORT #if PY_VERSION_HEX >= 0x03000000 PyObject* #else void #endif SWIG_init(void) { PyObject *m, *d, *md, *globals; #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef SWIG_module = { PyModuleDef_HEAD_INIT, SWIG_name, NULL, -1, SwigMethods, NULL, NULL, NULL, NULL }; #endif #if defined(SWIGPYTHON_BUILTIN) static SwigPyClientData SwigPyObject_clientdata = { 0, 0, 0, 0, 0, 0, 0 }; static PyGetSetDef this_getset_def = { (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL }; static SwigPyGetSet thisown_getset_closure = { SwigPyObject_own, SwigPyObject_own }; static PyGetSetDef thisown_getset_def = { (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure }; PyTypeObject *builtin_pytype; int builtin_base_count; swig_type_info *builtin_basetype; PyObject *tuple; PyGetSetDescrObject *static_getset; PyTypeObject *metatype; PyTypeObject *swigpyobject; SwigPyClientData *cd; PyObject *public_interface, *public_symbol; PyObject *this_descr; PyObject *thisown_descr; PyObject *self = 0; int i; (void)builtin_pytype; (void)builtin_base_count; (void)builtin_basetype; (void)tuple; (void)static_getset; (void)self; /* Metaclass is used to implement static member variables */ metatype = SwigPyObjectType(); assert(metatype); #endif (void)globals; /* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */ SWIG_This(); SWIG_Python_TypeCache(); SwigPyPacked_type(); #ifndef SWIGPYTHON_BUILTIN SwigPyObject_type(); #endif /* Fix SwigMethods to carry the callback ptrs when needed */ SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); #if PY_VERSION_HEX >= 0x03000000 m = PyModule_Create(&SWIG_module); #else m = Py_InitModule(SWIG_name, SwigMethods); #endif md = d = PyModule_GetDict(m); (void)md; SWIG_InitializeModule(0); #ifdef SWIGPYTHON_BUILTIN swigpyobject = SwigPyObject_TypeOnce(); SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); assert(SwigPyObject_stype); cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; if (!cd) { SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; SwigPyObject_clientdata.pytype = swigpyobject; } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) { PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); # if PY_VERSION_HEX >= 0x03000000 return NULL; # else return; # endif } /* All objects have a 'this' attribute */ this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); (void)this_descr; /* All objects have a 'thisown' attribute */ thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); (void)thisown_descr; public_interface = PyList_New(0); public_symbol = 0; (void)public_symbol; PyDict_SetItemString(md, "__all__", public_interface); Py_DECREF(public_interface); for (i = 0; SwigMethods[i].ml_name != NULL; ++i) SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); for (i = 0; swig_const_table[i].name != 0; ++i) SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); #endif SWIG_InstallConstants(d,swig_const_table); SWIG_Python_SetConstant(d, "OK",SWIG_From_int(static_cast< int >(marisa_swig::OK))); SWIG_Python_SetConstant(d, "STATE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::STATE_ERROR))); SWIG_Python_SetConstant(d, "NULL_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::NULL_ERROR))); SWIG_Python_SetConstant(d, "BOUND_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::BOUND_ERROR))); SWIG_Python_SetConstant(d, "RANGE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::RANGE_ERROR))); SWIG_Python_SetConstant(d, "CODE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::CODE_ERROR))); SWIG_Python_SetConstant(d, "RESET_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::RESET_ERROR))); SWIG_Python_SetConstant(d, "SIZE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::SIZE_ERROR))); SWIG_Python_SetConstant(d, "MEMORY_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::MEMORY_ERROR))); SWIG_Python_SetConstant(d, "IO_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::IO_ERROR))); SWIG_Python_SetConstant(d, "FORMAT_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::FORMAT_ERROR))); SWIG_Python_SetConstant(d, "MIN_NUM_TRIES",SWIG_From_int(static_cast< int >(marisa_swig::MIN_NUM_TRIES))); SWIG_Python_SetConstant(d, "MAX_NUM_TRIES",SWIG_From_int(static_cast< int >(marisa_swig::MAX_NUM_TRIES))); SWIG_Python_SetConstant(d, "DEFAULT_NUM_TRIES",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_NUM_TRIES))); SWIG_Python_SetConstant(d, "HUGE_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::HUGE_CACHE))); SWIG_Python_SetConstant(d, "LARGE_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::LARGE_CACHE))); SWIG_Python_SetConstant(d, "NORMAL_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::NORMAL_CACHE))); SWIG_Python_SetConstant(d, "SMALL_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::SMALL_CACHE))); SWIG_Python_SetConstant(d, "TINY_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::TINY_CACHE))); SWIG_Python_SetConstant(d, "DEFAULT_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_CACHE))); SWIG_Python_SetConstant(d, "TEXT_TAIL",SWIG_From_int(static_cast< int >(marisa_swig::TEXT_TAIL))); SWIG_Python_SetConstant(d, "BINARY_TAIL",SWIG_From_int(static_cast< int >(marisa_swig::BINARY_TAIL))); SWIG_Python_SetConstant(d, "DEFAULT_TAIL",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_TAIL))); SWIG_Python_SetConstant(d, "LABEL_ORDER",SWIG_From_int(static_cast< int >(marisa_swig::LABEL_ORDER))); SWIG_Python_SetConstant(d, "WEIGHT_ORDER",SWIG_From_int(static_cast< int >(marisa_swig::WEIGHT_ORDER))); SWIG_Python_SetConstant(d, "DEFAULT_ORDER",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_ORDER))); SWIG_Python_SetConstant(d, "INVALID_KEY_ID",SWIG_From_size_t(static_cast< size_t >(MARISA_INVALID_KEY_ID))); #if PY_VERSION_HEX >= 0x03000000 return m; #else return; #endif } marisa-trie-master/bindings/python/marisa.py000066400000000000000000000165171505027263100215430ustar00rootroot00000000000000# This file was automatically generated by SWIG (https://www.swig.org). # Version 4.2.0 # # Do not make changes to this file unless you know what you are doing - modify # the SWIG interface file instead. from sys import version_info as _swig_python_version_info # Import the low-level C/C++ module if __package__ or "." in __name__: from . import _marisa else: import _marisa try: import builtins as __builtin__ except ImportError: import __builtin__ def _swig_repr(self): try: strthis = "proxy of " + self.this.__repr__() except __builtin__.Exception: strthis = "" return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) def _swig_setattr_nondynamic_instance_variable(set): def set_instance_attr(self, name, value): if name == "this": set(self, name, value) elif name == "thisown": self.this.own(value) elif hasattr(self, name) and isinstance(getattr(type(self), name), property): set(self, name, value) else: raise AttributeError("You cannot add instance attributes to %s" % self) return set_instance_attr def _swig_setattr_nondynamic_class_variable(set): def set_class_attr(cls, name, value): if hasattr(cls, name) and not isinstance(getattr(cls, name), property): set(cls, name, value) else: raise AttributeError("You cannot add class attributes to %s" % cls) return set_class_attr def _swig_add_metaclass(metaclass): """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass""" def wrapper(cls): return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy()) return wrapper class _SwigNonDynamicMeta(type): """Meta class to enforce nondynamic attributes (no new attributes) for a class""" __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__) OK = _marisa.OK STATE_ERROR = _marisa.STATE_ERROR NULL_ERROR = _marisa.NULL_ERROR BOUND_ERROR = _marisa.BOUND_ERROR RANGE_ERROR = _marisa.RANGE_ERROR CODE_ERROR = _marisa.CODE_ERROR RESET_ERROR = _marisa.RESET_ERROR SIZE_ERROR = _marisa.SIZE_ERROR MEMORY_ERROR = _marisa.MEMORY_ERROR IO_ERROR = _marisa.IO_ERROR FORMAT_ERROR = _marisa.FORMAT_ERROR MIN_NUM_TRIES = _marisa.MIN_NUM_TRIES MAX_NUM_TRIES = _marisa.MAX_NUM_TRIES DEFAULT_NUM_TRIES = _marisa.DEFAULT_NUM_TRIES HUGE_CACHE = _marisa.HUGE_CACHE LARGE_CACHE = _marisa.LARGE_CACHE NORMAL_CACHE = _marisa.NORMAL_CACHE SMALL_CACHE = _marisa.SMALL_CACHE TINY_CACHE = _marisa.TINY_CACHE DEFAULT_CACHE = _marisa.DEFAULT_CACHE TEXT_TAIL = _marisa.TEXT_TAIL BINARY_TAIL = _marisa.BINARY_TAIL DEFAULT_TAIL = _marisa.DEFAULT_TAIL LABEL_ORDER = _marisa.LABEL_ORDER WEIGHT_ORDER = _marisa.WEIGHT_ORDER DEFAULT_ORDER = _marisa.DEFAULT_ORDER class Key(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined") __repr__ = _swig_repr def str(self): return _marisa.Key_str(self) def id(self): return _marisa.Key_id(self) def weight(self): return _marisa.Key_weight(self) __swig_destroy__ = _marisa.delete_Key # Register Key in _marisa: _marisa.Key_swigregister(Key) class Query(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined") __repr__ = _swig_repr def str(self): return _marisa.Query_str(self) def id(self): return _marisa.Query_id(self) __swig_destroy__ = _marisa.delete_Query # Register Query in _marisa: _marisa.Query_swigregister(Query) class Keyset(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") __repr__ = _swig_repr def __init__(self): _marisa.Keyset_swiginit(self, _marisa.new_Keyset()) __swig_destroy__ = _marisa.delete_Keyset def push_back(self, *args): return _marisa.Keyset_push_back(self, *args) def key(self, i): return _marisa.Keyset_key(self, i) def key_str(self, i): return _marisa.Keyset_key_str(self, i) def key_id(self, i): return _marisa.Keyset_key_id(self, i) def num_keys(self): return _marisa.Keyset_num_keys(self) def empty(self): return _marisa.Keyset_empty(self) def size(self): return _marisa.Keyset_size(self) def total_length(self): return _marisa.Keyset_total_length(self) def reset(self): return _marisa.Keyset_reset(self) def clear(self): return _marisa.Keyset_clear(self) # Register Keyset in _marisa: _marisa.Keyset_swigregister(Keyset) class Agent(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") __repr__ = _swig_repr def __init__(self): _marisa.Agent_swiginit(self, _marisa.new_Agent()) __swig_destroy__ = _marisa.delete_Agent def set_query(self, *args): return _marisa.Agent_set_query(self, *args) def key(self): return _marisa.Agent_key(self) def query(self): return _marisa.Agent_query(self) def key_str(self): return _marisa.Agent_key_str(self) def key_id(self): return _marisa.Agent_key_id(self) def query_str(self): return _marisa.Agent_query_str(self) def query_id(self): return _marisa.Agent_query_id(self) # Register Agent in _marisa: _marisa.Agent_swigregister(Agent) class Trie(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") __repr__ = _swig_repr def __init__(self): _marisa.Trie_swiginit(self, _marisa.new_Trie()) __swig_destroy__ = _marisa.delete_Trie def build(self, keyset, config_flags=0): return _marisa.Trie_build(self, keyset, config_flags) def mmap(self, filename, flags=0): return _marisa.Trie_mmap(self, filename, flags) def load(self, filename): return _marisa.Trie_load(self, filename) def save(self, filename): return _marisa.Trie_save(self, filename) def common_prefix_search(self, agent): return _marisa.Trie_common_prefix_search(self, agent) def predictive_search(self, agent): return _marisa.Trie_predictive_search(self, agent) def lookup(self, *args): return _marisa.Trie_lookup(self, *args) def reverse_lookup(self, *args): return _marisa.Trie_reverse_lookup(self, *args) def num_tries(self): return _marisa.Trie_num_tries(self) def num_keys(self): return _marisa.Trie_num_keys(self) def num_nodes(self): return _marisa.Trie_num_nodes(self) def tail_mode(self): return _marisa.Trie_tail_mode(self) def node_order(self): return _marisa.Trie_node_order(self) def empty(self): return _marisa.Trie_empty(self) def size(self): return _marisa.Trie_size(self) def total_size(self): return _marisa.Trie_total_size(self) def io_size(self): return _marisa.Trie_io_size(self) def clear(self): return _marisa.Trie_clear(self) # Register Trie in _marisa: _marisa.Trie_swigregister(Trie) INVALID_KEY_ID = _marisa.INVALID_KEY_ID marisa-trie-master/bindings/python/sample.py000066400000000000000000000027161505027263100215440ustar00rootroot00000000000000import marisa keyset = marisa.Keyset() keyset.push_back("cake") keyset.push_back("cookie") keyset.push_back("ice") keyset.push_back("ice-cream") trie = marisa.Trie() trie.build(keyset) print("no. keys: %d" % trie.num_keys()) print("no. tries: %d" % trie.num_tries()) print("no. nodes: %d" % trie.num_nodes()) print("size: %d" % trie.io_size()) agent = marisa.Agent() agent.set_query("cake") trie.lookup(agent) print("%s: %d" % (agent.query_str(), agent.key_id())) agent.set_query("cookie") trie.lookup(agent) print("%s: %d" % (agent.query_str(), agent.key_id())) agent.set_query("cockoo") if not trie.lookup(agent): print("%s: not found" % agent.query_str()) print("ice: %d" % trie.lookup("ice")) print("ice-cream: %d" % trie.lookup("ice-cream")) if trie.lookup("ice-age") == marisa.INVALID_KEY_ID: print("ice-age: not found") trie.save("sample.dic") trie.load("sample.dic") agent.set_query(0) trie.reverse_lookup(agent) print("%d: %s" % (agent.query_id(), agent.key_str())) agent.set_query(1) trie.reverse_lookup(agent) print("%d: %s" % (agent.query_id(), agent.key_str())) print("2: %s" % trie.reverse_lookup(2)) print("3: %s" % trie.reverse_lookup(3)) trie.mmap("sample.dic") agent.set_query("ice-cream soda") while trie.common_prefix_search(agent): print("%s: %s (%d)" % (agent.query_str(), agent.key_str(), agent.key_id())) agent.set_query("ic") while trie.predictive_search(agent): print("%s: %s (%d)" % (agent.query_str(), agent.key_str(), agent.key_id())) marisa-trie-master/bindings/python/setup.py000066400000000000000000000004551505027263100214210ustar00rootroot00000000000000from distutils.core import setup, Extension marisa_module = Extension("_marisa", sources=["marisa-swig_wrap.cxx", "marisa-swig.cxx"], libraries=["marisa"]) setup(name = "marisa", ext_modules = [marisa_module], py_modules = ["marisa"]) marisa-trie-master/bindings/python3/000077500000000000000000000000001505027263100177665ustar00rootroot00000000000000marisa-trie-master/bindings/python3/benchmark.py000066400000000000000000000041221505027263100222710ustar00rootroot00000000000000import datetime import marisa import sys time_begin = datetime.datetime.now() keys = [] for line in sys.stdin: keys.append(line.rstrip()) time_end = datetime.datetime.now() print "input:", time_end - time_begin time_begin = datetime.datetime.now() dic = dict() for i in range(len(keys)): dic[keys[i]] = i time_end = datetime.datetime.now() print "dict_build:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: dic.get(key) time_end = datetime.datetime.now() print "dict_lookup:", time_end - time_begin time_begin = datetime.datetime.now() keyset = marisa.Keyset() for key in keys: keyset.push_back(key) time_end = datetime.datetime.now() print "keyset_build:", time_end - time_begin time_begin = datetime.datetime.now() trie = marisa.Trie() trie.build(keyset) time_end = datetime.datetime.now() print "trie_build:", time_end - time_begin time_begin = datetime.datetime.now() agent = marisa.Agent() for key in keys: agent.set_query(key) trie.lookup(agent) agent.key_id() time_end = datetime.datetime.now() print "trie_agent_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: trie.lookup(key) time_end = datetime.datetime.now() print "trie_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for i in range(len(keys)): agent.set_query(i) trie.reverse_lookup(agent) agent.key_str() time_end = datetime.datetime.now() print "trie_agent_reverse_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for i in range(len(keys)): trie.reverse_lookup(i) time_end = datetime.datetime.now() print "trie_reverse_lookup:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: agent.set_query(key) while trie.common_prefix_search(agent): agent.key_str() time_end = datetime.datetime.now() print "trie_agent_common_prefix_search:", time_end - time_begin time_begin = datetime.datetime.now() for key in keys: agent.set_query(key) while trie.predictive_search(agent): agent.key_str() time_end = datetime.datetime.now() print "trie_agent_predictive_search:", time_end - time_begin marisa-trie-master/bindings/python3/marisa-swig-python3.cxx000066400000000000000000000116151505027263100243430ustar00rootroot00000000000000#include #include #include "marisa-swig-python3.h" namespace marisa_swig { void Key::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = key_.ptr(); *length_out = key_.length(); } size_t Key::key_id() const { return key_.id(); } float Key::weight() const { return key_.weight(); } void Query::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = query_.ptr(); *length_out = query_.length(); } size_t Query::query_id() const { return query_.id(); } Keyset::Keyset() : keyset_(new marisa::Keyset) { } Keyset::~Keyset() { delete keyset_; } void Keyset::push_back(const marisa::Key &key) { keyset_->push_back(key); } void Keyset::push_back(const char *ptr, size_t length, float weight) { keyset_->push_back(ptr, length, weight); } const Key &Keyset::key(size_t i) const { return reinterpret_cast((*keyset_)[i]); } void Keyset::key_str(size_t i, const char **ptr_out, size_t *length_out) const { *ptr_out = (*keyset_)[i].ptr(); *length_out = (*keyset_)[i].length(); } size_t Keyset::key_id(size_t i) const { return (*keyset_)[i].id(); } size_t Keyset::num_keys() const { return keyset_->num_keys(); } bool Keyset::empty() const { return keyset_->empty(); } size_t Keyset::size() const { return keyset_->size(); } size_t Keyset::total_length() const { return keyset_->total_length(); } void Keyset::reset() { keyset_->reset(); } void Keyset::clear() { keyset_->clear(); } Agent::Agent() : agent_(new marisa::Agent), buf_(NULL), buf_size_(0) { } Agent::~Agent() { delete agent_; delete [] buf_; } void Agent::set_query(const char *ptr, size_t length) { if (length > buf_size_) { size_t new_buf_size = (buf_size_ != 0) ? buf_size_ : 1; if (length >= (MARISA_SIZE_MAX / 2)) { new_buf_size = MARISA_SIZE_MAX; } else { while (new_buf_size < length) { new_buf_size *= 2; } } char *new_buf = new char[new_buf_size]; delete [] buf_; buf_ = new_buf; buf_size_ = new_buf_size; } std::memcpy(buf_, ptr, length); agent_->set_query(buf_, length); } void Agent::set_query(size_t id) { agent_->set_query(id); } const Key &Agent::key() const { return reinterpret_cast(agent_->key()); } const Query &Agent::query() const { return reinterpret_cast(agent_->query()); } void Agent::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->key().ptr(); *length_out = agent_->key().length(); } size_t Agent::key_id() const { return agent_->key().id(); } void Agent::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->query().ptr(); *length_out = agent_->query().length(); } size_t Agent::query_id() const { return agent_->query().id(); } Trie::Trie() : trie_(new marisa::Trie) { } Trie::~Trie() { delete trie_; } void Trie::build(Keyset &keyset, int config_flags) { trie_->build(*keyset.keyset_, config_flags); } void Trie::mmap(const char *filename, int flags) { trie_->mmap(filename, flags); } void Trie::load(const char *filename) { trie_->load(filename); } void Trie::save(const char *filename) const { trie_->save(filename); } bool Trie::lookup(Agent &agent) const { return trie_->lookup(*agent.agent_); } void Trie::reverse_lookup(Agent &agent) const { trie_->reverse_lookup(*agent.agent_); } bool Trie::common_prefix_search(Agent &agent) const { return trie_->common_prefix_search(*agent.agent_); } bool Trie::predictive_search(Agent &agent) const { return trie_->predictive_search(*agent.agent_); } size_t Trie::lookup(const char *ptr, size_t length) const { marisa::Agent agent; agent.set_query(ptr, length); if (!trie_->lookup(agent)) { return MARISA_INVALID_KEY_ID; } return agent.key().id(); } void Trie::reverse_lookup(size_t id, const char **ptr_out_to_be_deleted, size_t *length_out) const { marisa::Agent agent; agent.set_query(id); trie_->reverse_lookup(agent); char * const buf = new char[agent.key().length()]; std::memcpy(buf, agent.key().ptr(), agent.key().length()); *ptr_out_to_be_deleted = buf; *length_out = agent.key().length(); } size_t Trie::num_tries() const { return trie_->num_tries(); } size_t Trie::num_keys() const { return trie_->num_keys(); } size_t Trie::num_nodes() const { return trie_->num_nodes(); } TailMode Trie::tail_mode() const { if (trie_->tail_mode() == ::MARISA_TEXT_TAIL) { return TEXT_TAIL; } else { return BINARY_TAIL; } } NodeOrder Trie::node_order() const { if (trie_->node_order() == ::MARISA_LABEL_ORDER) { return LABEL_ORDER; } else { return WEIGHT_ORDER; } } bool Trie::empty() const { return trie_->empty(); } size_t Trie::size() const { return trie_->size(); } size_t Trie::total_size() const { return trie_->total_size(); } size_t Trie::io_size() const { return trie_->io_size(); } void Trie::clear() { trie_->clear(); } } // namespace marisa_swig marisa-trie-master/bindings/python3/marisa-swig-python3.h000066400000000000000000000076661505027263100240030ustar00rootroot00000000000000#ifndef MARISA_SWIG_H_ #define MARISA_SWIG_H_ #include namespace marisa_swig { #define MARISA_SWIG_ENUM_COPY(name) name = MARISA_ ## name enum ErrorCode { MARISA_SWIG_ENUM_COPY(OK), MARISA_SWIG_ENUM_COPY(STATE_ERROR), MARISA_SWIG_ENUM_COPY(NULL_ERROR), MARISA_SWIG_ENUM_COPY(BOUND_ERROR), MARISA_SWIG_ENUM_COPY(RANGE_ERROR), MARISA_SWIG_ENUM_COPY(CODE_ERROR), MARISA_SWIG_ENUM_COPY(RESET_ERROR), MARISA_SWIG_ENUM_COPY(SIZE_ERROR), MARISA_SWIG_ENUM_COPY(MEMORY_ERROR), MARISA_SWIG_ENUM_COPY(IO_ERROR), MARISA_SWIG_ENUM_COPY(FORMAT_ERROR) }; enum MapFlags { MARISA_SWIG_ENUM_COPY(MAP_POPULATE), }; enum NumTries { MARISA_SWIG_ENUM_COPY(MIN_NUM_TRIES), MARISA_SWIG_ENUM_COPY(MAX_NUM_TRIES), MARISA_SWIG_ENUM_COPY(DEFAULT_NUM_TRIES) }; enum CacheLevel { MARISA_SWIG_ENUM_COPY(HUGE_CACHE), MARISA_SWIG_ENUM_COPY(LARGE_CACHE), MARISA_SWIG_ENUM_COPY(NORMAL_CACHE), MARISA_SWIG_ENUM_COPY(SMALL_CACHE), MARISA_SWIG_ENUM_COPY(TINY_CACHE), MARISA_SWIG_ENUM_COPY(DEFAULT_CACHE) }; enum TailMode { MARISA_SWIG_ENUM_COPY(TEXT_TAIL), MARISA_SWIG_ENUM_COPY(BINARY_TAIL), MARISA_SWIG_ENUM_COPY(DEFAULT_TAIL) }; enum NodeOrder { MARISA_SWIG_ENUM_COPY(LABEL_ORDER), MARISA_SWIG_ENUM_COPY(WEIGHT_ORDER), MARISA_SWIG_ENUM_COPY(DEFAULT_ORDER) }; #undef MARISA_SWIG_ENUM_COPY class Key { public: void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; float weight() const; private: const marisa::Key key_; Key(); Key(const Key &key); Key &operator=(const Key &); }; class Query { public: void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: const marisa::Query query_; Query(); Query(const Query &query); Query &operator=(const Query &); }; class Keyset { friend class Trie; public: Keyset(); ~Keyset(); void push_back(const marisa::Key &key); void push_back(const char *ptr, std::size_t length, float weight = 1.0); const Key &key(std::size_t i) const; void key_str(std::size_t i, const char **ptr_out, std::size_t *length_out) const; std::size_t key_id(std::size_t i) const; std::size_t num_keys() const; bool empty() const; std::size_t size() const; std::size_t total_length() const; void reset(); void clear(); private: marisa::Keyset *keyset_; Keyset(const Keyset &); Keyset &operator=(const Keyset &); }; class Agent { friend class Trie; public: Agent(); ~Agent(); void set_query(const char *ptr, std::size_t length); void set_query(std::size_t id); const Key &key() const; const Query &query() const; void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: marisa::Agent *agent_; char *buf_; std::size_t buf_size_; Agent(const Agent &); Agent &operator=(const Agent &); }; class Trie { public: Trie(); ~Trie(); void build(Keyset &keyset, int config_flags = 0); void mmap(const char *filename, int flags = 0); void load(const char *filename); void save(const char *filename) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t lookup(const char *ptr, std::size_t length) const; void reverse_lookup(std::size_t id, const char **ptr_out_to_be_deleted, std::size_t *length_out) const; std::size_t num_tries() const; std::size_t num_keys() const; std::size_t num_nodes() const; TailMode tail_mode() const; NodeOrder node_order() const; bool empty() const; std::size_t size() const; std::size_t total_size() const; std::size_t io_size() const; void clear(); private: marisa::Trie *trie_; Trie(const Trie &); Trie &operator=(const Trie &); }; } // namespace marisa_swig #endif // MARISA_SWIG_H_ marisa-trie-master/bindings/python3/marisa-swig-python3_wrap.cxx000066400000000000000000006340631505027263100254040ustar00rootroot00000000000000/* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (https://www.swig.org). * Version 4.2.0 * * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ #define SWIG_VERSION 0x040200 #define SWIGPYTHON #define SWIG_PYTHON_DIRECTOR_NO_VTABLE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. * ----------------------------------------------------------------------------- */ /* template workaround for compilers that cannot correctly implement the C++ standard */ #ifndef SWIGTEMPLATEDISAMBIGUATOR # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) # define SWIGTEMPLATEDISAMBIGUATOR template # elif defined(__HP_aCC) /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ # define SWIGTEMPLATEDISAMBIGUATOR template # else # define SWIGTEMPLATEDISAMBIGUATOR # endif #endif /* inline attribute */ #ifndef SWIGINLINE # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) # define SWIGINLINE inline # else # define SWIGINLINE # endif #endif /* attribute recognised by some compilers to avoid 'unused' warnings */ #ifndef SWIGUNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif # elif defined(__ICC) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif #endif #ifndef SWIG_MSC_UNSUPPRESS_4505 # if defined(_MSC_VER) # pragma warning(disable : 4505) /* unreferenced local function has been removed */ # endif #endif #ifndef SWIGUNUSEDPARM # ifdef __cplusplus # define SWIGUNUSEDPARM(p) # else # define SWIGUNUSEDPARM(p) p SWIGUNUSED # endif #endif /* internal SWIG method */ #ifndef SWIGINTERN # define SWIGINTERN static SWIGUNUSED #endif /* internal inline SWIG method */ #ifndef SWIGINTERNINLINE # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE #endif /* exporting methods */ #if defined(__GNUC__) # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) # ifndef GCC_HASCLASSVISIBILITY # define GCC_HASCLASSVISIBILITY # endif # endif #endif #ifndef SWIGEXPORT # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # if defined(STATIC_LINKED) # define SWIGEXPORT # else # define SWIGEXPORT __declspec(dllexport) # endif # else # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) # define SWIGEXPORT __attribute__ ((visibility("default"))) # else # define SWIGEXPORT # endif # endif #endif /* calling conventions for Windows */ #ifndef SWIGSTDCALL # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # define SWIGSTDCALL __stdcall # else # define SWIGSTDCALL # endif #endif /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) # define _CRT_SECURE_NO_DEPRECATE #endif /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) # define _SCL_SECURE_NO_DEPRECATE #endif /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 #endif /* Intel's compiler complains if a variable which was never initialised is * cast to void, which is a common idiom which we use to indicate that we * are aware a variable isn't used. So we just silence that warning. * See: https://github.com/swig/swig/issues/192 for more discussion. */ #ifdef __INTEL_COMPILER # pragma warning disable 592 #endif #if __cplusplus >=201103L # define SWIG_NULLPTR nullptr #else # define SWIG_NULLPTR NULL #endif #if defined(__GNUC__) && defined(_WIN32) && !defined(SWIG_PYTHON_NO_HYPOT_WORKAROUND) /* Workaround for '::hypot' has not been declared', see https://bugs.python.org/issue11566 */ # include #endif #if !defined(PY_SSIZE_T_CLEAN) && !defined(SWIG_NO_PY_SSIZE_T_CLEAN) #define PY_SSIZE_T_CLEAN #endif #if __GNUC__ >= 7 #pragma GCC diagnostic push #if defined(__cplusplus) && __cplusplus >=201703L #pragma GCC diagnostic ignored "-Wregister" /* For python-2.7 headers that use register */ #endif #endif #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG) /* Use debug wrappers with the Python release dll */ #if defined(_MSC_VER) && _MSC_VER >= 1929 /* Workaround compilation errors when redefining _DEBUG in MSVC 2019 version 16.10 and later * See https://github.com/swig/swig/issues/2090 */ # include #endif # undef _DEBUG # include # define _DEBUG 1 #else # include #endif #if __GNUC__ >= 7 #pragma GCC diagnostic pop #endif #include /* ----------------------------------------------------------------------------- * swigrun.swg * * This file contains generic C API SWIG runtime support for pointer * type checking. * ----------------------------------------------------------------------------- */ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ #define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE # define SWIG_QUOTE_STRING(x) #x # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) #else # define SWIG_TYPE_TABLE_NAME #endif /* You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for creating a static or dynamic library from the SWIG runtime code. In 99.9% of the cases, SWIG just needs to declare them as 'static'. But only do this if strictly necessary, ie, if you have problems with your compiler or suchlike. */ #ifndef SWIGRUNTIME # define SWIGRUNTIME SWIGINTERN #endif #ifndef SWIGRUNTIMEINLINE # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE #endif /* Generic buffer size */ #ifndef SWIG_BUFFER_SIZE # define SWIG_BUFFER_SIZE 1024 #endif /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 #define SWIG_CAST_NEW_MEMORY 0x2 #define SWIG_POINTER_NO_NULL 0x4 #define SWIG_POINTER_CLEAR 0x8 #define SWIG_POINTER_RELEASE (SWIG_POINTER_CLEAR | SWIG_POINTER_DISOWN) /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 /* Flags/methods for returning states. The SWIG conversion methods, as ConvertPtr, return an integer that tells if the conversion was successful or not. And if not, an error code can be returned (see swigerrors.swg for the codes). Use the following macros/flags to set or process the returning states. In old versions of SWIG, code such as the following was usually written: if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { // success code } else { //fail code } Now you can be more explicit: int res = SWIG_ConvertPtr(obj,vptr,ty.flags); if (SWIG_IsOK(res)) { // success code } else { // fail code } which is the same really, but now you can also do Type *ptr; int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); if (SWIG_IsOK(res)) { // success code if (SWIG_IsNewObj(res) { ... delete *ptr; } else { ... } } else { // fail code } I.e., now SWIG_ConvertPtr can return new objects and you can identify the case and take care of the deallocation. Of course that also requires SWIG_ConvertPtr to return new result values, such as int SWIG_ConvertPtr(obj, ptr,...) { if () { if () { *ptr = ; return SWIG_NEWOBJ; } else { *ptr = ; return SWIG_OLDOBJ; } } else { return SWIG_BADOBJ; } } Of course, returning the plain '0(success)/-1(fail)' still works, but you can be more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the SWIG errors code. Finally, if the SWIG_CASTRANK_MODE is enabled, the result code allows returning the 'cast rank', for example, if you have this int food(double) int fooi(int); and you call food(1) // cast rank '1' (1 -> 1.0) fooi(1) // cast rank '0' just use the SWIG_AddCast()/SWIG_CheckState() */ #define SWIG_OK (0) /* Runtime errors are < 0 */ #define SWIG_ERROR (-1) /* Errors in range -1 to -99 are in swigerrors.swg (errors for all languages including those not using the runtime) */ /* Errors in range -100 to -199 are language specific errors defined in *errors.swg */ /* Errors < -200 are generic runtime specific errors */ #define SWIG_ERROR_RELEASE_NOT_OWNED (-200) #define SWIG_IsOK(r) (r >= 0) #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) /* The CastRankLimit says how many bits are used for the cast rank */ #define SWIG_CASTRANKLIMIT (1 << 8) /* The NewMask denotes the object was created (using new/malloc) */ #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) /* The TmpMask is for in/out typemaps that use temporary objects */ #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) /* Simple returning values */ #define SWIG_BADOBJ (SWIG_ERROR) #define SWIG_OLDOBJ (SWIG_OK) #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) /* Check, add and del object mask methods */ #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) /* Cast-Rank Mode */ #if defined(SWIG_CASTRANK_MODE) # ifndef SWIG_TypeRank # define SWIG_TypeRank unsigned long # endif # ifndef SWIG_MAXCASTRANK /* Default cast allowed */ # define SWIG_MAXCASTRANK (2) # endif # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) SWIGINTERNINLINE int SWIG_AddCast(int r) { return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; } SWIGINTERNINLINE int SWIG_CheckState(int r) { return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ # define SWIG_AddCast(r) (r) # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif /* C99 and C++11 should provide snprintf, but define SWIG_NO_SNPRINTF * if you're missing it. */ #if ((defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || \ (defined __cplusplus && __cplusplus >= 201103L) || \ defined SWIG_HAVE_SNPRINTF) && \ !defined SWIG_NO_SNPRINTF # define SWIG_snprintf(O,S,F,A) snprintf(O,S,F,A) # define SWIG_snprintf2(O,S,F,A,B) snprintf(O,S,F,A,B) #else /* Fallback versions ignore the buffer size, but most of our uses either have a * fixed maximum possible size or dynamically allocate a buffer that's large * enough. */ # define SWIG_snprintf(O,S,F,A) sprintf(O,F,A) # define SWIG_snprintf2(O,S,F,A,B) sprintf(O,F,A,B) #endif #include #ifdef __cplusplus extern "C" { #endif typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); /* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ struct swig_cast_info *cast; /* linked list of types that can cast into this type */ void *clientdata; /* language specific type data */ int owndata; /* flag if the structure owns the clientdata */ } swig_type_info; /* Structure to store a type and conversion function used for casting */ typedef struct swig_cast_info { swig_type_info *type; /* pointer to type that is equivalent to this type */ swig_converter_func converter; /* function to cast the void pointers */ struct swig_cast_info *next; /* pointer to next cast in linked list */ struct swig_cast_info *prev; /* pointer to the previous cast */ } swig_cast_info; /* Structure used to store module information * Each module generates one structure like this, and the runtime collects * all of these structures and stores them in a circularly linked list.*/ typedef struct swig_module_info { swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ size_t size; /* Number of types in this module */ struct swig_module_info *next; /* Pointer to next element in circularly linked list */ swig_type_info **type_initial; /* Array of initially generated type structures */ swig_cast_info **cast_initial; /* Array of initially generated casting structures */ void *clientdata; /* Language specific module data */ } swig_module_info; /* Compare two type names skipping the space characters, therefore "char*" == "char *" and "Class" == "Class", etc. Return 0 when the two name types are equivalent, as in strncmp, but skipping ' '. */ SWIGRUNTIME int SWIG_TypeNameComp(const char *f1, const char *l1, const char *f2, const char *l2) { for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { while ((*f1 == ' ') && (f1 != l1)) ++f1; while ((*f2 == ' ') && (f2 != l2)) ++f2; if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; } return (int)((l1 - f1) - (l2 - f2)); } /* Check type equivalence in a name list like ||... Return 0 if equal, -1 if nb < tb, 1 if nb > tb */ SWIGRUNTIME int SWIG_TypeCmp(const char *nb, const char *tb) { int equiv = 1; const char* te = tb + strlen(tb); const char* ne = nb; while (equiv != 0 && *ne) { for (nb = ne; *ne; ++ne) { if (*ne == '|') break; } equiv = SWIG_TypeNameComp(nb, ne, tb, te); if (*ne) ++ne; } return equiv; } /* Check type equivalence in a name list like ||... Return 0 if not equal, 1 if equal */ SWIGRUNTIME int SWIG_TypeEquiv(const char *nb, const char *tb) { return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; } /* Check the typename */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheck(const char *c, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (strcmp(iter->type->name, c) == 0) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheckStruct(const swig_type_info *from, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (iter->type == from) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* Dynamic pointer casting. Down an inheritance hierarchy */ SWIGRUNTIME swig_type_info * SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { swig_type_info *lastty = ty; if (!ty || !ty->dcast) return ty; while (ty && (ty->dcast)) { ty = (*ty->dcast)(ptr); if (ty) lastty = ty; } return lastty; } /* Return the name associated with this type */ SWIGRUNTIMEINLINE const char * SWIG_TypeName(const swig_type_info *ty) { return ty->name; } /* Return the pretty name associated with this type, that is an unmangled type name in a form presentable to the user. */ SWIGRUNTIME const char * SWIG_TypePrettyName(const swig_type_info *type) { /* The "str" field contains the equivalent pretty names of the type, separated by vertical-bar characters. Choose the last name. It should be the most specific; a fully resolved name but not necessarily with default template parameters expanded. */ if (!type) return NULL; if (type->str != NULL) { const char *last_name = type->str; const char *s; for (s = type->str; *s; s++) if (*s == '|') last_name = s+1; return last_name; } else return type->name; } /* Set the clientdata field for a type */ SWIGRUNTIME void SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { swig_cast_info *cast = ti->cast; /* if (ti->clientdata == clientdata) return; */ ti->clientdata = clientdata; while (cast) { if (!cast->converter) { swig_type_info *tc = cast->type; if (!tc->clientdata) { SWIG_TypeClientData(tc, clientdata); } } cast = cast->next; } } SWIGRUNTIME void SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { SWIG_TypeClientData(ti, clientdata); ti->owndata = 1; } /* Search for a swig_type_info structure only by mangled name Search is a O(log #types) We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_MangledTypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { swig_module_info *iter = start; do { if (iter->size) { size_t l = 0; size_t r = iter->size - 1; do { /* since l+r >= 0, we can (>> 1) instead (/ 2) */ size_t i = (l + r) >> 1; const char *iname = iter->types[i]->name; if (iname) { int compare = strcmp(name, iname); if (compare == 0) { return iter->types[i]; } else if (compare < 0) { if (i) { r = i - 1; } else { break; } } else if (compare > 0) { l = i + 1; } } else { break; /* should never happen */ } } while (l <= r); } iter = iter->next; } while (iter != end); return 0; } /* Search for a swig_type_info structure for either a mangled name or a human readable name. It first searches the mangled names of the types, which is a O(log #types) If a type is not found it then searches the human readable names, which is O(#types). We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_TypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { /* STEP 1: Search the name field using binary search */ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); if (ret) { return ret; } else { /* STEP 2: If the type hasn't been found, do a complete search of the str field (the human readable name) */ swig_module_info *iter = start; do { size_t i = 0; for (; i < iter->size; ++i) { if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) return iter->types[i]; } iter = iter->next; } while (iter != end); } /* neither found a match */ return 0; } /* Pack binary data into a string */ SWIGRUNTIME char * SWIG_PackData(char *c, void *ptr, size_t sz) { static const char hex[17] = "0123456789abcdef"; const unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { unsigned char uu = *u; *(c++) = hex[(uu & 0xf0) >> 4]; *(c++) = hex[uu & 0xf]; } return c; } /* Unpack binary data from a string */ SWIGRUNTIME const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { char d = *(c++); unsigned char uu; if ((d >= '0') && (d <= '9')) uu = (unsigned char)((d - '0') << 4); else if ((d >= 'a') && (d <= 'f')) uu = (unsigned char)((d - ('a'-10)) << 4); else return (char *) 0; d = *(c++); if ((d >= '0') && (d <= '9')) uu |= (unsigned char)(d - '0'); else if ((d >= 'a') && (d <= 'f')) uu |= (unsigned char)(d - ('a'-10)); else return (char *) 0; *u = uu; } return c; } /* Pack 'void *' into a string buffer. */ SWIGRUNTIME char * SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { char *r = buff; if ((2*sizeof(void *) + 2) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,&ptr,sizeof(void *)); if (strlen(name) + 1 > (bsz - (r - buff))) return 0; strcpy(r,name); return buff; } SWIGRUNTIME const char * SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { *ptr = (void *) 0; return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sizeof(void *)); } SWIGRUNTIME char * SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { char *r = buff; size_t lname = (name ? strlen(name) : 0); if ((2*sz + 2 + lname) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,ptr,sz); if (lname) { strncpy(r,name,lname+1); } else { *r = 0; } return buff; } SWIGRUNTIME const char * SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { memset(ptr,0,sz); return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sz); } #ifdef __cplusplus } #endif /* SWIG Errors applicable to all language modules, values are reserved from -1 to -99 */ #define SWIG_UnknownError -1 #define SWIG_IOError -2 #define SWIG_RuntimeError -3 #define SWIG_IndexError -4 #define SWIG_TypeError -5 #define SWIG_DivisionByZero -6 #define SWIG_OverflowError -7 #define SWIG_SyntaxError -8 #define SWIG_ValueError -9 #define SWIG_SystemError -10 #define SWIG_AttributeError -11 #define SWIG_MemoryError -12 #define SWIG_NullReferenceError -13 /* Compatibility macros for Python 3 */ #if PY_VERSION_HEX >= 0x03000000 #define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) #define PyInt_Check(x) PyLong_Check(x) #define PyInt_AsLong(x) PyLong_AsLong(x) #define PyInt_FromLong(x) PyLong_FromLong(x) #define PyInt_FromSize_t(x) PyLong_FromSize_t(x) #define PyString_Check(name) PyBytes_Check(name) #define PyString_FromString(x) PyUnicode_FromString(x) #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) #define PyString_AsString(str) PyBytes_AsString(str) #define PyString_Size(str) PyBytes_Size(str) #define PyString_InternFromString(key) PyUnicode_InternFromString(key) #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE #define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) #endif #ifndef Py_TYPE # define Py_TYPE(op) ((op)->ob_type) #endif /* SWIG APIs for compatibility of both Python 2 & 3 */ #if PY_VERSION_HEX >= 0x03000000 # define SWIG_Python_str_FromFormat PyUnicode_FromFormat #else # define SWIG_Python_str_FromFormat PyString_FromFormat #endif /* Wrapper around PyUnicode_AsUTF8AndSize - call Py_XDECREF on the returned pbytes when finished with the returned string */ SWIGINTERN const char * SWIG_PyUnicode_AsUTF8AndSize(PyObject *str, Py_ssize_t *psize, PyObject **pbytes) { #if PY_VERSION_HEX >= 0x03030000 # if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 *pbytes = NULL; return PyUnicode_AsUTF8AndSize(str, psize); # else *pbytes = PyUnicode_AsUTF8String(str); const char *chars = *pbytes ? PyBytes_AsString(*pbytes) : NULL; if (chars && psize) *psize = PyBytes_Size(*pbytes); return chars; # endif #else char *chars = NULL; *pbytes = NULL; PyString_AsStringAndSize(str, &chars, psize); return chars; #endif } SWIGINTERN PyObject* SWIG_Python_str_FromChar(const char *c) { #if PY_VERSION_HEX >= 0x03000000 return PyUnicode_FromString(c); #else return PyString_FromString(c); #endif } #ifndef PyObject_DEL # define PyObject_DEL PyObject_Del #endif /* SWIGPY_USE_CAPSULE is no longer used within SWIG itself, but some user interface files check for it. */ # define SWIGPY_USE_CAPSULE #ifdef SWIGPYTHON_BUILTIN # define SWIGPY_CAPSULE_ATTR_NAME "type_pointer_capsule_builtin" SWIG_TYPE_TABLE_NAME #else # define SWIGPY_CAPSULE_ATTR_NAME "type_pointer_capsule" SWIG_TYPE_TABLE_NAME #endif # define SWIGPY_CAPSULE_NAME ("swig_runtime_data" SWIG_RUNTIME_VERSION "." SWIGPY_CAPSULE_ATTR_NAME) #if PY_VERSION_HEX < 0x03020000 #define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type) #define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name) #define Py_hash_t long #endif #ifdef Py_LIMITED_API # define PyTuple_GET_ITEM PyTuple_GetItem /* Note that PyTuple_SetItem() has different semantics from PyTuple_SET_ITEM as it decref's the original tuple item, so in general they cannot be used interchangeably. However in SWIG-generated code PyTuple_SET_ITEM is only used with newly initialized tuples without any items and for them this does work. */ # define PyTuple_SET_ITEM PyTuple_SetItem # define PyTuple_GET_SIZE PyTuple_Size # define PyCFunction_GET_FLAGS PyCFunction_GetFlags # define PyCFunction_GET_FUNCTION PyCFunction_GetFunction # define PyCFunction_GET_SELF PyCFunction_GetSelf # define PyList_GET_ITEM PyList_GetItem # define PyList_SET_ITEM PyList_SetItem # define PySliceObject PyObject #endif /* ----------------------------------------------------------------------------- * error manipulation * ----------------------------------------------------------------------------- */ SWIGRUNTIME PyObject* SWIG_Python_ErrorType(int code) { PyObject* type = 0; switch(code) { case SWIG_MemoryError: type = PyExc_MemoryError; break; case SWIG_IOError: type = PyExc_IOError; break; case SWIG_RuntimeError: type = PyExc_RuntimeError; break; case SWIG_IndexError: type = PyExc_IndexError; break; case SWIG_TypeError: type = PyExc_TypeError; break; case SWIG_DivisionByZero: type = PyExc_ZeroDivisionError; break; case SWIG_OverflowError: type = PyExc_OverflowError; break; case SWIG_SyntaxError: type = PyExc_SyntaxError; break; case SWIG_ValueError: type = PyExc_ValueError; break; case SWIG_SystemError: type = PyExc_SystemError; break; case SWIG_AttributeError: type = PyExc_AttributeError; break; default: type = PyExc_RuntimeError; } return type; } SWIGRUNTIME void SWIG_Python_AddErrorMsg(const char* mesg) { PyObject *type = 0; PyObject *value = 0; PyObject *traceback = 0; if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); if (value) { PyObject *old_str = PyObject_Str(value); PyObject *bytes = NULL; const char *tmp = SWIG_PyUnicode_AsUTF8AndSize(old_str, NULL, &bytes); PyErr_Clear(); Py_XINCREF(type); if (tmp) PyErr_Format(type, "%s %s", tmp, mesg); else PyErr_Format(type, "%s", mesg); Py_XDECREF(bytes); Py_DECREF(old_str); Py_DECREF(value); } else { PyErr_SetString(PyExc_RuntimeError, mesg); } } SWIGRUNTIME int SWIG_Python_TypeErrorOccurred(PyObject *obj) { PyObject *error; if (obj) return 0; error = PyErr_Occurred(); return error && PyErr_GivenExceptionMatches(error, PyExc_TypeError); } SWIGRUNTIME void SWIG_Python_RaiseOrModifyTypeError(const char *message) { if (SWIG_Python_TypeErrorOccurred(NULL)) { /* Use existing TypeError to preserve stacktrace and enhance with given message */ PyObject *newvalue; PyObject *type = NULL, *value = NULL, *traceback = NULL; PyErr_Fetch(&type, &value, &traceback); #if PY_VERSION_HEX >= 0x03000000 newvalue = PyUnicode_FromFormat("%S\nAdditional information:\n%s", value, message); #else newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message); #endif if (newvalue) { Py_XDECREF(value); PyErr_Restore(type, newvalue, traceback); } else { PyErr_Restore(type, value, traceback); } } else { /* Raise TypeError using given message */ PyErr_SetString(PyExc_TypeError, message); } } #if defined(SWIG_PYTHON_NO_THREADS) # if defined(SWIG_PYTHON_THREADS) # undef SWIG_PYTHON_THREADS # endif #endif #if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ # if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) # define SWIG_PYTHON_USE_GIL # endif # if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ # if !defined(SWIG_PYTHON_INITIALIZE_THREADS) # if PY_VERSION_HEX < 0x03070000 # define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() # else # define SWIG_PYTHON_INITIALIZE_THREADS # endif # endif # ifdef __cplusplus /* C++ code */ class SWIG_Python_Thread_Block { bool status; PyGILState_STATE state; public: void end() { if (status) { PyGILState_Release(state); status = false;} } SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} ~SWIG_Python_Thread_Block() { end(); } }; class SWIG_Python_Thread_Allow { bool status; PyThreadState *save; public: void end() { if (status) { status = false; PyEval_RestoreThread(save); }} SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} ~SWIG_Python_Thread_Allow() { end(); } }; # define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block # define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() # define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow # define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() # else /* C code */ # define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() # define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) # define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() # define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) # endif # else /* Old thread way, not implemented, user must provide it */ # if !defined(SWIG_PYTHON_INITIALIZE_THREADS) # define SWIG_PYTHON_INITIALIZE_THREADS # endif # if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) # define SWIG_PYTHON_THREAD_BEGIN_BLOCK # endif # if !defined(SWIG_PYTHON_THREAD_END_BLOCK) # define SWIG_PYTHON_THREAD_END_BLOCK # endif # if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) # define SWIG_PYTHON_THREAD_BEGIN_ALLOW # endif # if !defined(SWIG_PYTHON_THREAD_END_ALLOW) # define SWIG_PYTHON_THREAD_END_ALLOW # endif # endif #else /* No thread support */ # define SWIG_PYTHON_INITIALIZE_THREADS # define SWIG_PYTHON_THREAD_BEGIN_BLOCK # define SWIG_PYTHON_THREAD_END_BLOCK # define SWIG_PYTHON_THREAD_BEGIN_ALLOW # define SWIG_PYTHON_THREAD_END_ALLOW #endif /* ----------------------------------------------------------------------------- * Python API portion that goes into the runtime * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #endif /* ----------------------------------------------------------------------------- * Constant declarations * ----------------------------------------------------------------------------- */ /* Constant Types */ #define SWIG_PY_POINTER 4 #define SWIG_PY_BINARY 5 /* Constant information structure */ typedef struct swig_const_info { int type; const char *name; long lvalue; double dvalue; void *pvalue; swig_type_info **ptype; } swig_const_info; #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * pyrun.swg * * This file contains the runtime support for Python modules * and includes code for managing global variables and pointer * type checking. * * ----------------------------------------------------------------------------- */ #if PY_VERSION_HEX < 0x02070000 /* 2.7.0 */ # error "This version of SWIG only supports Python >= 2.7" #endif #if PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03030000 # error "This version of SWIG only supports Python 3 >= 3.3" #endif /* Common SWIG API */ /* for raw pointers */ #define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) #ifdef SWIGPYTHON_BUILTIN #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(self, ptr, type, flags) #else #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) #endif #define SWIG_InternalNewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) #define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) #define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) #define swig_owntype int /* for raw packed data */ #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) /* for class or struct pointers */ #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) /* for C or C++ function pointers */ #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(NULL, ptr, type, 0) /* for C++ member pointers, ie, member methods */ #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) /* Runtime API */ #define SWIG_GetModule(clientdata) SWIG_Python_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) #define SWIG_NewClientData(obj) SwigPyClientData_New(obj) #define SWIG_SetErrorObj SWIG_Python_SetErrorObj #define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg #define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) #define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) #define SWIG_fail goto fail /* Runtime API implementation */ /* Error manipulation */ SWIGINTERN void SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetObject(errtype, obj); Py_DECREF(obj); SWIG_PYTHON_THREAD_END_BLOCK; } SWIGINTERN void SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetString(errtype, msg); SWIG_PYTHON_THREAD_END_BLOCK; } #define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) /* Set a constant value */ #if defined(SWIGPYTHON_BUILTIN) SWIGINTERN void SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) { PyObject *s = PyString_InternFromString(key); PyList_Append(seq, s); Py_DECREF(s); } SWIGINTERN void SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { PyDict_SetItemString(d, name, obj); Py_DECREF(obj); if (public_interface) SwigPyBuiltin_AddPublicSymbol(public_interface, name); } #else SWIGINTERN void SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { PyDict_SetItemString(d, name, obj); Py_DECREF(obj); } #endif /* Append a value to the result obj */ SWIGINTERN PyObject* SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { if (!result) { result = obj; } else if (result == Py_None) { Py_DECREF(result); result = obj; } else { if (!PyList_Check(result)) { PyObject *o2 = result; result = PyList_New(1); if (result) { PyList_SET_ITEM(result, 0, o2); } else { Py_DECREF(obj); return o2; } } PyList_Append(result,obj); Py_DECREF(obj); } return result; } /* Unpack the argument tuple */ SWIGINTERN Py_ssize_t SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) { if (!args) { if (!min && !max) { return 1; } else { PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", name, (min == max ? "" : "at least "), (int)min); return 0; } } if (!PyTuple_Check(args)) { if (min <= 1 && max >= 1) { Py_ssize_t i; objs[0] = args; for (i = 1; i < max; ++i) { objs[i] = 0; } return 2; } PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); return 0; } else { Py_ssize_t l = PyTuple_GET_SIZE(args); if (l < min) { PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", name, (min == max ? "" : "at least "), (int)min, (int)l); return 0; } else if (l > max) { PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", name, (min == max ? "" : "at most "), (int)max, (int)l); return 0; } else { Py_ssize_t i; for (i = 0; i < l; ++i) { objs[i] = PyTuple_GET_ITEM(args, i); } for (; l < max; ++l) { objs[l] = 0; } return i + 1; } } } SWIGINTERN int SWIG_Python_CheckNoKeywords(PyObject *kwargs, const char *name) { int no_kwargs = 1; if (kwargs) { assert(PyDict_Check(kwargs)); if (PyDict_Size(kwargs) > 0) { PyErr_Format(PyExc_TypeError, "%s() does not take keyword arguments", name); no_kwargs = 0; } } return no_kwargs; } /* A functor is a function object with one single object argument */ #define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); /* Helper for static pointer initialization for both C and C++ code, for example static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); */ #ifdef __cplusplus #define SWIG_STATIC_POINTER(var) var #else #define SWIG_STATIC_POINTER(var) var = 0; if (!var) var #endif #ifdef __cplusplus extern "C" { #endif /* Python-specific SWIG API */ #define SWIG_newvarlink() SWIG_Python_newvarlink() #define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) #define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) /* ----------------------------------------------------------------------------- * global variable support code. * ----------------------------------------------------------------------------- */ typedef struct swig_globalvar { char *name; /* Name of global variable */ PyObject *(*get_attr)(void); /* Return the current value */ int (*set_attr)(PyObject *); /* Set the value */ struct swig_globalvar *next; } swig_globalvar; typedef struct swig_varlinkobject { PyObject_HEAD swig_globalvar *vars; } swig_varlinkobject; SWIGINTERN PyObject * swig_varlink_repr(PyObject *SWIGUNUSEDPARM(v)) { #if PY_VERSION_HEX >= 0x03000000 return PyUnicode_InternFromString(""); #else return PyString_FromString(""); #endif } SWIGINTERN PyObject * swig_varlink_str(PyObject *o) { swig_varlinkobject *v = (swig_varlinkobject *) o; #if PY_VERSION_HEX >= 0x03000000 PyObject *str = PyUnicode_InternFromString("("); PyObject *tail; PyObject *joined; swig_globalvar *var; for (var = v->vars; var; var=var->next) { tail = PyUnicode_FromString(var->name); joined = PyUnicode_Concat(str, tail); Py_DecRef(str); Py_DecRef(tail); str = joined; if (var->next) { tail = PyUnicode_InternFromString(", "); joined = PyUnicode_Concat(str, tail); Py_DecRef(str); Py_DecRef(tail); str = joined; } } tail = PyUnicode_InternFromString(")"); joined = PyUnicode_Concat(str, tail); Py_DecRef(str); Py_DecRef(tail); str = joined; #else PyObject *str = PyString_FromString("("); swig_globalvar *var; for (var = v->vars; var; var=var->next) { PyString_ConcatAndDel(&str,PyString_FromString(var->name)); if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); } PyString_ConcatAndDel(&str,PyString_FromString(")")); #endif return str; } SWIGINTERN void swig_varlink_dealloc(PyObject *o) { swig_varlinkobject *v = (swig_varlinkobject *) o; swig_globalvar *var = v->vars; while (var) { swig_globalvar *n = var->next; free(var->name); free(var); var = n; } } SWIGINTERN PyObject * swig_varlink_getattr(PyObject *o, char *n) { swig_varlinkobject *v = (swig_varlinkobject *) o; PyObject *res = NULL; swig_globalvar *var = v->vars; while (var) { if (strcmp(var->name,n) == 0) { res = (*var->get_attr)(); break; } var = var->next; } if (res == NULL && !PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; } SWIGINTERN int swig_varlink_setattr(PyObject *o, char *n, PyObject *p) { swig_varlinkobject *v = (swig_varlinkobject *) o; int res = 1; swig_globalvar *var = v->vars; while (var) { if (strcmp(var->name,n) == 0) { res = (*var->set_attr)(p); break; } var = var->next; } if (res == 1 && !PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; } SWIGINTERN PyTypeObject* swig_varlink_type(void) { static char varlink__doc__[] = "Swig var link object"; #ifndef Py_LIMITED_API static PyTypeObject varlink_type; static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { #if PY_VERSION_HEX >= 0x03000000 PyVarObject_HEAD_INIT(NULL, 0) #else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif "swigvarlink", /* tp_name */ sizeof(swig_varlinkobject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor) swig_varlink_dealloc, /* tp_dealloc */ #if PY_VERSION_HEX < 0x030800b4 (printfunc)0, /*tp_print*/ #else (Py_ssize_t)0, /*tp_vectorcall_offset*/ #endif (getattrfunc) swig_varlink_getattr, /* tp_getattr */ (setattrfunc) swig_varlink_setattr, /* tp_setattr */ 0, /* tp_compare */ (reprfunc) swig_varlink_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ (reprfunc) swig_varlink_str, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ 0, /* tp_flags */ varlink__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ 0, /* tp_del */ 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif #if PY_VERSION_HEX >= 0x03080000 0, /* tp_vectorcall */ #endif #if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) 0, /* tp_print */ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /* tp_watched */ #endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ 0, /* tp_maxalloc */ 0, /* tp_prev */ 0 /* tp_next */ #endif }; varlink_type = tmp; type_init = 1; if (PyType_Ready(&varlink_type) < 0) return NULL; } return &varlink_type; #else PyType_Slot slots[] = { { Py_tp_dealloc, (void *)swig_varlink_dealloc }, { Py_tp_repr, (void *)swig_varlink_repr }, { Py_tp_getattr, (void *)swig_varlink_getattr }, { Py_tp_setattr, (void *)swig_varlink_setattr }, { Py_tp_str, (void *)swig_varlink_str }, { Py_tp_doc, (void *)varlink__doc__ }, { 0, NULL } }; PyType_Spec spec = { "swigvarlink", sizeof(swig_varlinkobject), 0, Py_TPFLAGS_DEFAULT, slots }; return (PyTypeObject *)PyType_FromSpec(&spec); #endif } /* Create a variable linking object for use later */ SWIGINTERN PyObject * SWIG_Python_newvarlink(void) { swig_varlinkobject *result = PyObject_New(swig_varlinkobject, swig_varlink_type()); if (result) { result->vars = 0; } return ((PyObject*) result); } SWIGINTERN void SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { swig_varlinkobject *v = (swig_varlinkobject *) p; swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); if (gv) { size_t size = strlen(name)+1; gv->name = (char *)malloc(size); if (gv->name) { memcpy(gv->name, name, size); gv->get_attr = get_attr; gv->set_attr = set_attr; gv->next = v->vars; } } v->vars = gv; } static PyObject *Swig_Globals_global = NULL; SWIGINTERN PyObject * SWIG_globals(void) { if (Swig_Globals_global == NULL) { Swig_Globals_global = SWIG_newvarlink(); } return Swig_Globals_global; } #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * Pointer declarations * ----------------------------------------------------------------------------- */ /* Flags for new pointer objects */ #define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) #define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) #define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) #define SWIG_BUILTIN_TP_INIT (SWIG_POINTER_OWN << 2) #define SWIG_BUILTIN_INIT (SWIG_BUILTIN_TP_INIT | SWIG_POINTER_OWN) #ifdef __cplusplus extern "C" { #endif /* The python void return value */ SWIGRUNTIMEINLINE PyObject * SWIG_Py_Void(void) { PyObject *none = Py_None; Py_INCREF(none); return none; } /* SwigPyClientData */ typedef struct { PyObject *klass; PyObject *newraw; PyObject *newargs; PyObject *destroy; int delargs; int implicitconv; PyTypeObject *pytype; } SwigPyClientData; SWIGRUNTIMEINLINE int SWIG_Python_CheckImplicit(swig_type_info *ty) { SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; int fail = data ? data->implicitconv : 0; if (fail) PyErr_SetString(PyExc_TypeError, "Implicit conversion is prohibited for explicit constructors."); return fail; } SWIGRUNTIMEINLINE PyObject * SWIG_Python_ExceptionType(swig_type_info *desc) { SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; PyObject *klass = data ? data->klass : 0; return (klass ? klass : PyExc_RuntimeError); } SWIGRUNTIME SwigPyClientData * SwigPyClientData_New(PyObject* obj) { if (!obj) { return 0; } else { SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); /* the klass element */ data->klass = obj; Py_INCREF(data->klass); /* the newraw method and newargs arguments used to create a new raw instance */ if (PyClass_Check(obj)) { data->newraw = 0; Py_INCREF(obj); data->newargs = obj; } else { data->newraw = PyObject_GetAttrString(data->klass, "__new__"); if (data->newraw) { data->newargs = PyTuple_New(1); if (data->newargs) { Py_INCREF(obj); PyTuple_SET_ITEM(data->newargs, 0, obj); } else { Py_DECREF(data->newraw); Py_DECREF(data->klass); free(data); return 0; } } else { Py_INCREF(obj); data->newargs = obj; } } /* the destroy method, aka as the C++ delete method */ data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__"); if (PyErr_Occurred()) { PyErr_Clear(); data->destroy = 0; } if (data->destroy) { data->delargs = !(PyCFunction_GET_FLAGS(data->destroy) & METH_O); } else { data->delargs = 0; } data->implicitconv = 0; data->pytype = 0; return data; } } SWIGRUNTIME void SwigPyClientData_Del(SwigPyClientData *data) { Py_XDECREF(data->klass); Py_XDECREF(data->newraw); Py_XDECREF(data->newargs); Py_XDECREF(data->destroy); free(data); } /* =============== SwigPyObject =====================*/ typedef struct { PyObject_HEAD void *ptr; swig_type_info *ty; int own; PyObject *next; #ifdef SWIGPYTHON_BUILTIN PyObject *dict; #endif } SwigPyObject; #ifdef SWIGPYTHON_BUILTIN SWIGRUNTIME PyObject * SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)v; if (!sobj->dict) sobj->dict = PyDict_New(); Py_XINCREF(sobj->dict); return sobj->dict; } #endif SWIGRUNTIME PyObject * SwigPyObject_long(SwigPyObject *v) { return PyLong_FromVoidPtr(v->ptr); } SWIGRUNTIME PyObject * SwigPyObject_format(const char* fmt, SwigPyObject *v) { PyObject *res = NULL; PyObject *args = PyTuple_New(1); if (args) { PyObject *val = SwigPyObject_long(v); if (val) { PyObject *ofmt; PyTuple_SET_ITEM(args, 0, val); ofmt = SWIG_Python_str_FromChar(fmt); if (ofmt) { #if PY_VERSION_HEX >= 0x03000000 res = PyUnicode_Format(ofmt,args); #else res = PyString_Format(ofmt,args); #endif Py_DECREF(ofmt); } } Py_DECREF(args); } return res; } SWIGRUNTIME PyObject * SwigPyObject_oct(SwigPyObject *v) { return SwigPyObject_format("%o",v); } SWIGRUNTIME PyObject * SwigPyObject_hex(SwigPyObject *v) { return SwigPyObject_format("%x",v); } SWIGRUNTIME PyObject * SwigPyObject_repr(SwigPyObject *v) { const char *name = SWIG_TypePrettyName(v->ty); PyObject *repr = SWIG_Python_str_FromFormat("", (name ? name : "unknown"), (void *)v); if (repr && v->next) { PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); if (nrep) { # if PY_VERSION_HEX >= 0x03000000 PyObject *joined = PyUnicode_Concat(repr, nrep); Py_DecRef(repr); Py_DecRef(nrep); repr = joined; # else PyString_ConcatAndDel(&repr,nrep); # endif } else { Py_DecRef(repr); repr = NULL; } } return repr; } /* We need a version taking two PyObject* parameters so it's a valid * PyCFunction to use in swigobject_methods[]. */ SWIGRUNTIME PyObject * SwigPyObject_repr2(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { return SwigPyObject_repr((SwigPyObject*)v); } SWIGRUNTIME int SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) { void *i = v->ptr; void *j = w->ptr; return (i < j) ? -1 : ((i > j) ? 1 : 0); } /* Added for Python 3.x, would it also be useful for Python 2.x? */ SWIGRUNTIME PyObject* SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) { PyObject* res = NULL; if (!PyErr_Occurred()) { if (op != Py_EQ && op != Py_NE) { Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0); } return res; } SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void); #ifdef SWIGPYTHON_BUILTIN static swig_type_info *SwigPyObject_stype = 0; SWIGRUNTIME PyTypeObject* SwigPyObject_type(void) { SwigPyClientData *cd; assert(SwigPyObject_stype); cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; assert(cd); assert(cd->pytype); return cd->pytype; } #else SWIGRUNTIME PyTypeObject* SwigPyObject_type(void) { static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce(); return type; } #endif SWIGRUNTIMEINLINE int SwigPyObject_Check(PyObject *op) { PyTypeObject *target_tp = SwigPyObject_type(); PyTypeObject *op_type = Py_TYPE(op); #ifdef SWIGPYTHON_BUILTIN if (PyType_IsSubtype(op_type, target_tp)) return 1; return (strcmp(op_type->tp_name, "SwigPyObject") == 0); #else if (op_type == target_tp) return 1; # ifdef Py_LIMITED_API int cmp; PyObject *tp_name = PyObject_GetAttrString((PyObject *)op_type, "__name__"); if (!tp_name) return 0; cmp = PyUnicode_CompareWithASCIIString(tp_name, "SwigPyObject"); Py_DECREF(tp_name); return cmp == 0; # else return (strcmp(op_type->tp_name, "SwigPyObject") == 0); # endif #endif } SWIGRUNTIME PyObject * SwigPyObject_New(void *ptr, swig_type_info *ty, int own); static PyObject* Swig_Capsule_global = NULL; SWIGRUNTIME void SwigPyObject_dealloc(PyObject *v) { SwigPyObject *sobj = (SwigPyObject *) v; PyObject *next = sobj->next; if (sobj->own == SWIG_POINTER_OWN) { swig_type_info *ty = sobj->ty; SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; PyObject *destroy = data ? data->destroy : 0; if (destroy) { /* destroy is always a VARARGS method */ PyObject *res; /* PyObject_CallFunction() has the potential to silently drop the active exception. In cases of unnamed temporary variable or where we just finished iterating over a generator StopIteration will be active right now, and this needs to remain true upon return from SwigPyObject_dealloc. So save and restore. */ PyObject *type = NULL, *value = NULL, *traceback = NULL; PyErr_Fetch(&type, &value, &traceback); if (data->delargs) { /* we need to create a temporary object to carry the destroy operation */ PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); if (tmp) { res = SWIG_Python_CallFunctor(destroy, tmp); } else { res = 0; } Py_XDECREF(tmp); } else { PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); PyObject *mself = PyCFunction_GET_SELF(destroy); res = ((*meth)(mself, v)); } if (!res) PyErr_WriteUnraisable(destroy); PyErr_Restore(type, value, traceback); Py_XDECREF(res); } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) else { const char *name = SWIG_TypePrettyName(ty); printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); } #endif Py_XDECREF(Swig_Capsule_global); } Py_XDECREF(next); #ifdef SWIGPYTHON_BUILTIN Py_XDECREF(sobj->dict); #endif PyObject_DEL(v); } SWIGRUNTIME PyObject* SwigPyObject_append(PyObject* v, PyObject* next) { SwigPyObject *sobj = (SwigPyObject *) v; if (!SwigPyObject_Check(next)) { PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject"); return NULL; } ((SwigPyObject *)next)->next = sobj->next; sobj->next = next; Py_INCREF(next); return SWIG_Py_Void(); } SWIGRUNTIME PyObject* SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *) v; if (sobj->next) { Py_INCREF(sobj->next); return sobj->next; } else { return SWIG_Py_Void(); } } SWIGINTERN PyObject* SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)v; sobj->own = 0; return SWIG_Py_Void(); } SWIGINTERN PyObject* SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)v; sobj->own = SWIG_POINTER_OWN; return SWIG_Py_Void(); } SWIGINTERN PyObject* SwigPyObject_own(PyObject *v, PyObject *args) { PyObject *val = 0; if (!PyArg_UnpackTuple(args, "own", 0, 1, &val)) { return NULL; } else { SwigPyObject *sobj = (SwigPyObject *)v; PyObject *obj = PyBool_FromLong(sobj->own); if (val) { if (PyObject_IsTrue(val)) { Py_DECREF(SwigPyObject_acquire(v,args)); } else { Py_DECREF(SwigPyObject_disown(v,args)); } } return obj; } } static PyMethodDef swigobject_methods[] = { {"disown", SwigPyObject_disown, METH_NOARGS, "releases ownership of the pointer"}, {"acquire", SwigPyObject_acquire, METH_NOARGS, "acquires ownership of the pointer"}, {"own", SwigPyObject_own, METH_VARARGS, "returns/sets ownership of the pointer"}, {"append", SwigPyObject_append, METH_O, "appends another 'this' object"}, {"next", SwigPyObject_next, METH_NOARGS, "returns the next 'this' object"}, {"__repr__",SwigPyObject_repr2, METH_NOARGS, "returns object representation"}, {0, 0, 0, 0} }; SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void) { static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; #ifndef Py_LIMITED_API static PyNumberMethods SwigPyObject_as_number = { (binaryfunc)0, /*nb_add*/ (binaryfunc)0, /*nb_subtract*/ (binaryfunc)0, /*nb_multiply*/ /* nb_divide removed in Python 3 */ #if PY_VERSION_HEX < 0x03000000 (binaryfunc)0, /*nb_divide*/ #endif (binaryfunc)0, /*nb_remainder*/ (binaryfunc)0, /*nb_divmod*/ (ternaryfunc)0,/*nb_power*/ (unaryfunc)0, /*nb_negative*/ (unaryfunc)0, /*nb_positive*/ (unaryfunc)0, /*nb_absolute*/ (inquiry)0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_VERSION_HEX < 0x03000000 0, /*nb_coerce*/ #endif (unaryfunc)SwigPyObject_long, /*nb_int*/ #if PY_VERSION_HEX < 0x03000000 (unaryfunc)SwigPyObject_long, /*nb_long*/ #else 0, /*nb_reserved*/ #endif (unaryfunc)0, /*nb_float*/ #if PY_VERSION_HEX < 0x03000000 (unaryfunc)SwigPyObject_oct, /*nb_oct*/ (unaryfunc)SwigPyObject_hex, /*nb_hex*/ #endif #if PY_VERSION_HEX >= 0x03050000 /* 3.5 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_matrix_multiply */ #elif PY_VERSION_HEX >= 0x03000000 /* 3.0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ #else 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ #endif }; static PyTypeObject swigpyobject_type; static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { #if PY_VERSION_HEX >= 0x03000000 PyVarObject_HEAD_INIT(NULL, 0) #else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif "SwigPyObject", /* tp_name */ sizeof(SwigPyObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)SwigPyObject_dealloc, /* tp_dealloc */ #if PY_VERSION_HEX < 0x030800b4 (printfunc)0, /*tp_print*/ #else (Py_ssize_t)0, /*tp_vectorcall_offset*/ #endif (getattrfunc)0, /* tp_getattr */ (setattrfunc)0, /* tp_setattr */ #if PY_VERSION_HEX >= 0x03000000 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ #else (cmpfunc)SwigPyObject_compare, /* tp_compare */ #endif (reprfunc)SwigPyObject_repr, /* tp_repr */ &SwigPyObject_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)0, /* tp_hash */ (ternaryfunc)0, /* tp_call */ 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ swigobject_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ (richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ swigobject_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ 0, /* tp_bases */ 0, /* tp_mro */ 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ 0, /* tp_del */ 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif #if PY_VERSION_HEX >= 0x03080000 0, /* tp_vectorcall */ #endif #if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) 0, /* tp_print */ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /* tp_watched */ #endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ 0, /* tp_maxalloc */ 0, /* tp_prev */ 0 /* tp_next */ #endif }; swigpyobject_type = tmp; type_init = 1; if (PyType_Ready(&swigpyobject_type) != 0) return NULL; } return &swigpyobject_type; #else PyType_Slot slots[] = { { Py_tp_dealloc, (void *)SwigPyObject_dealloc }, { Py_tp_repr, (void *)SwigPyObject_repr }, { Py_tp_getattro, (void *)PyObject_GenericGetAttr }, { Py_tp_doc, (void *)swigobject_doc }, { Py_tp_richcompare, (void *)SwigPyObject_richcompare }, { Py_tp_methods, (void *)swigobject_methods }, { Py_nb_int, (void *)SwigPyObject_long }, { 0, NULL } }; PyType_Spec spec = { "SwigPyObject", sizeof(SwigPyObject), 0, Py_TPFLAGS_DEFAULT, slots }; return (PyTypeObject *)PyType_FromSpec(&spec); #endif } SWIGRUNTIME PyObject * SwigPyObject_New(void *ptr, swig_type_info *ty, int own) { SwigPyObject *sobj = PyObject_New(SwigPyObject, SwigPyObject_type()); if (sobj) { sobj->ptr = ptr; sobj->ty = ty; sobj->own = own; sobj->next = 0; #ifdef SWIGPYTHON_BUILTIN sobj->dict = 0; #endif if (own == SWIG_POINTER_OWN) { /* Obtain a reference to the Python capsule wrapping the module information, so that the * module information is correctly destroyed after all SWIG python objects have been freed * by the GC (and corresponding destructors invoked) */ Py_XINCREF(Swig_Capsule_global); } } return (PyObject *)sobj; } /* ----------------------------------------------------------------------------- * Implements a simple Swig Packed type, and use it instead of string * ----------------------------------------------------------------------------- */ typedef struct { PyObject_HEAD void *pack; swig_type_info *ty; size_t size; } SwigPyPacked; SWIGRUNTIME PyObject * SwigPyPacked_repr(SwigPyPacked *v) { char result[SWIG_BUFFER_SIZE]; if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { return SWIG_Python_str_FromFormat("", result, v->ty->name); } else { return SWIG_Python_str_FromFormat("", v->ty->name); } } SWIGRUNTIME PyObject * SwigPyPacked_str(SwigPyPacked *v) { char result[SWIG_BUFFER_SIZE]; if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); } else { return SWIG_Python_str_FromChar(v->ty->name); } } SWIGRUNTIME int SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) { size_t i = v->size; size_t j = w->size; int s = (i < j) ? -1 : ((i > j) ? 1 : 0); return s ? s : strncmp((const char *)v->pack, (const char *)w->pack, 2*v->size); } SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void); SWIGRUNTIME PyTypeObject* SwigPyPacked_type(void) { static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce(); return type; } SWIGRUNTIMEINLINE int SwigPyPacked_Check(PyObject *op) { PyTypeObject* op_type = Py_TYPE(op); if (op_type == SwigPyPacked_TypeOnce()) return 1; #ifdef Py_LIMITED_API int cmp; PyObject *tp_name = PyObject_GetAttrString((PyObject *)op_type, "__name__"); if (!tp_name) return 0; cmp = PyUnicode_CompareWithASCIIString(tp_name, "SwigPyPacked"); Py_DECREF(tp_name); return cmp == 0; #else return (strcmp(op_type->tp_name, "SwigPyPacked") == 0); #endif } SWIGRUNTIME void SwigPyPacked_dealloc(PyObject *v) { if (SwigPyPacked_Check(v)) { SwigPyPacked *sobj = (SwigPyPacked *) v; free(sobj->pack); } PyObject_DEL(v); } SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void) { static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; #ifndef Py_LIMITED_API static PyTypeObject swigpypacked_type; static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { #if PY_VERSION_HEX>=0x03000000 PyVarObject_HEAD_INIT(NULL, 0) #else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif "SwigPyPacked", /* tp_name */ sizeof(SwigPyPacked), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ #if PY_VERSION_HEX < 0x030800b4 (printfunc)0, /*tp_print*/ #else (Py_ssize_t)0, /*tp_vectorcall_offset*/ #endif (getattrfunc)0, /* tp_getattr */ (setattrfunc)0, /* tp_setattr */ #if PY_VERSION_HEX>=0x03000000 0, /* tp_reserved in 3.0.1 */ #else (cmpfunc)SwigPyPacked_compare, /* tp_compare */ #endif (reprfunc)SwigPyPacked_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)0, /* tp_hash */ (ternaryfunc)0, /* tp_call */ (reprfunc)SwigPyPacked_str, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ swigpacked_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ 0, /* tp_bases */ 0, /* tp_mro */ 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ 0, /* tp_del */ 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif #if PY_VERSION_HEX >= 0x03080000 0, /* tp_vectorcall */ #endif #if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) 0, /* tp_print */ #endif #if PY_VERSION_HEX >= 0x030C0000 0, /* tp_watched */ #endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ 0, /* tp_maxalloc */ 0, /* tp_prev */ 0 /* tp_next */ #endif }; swigpypacked_type = tmp; type_init = 1; if (PyType_Ready(&swigpypacked_type) != 0) return NULL; } return &swigpypacked_type; #else PyType_Slot slots[] = { { Py_tp_dealloc, (void *)SwigPyPacked_dealloc }, { Py_tp_repr, (void *)SwigPyPacked_repr }, { Py_tp_str, (void *)SwigPyPacked_str }, { Py_tp_getattro, (void *)PyObject_GenericGetAttr }, { Py_tp_doc, (void *)swigpacked_doc }, { 0, NULL } }; PyType_Spec spec = { "SwigPyPacked", sizeof(SwigPyPacked), 0, Py_TPFLAGS_DEFAULT, slots }; return (PyTypeObject *)PyType_FromSpec(&spec); #endif } SWIGRUNTIME PyObject * SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) { SwigPyPacked *sobj = PyObject_New(SwigPyPacked, SwigPyPacked_type()); if (sobj) { void *pack = malloc(size); if (pack) { memcpy(pack, ptr, size); sobj->pack = pack; sobj->ty = ty; sobj->size = size; } else { PyObject_DEL((PyObject *) sobj); sobj = 0; } } return (PyObject *) sobj; } SWIGRUNTIME swig_type_info * SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) { if (SwigPyPacked_Check(obj)) { SwigPyPacked *sobj = (SwigPyPacked *)obj; if (sobj->size != size) return 0; memcpy(ptr, sobj->pack, size); return sobj->ty; } else { return 0; } } /* ----------------------------------------------------------------------------- * pointers/data manipulation * ----------------------------------------------------------------------------- */ static PyObject *Swig_This_global = NULL; SWIGRUNTIME PyObject * SWIG_This(void) { if (Swig_This_global == NULL) Swig_This_global = SWIG_Python_str_FromChar("this"); return Swig_This_global; } /* #define SWIG_PYTHON_SLOW_GETSET_THIS */ /* TODO: I don't know how to implement the fast getset in Python 3 right now */ #if PY_VERSION_HEX>=0x03000000 #define SWIG_PYTHON_SLOW_GETSET_THIS #endif SWIGRUNTIME SwigPyObject * SWIG_Python_GetSwigThis(PyObject *pyobj) { PyObject *obj; if (SwigPyObject_Check(pyobj)) return (SwigPyObject *) pyobj; #ifdef SWIGPYTHON_BUILTIN (void)obj; # ifdef PyWeakref_CheckProxy if (PyWeakref_CheckProxy(pyobj)) { pyobj = PyWeakref_GET_OBJECT(pyobj); if (pyobj && SwigPyObject_Check(pyobj)) return (SwigPyObject*) pyobj; } # endif return NULL; #else obj = 0; #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) if (PyInstance_Check(pyobj)) { obj = _PyInstance_Lookup(pyobj, SWIG_This()); } else { PyObject **dictptr = _PyObject_GetDictPtr(pyobj); if (dictptr != NULL) { PyObject *dict = *dictptr; obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; } else { #ifdef PyWeakref_CheckProxy if (PyWeakref_CheckProxy(pyobj)) { PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; } #endif obj = PyObject_GetAttr(pyobj,SWIG_This()); if (obj) { Py_DECREF(obj); } else { if (PyErr_Occurred()) PyErr_Clear(); return 0; } } } #else obj = PyObject_GetAttr(pyobj,SWIG_This()); if (obj) { Py_DECREF(obj); } else { if (PyErr_Occurred()) PyErr_Clear(); return 0; } #endif if (obj && !SwigPyObject_Check(obj)) { /* a PyObject is called 'this', try to get the 'real this' SwigPyObject from it */ return SWIG_Python_GetSwigThis(obj); } return (SwigPyObject *)obj; #endif } /* Acquire a pointer value */ SWIGRUNTIME int SWIG_Python_AcquirePtr(PyObject *obj, int own) { if (own == SWIG_POINTER_OWN) { SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); if (sobj) { int oldown = sobj->own; sobj->own = own; return oldown; } } return 0; } /* Convert a pointer value */ SWIGRUNTIME int SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { int res; SwigPyObject *sobj; int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0; if (!obj) return SWIG_ERROR; if (obj == Py_None && !implicit_conv) { if (ptr) *ptr = 0; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } res = SWIG_ERROR; sobj = SWIG_Python_GetSwigThis(obj); if (own) *own = 0; while (sobj) { void *vptr = sobj->ptr; if (ty) { swig_type_info *to = sobj->ty; if (to == ty) { /* no type cast needed */ if (ptr) *ptr = vptr; break; } else { swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); if (!tc) { sobj = (SwigPyObject *)sobj->next; } else { if (ptr) { int newmemory = 0; *ptr = SWIG_TypeCast(tc,vptr,&newmemory); if (newmemory == SWIG_CAST_NEW_MEMORY) { assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ if (own) *own = *own | SWIG_CAST_NEW_MEMORY; } } break; } } } else { if (ptr) *ptr = vptr; break; } } if (sobj) { if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !sobj->own) { res = SWIG_ERROR_RELEASE_NOT_OWNED; } else { if (own) *own = *own | sobj->own; if (flags & SWIG_POINTER_DISOWN) { sobj->own = 0; } if (flags & SWIG_POINTER_CLEAR) { sobj->ptr = 0; } res = SWIG_OK; } } else { if (implicit_conv) { SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; if (data && !data->implicitconv) { PyObject *klass = data->klass; if (klass) { PyObject *impconv; data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ impconv = SWIG_Python_CallFunctor(klass, obj); data->implicitconv = 0; if (PyErr_Occurred()) { PyErr_Clear(); impconv = 0; } if (impconv) { SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); if (iobj) { void *vptr; res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); if (SWIG_IsOK(res)) { if (ptr) { *ptr = vptr; /* transfer the ownership to 'ptr' */ iobj->own = 0; res = SWIG_AddCast(res); res = SWIG_AddNewMask(res); } else { res = SWIG_AddCast(res); } } } Py_DECREF(impconv); } } } if (!SWIG_IsOK(res) && obj == Py_None) { if (ptr) *ptr = 0; if (PyErr_Occurred()) PyErr_Clear(); res = SWIG_OK; } } } return res; } /* Convert a function ptr value */ SWIGRUNTIME int SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { if (!PyCFunction_Check(obj)) { return SWIG_ConvertPtr(obj, ptr, ty, 0); } else { void *vptr = 0; swig_cast_info *tc; /* here we get the method pointer for callbacks */ #ifndef Py_LIMITED_API const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); #else PyObject* pystr_doc = PyObject_GetAttrString(obj, "__doc__"); PyObject *bytes = NULL; const char *doc = pystr_doc ? SWIG_PyUnicode_AsUTF8AndSize(pystr_doc, NULL, &bytes) : 0; #endif const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; if (desc) desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; #ifdef Py_LIMITED_API Py_XDECREF(bytes); Py_XDECREF(pystr_doc); #endif if (!desc) return SWIG_ERROR; tc = SWIG_TypeCheck(desc,ty); if (tc) { int newmemory = 0; *ptr = SWIG_TypeCast(tc,vptr,&newmemory); assert(!newmemory); /* newmemory handling not yet implemented */ } else { return SWIG_ERROR; } return SWIG_OK; } } /* Convert a packed pointer value */ SWIGRUNTIME int SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); if (!to) return SWIG_ERROR; if (ty) { if (to != ty) { /* check type cast? */ swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); if (!tc) return SWIG_ERROR; } } return SWIG_OK; } /* ----------------------------------------------------------------------------- * Create a new pointer object * ----------------------------------------------------------------------------- */ /* Create a new instance object, without calling __init__, and set the 'this' attribute. */ SWIGRUNTIME PyObject* SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) { PyObject *inst = 0; PyObject *newraw = data->newraw; if (newraw) { inst = PyObject_Call(newraw, data->newargs, NULL); if (inst) { #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) PyObject **dictptr = _PyObject_GetDictPtr(inst); if (dictptr != NULL) { PyObject *dict = *dictptr; if (dict == NULL) { dict = PyDict_New(); *dictptr = dict; } if (dict) { PyDict_SetItem(dict, SWIG_This(), swig_this); } else{ Py_DECREF(inst); inst = 0; } } #else if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) { Py_DECREF(inst); inst = 0; } #endif } } else { #if PY_VERSION_HEX >= 0x03000000 PyObject *empty_args = PyTuple_New(0); if (empty_args) { PyObject *empty_kwargs = PyDict_New(); if (empty_kwargs) { #ifndef Py_LIMITED_API newfunc newfn = ((PyTypeObject *)data->newargs)->tp_new; #else newfunc newfn = (newfunc)PyType_GetSlot((PyTypeObject *)data->newargs, Py_tp_new); #endif inst = newfn((PyTypeObject *)data->newargs, empty_args, empty_kwargs); Py_DECREF(empty_kwargs); if (inst) { if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) { Py_DECREF(inst); inst = 0; } else { PyType_Modified(Py_TYPE(inst)); } } } Py_DECREF(empty_args); } #else PyObject *dict = PyDict_New(); if (dict) { PyDict_SetItem(dict, SWIG_This(), swig_this); inst = PyInstance_NewRaw(data->newargs, dict); Py_DECREF(dict); } #endif } return inst; } SWIGRUNTIME int SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) { #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) PyObject **dictptr = _PyObject_GetDictPtr(inst); if (dictptr != NULL) { PyObject *dict = *dictptr; if (dict == NULL) { dict = PyDict_New(); *dictptr = dict; } if (dict) { return PyDict_SetItem(dict, SWIG_This(), swig_this); } else{ return -1; } } #endif return PyObject_SetAttr(inst, SWIG_This(), swig_this); } SWIGINTERN PyObject * SWIG_Python_InitShadowInstance(PyObject *args) { PyObject *obj[2]; if (!SWIG_Python_UnpackTuple(args, "swiginit", 2, 2, obj)) { return NULL; } else { SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); if (sthis) { Py_DECREF(SwigPyObject_append((PyObject*) sthis, obj[1])); } else { if (SWIG_Python_SetSwigThis(obj[0], obj[1]) != 0) return NULL; } return SWIG_Py_Void(); } } /* Create a new pointer object */ SWIGRUNTIME PyObject * SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { SwigPyClientData *clientdata; PyObject * robj; int own; if (!ptr) return SWIG_Py_Void(); clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; if (clientdata && clientdata->pytype) { SwigPyObject *newobj; if (flags & SWIG_BUILTIN_TP_INIT) { newobj = (SwigPyObject*) self; if (newobj->ptr) { #ifndef Py_LIMITED_API allocfunc alloc = clientdata->pytype->tp_alloc; #else allocfunc alloc = (allocfunc)PyType_GetSlot(clientdata->pytype, Py_tp_alloc); #endif PyObject *next_self = alloc(clientdata->pytype, 0); while (newobj->next) newobj = (SwigPyObject *) newobj->next; newobj->next = next_self; newobj = (SwigPyObject *)next_self; #ifdef SWIGPYTHON_BUILTIN newobj->dict = 0; #endif } } else { newobj = PyObject_New(SwigPyObject, clientdata->pytype); #ifdef SWIGPYTHON_BUILTIN if (newobj) { newobj->dict = 0; } #endif } if (newobj) { newobj->ptr = ptr; newobj->ty = type; newobj->own = own; newobj->next = 0; return (PyObject*) newobj; } return SWIG_Py_Void(); } assert(!(flags & SWIG_BUILTIN_TP_INIT)); robj = SwigPyObject_New(ptr, type, own); if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); Py_DECREF(robj); robj = inst; } return robj; } /* Create a new packed object */ SWIGRUNTIMEINLINE PyObject * SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); } /* -----------------------------------------------------------------------------* * Get type list * -----------------------------------------------------------------------------*/ #ifdef SWIG_LINK_RUNTIME void *SWIG_ReturnGlobalTypeList(void *); #endif static PyObject *Swig_TypeCache_global = NULL; /* The python cached type query */ SWIGRUNTIME PyObject * SWIG_Python_TypeCache(void) { if (Swig_TypeCache_global == NULL) { Swig_TypeCache_global = PyDict_New(); } return Swig_TypeCache_global; } SWIGRUNTIME swig_module_info * SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { #ifdef SWIG_LINK_RUNTIME static void *type_pointer = (void *)0; /* first check if module already created */ if (!type_pointer) { type_pointer = SWIG_ReturnGlobalTypeList((void *)0); } #else void *type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); if (PyErr_Occurred()) { PyErr_Clear(); type_pointer = (void *)0; } #endif return (swig_module_info *) type_pointer; } static int interpreter_counter = 0; /* how many (sub-)interpreters are using swig_module's types */ SWIGRUNTIME void SWIG_Python_DestroyModule(PyObject *obj) { swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME); swig_type_info **types = swig_module->types; size_t i; if (--interpreter_counter != 0) /* another sub-interpreter may still be using the swig_module's types */ return; for (i =0; i < swig_module->size; ++i) { swig_type_info *ty = types[i]; if (ty->owndata) { SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; ty->clientdata = 0; if (data) SwigPyClientData_Del(data); } } Py_DECREF(SWIG_This()); Swig_This_global = NULL; Py_DECREF(SWIG_globals()); Swig_Globals_global = NULL; Py_DECREF(SWIG_Python_TypeCache()); Swig_TypeCache_global = NULL; Swig_Capsule_global = NULL; } SWIGRUNTIME void SWIG_Python_SetModule(swig_module_info *swig_module) { #if PY_VERSION_HEX >= 0x03000000 /* Add a dummy module object into sys.modules */ PyObject *module = PyImport_AddModule("swig_runtime_data" SWIG_RUNTIME_VERSION); #else static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */ PyObject *module = Py_InitModule("swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table); #endif PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); if (pointer && module) { if (PyModule_AddObject(module, SWIGPY_CAPSULE_ATTR_NAME, pointer) == 0) { ++interpreter_counter; Swig_Capsule_global = pointer; } else { Py_DECREF(pointer); } } else { Py_XDECREF(pointer); } } SWIGRUNTIME swig_type_info * SWIG_Python_TypeQuery(const char *type) { PyObject *cache = SWIG_Python_TypeCache(); PyObject *key = SWIG_Python_str_FromChar(type); PyObject *obj = PyDict_GetItem(cache, key); swig_type_info *descriptor; if (obj) { descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, NULL); } else { swig_module_info *swig_module = SWIG_GetModule(0); descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); if (descriptor) { obj = PyCapsule_New((void*) descriptor, NULL, NULL); if (obj) { PyDict_SetItem(cache, key, obj); Py_DECREF(obj); } } } Py_DECREF(key); return descriptor; } /* For backward compatibility only */ #define SWIG_POINTER_EXCEPTION 0 #define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) #define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) SWIGRUNTIME int SWIG_Python_AddErrMesg(const char* mesg, int infront) { if (PyErr_Occurred()) { PyObject *type = 0; PyObject *value = 0; PyObject *traceback = 0; PyErr_Fetch(&type, &value, &traceback); if (value) { PyObject *old_str = PyObject_Str(value); PyObject *bytes = NULL; const char *tmp = SWIG_PyUnicode_AsUTF8AndSize(old_str, NULL, &bytes); const char *errmesg = tmp ? tmp : "Invalid error message"; Py_XINCREF(type); PyErr_Clear(); if (infront) { PyErr_Format(type, "%s %s", mesg, errmesg); } else { PyErr_Format(type, "%s %s", errmesg, mesg); } Py_XDECREF(bytes); Py_DECREF(old_str); } return 1; } else { return 0; } } SWIGRUNTIME int SWIG_Python_ArgFail(int argnum) { if (PyErr_Occurred()) { /* add information about failing argument */ char mesg[256]; PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); return SWIG_Python_AddErrMesg(mesg, 1); } else { return 0; } } SWIGRUNTIMEINLINE const char * SwigPyObject_GetDesc(PyObject *self) { SwigPyObject *v = (SwigPyObject *)self; swig_type_info *ty = v ? v->ty : 0; return ty ? ty->str : ""; } SWIGRUNTIME void SWIG_Python_TypeError(const char *type, PyObject *obj) { if (type) { #if defined(SWIG_COBJECT_TYPES) if (obj && SwigPyObject_Check(obj)) { const char *otype = (const char *) SwigPyObject_GetDesc(obj); if (otype) { PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", type, otype); return; } } else #endif { #ifndef Py_LIMITED_API /* tp_name is not accessible */ const char *otype = (obj ? obj->ob_type->tp_name : 0); if (otype) { PyObject *str = PyObject_Str(obj); PyObject *bytes = NULL; const char *cstr = str ? SWIG_PyUnicode_AsUTF8AndSize(str, NULL, &bytes) : 0; if (cstr) { PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", type, otype, cstr); } else { PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", type, otype); } Py_XDECREF(bytes); Py_XDECREF(str); return; } #endif } PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); } else { PyErr_Format(PyExc_TypeError, "unexpected type is received"); } } /* Convert a pointer value, signal an exception on a type mismatch */ SWIGRUNTIME void * SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) { void *result; if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { PyErr_Clear(); } return result; } #ifdef SWIGPYTHON_BUILTIN SWIGRUNTIME int SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyTypeObject *tp = obj->ob_type; PyObject *descr; PyObject *encoded_name; descrsetfunc f; int res = -1; # ifdef Py_USING_UNICODE if (PyString_Check(name)) { name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); if (!name) return -1; } else if (!PyUnicode_Check(name)) # else if (!PyString_Check(name)) # endif { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); return -1; } else { Py_INCREF(name); } if (!tp->tp_dict) { if (PyType_Ready(tp) != 0) goto done; } descr = _PyType_Lookup(tp, name); f = NULL; if (descr != NULL) f = descr->ob_type->tp_descr_set; if (!f) { if (PyString_Check(name)) { encoded_name = name; Py_INCREF(name); } else { encoded_name = PyUnicode_AsUTF8String(name); if (!encoded_name) goto done; } PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); Py_DECREF(encoded_name); } else { res = f(descr, obj, value); } done: Py_DECREF(name); return res; } #endif #ifdef __cplusplus } #endif #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) #define SWIG_contract_assert(expr, msg) do { if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } } while (0) #define SWIG_exception(code, msg) do { SWIG_Error(code, msg); SWIG_fail;; } while(0) /* -------- TYPES TABLE (BEGIN) -------- */ #define SWIGTYPE_p_char swig_types[0] #define SWIGTYPE_p_marisa__Key swig_types[1] #define SWIGTYPE_p_marisa_swig__Agent swig_types[2] #define SWIGTYPE_p_marisa_swig__Key swig_types[3] #define SWIGTYPE_p_marisa_swig__Keyset swig_types[4] #define SWIGTYPE_p_marisa_swig__Query swig_types[5] #define SWIGTYPE_p_marisa_swig__Trie swig_types[6] #define SWIGTYPE_p_p_char swig_types[7] #define SWIGTYPE_p_std__size_t swig_types[8] static swig_type_info *swig_types[10]; static swig_module_info swig_module = {swig_types, 9, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) /* -------- TYPES TABLE (END) -------- */ #ifdef SWIG_TypeQuery # undef SWIG_TypeQuery #endif #define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _marisa.so ------------------------------------------------*/ #if PY_VERSION_HEX >= 0x03000000 # define SWIG_init PyInit__marisa #else # define SWIG_init init_marisa #endif #define SWIG_name "_marisa" #ifdef __cplusplus #include /* SwigValueWrapper is described in swig.swg */ template class SwigValueWrapper { struct SwigSmartPointer { T *ptr; SwigSmartPointer(T *p) : ptr(p) { } ~SwigSmartPointer() { delete ptr; } SwigSmartPointer& operator=(SwigSmartPointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } void reset(T *p) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = p; } } pointer; SwigValueWrapper& operator=(const SwigValueWrapper& rhs); SwigValueWrapper(const SwigValueWrapper& rhs); public: SwigValueWrapper() : pointer(0) { } SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; } #if __cplusplus >=201103L SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; } operator T&&() const { return std::move(*pointer.ptr); } #else operator T&() const { return *pointer.ptr; } #endif T *operator&() const { return pointer.ptr; } static void reset(SwigValueWrapper& t, T *p) { t.pointer.reset(p); } }; /* * SwigValueInit() is a generic initialisation solution as the following approach: * * T c_result = T(); * * doesn't compile for all types for example: * * unsigned int c_result = unsigned int(); */ template T SwigValueInit() { return T(); } #if __cplusplus >=201103L # define SWIG_STD_MOVE(OBJ) std::move(OBJ) #else # define SWIG_STD_MOVE(OBJ) OBJ #endif #endif #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) #include namespace swig { class SwigPtr_PyObject { protected: PyObject *_obj; public: SwigPtr_PyObject() :_obj(0) { } SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); SWIG_PYTHON_THREAD_END_BLOCK; } SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) { if (initial_ref) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); SWIG_PYTHON_THREAD_END_BLOCK; } } SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(item._obj); Py_XDECREF(_obj); _obj = item._obj; SWIG_PYTHON_THREAD_END_BLOCK; return *this; } ~SwigPtr_PyObject() { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XDECREF(_obj); SWIG_PYTHON_THREAD_END_BLOCK; } operator PyObject *() const { return _obj; } PyObject *operator->() const { return _obj; } }; } namespace swig { struct SwigVar_PyObject : SwigPtr_PyObject { SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { } SwigVar_PyObject & operator = (PyObject* obj) { Py_XDECREF(_obj); _obj = obj; return *this; } }; } #include "marisa-swig-python3.h" SWIGINTERNINLINE PyObject* SWIG_From_int (int value) { return PyInt_FromLong((long) value); } SWIGINTERN swig_type_info* SWIG_pchar_descriptor(void) { static int init = 0; static swig_type_info* info = 0; if (!init) { info = SWIG_TypeQuery("_p_char"); init = 1; } return info; } SWIGINTERNINLINE PyObject * SWIG_FromCharPtrAndSize(const char* carray, size_t size) { if (carray) { if (size > INT_MAX) { swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); return pchar_descriptor ? SWIG_InternalNewPointerObj(const_cast< char * >(carray), pchar_descriptor, 0) : SWIG_Py_Void(); } else { #if PY_VERSION_HEX >= 0x03000000 #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) return PyBytes_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); #else return PyUnicode_DecodeUTF8(carray, static_cast< Py_ssize_t >(size), "surrogateescape"); #endif #else return PyString_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); #endif } } else { return SWIG_Py_Void(); } } #define SWIG_From_long PyInt_FromLong SWIGINTERNINLINE PyObject* SWIG_From_unsigned_SS_long (unsigned long value) { return (value > LONG_MAX) ? PyLong_FromUnsignedLong(value) : PyInt_FromLong(static_cast< long >(value)); } #include #if !defined(SWIG_NO_LLONG_MAX) # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) # define LLONG_MAX __LONG_LONG_MAX__ # define LLONG_MIN (-LLONG_MAX - 1LL) # define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) # endif #endif #if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE) # define SWIG_LONG_LONG_AVAILABLE #endif #ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE PyObject* SWIG_From_unsigned_SS_long_SS_long (unsigned long long value) { return (value > LONG_MAX) ? PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(static_cast< long >(value)); } #endif SWIGINTERNINLINE PyObject * SWIG_From_size_t (size_t value) { #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif return SWIG_From_unsigned_SS_long (static_cast< unsigned long >(value)); #ifdef SWIG_LONG_LONG_AVAILABLE } else { /* assume sizeof(size_t) <= sizeof(unsigned long long) */ return SWIG_From_unsigned_SS_long_SS_long (static_cast< unsigned long long >(value)); } #endif } #define SWIG_From_double PyFloat_FromDouble SWIGINTERNINLINE PyObject * SWIG_From_float (float value) { return SWIG_From_double (value); } /* Return string from Python obj. NOTE: obj must remain in scope in order to use the returned cptr (but only when alloc is set to SWIG_OLDOBJ) */ SWIGINTERN int SWIG_AsCharPtrAndSize(PyObject *obj, char **cptr, size_t *psize, int *alloc) { #if PY_VERSION_HEX>=0x03000000 #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) if (PyBytes_Check(obj)) #else if (PyUnicode_Check(obj)) #endif #else if (PyString_Check(obj)) #endif { char *cstr; Py_ssize_t len; PyObject *bytes = NULL; int ret = SWIG_OK; if (alloc) *alloc = SWIG_OLDOBJ; #if PY_VERSION_HEX>=0x03000000 && defined(SWIG_PYTHON_STRICT_BYTE_CHAR) if (PyBytes_AsStringAndSize(obj, &cstr, &len) == -1) return SWIG_TypeError; #else cstr = (char *)SWIG_PyUnicode_AsUTF8AndSize(obj, &len, &bytes); if (!cstr) return SWIG_TypeError; /* The returned string is only duplicated if the char * returned is not owned and memory managed by obj */ if (bytes && cptr) { if (alloc) { cstr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); *alloc = SWIG_NEWOBJ; } else { /* alloc must be set in order to clean up allocated memory */ return SWIG_RuntimeError; } } #endif if (cptr) *cptr = cstr; if (psize) *psize = len + 1; Py_XDECREF(bytes); return ret; } else { #if defined(SWIG_PYTHON_2_UNICODE) #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) #error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once" #endif #if PY_VERSION_HEX<0x03000000 if (PyUnicode_Check(obj)) { char *cstr; Py_ssize_t len; if (!alloc && cptr) { return SWIG_RuntimeError; } obj = PyUnicode_AsUTF8String(obj); if (!obj) return SWIG_TypeError; if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) { if (cptr) { if (alloc) *alloc = SWIG_NEWOBJ; *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); } if (psize) *psize = len + 1; Py_XDECREF(obj); return SWIG_OK; } else { Py_XDECREF(obj); } } #endif #endif swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); if (pchar_descriptor) { void* vptr = 0; if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { if (cptr) *cptr = (char *) vptr; if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; if (alloc) *alloc = SWIG_OLDOBJ; return SWIG_OK; } } } return SWIG_TypeError; } #include #include /* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ #ifndef SWIG_isfinite /* isfinite() is a macro for C99 */ # if defined(isfinite) # define SWIG_isfinite(X) (isfinite(X)) # elif defined(__cplusplus) && __cplusplus >= 201103L /* Use a template so that this works whether isfinite() is std::isfinite() or * in the global namespace. The reality seems to vary between compiler * versions. * * Make sure namespace std exists to avoid compiler warnings. * * extern "C++" is required as this fragment can end up inside an extern "C" { } block */ namespace std { } extern "C++" template inline int SWIG_isfinite_func(T x) { using namespace std; return isfinite(x); } # define SWIG_isfinite(X) (SWIG_isfinite_func(X)) # elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) # define SWIG_isfinite(X) (__builtin_isfinite(X)) # elif defined(_MSC_VER) # define SWIG_isfinite(X) (_finite(X)) # elif defined(__sun) && defined(__SVR4) # include # define SWIG_isfinite(X) (finite(X)) # endif #endif /* Accept infinite as a valid float value unless we are unable to check if a value is finite */ #ifdef SWIG_isfinite # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX) && SWIG_isfinite(X)) #else # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX)) #endif SWIGINTERN int SWIG_AsVal_double (PyObject *obj, double *val) { int res = SWIG_TypeError; if (PyFloat_Check(obj)) { if (val) *val = PyFloat_AsDouble(obj); return SWIG_OK; #if PY_VERSION_HEX < 0x03000000 } else if (PyInt_Check(obj)) { if (val) *val = (double) PyInt_AsLong(obj); return SWIG_OK; #endif } else if (PyLong_Check(obj)) { double v = PyLong_AsDouble(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); } } #ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; double d = PyFloat_AsDouble(obj); if (!PyErr_Occurred()) { if (val) *val = d; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { long v = PyLong_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); } else { PyErr_Clear(); } } } #endif return res; } SWIGINTERN int SWIG_AsVal_float (PyObject * obj, float *val) { double v; int res = SWIG_AsVal_double (obj, &v); if (SWIG_IsOK(res)) { if (SWIG_Float_Overflow_Check(v)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< float >(v); } } return res; } SWIGINTERNINLINE int SWIG_CanCastAsInteger(double *d, double min, double max) { double x = *d; if ((min <= x && x <= max)) { double fx, cx, rd; errno = 0; fx = floor(x); cx = ceil(x); rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ if ((errno == EDOM) || (errno == ERANGE)) { errno = 0; } else { double summ, reps, diff; if (rd < x) { diff = x - rd; } else if (rd > x) { diff = rd - x; } else { return 1; } summ = rd + x; reps = diff/summ; if (reps < 8*DBL_EPSILON) { *d = rd; return 1; } } } return 0; } SWIGINTERN int SWIG_AsVal_unsigned_SS_long (PyObject *obj, unsigned long *val) { #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { long v = PyInt_AsLong(obj); if (v >= 0) { if (val) *val = v; return SWIG_OK; } else { return SWIG_OverflowError; } } else #endif if (PyLong_Check(obj)) { unsigned long v = PyLong_AsUnsignedLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); return SWIG_OverflowError; } } #ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; unsigned long v = PyLong_AsUnsignedLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); // Largest double not larger than ULONG_MAX (not portably calculated easily) // Note that double(ULONG_MAX) is stored in a double rounded up by one (for 64-bit unsigned long) // 0xfffffffffffff800ULL == (uint64_t)std::nextafter(double(__uint128_t(ULONG_MAX)+1), double(0)) const double ulong_max = sizeof(unsigned long) == 8 ? 0xfffffffffffff800ULL : ULONG_MAX; if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ulong_max)) { if (val) *val = (unsigned long)(d); return res; } } } #endif return SWIG_TypeError; } #ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_unsigned_SS_long_SS_long (PyObject *obj, unsigned long long *val) { int res = SWIG_TypeError; if (PyLong_Check(obj)) { unsigned long long v = PyLong_AsUnsignedLongLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); res = SWIG_OverflowError; } } else { unsigned long v; res = SWIG_AsVal_unsigned_SS_long (obj,&v); if (SWIG_IsOK(res)) { if (val) *val = v; return res; } } #ifdef SWIG_PYTHON_CAST_MODE { const double mant_max = 1LL << DBL_MANT_DIG; double d; res = SWIG_AsVal_double (obj,&d); if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, 0, mant_max)) return SWIG_OverflowError; if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) { if (val) *val = (unsigned long long)(d); return SWIG_AddCast(res); } res = SWIG_TypeError; } #endif return res; } #endif SWIGINTERNINLINE int SWIG_AsVal_size_t (PyObject * obj, size_t *val) { int res = SWIG_TypeError; #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif unsigned long v; res = SWIG_AsVal_unsigned_SS_long (obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); #ifdef SWIG_LONG_LONG_AVAILABLE } else if (sizeof(size_t) <= sizeof(unsigned long long)) { unsigned long long v; res = SWIG_AsVal_unsigned_SS_long_SS_long (obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); } #endif return res; } SWIGINTERNINLINE PyObject* SWIG_From_bool (bool value) { return PyBool_FromLong(value ? 1 : 0); } SWIGINTERN int SWIG_AsVal_long (PyObject *obj, long* val) { #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { if (val) *val = PyInt_AsLong(obj); return SWIG_OK; } else #endif if (PyLong_Check(obj)) { long v = PyLong_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); return SWIG_OverflowError; } } #ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; long v = PyInt_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); // Largest double not larger than LONG_MAX (not portably calculated easily) // Note that double(LONG_MAX) is stored in a double rounded up by one (for 64-bit long) // 0x7ffffffffffffc00LL == (int64_t)std::nextafter(double(__uint128_t(LONG_MAX)+1), double(0)) const double long_max = sizeof(long) == 8 ? 0x7ffffffffffffc00LL : LONG_MAX; // No equivalent needed for 64-bit double(LONG_MIN) is exactly LONG_MIN if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, long_max)) { if (val) *val = (long)(d); return res; } } } #endif return SWIG_TypeError; } SWIGINTERN int SWIG_AsVal_int (PyObject * obj, int *val) { long v; int res = SWIG_AsVal_long (obj, &v); if (SWIG_IsOK(res)) { if ((v < INT_MIN || v > INT_MAX)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< int >(v); } } return res; } #ifdef __cplusplus extern "C" { #endif SWIGINTERN PyObject *_wrap_Key_key_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_key_str" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { ((marisa_swig::Key const *)arg1)->key_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Key_key_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_key_id" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = ((marisa_swig::Key const *)arg1)->key_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Key_weight(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; float result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Key_weight" "', argument " "1"" of type '" "marisa_swig::Key const *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = (float)((marisa_swig::Key const *)arg1)->weight(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_float(static_cast< float >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Key(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Key, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Key" "', argument " "1"" of type '" "marisa_swig::Key *""'"); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Key_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Key, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *_wrap_Query_query_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Query_query_str" "', argument " "1"" of type '" "marisa_swig::Query const *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { ((marisa_swig::Query const *)arg1)->query_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Query_query_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Query_query_id" "', argument " "1"" of type '" "marisa_swig::Query const *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { result = ((marisa_swig::Query const *)arg1)->query_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Query(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Query, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Query" "', argument " "1"" of type '" "marisa_swig::Query *""'"); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Query_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Query, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *_wrap_new_Keyset(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "new_Keyset", 0, 0, 0)) SWIG_fail; { try { result = (marisa_swig::Keyset *)new marisa_swig::Keyset(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NEW | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Keyset(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Keyset" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; marisa::Key *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa__Key, 0 | 0); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "marisa::Key const &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Keyset_push_back" "', argument " "2"" of type '" "marisa::Key const &""'"); } arg2 = reinterpret_cast< marisa::Key * >(argp2); { try { (arg1)->push_back((marisa::Key const &)*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; float arg4 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; float val4 ; int ecode4 = 0 ; (void)self; if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); ecode4 = SWIG_AsVal_float(swig_obj[2], &val4); if (!SWIG_IsOK(ecode4)) { SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Keyset_push_back" "', argument " "4"" of type '" "float""'"); } arg4 = static_cast< float >(val4); { try { (arg1)->push_back((char const *)arg2,arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back__SWIG_2(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_push_back" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Keyset_push_back" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->push_back((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Keyset_push_back(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[4] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Keyset_push_back", 0, 3, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_ConvertPtr(argv[1], 0, SWIGTYPE_p_marisa__Key, SWIG_POINTER_NO_NULL | 0); _v = SWIG_CheckState(res); if (_v) { return _wrap_Keyset_push_back__SWIG_0(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Keyset_push_back__SWIG_2(self, argc, argv); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Keyset_push_back__SWIG_2(self, argc, argv); } } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_float(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Keyset_push_back__SWIG_1(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Keyset_push_back'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Keyset::push_back(marisa::Key const &)\n" " marisa_swig::Keyset::push_back(char const *,std::size_t,float)\n" " marisa_swig::Keyset::push_back(char const *,std::size_t)\n"); return 0; } SWIGINTERN PyObject *_wrap_Keyset_key(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; PyObject *swig_obj[2] ; marisa_swig::Key *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "Keyset_key", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { result = (marisa_swig::Key *) &((marisa_swig::Keyset const *)arg1)->key(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_key_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; PyObject *swig_obj[2] ; arg3 = &temp3; arg4 = &tempn3; (void)self; if (!SWIG_Python_UnpackTuple(args, "Keyset_key_str", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key_str" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key_str" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Keyset const *)arg1)->key_str(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg3) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg3,*arg4)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_key_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; PyObject *swig_obj[2] ; std::size_t result; (void)self; if (!SWIG_Python_UnpackTuple(args, "Keyset_key_id", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_key_id" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Keyset_key_id" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { result = ((marisa_swig::Keyset const *)arg1)->key_id(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_num_keys(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_num_keys" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_empty(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; bool result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_empty" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = (bool)((marisa_swig::Keyset const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_size" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_total_length(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_total_length" "', argument " "1"" of type '" "marisa_swig::Keyset const *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->total_length(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_reset(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_reset" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->reset(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Keyset_clear(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Keyset_clear" "', argument " "1"" of type '" "marisa_swig::Keyset *""'"); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Keyset_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Keyset, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *Keyset_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { return SWIG_Python_InitShadowInstance(args); } SWIGINTERN PyObject *_wrap_new_Agent(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "new_Agent", 0, 0, 0)) SWIG_fail; { try { result = (marisa_swig::Agent *)new marisa_swig::Agent(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NEW | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Agent(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Agent" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_set_query__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_set_query" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Agent_set_query" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->set_query((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Agent_set_query__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_set_query" "', argument " "1"" of type '" "marisa_swig::Agent *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Agent_set_query" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { (arg1)->set_query(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_set_query(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[3] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Agent_set_query", 0, 2, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_size_t(argv[1], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Agent_set_query__SWIG_1(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Agent_set_query__SWIG_0(self, argc, argv); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Agent_set_query__SWIG_0(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Agent_set_query'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Agent::set_query(char const *,std::size_t)\n" " marisa_swig::Agent::set_query(std::size_t)\n"); return 0; } SWIGINTERN PyObject *_wrap_Agent_key(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::Key *result = 0 ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Key *) &((marisa_swig::Agent const *)arg1)->key(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_query(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::Query *result = 0 ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Query *) &((marisa_swig::Agent const *)arg1)->query(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_key_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key_str" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->key_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_key_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_key_id" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->key_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_query_str(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; PyObject *swig_obj[1] ; arg2 = &temp2; arg3 = &tempn2; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query_str" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->query_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg2) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Agent_query_id(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Agent_query_id" "', argument " "1"" of type '" "marisa_swig::Agent const *""'"); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->query_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Agent_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Agent, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *Agent_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { return SWIG_Python_InitShadowInstance(args); } SWIGINTERN PyObject *_wrap_new_Trie(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *result = 0 ; (void)self; if (!SWIG_Python_UnpackTuple(args, "new_Trie", 0, 0, 0)) SWIG_fail; { try { result = (marisa_swig::Trie *)new marisa_swig::Trie(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Trie, SWIG_POINTER_NEW | 0 ); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_delete_Trie(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Trie" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { delete arg1; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_build__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int val3 ; int ecode3 = 0 ; (void)self; if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_build" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); ecode3 = SWIG_AsVal_int(swig_obj[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Trie_build" "', argument " "3"" of type '" "int""'"); } arg3 = static_cast< int >(val3); { try { (arg1)->build(*arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_build__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_build" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_build" "', argument " "2"" of type '" "marisa_swig::Keyset &""'"); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); { try { (arg1)->build(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_build(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[4] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_build", 0, 3, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_build__SWIG_1(self, argc, argv); } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_int(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_build__SWIG_0(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_build'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::build(marisa_swig::Keyset &,int)\n" " marisa_swig::Trie::build(marisa_swig::Keyset &)\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_mmap__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; int val3 ; int ecode3 = 0 ; (void)self; if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_mmap" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_mmap" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); ecode3 = SWIG_AsVal_int(swig_obj[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Trie_mmap" "', argument " "3"" of type '" "int""'"); } arg3 = static_cast< int >(val3); { try { (arg1)->mmap((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_mmap__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_mmap" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_mmap" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->mmap((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_mmap(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[4] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_mmap", 0, 3, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_mmap__SWIG_1(self, argc, argv); } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_int(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_mmap__SWIG_0(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_mmap'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::mmap(char const *,int)\n" " marisa_swig::Trie::mmap(char const *)\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_load(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; PyObject *swig_obj[2] ; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_load", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_load" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_load" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->load((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_save(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; PyObject *swig_obj[2] ; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_save", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_save" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_save" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); { try { ((marisa_swig::Trie const *)arg1)->save((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_lookup__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; bool result; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_reverse_lookup__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_reverse_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_common_prefix_search(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; PyObject *swig_obj[2] ; bool result; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_common_prefix_search", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_common_prefix_search" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_common_prefix_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_common_prefix_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->common_prefix_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_predictive_search(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; PyObject *swig_obj[2] ; bool result; (void)self; if (!SWIG_Python_UnpackTuple(args, "Trie_predictive_search", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_predictive_search" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_predictive_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "Trie_predictive_search" "', argument " "2"" of type '" "marisa_swig::Agent &""'"); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->predictive_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_lookup__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; std::size_t result; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Trie_lookup" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { result = ((marisa_swig::Trie const *)arg1)->lookup((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return NULL; } SWIGINTERN PyObject *_wrap_Trie_lookup(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[3] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_lookup", 0, 2, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_lookup__SWIG_0(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Trie_lookup__SWIG_1(self, argc, argv); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_lookup__SWIG_1(self, argc, argv); } } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_lookup'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::lookup(marisa_swig::Agent &) const\n" " marisa_swig::Trie::lookup(char const *,std::size_t) const\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_reverse_lookup__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; arg3 = &temp3; arg4 = &tempn3; (void)self; if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_reverse_lookup" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Trie_reverse_lookup" "', argument " "2"" of type '" "std::size_t""'"); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); if (*arg3) { resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_FromCharPtrAndSize(*arg3,*arg4)); delete [] (*arg3); } return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_reverse_lookup(PyObject *self, PyObject *args) { Py_ssize_t argc; PyObject *argv[3] = { 0 }; if (!(argc = SWIG_Python_UnpackTuple(args, "Trie_reverse_lookup", 0, 2, argv))) SWIG_fail; --argc; if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_reverse_lookup__SWIG_0(self, argc, argv); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_size_t(argv[1], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_reverse_lookup__SWIG_1(self, argc, argv); } } } fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'Trie_reverse_lookup'.\n" " Possible C/C++ prototypes are:\n" " marisa_swig::Trie::reverse_lookup(marisa_swig::Agent &) const\n" " marisa_swig::Trie::reverse_lookup(std::size_t,char const **,std::size_t *) const\n"); return 0; } SWIGINTERN PyObject *_wrap_Trie_num_tries(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_tries" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_tries(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_num_keys(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_keys" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_num_nodes(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_num_nodes" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_nodes(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_tail_mode(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::TailMode result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_tail_mode" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::TailMode)((marisa_swig::Trie const *)arg1)->tail_mode(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_int(static_cast< int >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_node_order(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; marisa_swig::NodeOrder result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_node_order" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::NodeOrder)((marisa_swig::Trie const *)arg1)->node_order(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_int(static_cast< int >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_empty(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; bool result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_empty" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (bool)((marisa_swig::Trie const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_total_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_total_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->total_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_io_size(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; std::size_t result; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_io_size" "', argument " "1"" of type '" "marisa_swig::Trie const *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->io_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: return NULL; } SWIGINTERN PyObject *_wrap_Trie_clear(PyObject *self, PyObject *args) { PyObject *resultobj = 0; marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; (void)self; if (!args) SWIG_fail; swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Trie_clear" "', argument " "1"" of type '" "marisa_swig::Trie *""'"); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } SWIGINTERN PyObject *Trie_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_marisa_swig__Trie, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } SWIGINTERN PyObject *Trie_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { return SWIG_Python_InitShadowInstance(args); } static PyMethodDef SwigMethods[] = { { "Key_key_str", _wrap_Key_key_str, METH_O, NULL}, { "Key_key_id", _wrap_Key_key_id, METH_O, NULL}, { "Key_weight", _wrap_Key_weight, METH_O, NULL}, { "delete_Key", _wrap_delete_Key, METH_O, NULL}, { "Key_swigregister", Key_swigregister, METH_O, NULL}, { "Query_query_str", _wrap_Query_query_str, METH_O, NULL}, { "Query_query_id", _wrap_Query_query_id, METH_O, NULL}, { "delete_Query", _wrap_delete_Query, METH_O, NULL}, { "Query_swigregister", Query_swigregister, METH_O, NULL}, { "new_Keyset", _wrap_new_Keyset, METH_NOARGS, NULL}, { "delete_Keyset", _wrap_delete_Keyset, METH_O, NULL}, { "Keyset_push_back", _wrap_Keyset_push_back, METH_VARARGS, NULL}, { "Keyset_key", _wrap_Keyset_key, METH_VARARGS, NULL}, { "Keyset_key_str", _wrap_Keyset_key_str, METH_VARARGS, NULL}, { "Keyset_key_id", _wrap_Keyset_key_id, METH_VARARGS, NULL}, { "Keyset_num_keys", _wrap_Keyset_num_keys, METH_O, NULL}, { "Keyset_empty", _wrap_Keyset_empty, METH_O, NULL}, { "Keyset_size", _wrap_Keyset_size, METH_O, NULL}, { "Keyset_total_length", _wrap_Keyset_total_length, METH_O, NULL}, { "Keyset_reset", _wrap_Keyset_reset, METH_O, NULL}, { "Keyset_clear", _wrap_Keyset_clear, METH_O, NULL}, { "Keyset_swigregister", Keyset_swigregister, METH_O, NULL}, { "Keyset_swiginit", Keyset_swiginit, METH_VARARGS, NULL}, { "new_Agent", _wrap_new_Agent, METH_NOARGS, NULL}, { "delete_Agent", _wrap_delete_Agent, METH_O, NULL}, { "Agent_set_query", _wrap_Agent_set_query, METH_VARARGS, NULL}, { "Agent_key", _wrap_Agent_key, METH_O, NULL}, { "Agent_query", _wrap_Agent_query, METH_O, NULL}, { "Agent_key_str", _wrap_Agent_key_str, METH_O, NULL}, { "Agent_key_id", _wrap_Agent_key_id, METH_O, NULL}, { "Agent_query_str", _wrap_Agent_query_str, METH_O, NULL}, { "Agent_query_id", _wrap_Agent_query_id, METH_O, NULL}, { "Agent_swigregister", Agent_swigregister, METH_O, NULL}, { "Agent_swiginit", Agent_swiginit, METH_VARARGS, NULL}, { "new_Trie", _wrap_new_Trie, METH_NOARGS, NULL}, { "delete_Trie", _wrap_delete_Trie, METH_O, NULL}, { "Trie_build", _wrap_Trie_build, METH_VARARGS, NULL}, { "Trie_mmap", _wrap_Trie_mmap, METH_VARARGS, NULL}, { "Trie_load", _wrap_Trie_load, METH_VARARGS, NULL}, { "Trie_save", _wrap_Trie_save, METH_VARARGS, NULL}, { "Trie_common_prefix_search", _wrap_Trie_common_prefix_search, METH_VARARGS, NULL}, { "Trie_predictive_search", _wrap_Trie_predictive_search, METH_VARARGS, NULL}, { "Trie_lookup", _wrap_Trie_lookup, METH_VARARGS, NULL}, { "Trie_reverse_lookup", _wrap_Trie_reverse_lookup, METH_VARARGS, NULL}, { "Trie_num_tries", _wrap_Trie_num_tries, METH_O, NULL}, { "Trie_num_keys", _wrap_Trie_num_keys, METH_O, NULL}, { "Trie_num_nodes", _wrap_Trie_num_nodes, METH_O, NULL}, { "Trie_tail_mode", _wrap_Trie_tail_mode, METH_O, NULL}, { "Trie_node_order", _wrap_Trie_node_order, METH_O, NULL}, { "Trie_empty", _wrap_Trie_empty, METH_O, NULL}, { "Trie_size", _wrap_Trie_size, METH_O, NULL}, { "Trie_total_size", _wrap_Trie_total_size, METH_O, NULL}, { "Trie_io_size", _wrap_Trie_io_size, METH_O, NULL}, { "Trie_clear", _wrap_Trie_clear, METH_O, NULL}, { "Trie_swigregister", Trie_swigregister, METH_O, NULL}, { "Trie_swiginit", Trie_swiginit, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa__Key = {"_p_marisa__Key", "marisa::Key *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Agent = {"_p_marisa_swig__Agent", "marisa_swig::Agent *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Key = {"_p_marisa_swig__Key", "marisa_swig::Key *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Keyset = {"_p_marisa_swig__Keyset", "marisa_swig::Keyset *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Query = {"_p_marisa_swig__Query", "marisa_swig::Query *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Trie = {"_p_marisa_swig__Trie", "marisa_swig::Trie *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_std__size_t = {"_p_std__size_t", "std::size_t *", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { &_swigt__p_char, &_swigt__p_marisa__Key, &_swigt__p_marisa_swig__Agent, &_swigt__p_marisa_swig__Key, &_swigt__p_marisa_swig__Keyset, &_swigt__p_marisa_swig__Query, &_swigt__p_marisa_swig__Trie, &_swigt__p_p_char, &_swigt__p_std__size_t, }; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa__Key[] = { {&_swigt__p_marisa__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Agent[] = { {&_swigt__p_marisa_swig__Agent, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Key[] = { {&_swigt__p_marisa_swig__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Keyset[] = { {&_swigt__p_marisa_swig__Keyset, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Query[] = { {&_swigt__p_marisa_swig__Query, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Trie[] = { {&_swigt__p_marisa_swig__Trie, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_std__size_t[] = { {&_swigt__p_std__size_t, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { _swigc__p_char, _swigc__p_marisa__Key, _swigc__p_marisa_swig__Agent, _swigc__p_marisa_swig__Key, _swigc__p_marisa_swig__Keyset, _swigc__p_marisa_swig__Query, _swigc__p_marisa_swig__Trie, _swigc__p_p_char, _swigc__p_std__size_t, }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ static swig_const_info swig_const_table[] = { {0, 0, 0, 0.0, 0, 0}}; #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * Type initialization: * This problem is tough by the requirement that no dynamic * memory is used. Also, since swig_type_info structures store pointers to * swig_cast_info structures and swig_cast_info structures store pointers back * to swig_type_info structures, we need some lookup code at initialization. * The idea is that swig generates all the structures that are needed. * The runtime then collects these partially filled structures. * The SWIG_InitializeModule function takes these initial arrays out of * swig_module, and does all the lookup, filling in the swig_module.types * array with the correct data and linking the correct swig_cast_info * structures together. * * The generated swig_type_info structures are assigned statically to an initial * array. We just loop through that array, and handle each type individually. * First we lookup if this type has been already loaded, and if so, use the * loaded structure instead of the generated one. Then we have to fill in the * cast linked list. The cast data is initially stored in something like a * two-dimensional array. Each row corresponds to a type (there are the same * number of rows as there are in the swig_type_initial array). Each entry in * a column is one of the swig_cast_info structures for that type. * The cast_initial array is actually an array of arrays, because each row has * a variable number of columns. So to actually build the cast linked list, * we find the array of casts associated with the type, and loop through it * adding the casts to the list. The one last trick we need to do is making * sure the type pointer in the swig_cast_info struct is correct. * * First off, we lookup the cast->type name to see if it is already loaded. * There are three cases to handle: * 1) If the cast->type has already been loaded AND the type we are adding * casting info to has not been loaded (it is in this module), THEN we * replace the cast->type pointer with the type pointer that has already * been loaded. * 2) If BOTH types (the one we are adding casting info to, and the * cast->type) are loaded, THEN the cast info has already been loaded by * the previous module so we just ignore it. * 3) Finally, if cast->type has not already been loaded, then we add that * swig_cast_info to the linked list (because the cast->type) pointer will * be correct. * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #if 0 } /* c-mode */ #endif #endif #if 0 #define SWIGRUNTIME_DEBUG #endif #ifndef SWIG_INIT_CLIENT_DATA_TYPE #define SWIG_INIT_CLIENT_DATA_TYPE void * #endif SWIGRUNTIME void SWIG_InitializeModule(SWIG_INIT_CLIENT_DATA_TYPE clientdata) { size_t i; swig_module_info *module_head, *iter; int init; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { /* Initialize the swig_module */ swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; init = 1; } else { init = 0; } /* Try and load any already created modules */ module_head = SWIG_GetModule(clientdata); if (!module_head) { /* This is the first module loaded for this interpreter */ /* so set the swig module into the interpreter */ SWIG_SetModule(clientdata, &swig_module); } else { /* the interpreter has loaded a SWIG module, but has it loaded this one? */ iter=module_head; do { if (iter==&swig_module) { /* Our module is already in the list, so there's nothing more to do. */ return; } iter=iter->next; } while (iter!= module_head); /* otherwise we must add our module into the list */ swig_module.next = module_head->next; module_head->next = &swig_module; } /* When multiple interpreters are used, a module could have already been initialized in a different interpreter, but not yet have a pointer in this interpreter. In this case, we do not want to continue adding types... everything should be set up already */ if (init == 0) return; /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); #endif for (i = 0; i < swig_module.size; ++i) { swig_type_info *type = 0; swig_type_info *ret; swig_cast_info *cast; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); #endif /* if there is another module already loaded */ if (swig_module.next != &swig_module) { type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); } if (type) { /* Overwrite clientdata field */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found type %s\n", type->name); #endif if (swig_module.type_initial[i]->clientdata) { type->clientdata = swig_module.type_initial[i]->clientdata; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); #endif } } else { type = swig_module.type_initial[i]; } /* Insert casting types */ cast = swig_module.cast_initial[i]; while (cast->type) { /* Don't need to add information already in the list */ ret = 0; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); #endif if (swig_module.next != &swig_module) { ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); #ifdef SWIGRUNTIME_DEBUG if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); #endif } if (ret) { if (type == swig_module.type_initial[i]) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: skip old type %s\n", ret->name); #endif cast->type = ret; ret = 0; } else { /* Check for casting already in the list */ swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); #ifdef SWIGRUNTIME_DEBUG if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); #endif if (!ocast) ret = 0; } } if (!ret) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); #endif if (type->cast) { type->cast->prev = cast; cast->next = type->cast; } type->cast = cast; } cast++; } /* Set entry in modules->types array equal to the type */ swig_module.types[i] = type; } swig_module.types[i] = 0; #ifdef SWIGRUNTIME_DEBUG printf("**** SWIG_InitializeModule: Cast List ******\n"); for (i = 0; i < swig_module.size; ++i) { int j = 0; swig_cast_info *cast = swig_module.cast_initial[i]; printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); while (cast->type) { printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); cast++; ++j; } printf("---- Total casts: %d\n",j); } printf("**** SWIG_InitializeModule: Cast List ******\n"); #endif } /* This function will propagate the clientdata field of type to * any new swig_type_info structures that have been added into the list * of equivalent types. It is like calling * SWIG_TypeClientData(type, clientdata) a second time. */ SWIGRUNTIME void SWIG_PropagateClientData(void) { size_t i; swig_cast_info *equiv; static int init_run = 0; if (init_run) return; init_run = 1; for (i = 0; i < swig_module.size; i++) { if (swig_module.types[i]->clientdata) { equiv = swig_module.types[i]->cast; while (equiv) { if (!equiv->converter) { if (equiv->type && !equiv->type->clientdata) SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); } equiv = equiv->next; } } } } #ifdef __cplusplus #if 0 { /* c-mode */ #endif } #endif #ifdef __cplusplus extern "C" { #endif /* ----------------------------------------------------------------------------- * constants/methods manipulation * ----------------------------------------------------------------------------- */ /* Install Constants */ SWIGINTERN void SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { PyObject *obj = 0; size_t i; for (i = 0; constants[i].type; ++i) { switch(constants[i].type) { case SWIG_PY_POINTER: obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); break; case SWIG_PY_BINARY: obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); break; default: obj = 0; break; } if (obj) { PyDict_SetItemString(d, constants[i].name, obj); Py_DECREF(obj); } } } /* ----------------------------------------------------------------------------- * Patch %callback methods' docstrings to hold the callback ptrs * -----------------------------------------------------------------------------*/ SWIGINTERN void SWIG_Python_FixMethods(PyMethodDef *methods, const swig_const_info *const_table, swig_type_info **types, swig_type_info **types_initial) { size_t i; for (i = 0; methods[i].ml_name; ++i) { const char *c = methods[i].ml_doc; if (!c) continue; c = strstr(c, "swig_ptr: "); if (c) { int j; const swig_const_info *ci = 0; const char *name = c + 10; for (j = 0; const_table[j].type; ++j) { if (strncmp(const_table[j].name, name, strlen(const_table[j].name)) == 0) { ci = &(const_table[j]); break; } } if (ci) { void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; if (ptr) { size_t shift = (ci->ptype) - types; swig_type_info *ty = types_initial[shift]; size_t ldoc = (c - methods[i].ml_doc); size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; char *ndoc = (char*)malloc(ldoc + lptr + 10); if (ndoc) { char *buff = ndoc; memcpy(buff, methods[i].ml_doc, ldoc); buff += ldoc; memcpy(buff, "swig_ptr: ", 10); buff += 10; SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); methods[i].ml_doc = ndoc; } } } } } } #ifdef __cplusplus } #endif /* -----------------------------------------------------------------------------* * Partial Init method * -----------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" #endif SWIGEXPORT #if PY_VERSION_HEX >= 0x03000000 PyObject* #else void #endif SWIG_init(void) { PyObject *m, *d, *md, *globals; #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef SWIG_module = { PyModuleDef_HEAD_INIT, SWIG_name, NULL, -1, SwigMethods, NULL, NULL, NULL, NULL }; #endif #if defined(SWIGPYTHON_BUILTIN) static SwigPyClientData SwigPyObject_clientdata = { 0, 0, 0, 0, 0, 0, 0 }; static PyGetSetDef this_getset_def = { (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL }; static SwigPyGetSet thisown_getset_closure = { SwigPyObject_own, SwigPyObject_own }; static PyGetSetDef thisown_getset_def = { (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure }; PyTypeObject *builtin_pytype; int builtin_base_count; swig_type_info *builtin_basetype; PyObject *tuple; PyGetSetDescrObject *static_getset; PyTypeObject *metatype; PyTypeObject *swigpyobject; SwigPyClientData *cd; PyObject *public_interface, *public_symbol; PyObject *this_descr; PyObject *thisown_descr; PyObject *self = 0; int i; (void)builtin_pytype; (void)builtin_base_count; (void)builtin_basetype; (void)tuple; (void)static_getset; (void)self; /* Metaclass is used to implement static member variables */ metatype = SwigPyObjectType(); assert(metatype); #endif (void)globals; /* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */ SWIG_This(); SWIG_Python_TypeCache(); SwigPyPacked_type(); #ifndef SWIGPYTHON_BUILTIN SwigPyObject_type(); #endif /* Fix SwigMethods to carry the callback ptrs when needed */ SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); #if PY_VERSION_HEX >= 0x03000000 m = PyModule_Create(&SWIG_module); #else m = Py_InitModule(SWIG_name, SwigMethods); #endif md = d = PyModule_GetDict(m); (void)md; SWIG_InitializeModule(0); #ifdef SWIGPYTHON_BUILTIN swigpyobject = SwigPyObject_TypeOnce(); SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); assert(SwigPyObject_stype); cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; if (!cd) { SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; SwigPyObject_clientdata.pytype = swigpyobject; } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) { PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); # if PY_VERSION_HEX >= 0x03000000 return NULL; # else return; # endif } /* All objects have a 'this' attribute */ this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); (void)this_descr; /* All objects have a 'thisown' attribute */ thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); (void)thisown_descr; public_interface = PyList_New(0); public_symbol = 0; (void)public_symbol; PyDict_SetItemString(md, "__all__", public_interface); Py_DECREF(public_interface); for (i = 0; SwigMethods[i].ml_name != NULL; ++i) SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); for (i = 0; swig_const_table[i].name != 0; ++i) SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); #endif SWIG_InstallConstants(d,swig_const_table); SWIG_Python_SetConstant(d, "OK",SWIG_From_int(static_cast< int >(marisa_swig::OK))); SWIG_Python_SetConstant(d, "STATE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::STATE_ERROR))); SWIG_Python_SetConstant(d, "NULL_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::NULL_ERROR))); SWIG_Python_SetConstant(d, "BOUND_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::BOUND_ERROR))); SWIG_Python_SetConstant(d, "RANGE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::RANGE_ERROR))); SWIG_Python_SetConstant(d, "CODE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::CODE_ERROR))); SWIG_Python_SetConstant(d, "RESET_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::RESET_ERROR))); SWIG_Python_SetConstant(d, "SIZE_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::SIZE_ERROR))); SWIG_Python_SetConstant(d, "MEMORY_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::MEMORY_ERROR))); SWIG_Python_SetConstant(d, "IO_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::IO_ERROR))); SWIG_Python_SetConstant(d, "FORMAT_ERROR",SWIG_From_int(static_cast< int >(marisa_swig::FORMAT_ERROR))); SWIG_Python_SetConstant(d, "MAP_POPULATE",SWIG_From_int(static_cast< int >(marisa_swig::MAP_POPULATE))); SWIG_Python_SetConstant(d, "MIN_NUM_TRIES",SWIG_From_int(static_cast< int >(marisa_swig::MIN_NUM_TRIES))); SWIG_Python_SetConstant(d, "MAX_NUM_TRIES",SWIG_From_int(static_cast< int >(marisa_swig::MAX_NUM_TRIES))); SWIG_Python_SetConstant(d, "DEFAULT_NUM_TRIES",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_NUM_TRIES))); SWIG_Python_SetConstant(d, "HUGE_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::HUGE_CACHE))); SWIG_Python_SetConstant(d, "LARGE_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::LARGE_CACHE))); SWIG_Python_SetConstant(d, "NORMAL_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::NORMAL_CACHE))); SWIG_Python_SetConstant(d, "SMALL_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::SMALL_CACHE))); SWIG_Python_SetConstant(d, "TINY_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::TINY_CACHE))); SWIG_Python_SetConstant(d, "DEFAULT_CACHE",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_CACHE))); SWIG_Python_SetConstant(d, "TEXT_TAIL",SWIG_From_int(static_cast< int >(marisa_swig::TEXT_TAIL))); SWIG_Python_SetConstant(d, "BINARY_TAIL",SWIG_From_int(static_cast< int >(marisa_swig::BINARY_TAIL))); SWIG_Python_SetConstant(d, "DEFAULT_TAIL",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_TAIL))); SWIG_Python_SetConstant(d, "LABEL_ORDER",SWIG_From_int(static_cast< int >(marisa_swig::LABEL_ORDER))); SWIG_Python_SetConstant(d, "WEIGHT_ORDER",SWIG_From_int(static_cast< int >(marisa_swig::WEIGHT_ORDER))); SWIG_Python_SetConstant(d, "DEFAULT_ORDER",SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_ORDER))); SWIG_Python_SetConstant(d, "INVALID_KEY_ID",SWIG_From_size_t(static_cast< size_t >(MARISA_INVALID_KEY_ID))); #if PY_VERSION_HEX >= 0x03000000 return m; #else return; #endif } marisa-trie-master/bindings/python3/marisa.py000066400000000000000000000166331505027263100216250ustar00rootroot00000000000000# This file was automatically generated by SWIG (https://www.swig.org). # Version 4.2.0 # # Do not make changes to this file unless you know what you are doing - modify # the SWIG interface file instead. from sys import version_info as _swig_python_version_info # Import the low-level C/C++ module if __package__ or "." in __name__: from . import _marisa else: import _marisa try: import builtins as __builtin__ except ImportError: import __builtin__ def _swig_repr(self): try: strthis = "proxy of " + self.this.__repr__() except __builtin__.Exception: strthis = "" return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) def _swig_setattr_nondynamic_instance_variable(set): def set_instance_attr(self, name, value): if name == "this": set(self, name, value) elif name == "thisown": self.this.own(value) elif hasattr(self, name) and isinstance(getattr(type(self), name), property): set(self, name, value) else: raise AttributeError("You cannot add instance attributes to %s" % self) return set_instance_attr def _swig_setattr_nondynamic_class_variable(set): def set_class_attr(cls, name, value): if hasattr(cls, name) and not isinstance(getattr(cls, name), property): set(cls, name, value) else: raise AttributeError("You cannot add class attributes to %s" % cls) return set_class_attr def _swig_add_metaclass(metaclass): """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass""" def wrapper(cls): return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy()) return wrapper class _SwigNonDynamicMeta(type): """Meta class to enforce nondynamic attributes (no new attributes) for a class""" __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__) OK = _marisa.OK STATE_ERROR = _marisa.STATE_ERROR NULL_ERROR = _marisa.NULL_ERROR BOUND_ERROR = _marisa.BOUND_ERROR RANGE_ERROR = _marisa.RANGE_ERROR CODE_ERROR = _marisa.CODE_ERROR RESET_ERROR = _marisa.RESET_ERROR SIZE_ERROR = _marisa.SIZE_ERROR MEMORY_ERROR = _marisa.MEMORY_ERROR IO_ERROR = _marisa.IO_ERROR FORMAT_ERROR = _marisa.FORMAT_ERROR MAP_POPULATE = _marisa.MAP_POPULATE MIN_NUM_TRIES = _marisa.MIN_NUM_TRIES MAX_NUM_TRIES = _marisa.MAX_NUM_TRIES DEFAULT_NUM_TRIES = _marisa.DEFAULT_NUM_TRIES HUGE_CACHE = _marisa.HUGE_CACHE LARGE_CACHE = _marisa.LARGE_CACHE NORMAL_CACHE = _marisa.NORMAL_CACHE SMALL_CACHE = _marisa.SMALL_CACHE TINY_CACHE = _marisa.TINY_CACHE DEFAULT_CACHE = _marisa.DEFAULT_CACHE TEXT_TAIL = _marisa.TEXT_TAIL BINARY_TAIL = _marisa.BINARY_TAIL DEFAULT_TAIL = _marisa.DEFAULT_TAIL LABEL_ORDER = _marisa.LABEL_ORDER WEIGHT_ORDER = _marisa.WEIGHT_ORDER DEFAULT_ORDER = _marisa.DEFAULT_ORDER class Key(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined") __repr__ = _swig_repr def key_str(self): return _marisa.Key_key_str(self) def key_id(self): return _marisa.Key_key_id(self) def weight(self): return _marisa.Key_weight(self) __swig_destroy__ = _marisa.delete_Key # Register Key in _marisa: _marisa.Key_swigregister(Key) class Query(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined") __repr__ = _swig_repr def query_str(self): return _marisa.Query_query_str(self) def query_id(self): return _marisa.Query_query_id(self) __swig_destroy__ = _marisa.delete_Query # Register Query in _marisa: _marisa.Query_swigregister(Query) class Keyset(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") __repr__ = _swig_repr def __init__(self): _marisa.Keyset_swiginit(self, _marisa.new_Keyset()) __swig_destroy__ = _marisa.delete_Keyset def push_back(self, *args): return _marisa.Keyset_push_back(self, *args) def key(self, i): return _marisa.Keyset_key(self, i) def key_str(self, i): return _marisa.Keyset_key_str(self, i) def key_id(self, i): return _marisa.Keyset_key_id(self, i) def num_keys(self): return _marisa.Keyset_num_keys(self) def empty(self): return _marisa.Keyset_empty(self) def size(self): return _marisa.Keyset_size(self) def total_length(self): return _marisa.Keyset_total_length(self) def reset(self): return _marisa.Keyset_reset(self) def clear(self): return _marisa.Keyset_clear(self) # Register Keyset in _marisa: _marisa.Keyset_swigregister(Keyset) class Agent(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") __repr__ = _swig_repr def __init__(self): _marisa.Agent_swiginit(self, _marisa.new_Agent()) __swig_destroy__ = _marisa.delete_Agent def set_query(self, *args): return _marisa.Agent_set_query(self, *args) def key(self): return _marisa.Agent_key(self) def query(self): return _marisa.Agent_query(self) def key_str(self): return _marisa.Agent_key_str(self) def key_id(self): return _marisa.Agent_key_id(self) def query_str(self): return _marisa.Agent_query_str(self) def query_id(self): return _marisa.Agent_query_id(self) # Register Agent in _marisa: _marisa.Agent_swigregister(Agent) class Trie(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") __repr__ = _swig_repr def __init__(self): _marisa.Trie_swiginit(self, _marisa.new_Trie()) __swig_destroy__ = _marisa.delete_Trie def build(self, keyset, config_flags=0): return _marisa.Trie_build(self, keyset, config_flags) def mmap(self, filename, flags=0): return _marisa.Trie_mmap(self, filename, flags) def load(self, filename): return _marisa.Trie_load(self, filename) def save(self, filename): return _marisa.Trie_save(self, filename) def common_prefix_search(self, agent): return _marisa.Trie_common_prefix_search(self, agent) def predictive_search(self, agent): return _marisa.Trie_predictive_search(self, agent) def lookup(self, *args): return _marisa.Trie_lookup(self, *args) def reverse_lookup(self, *args): return _marisa.Trie_reverse_lookup(self, *args) def num_tries(self): return _marisa.Trie_num_tries(self) def num_keys(self): return _marisa.Trie_num_keys(self) def num_nodes(self): return _marisa.Trie_num_nodes(self) def tail_mode(self): return _marisa.Trie_tail_mode(self) def node_order(self): return _marisa.Trie_node_order(self) def empty(self): return _marisa.Trie_empty(self) def size(self): return _marisa.Trie_size(self) def total_size(self): return _marisa.Trie_total_size(self) def io_size(self): return _marisa.Trie_io_size(self) def clear(self): return _marisa.Trie_clear(self) # Register Trie in _marisa: _marisa.Trie_swigregister(Trie) INVALID_KEY_ID = _marisa.INVALID_KEY_ID marisa-trie-master/bindings/python3/sample.py000066400000000000000000000027161505027263100216270ustar00rootroot00000000000000import marisa keyset = marisa.Keyset() keyset.push_back("cake") keyset.push_back("cookie") keyset.push_back("ice") keyset.push_back("ice-cream") trie = marisa.Trie() trie.build(keyset) print("no. keys: %d" % trie.num_keys()) print("no. tries: %d" % trie.num_tries()) print("no. nodes: %d" % trie.num_nodes()) print("size: %d" % trie.io_size()) agent = marisa.Agent() agent.set_query("cake") trie.lookup(agent) print("%s: %d" % (agent.query_str(), agent.key_id())) agent.set_query("cookie") trie.lookup(agent) print("%s: %d" % (agent.query_str(), agent.key_id())) agent.set_query("cockoo") if not trie.lookup(agent): print("%s: not found" % agent.query_str()) print("ice: %d" % trie.lookup("ice")) print("ice-cream: %d" % trie.lookup("ice-cream")) if trie.lookup("ice-age") == marisa.INVALID_KEY_ID: print("ice-age: not found") trie.save("sample.dic") trie.load("sample.dic") agent.set_query(0) trie.reverse_lookup(agent) print("%d: %s" % (agent.query_id(), agent.key_str())) agent.set_query(1) trie.reverse_lookup(agent) print("%d: %s" % (agent.query_id(), agent.key_str())) print("2: %s" % trie.reverse_lookup(2)) print("3: %s" % trie.reverse_lookup(3)) trie.mmap("sample.dic") agent.set_query("ice-cream soda") while trie.common_prefix_search(agent): print("%s: %s (%d)" % (agent.query_str(), agent.key_str(), agent.key_id())) agent.set_query("ic") while trie.predictive_search(agent): print("%s: %s (%d)" % (agent.query_str(), agent.key_str(), agent.key_id())) marisa-trie-master/bindings/python3/setup.py000066400000000000000000000005341505027263100215020ustar00rootroot00000000000000from setuptools import setup, Extension marisa_module = Extension("_marisa", sources=["marisa-swig-python3_wrap.cxx", "marisa-swig-python3.cxx"], libraries=["marisa"]) setup(name = "marisa", ext_modules = [marisa_module], py_modules = ["marisa"]) marisa-trie-master/bindings/ruby/000077500000000000000000000000001505027263100173435ustar00rootroot00000000000000marisa-trie-master/bindings/ruby/benchmark.rb000066400000000000000000000035361505027263100216310ustar00rootroot00000000000000require "marisa" time_begin = Time.now keys = STDIN.read.split("\n") time_end = Time.now print "input: ", time_end - time_begin, "\n" time_begin = Time.now hash = Hash.new for key in keys hash[key] = 0 end time_end = Time.now print "hash_build: ", time_end - time_begin, "\n" time_begin = Time.now hash = Hash.new for key in keys hash[key] end time_end = Time.now print "hash_lookup: ", time_end - time_begin, "\n" time_begin = Time.now keyset = Marisa::Keyset.new for key in keys keyset.push_back(key) end time_end = Time.now print "keyset_build: ", time_end - time_begin, "\n" time_begin = Time.now trie = Marisa::Trie.new trie.build(keyset) time_end = Time.now print "trie_build: ", time_end - time_begin, "\n" time_begin = Time.now agent = Marisa::Agent.new for key in keys agent.set_query(key) trie.lookup(agent) agent.key_str end time_end = Time.now print "trie_agent_lookup: ", time_end - time_begin, "\n" time_begin = Time.now for key in keys trie.lookup(key) end time_end = Time.now print "trie_lookup: ", time_end - time_begin, "\n" time_begin = Time.now max_key_id = trie.size() - 1 0.upto(max_key_id) { |i| agent.set_query(i) trie.reverse_lookup(agent) agent.key_str } time_end = Time.now print "trie_agent_reverse_lookup: ", time_end - time_begin, "\n" time_begin = Time.now 0.upto(max_key_id) { |i| trie.reverse_lookup(i) } time_end = Time.now print "trie_reverse_lookup: ", time_end - time_begin, "\n" time_begin = Time.now for key in keys agent.set_query(key) while trie.common_prefix_search(agent) agent.key_str end end time_end = Time.now print "trie_agent_common_prefix_search: ", time_end - time_begin, "\n" time_begin = Time.now for key in keys agent.set_query(key) while trie.predictive_search(agent) agent.key_str end end time_end = Time.now print "trie_agent_predictive_search: ", time_end - time_begin, "\n" marisa-trie-master/bindings/ruby/extconf.rb000066400000000000000000000001021505027263100213270ustar00rootroot00000000000000require "mkmf" have_library("marisa") create_makefile("marisa") marisa-trie-master/bindings/ruby/marisa-swig.cxx000066400000000000000000000115611505027263100223160ustar00rootroot00000000000000#include #include #include "marisa-swig.h" namespace marisa_swig { void Key::str(const char **ptr_out, size_t *length_out) const { *ptr_out = key_.ptr(); *length_out = key_.length(); } size_t Key::id() const { return key_.id(); } float Key::weight() const { return key_.weight(); } void Query::str(const char **ptr_out, size_t *length_out) const { *ptr_out = query_.ptr(); *length_out = query_.length(); } size_t Query::id() const { return query_.id(); } Keyset::Keyset() : keyset_(new marisa::Keyset) { } Keyset::~Keyset() { delete keyset_; } void Keyset::push_back(const marisa::Key &key) { keyset_->push_back(key); } void Keyset::push_back(const char *ptr, size_t length, float weight) { keyset_->push_back(ptr, length, weight); } const Key &Keyset::key(size_t i) const { return reinterpret_cast((*keyset_)[i]); } void Keyset::key_str(size_t i, const char **ptr_out, size_t *length_out) const { *ptr_out = (*keyset_)[i].ptr(); *length_out = (*keyset_)[i].length(); } size_t Keyset::key_id(size_t i) const { return (*keyset_)[i].id(); } size_t Keyset::num_keys() const { return keyset_->num_keys(); } bool Keyset::empty() const { return keyset_->empty(); } size_t Keyset::size() const { return keyset_->size(); } size_t Keyset::total_length() const { return keyset_->total_length(); } void Keyset::reset() { keyset_->reset(); } void Keyset::clear() { keyset_->clear(); } Agent::Agent() : agent_(new marisa::Agent), buf_(NULL), buf_size_(0) { } Agent::~Agent() { delete agent_; delete [] buf_; } void Agent::set_query(const char *ptr, size_t length) { if (length > buf_size_) { size_t new_buf_size = (buf_size_ != 0) ? buf_size_ : 1; if (length >= (MARISA_SIZE_MAX / 2)) { new_buf_size = MARISA_SIZE_MAX; } else { while (new_buf_size < length) { new_buf_size *= 2; } } char *new_buf = new char[new_buf_size]; delete [] buf_; buf_ = new_buf; buf_size_ = new_buf_size; } std::memcpy(buf_, ptr, length); agent_->set_query(buf_, length); } void Agent::set_query(size_t id) { agent_->set_query(id); } const Key &Agent::key() const { return reinterpret_cast(agent_->key()); } const Query &Agent::query() const { return reinterpret_cast(agent_->query()); } void Agent::key_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->key().ptr(); *length_out = agent_->key().length(); } size_t Agent::key_id() const { return agent_->key().id(); } void Agent::query_str(const char **ptr_out, size_t *length_out) const { *ptr_out = agent_->query().ptr(); *length_out = agent_->query().length(); } size_t Agent::query_id() const { return agent_->query().id(); } Trie::Trie() : trie_(new marisa::Trie) { } Trie::~Trie() { delete trie_; } void Trie::build(Keyset &keyset, int config_flags) { trie_->build(*keyset.keyset_, config_flags); } void Trie::mmap(const char *filename, int flags) { trie_->mmap(filename, flags); } void Trie::load(const char *filename) { trie_->load(filename); } void Trie::save(const char *filename) const { trie_->save(filename); } bool Trie::lookup(Agent &agent) const { return trie_->lookup(*agent.agent_); } void Trie::reverse_lookup(Agent &agent) const { trie_->reverse_lookup(*agent.agent_); } bool Trie::common_prefix_search(Agent &agent) const { return trie_->common_prefix_search(*agent.agent_); } bool Trie::predictive_search(Agent &agent) const { return trie_->predictive_search(*agent.agent_); } size_t Trie::lookup(const char *ptr, size_t length) const { marisa::Agent agent; agent.set_query(ptr, length); if (!trie_->lookup(agent)) { return MARISA_INVALID_KEY_ID; } return agent.key().id(); } void Trie::reverse_lookup(size_t id, const char **ptr_out_to_be_deleted, size_t *length_out) const { marisa::Agent agent; agent.set_query(id); trie_->reverse_lookup(agent); char * const buf = new char[agent.key().length()]; std::memcpy(buf, agent.key().ptr(), agent.key().length()); *ptr_out_to_be_deleted = buf; *length_out = agent.key().length(); } size_t Trie::num_tries() const { return trie_->num_tries(); } size_t Trie::num_keys() const { return trie_->num_keys(); } size_t Trie::num_nodes() const { return trie_->num_nodes(); } TailMode Trie::tail_mode() const { if (trie_->tail_mode() == ::MARISA_TEXT_TAIL) { return TEXT_TAIL; } else { return BINARY_TAIL; } } NodeOrder Trie::node_order() const { if (trie_->node_order() == ::MARISA_LABEL_ORDER) { return LABEL_ORDER; } else { return WEIGHT_ORDER; } } bool Trie::empty() const { return trie_->empty(); } size_t Trie::size() const { return trie_->size(); } size_t Trie::total_size() const { return trie_->total_size(); } size_t Trie::io_size() const { return trie_->io_size(); } void Trie::clear() { trie_->clear(); } } // namespace marisa_swig marisa-trie-master/bindings/ruby/marisa-swig.h000066400000000000000000000076421505027263100217500ustar00rootroot00000000000000#ifndef MARISA_SWIG_H_ #define MARISA_SWIG_H_ #include namespace marisa_swig { #define MARISA_SWIG_ENUM_COPY(name) name = MARISA_ ## name enum ErrorCode { MARISA_SWIG_ENUM_COPY(OK), MARISA_SWIG_ENUM_COPY(STATE_ERROR), MARISA_SWIG_ENUM_COPY(NULL_ERROR), MARISA_SWIG_ENUM_COPY(BOUND_ERROR), MARISA_SWIG_ENUM_COPY(RANGE_ERROR), MARISA_SWIG_ENUM_COPY(CODE_ERROR), MARISA_SWIG_ENUM_COPY(RESET_ERROR), MARISA_SWIG_ENUM_COPY(SIZE_ERROR), MARISA_SWIG_ENUM_COPY(MEMORY_ERROR), MARISA_SWIG_ENUM_COPY(IO_ERROR), MARISA_SWIG_ENUM_COPY(FORMAT_ERROR) }; enum MapFlags { MARISA_SWIG_ENUM_COPY(MAP_POPULATE), }; enum NumTries { MARISA_SWIG_ENUM_COPY(MIN_NUM_TRIES), MARISA_SWIG_ENUM_COPY(MAX_NUM_TRIES), MARISA_SWIG_ENUM_COPY(DEFAULT_NUM_TRIES) }; enum CacheLevel { MARISA_SWIG_ENUM_COPY(HUGE_CACHE), MARISA_SWIG_ENUM_COPY(LARGE_CACHE), MARISA_SWIG_ENUM_COPY(NORMAL_CACHE), MARISA_SWIG_ENUM_COPY(SMALL_CACHE), MARISA_SWIG_ENUM_COPY(TINY_CACHE), MARISA_SWIG_ENUM_COPY(DEFAULT_CACHE) }; enum TailMode { MARISA_SWIG_ENUM_COPY(TEXT_TAIL), MARISA_SWIG_ENUM_COPY(BINARY_TAIL), MARISA_SWIG_ENUM_COPY(DEFAULT_TAIL) }; enum NodeOrder { MARISA_SWIG_ENUM_COPY(LABEL_ORDER), MARISA_SWIG_ENUM_COPY(WEIGHT_ORDER), MARISA_SWIG_ENUM_COPY(DEFAULT_ORDER) }; #undef MARISA_SWIG_ENUM_COPY class Key { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; float weight() const; private: const marisa::Key key_; Key(); Key(const Key &key); Key &operator=(const Key &); }; class Query { public: void str(const char **ptr_out, std::size_t *length_out) const; std::size_t id() const; private: const marisa::Query query_; Query(); Query(const Query &query); Query &operator=(const Query &); }; class Keyset { friend class Trie; public: Keyset(); ~Keyset(); void push_back(const marisa::Key &key); void push_back(const char *ptr, std::size_t length, float weight = 1.0); const Key &key(std::size_t i) const; void key_str(std::size_t i, const char **ptr_out, std::size_t *length_out) const; std::size_t key_id(std::size_t i) const; std::size_t num_keys() const; bool empty() const; std::size_t size() const; std::size_t total_length() const; void reset(); void clear(); private: marisa::Keyset *keyset_; Keyset(const Keyset &); Keyset &operator=(const Keyset &); }; class Agent { friend class Trie; public: Agent(); ~Agent(); void set_query(const char *ptr, std::size_t length); void set_query(std::size_t id); const Key &key() const; const Query &query() const; void key_str(const char **ptr_out, std::size_t *length_out) const; std::size_t key_id() const; void query_str(const char **ptr_out, std::size_t *length_out) const; std::size_t query_id() const; private: marisa::Agent *agent_; char *buf_; std::size_t buf_size_; Agent(const Agent &); Agent &operator=(const Agent &); }; class Trie { public: Trie(); ~Trie(); void build(Keyset &keyset, int config_flags = 0); void mmap(const char *filename, int flags = 0); void load(const char *filename); void save(const char *filename) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t lookup(const char *ptr, std::size_t length) const; void reverse_lookup(std::size_t id, const char **ptr_out_to_be_deleted, std::size_t *length_out) const; std::size_t num_tries() const; std::size_t num_keys() const; std::size_t num_nodes() const; TailMode tail_mode() const; NodeOrder node_order() const; bool empty() const; std::size_t size() const; std::size_t total_size() const; std::size_t io_size() const; void clear(); private: marisa::Trie *trie_; Trie(const Trie &); Trie &operator=(const Trie &); }; } // namespace marisa_swig #endif // MARISA_SWIG_H_ marisa-trie-master/bindings/ruby/marisa-swig_wrap.cxx000066400000000000000000004606371505027263100233630ustar00rootroot00000000000000/* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (https://www.swig.org). * Version 4.2.0 * * Do not make changes to this file unless you know what you are doing - modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ #define SWIG_VERSION 0x040200 #define SWIGRUBY /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. * ----------------------------------------------------------------------------- */ /* template workaround for compilers that cannot correctly implement the C++ standard */ #ifndef SWIGTEMPLATEDISAMBIGUATOR # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) # define SWIGTEMPLATEDISAMBIGUATOR template # elif defined(__HP_aCC) /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ # define SWIGTEMPLATEDISAMBIGUATOR template # else # define SWIGTEMPLATEDISAMBIGUATOR # endif #endif /* inline attribute */ #ifndef SWIGINLINE # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) # define SWIGINLINE inline # else # define SWIGINLINE # endif #endif /* attribute recognised by some compilers to avoid 'unused' warnings */ #ifndef SWIGUNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif # elif defined(__ICC) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif #endif #ifndef SWIG_MSC_UNSUPPRESS_4505 # if defined(_MSC_VER) # pragma warning(disable : 4505) /* unreferenced local function has been removed */ # endif #endif #ifndef SWIGUNUSEDPARM # ifdef __cplusplus # define SWIGUNUSEDPARM(p) # else # define SWIGUNUSEDPARM(p) p SWIGUNUSED # endif #endif /* internal SWIG method */ #ifndef SWIGINTERN # define SWIGINTERN static SWIGUNUSED #endif /* internal inline SWIG method */ #ifndef SWIGINTERNINLINE # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE #endif /* exporting methods */ #if defined(__GNUC__) # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) # ifndef GCC_HASCLASSVISIBILITY # define GCC_HASCLASSVISIBILITY # endif # endif #endif #ifndef SWIGEXPORT # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # if defined(STATIC_LINKED) # define SWIGEXPORT # else # define SWIGEXPORT __declspec(dllexport) # endif # else # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) # define SWIGEXPORT __attribute__ ((visibility("default"))) # else # define SWIGEXPORT # endif # endif #endif /* calling conventions for Windows */ #ifndef SWIGSTDCALL # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # define SWIGSTDCALL __stdcall # else # define SWIGSTDCALL # endif #endif /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) # define _CRT_SECURE_NO_DEPRECATE #endif /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) # define _SCL_SECURE_NO_DEPRECATE #endif /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 #endif /* Intel's compiler complains if a variable which was never initialised is * cast to void, which is a common idiom which we use to indicate that we * are aware a variable isn't used. So we just silence that warning. * See: https://github.com/swig/swig/issues/192 for more discussion. */ #ifdef __INTEL_COMPILER # pragma warning disable 592 #endif #if __cplusplus >=201103L # define SWIG_NULLPTR nullptr #else # define SWIG_NULLPTR NULL #endif /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. * ----------------------------------------------------------------------------- */ /* template workaround for compilers that cannot correctly implement the C++ standard */ #ifndef SWIGTEMPLATEDISAMBIGUATOR # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) # define SWIGTEMPLATEDISAMBIGUATOR template # elif defined(__HP_aCC) /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ # define SWIGTEMPLATEDISAMBIGUATOR template # else # define SWIGTEMPLATEDISAMBIGUATOR # endif #endif /* inline attribute */ #ifndef SWIGINLINE # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) # define SWIGINLINE inline # else # define SWIGINLINE # endif #endif /* attribute recognised by some compilers to avoid 'unused' warnings */ #ifndef SWIGUNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif # elif defined(__ICC) # define SWIGUNUSED __attribute__ ((__unused__)) # else # define SWIGUNUSED # endif #endif #ifndef SWIG_MSC_UNSUPPRESS_4505 # if defined(_MSC_VER) # pragma warning(disable : 4505) /* unreferenced local function has been removed */ # endif #endif #ifndef SWIGUNUSEDPARM # ifdef __cplusplus # define SWIGUNUSEDPARM(p) # else # define SWIGUNUSEDPARM(p) p SWIGUNUSED # endif #endif /* internal SWIG method */ #ifndef SWIGINTERN # define SWIGINTERN static SWIGUNUSED #endif /* internal inline SWIG method */ #ifndef SWIGINTERNINLINE # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE #endif /* exporting methods */ #if defined(__GNUC__) # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) # ifndef GCC_HASCLASSVISIBILITY # define GCC_HASCLASSVISIBILITY # endif # endif #endif #ifndef SWIGEXPORT # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # if defined(STATIC_LINKED) # define SWIGEXPORT # else # define SWIGEXPORT __declspec(dllexport) # endif # else # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) # define SWIGEXPORT __attribute__ ((visibility("default"))) # else # define SWIGEXPORT # endif # endif #endif /* calling conventions for Windows */ #ifndef SWIGSTDCALL # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # define SWIGSTDCALL __stdcall # else # define SWIGSTDCALL # endif #endif /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) # define _CRT_SECURE_NO_DEPRECATE #endif /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) # define _SCL_SECURE_NO_DEPRECATE #endif /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 #endif /* Intel's compiler complains if a variable which was never initialised is * cast to void, which is a common idiom which we use to indicate that we * are aware a variable isn't used. So we just silence that warning. * See: https://github.com/swig/swig/issues/192 for more discussion. */ #ifdef __INTEL_COMPILER # pragma warning disable 592 #endif #if __cplusplus >=201103L # define SWIG_NULLPTR nullptr #else # define SWIG_NULLPTR NULL #endif /* ----------------------------------------------------------------------------- * swigrun.swg * * This file contains generic C API SWIG runtime support for pointer * type checking. * ----------------------------------------------------------------------------- */ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ #define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE # define SWIG_QUOTE_STRING(x) #x # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) #else # define SWIG_TYPE_TABLE_NAME #endif /* You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for creating a static or dynamic library from the SWIG runtime code. In 99.9% of the cases, SWIG just needs to declare them as 'static'. But only do this if strictly necessary, ie, if you have problems with your compiler or suchlike. */ #ifndef SWIGRUNTIME # define SWIGRUNTIME SWIGINTERN #endif #ifndef SWIGRUNTIMEINLINE # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE #endif /* Generic buffer size */ #ifndef SWIG_BUFFER_SIZE # define SWIG_BUFFER_SIZE 1024 #endif /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 #define SWIG_CAST_NEW_MEMORY 0x2 #define SWIG_POINTER_NO_NULL 0x4 #define SWIG_POINTER_CLEAR 0x8 #define SWIG_POINTER_RELEASE (SWIG_POINTER_CLEAR | SWIG_POINTER_DISOWN) /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 /* Flags/methods for returning states. The SWIG conversion methods, as ConvertPtr, return an integer that tells if the conversion was successful or not. And if not, an error code can be returned (see swigerrors.swg for the codes). Use the following macros/flags to set or process the returning states. In old versions of SWIG, code such as the following was usually written: if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { // success code } else { //fail code } Now you can be more explicit: int res = SWIG_ConvertPtr(obj,vptr,ty.flags); if (SWIG_IsOK(res)) { // success code } else { // fail code } which is the same really, but now you can also do Type *ptr; int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); if (SWIG_IsOK(res)) { // success code if (SWIG_IsNewObj(res) { ... delete *ptr; } else { ... } } else { // fail code } I.e., now SWIG_ConvertPtr can return new objects and you can identify the case and take care of the deallocation. Of course that also requires SWIG_ConvertPtr to return new result values, such as int SWIG_ConvertPtr(obj, ptr,...) { if () { if () { *ptr = ; return SWIG_NEWOBJ; } else { *ptr = ; return SWIG_OLDOBJ; } } else { return SWIG_BADOBJ; } } Of course, returning the plain '0(success)/-1(fail)' still works, but you can be more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the SWIG errors code. Finally, if the SWIG_CASTRANK_MODE is enabled, the result code allows returning the 'cast rank', for example, if you have this int food(double) int fooi(int); and you call food(1) // cast rank '1' (1 -> 1.0) fooi(1) // cast rank '0' just use the SWIG_AddCast()/SWIG_CheckState() */ #define SWIG_OK (0) /* Runtime errors are < 0 */ #define SWIG_ERROR (-1) /* Errors in range -1 to -99 are in swigerrors.swg (errors for all languages including those not using the runtime) */ /* Errors in range -100 to -199 are language specific errors defined in *errors.swg */ /* Errors < -200 are generic runtime specific errors */ #define SWIG_ERROR_RELEASE_NOT_OWNED (-200) #define SWIG_IsOK(r) (r >= 0) #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) /* The CastRankLimit says how many bits are used for the cast rank */ #define SWIG_CASTRANKLIMIT (1 << 8) /* The NewMask denotes the object was created (using new/malloc) */ #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) /* The TmpMask is for in/out typemaps that use temporary objects */ #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) /* Simple returning values */ #define SWIG_BADOBJ (SWIG_ERROR) #define SWIG_OLDOBJ (SWIG_OK) #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) /* Check, add and del object mask methods */ #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) /* Cast-Rank Mode */ #if defined(SWIG_CASTRANK_MODE) # ifndef SWIG_TypeRank # define SWIG_TypeRank unsigned long # endif # ifndef SWIG_MAXCASTRANK /* Default cast allowed */ # define SWIG_MAXCASTRANK (2) # endif # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) SWIGINTERNINLINE int SWIG_AddCast(int r) { return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; } SWIGINTERNINLINE int SWIG_CheckState(int r) { return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ # define SWIG_AddCast(r) (r) # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) #endif /* C99 and C++11 should provide snprintf, but define SWIG_NO_SNPRINTF * if you're missing it. */ #if ((defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || \ (defined __cplusplus && __cplusplus >= 201103L) || \ defined SWIG_HAVE_SNPRINTF) && \ !defined SWIG_NO_SNPRINTF # define SWIG_snprintf(O,S,F,A) snprintf(O,S,F,A) # define SWIG_snprintf2(O,S,F,A,B) snprintf(O,S,F,A,B) #else /* Fallback versions ignore the buffer size, but most of our uses either have a * fixed maximum possible size or dynamically allocate a buffer that's large * enough. */ # define SWIG_snprintf(O,S,F,A) sprintf(O,F,A) # define SWIG_snprintf2(O,S,F,A,B) sprintf(O,F,A,B) #endif #include #ifdef __cplusplus extern "C" { #endif typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); /* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ struct swig_cast_info *cast; /* linked list of types that can cast into this type */ void *clientdata; /* language specific type data */ int owndata; /* flag if the structure owns the clientdata */ } swig_type_info; /* Structure to store a type and conversion function used for casting */ typedef struct swig_cast_info { swig_type_info *type; /* pointer to type that is equivalent to this type */ swig_converter_func converter; /* function to cast the void pointers */ struct swig_cast_info *next; /* pointer to next cast in linked list */ struct swig_cast_info *prev; /* pointer to the previous cast */ } swig_cast_info; /* Structure used to store module information * Each module generates one structure like this, and the runtime collects * all of these structures and stores them in a circularly linked list.*/ typedef struct swig_module_info { swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ size_t size; /* Number of types in this module */ struct swig_module_info *next; /* Pointer to next element in circularly linked list */ swig_type_info **type_initial; /* Array of initially generated type structures */ swig_cast_info **cast_initial; /* Array of initially generated casting structures */ void *clientdata; /* Language specific module data */ } swig_module_info; /* Compare two type names skipping the space characters, therefore "char*" == "char *" and "Class" == "Class", etc. Return 0 when the two name types are equivalent, as in strncmp, but skipping ' '. */ SWIGRUNTIME int SWIG_TypeNameComp(const char *f1, const char *l1, const char *f2, const char *l2) { for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { while ((*f1 == ' ') && (f1 != l1)) ++f1; while ((*f2 == ' ') && (f2 != l2)) ++f2; if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; } return (int)((l1 - f1) - (l2 - f2)); } /* Check type equivalence in a name list like ||... Return 0 if equal, -1 if nb < tb, 1 if nb > tb */ SWIGRUNTIME int SWIG_TypeCmp(const char *nb, const char *tb) { int equiv = 1; const char* te = tb + strlen(tb); const char* ne = nb; while (equiv != 0 && *ne) { for (nb = ne; *ne; ++ne) { if (*ne == '|') break; } equiv = SWIG_TypeNameComp(nb, ne, tb, te); if (*ne) ++ne; } return equiv; } /* Check type equivalence in a name list like ||... Return 0 if not equal, 1 if equal */ SWIGRUNTIME int SWIG_TypeEquiv(const char *nb, const char *tb) { return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; } /* Check the typename */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheck(const char *c, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (strcmp(iter->type->name, c) == 0) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheckStruct(const swig_type_info *from, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { if (iter->type == from) { if (iter == ty->cast) return iter; /* Move iter to the top of the linked list */ iter->prev->next = iter->next; if (iter->next) iter->next->prev = iter->prev; iter->next = ty->cast; iter->prev = 0; if (ty->cast) ty->cast->prev = iter; ty->cast = iter; return iter; } iter = iter->next; } } return 0; } /* Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* Dynamic pointer casting. Down an inheritance hierarchy */ SWIGRUNTIME swig_type_info * SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { swig_type_info *lastty = ty; if (!ty || !ty->dcast) return ty; while (ty && (ty->dcast)) { ty = (*ty->dcast)(ptr); if (ty) lastty = ty; } return lastty; } /* Return the name associated with this type */ SWIGRUNTIMEINLINE const char * SWIG_TypeName(const swig_type_info *ty) { return ty->name; } /* Return the pretty name associated with this type, that is an unmangled type name in a form presentable to the user. */ SWIGRUNTIME const char * SWIG_TypePrettyName(const swig_type_info *type) { /* The "str" field contains the equivalent pretty names of the type, separated by vertical-bar characters. Choose the last name. It should be the most specific; a fully resolved name but not necessarily with default template parameters expanded. */ if (!type) return NULL; if (type->str != NULL) { const char *last_name = type->str; const char *s; for (s = type->str; *s; s++) if (*s == '|') last_name = s+1; return last_name; } else return type->name; } /* Set the clientdata field for a type */ SWIGRUNTIME void SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { swig_cast_info *cast = ti->cast; /* if (ti->clientdata == clientdata) return; */ ti->clientdata = clientdata; while (cast) { if (!cast->converter) { swig_type_info *tc = cast->type; if (!tc->clientdata) { SWIG_TypeClientData(tc, clientdata); } } cast = cast->next; } } SWIGRUNTIME void SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { SWIG_TypeClientData(ti, clientdata); ti->owndata = 1; } /* Search for a swig_type_info structure only by mangled name Search is a O(log #types) We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_MangledTypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { swig_module_info *iter = start; do { if (iter->size) { size_t l = 0; size_t r = iter->size - 1; do { /* since l+r >= 0, we can (>> 1) instead (/ 2) */ size_t i = (l + r) >> 1; const char *iname = iter->types[i]->name; if (iname) { int compare = strcmp(name, iname); if (compare == 0) { return iter->types[i]; } else if (compare < 0) { if (i) { r = i - 1; } else { break; } } else if (compare > 0) { l = i + 1; } } else { break; /* should never happen */ } } while (l <= r); } iter = iter->next; } while (iter != end); return 0; } /* Search for a swig_type_info structure for either a mangled name or a human readable name. It first searches the mangled names of the types, which is a O(log #types) If a type is not found it then searches the human readable names, which is O(#types). We start searching at module start, and finish searching when start == end. Note: if start == end at the beginning of the function, we go all the way around the circular list. */ SWIGRUNTIME swig_type_info * SWIG_TypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name) { /* STEP 1: Search the name field using binary search */ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); if (ret) { return ret; } else { /* STEP 2: If the type hasn't been found, do a complete search of the str field (the human readable name) */ swig_module_info *iter = start; do { size_t i = 0; for (; i < iter->size; ++i) { if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) return iter->types[i]; } iter = iter->next; } while (iter != end); } /* neither found a match */ return 0; } /* Pack binary data into a string */ SWIGRUNTIME char * SWIG_PackData(char *c, void *ptr, size_t sz) { static const char hex[17] = "0123456789abcdef"; const unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { unsigned char uu = *u; *(c++) = hex[(uu & 0xf0) >> 4]; *(c++) = hex[uu & 0xf]; } return c; } /* Unpack binary data from a string */ SWIGRUNTIME const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { unsigned char *u = (unsigned char *) ptr; const unsigned char *eu = u + sz; for (; u != eu; ++u) { char d = *(c++); unsigned char uu; if ((d >= '0') && (d <= '9')) uu = (unsigned char)((d - '0') << 4); else if ((d >= 'a') && (d <= 'f')) uu = (unsigned char)((d - ('a'-10)) << 4); else return (char *) 0; d = *(c++); if ((d >= '0') && (d <= '9')) uu |= (unsigned char)(d - '0'); else if ((d >= 'a') && (d <= 'f')) uu |= (unsigned char)(d - ('a'-10)); else return (char *) 0; *u = uu; } return c; } /* Pack 'void *' into a string buffer. */ SWIGRUNTIME char * SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { char *r = buff; if ((2*sizeof(void *) + 2) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,&ptr,sizeof(void *)); if (strlen(name) + 1 > (bsz - (r - buff))) return 0; strcpy(r,name); return buff; } SWIGRUNTIME const char * SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { *ptr = (void *) 0; return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sizeof(void *)); } SWIGRUNTIME char * SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { char *r = buff; size_t lname = (name ? strlen(name) : 0); if ((2*sz + 2 + lname) > bsz) return 0; *(r++) = '_'; r = SWIG_PackData(r,ptr,sz); if (lname) { strncpy(r,name,lname+1); } else { *r = 0; } return buff; } SWIGRUNTIME const char * SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { if (*c != '_') { if (strcmp(c,"NULL") == 0) { memset(ptr,0,sz); return name; } else { return 0; } } return SWIG_UnpackData(++c,ptr,sz); } #ifdef __cplusplus } #endif /* SWIG Errors applicable to all language modules, values are reserved from -1 to -99 */ #define SWIG_UnknownError -1 #define SWIG_IOError -2 #define SWIG_RuntimeError -3 #define SWIG_IndexError -4 #define SWIG_TypeError -5 #define SWIG_DivisionByZero -6 #define SWIG_OverflowError -7 #define SWIG_SyntaxError -8 #define SWIG_ValueError -9 #define SWIG_SystemError -10 #define SWIG_AttributeError -11 #define SWIG_MemoryError -12 #define SWIG_NullReferenceError -13 #if __GNUC__ >= 7 #pragma GCC diagnostic push #if defined(__cplusplus) #pragma GCC diagnostic ignored "-Wregister" #if __GNUC__ >= 10 #pragma GCC diagnostic ignored "-Wvolatile" #if __GNUC__ >= 11 #pragma GCC diagnostic ignored "-Wdeprecated-enum-enum-conversion" #endif #endif #endif #endif #include #include /* For RUBY_API_VERSION_CODE */ #if __GNUC__ >= 7 #pragma GCC diagnostic pop #endif /* Ruby 1.9.1 has a "memoisation optimisation" when compiling with GCC which * breaks using rb_intern as an lvalue, as SWIG does. We work around this * issue for now by disabling this. * https://sourceforge.net/tracker/?func=detail&aid=2859614&group_id=1645&atid=101645 */ #ifdef rb_intern # undef rb_intern #endif /* Remove global macros defined in Ruby's win32.h */ #ifdef write # undef write #endif #ifdef read # undef read #endif #ifdef bind # undef bind #endif #ifdef close # undef close #endif #ifdef connect # undef connect #endif /* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */ #ifndef NUM2LL #define NUM2LL(x) NUM2LONG((x)) #endif #ifndef LL2NUM #define LL2NUM(x) INT2NUM((long) (x)) #endif #ifndef ULL2NUM #define ULL2NUM(x) UINT2NUM((unsigned long) (x)) #endif /* Ruby 1.7 doesn't (yet) define NUM2ULL() */ #ifndef NUM2ULL #ifdef HAVE_LONG_LONG #define NUM2ULL(x) rb_num2ull((x)) #else #define NUM2ULL(x) NUM2ULONG(x) #endif #endif /* RSTRING_LEN, etc are new in Ruby 1.9, but ->ptr and ->len no longer work */ /* Define these for older versions so we can just write code the new way */ #ifndef RSTRING_LEN # define RSTRING_LEN(x) RSTRING(x)->len #endif #ifndef RSTRING_PTR # define RSTRING_PTR(x) RSTRING(x)->ptr #endif #ifndef RSTRING_END # define RSTRING_END(x) (RSTRING_PTR(x) + RSTRING_LEN(x)) #endif #ifndef RARRAY_LEN # define RARRAY_LEN(x) RARRAY(x)->len #endif #ifndef RARRAY_PTR # define RARRAY_PTR(x) RARRAY(x)->ptr #endif #ifndef RFLOAT_VALUE # define RFLOAT_VALUE(x) RFLOAT(x)->value #endif #ifndef DOUBLE2NUM # define DOUBLE2NUM(x) rb_float_new(x) #endif #ifndef RHASH_TBL # define RHASH_TBL(x) (RHASH(x)->tbl) #endif #ifndef RHASH_ITER_LEV # define RHASH_ITER_LEV(x) (RHASH(x)->iter_lev) #endif #ifndef RHASH_IFNONE # define RHASH_IFNONE(x) (RHASH(x)->ifnone) #endif #ifndef RHASH_SIZE # define RHASH_SIZE(x) (RHASH(x)->tbl->num_entries) #endif #ifndef RHASH_EMPTY_P # define RHASH_EMPTY_P(x) (RHASH_SIZE(x) == 0) #endif #ifndef RSTRUCT_LEN # define RSTRUCT_LEN(x) RSTRUCT(x)->len #endif #ifndef RSTRUCT_PTR # define RSTRUCT_PTR(x) RSTRUCT(x)->ptr #endif #ifndef RTYPEDDATA_P # define RTYPEDDATA_P(x) (TYPE(x) != T_DATA) #endif /* * The following macros are used for providing the correct type of a * function pointer to the Ruby C API. * * Starting with Ruby 2.7 these macros act transparently due to Ruby's moving * moving away from ANYARGS and instead employing strict function signatures. * * Note: In case of C (not C++) the macros are transparent even before * Ruby 2.7 due to the fact that the Ruby C API used function declarators * with empty parentheses, which allows for an unspecified number of * arguments. * * PROTECTFUNC(f) is used for the function pointer argument of the Ruby * C API function rb_protect(). * * VALUEFUNC(f) is used for the function pointer argument(s) of Ruby C API * functions like rb_define_method() and rb_define_singleton_method(). * * VOIDFUNC(f) is used to typecast a C function that implements either * the "mark" or "free" stuff for a Ruby Data object, so that it can be * passed as an argument to Ruby C API functions like Data_Wrap_Struct() * and Data_Make_Struct(). * * SWIG_RUBY_VOID_ANYARGS_FUNC(f) is used for the function pointer * argument(s) of Ruby C API functions like rb_define_virtual_variable(). * * SWIG_RUBY_INT_ANYARGS_FUNC(f) is used for the function pointer * argument(s) of Ruby C API functions like st_foreach(). */ #if defined(__cplusplus) && RUBY_API_VERSION_CODE < 20700 # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f) # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f) # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) # define SWIG_RUBY_VOID_ANYARGS_FUNC(f) ((void (*)(ANYARGS))(f)) # define SWIG_RUBY_INT_ANYARGS_FUNC(f) ((int (*)(ANYARGS))(f)) #else # define PROTECTFUNC(f) (f) # define VALUEFUNC(f) (f) # define VOIDFUNC(f) (f) # define SWIG_RUBY_VOID_ANYARGS_FUNC(f) (f) # define SWIG_RUBY_INT_ANYARGS_FUNC(f) (f) #endif /* Don't use for expressions have side effect */ #ifndef RB_STRING_VALUE #define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s))) #endif #ifndef StringValue #define StringValue(s) RB_STRING_VALUE(s) #endif #ifndef StringValuePtr #define StringValuePtr(s) RSTRING_PTR(RB_STRING_VALUE(s)) #endif #ifndef StringValueLen #define StringValueLen(s) RSTRING_LEN(RB_STRING_VALUE(s)) #endif #ifndef SafeStringValue #define SafeStringValue(v) do {\ StringValue(v);\ rb_check_safe_str(v);\ } while (0) #endif #ifndef HAVE_RB_DEFINE_ALLOC_FUNC #define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1) #define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new") #endif static VALUE _mSWIG = Qnil; /* ----------------------------------------------------------------------------- * error manipulation * ----------------------------------------------------------------------------- */ /* Define some additional error types */ #define SWIG_ObjectPreviouslyDeletedError -100 /* Define custom exceptions for errors that do not map to existing Ruby exceptions. Note this only works for C++ since a global cannot be initialized by a function in C. For C, fallback to rb_eRuntimeError.*/ SWIGINTERN VALUE getNullReferenceError(void) { static int init = 0; static VALUE rb_eNullReferenceError ; if (!init) { init = 1; rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError); } return rb_eNullReferenceError; } SWIGINTERN VALUE getObjectPreviouslyDeletedError(void) { static int init = 0; static VALUE rb_eObjectPreviouslyDeleted ; if (!init) { init = 1; rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError); } return rb_eObjectPreviouslyDeleted; } SWIGINTERN VALUE SWIG_Ruby_ErrorType(int SWIG_code) { VALUE type; switch (SWIG_code) { case SWIG_MemoryError: type = rb_eNoMemError; break; case SWIG_IOError: type = rb_eIOError; break; case SWIG_RuntimeError: type = rb_eRuntimeError; break; case SWIG_IndexError: type = rb_eIndexError; break; case SWIG_TypeError: type = rb_eTypeError; break; case SWIG_DivisionByZero: type = rb_eZeroDivError; break; case SWIG_OverflowError: type = rb_eRangeError; break; case SWIG_SyntaxError: type = rb_eSyntaxError; break; case SWIG_ValueError: type = rb_eArgError; break; case SWIG_SystemError: type = rb_eFatal; break; case SWIG_AttributeError: type = rb_eRuntimeError; break; case SWIG_NullReferenceError: type = getNullReferenceError(); break; case SWIG_ObjectPreviouslyDeletedError: type = getObjectPreviouslyDeletedError(); break; case SWIG_UnknownError: type = rb_eRuntimeError; break; default: type = rb_eRuntimeError; } return type; } /* This function is called when a user inputs a wrong argument to a method. */ SWIGINTERN const char* Ruby_Format_TypeError( const char* msg, const char* type, const char* name, const int argn, VALUE input ) { char buf[128]; VALUE str; VALUE asStr; if ( msg && *msg ) { str = rb_str_new2(msg); } else { str = rb_str_new(NULL, 0); } str = rb_str_cat2( str, "Expected argument " ); SWIG_snprintf( buf, sizeof( buf), "%d of type ", argn-1 ); str = rb_str_cat2( str, buf ); str = rb_str_cat2( str, type ); str = rb_str_cat2( str, ", but got " ); str = rb_str_cat2( str, rb_obj_classname(input) ); str = rb_str_cat2( str, " " ); asStr = rb_inspect(input); if ( RSTRING_LEN(asStr) > 30 ) { str = rb_str_cat( str, StringValuePtr(asStr), 30 ); str = rb_str_cat2( str, "..." ); } else { str = rb_str_append( str, asStr ); } if ( name ) { str = rb_str_cat2( str, "\n\tin SWIG method '" ); str = rb_str_cat2( str, name ); str = rb_str_cat2( str, "'" ); } return StringValuePtr( str ); } /* This function is called when an overloaded method fails */ SWIGINTERN void Ruby_Format_OverloadedError( const int argc, const int maxargs, const char* method, const char* prototypes ) { const char* msg = "Wrong # of arguments"; if ( argc <= maxargs ) msg = "Wrong arguments"; rb_raise(rb_eArgError,"%s for overloaded method '%s'.\n" "Possible C/C++ prototypes are:\n%s", msg, method, prototypes); } /* ----------------------------------------------------------------------------- * rubytracking.swg * * This file contains support for tracking mappings from * Ruby objects to C++ objects. This functionality is needed * to implement mark functions for Ruby's mark and sweep * garbage collector. * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #endif #if !defined(ST_DATA_T_DEFINED) /* Needs to be explicitly included for Ruby 1.8 and earlier */ #include #endif /* Ruby 1.8 actually assumes the first case. */ #if SIZEOF_VOIDP == SIZEOF_LONG # define SWIG2NUM(v) LONG2NUM((unsigned long)v) # define NUM2SWIG(x) (unsigned long)NUM2LONG(x) #elif SIZEOF_VOIDP == SIZEOF_LONG_LONG # define SWIG2NUM(v) LL2NUM((unsigned long long)v) # define NUM2SWIG(x) (unsigned long long)NUM2LL(x) #else # error sizeof(void*) is not the same as long or long long #endif /* Global hash table to store Trackings from C/C++ structs to Ruby Objects. */ static st_table* swig_ruby_trackings = NULL; static VALUE swig_ruby_trackings_count(ID id, VALUE *var) { return SWIG2NUM(swig_ruby_trackings->num_entries); } /* Setup a hash table to store Trackings */ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) { /* Create a hash table to store Trackings from C++ objects to Ruby objects. */ /* Try to see if some other .so has already created a tracking hash table, which we keep hidden in an instance var in the SWIG module. This is done to allow multiple DSOs to share the same tracking table. */ VALUE trackings_value = Qnil; /* change the variable name so that we can mix modules compiled with older SWIG's - this used to be called "@__trackings__" */ ID trackings_id = rb_intern( "@__safetrackings__" ); VALUE verbose = rb_gv_get("VERBOSE"); rb_gv_set("VERBOSE", Qfalse); trackings_value = rb_ivar_get( _mSWIG, trackings_id ); rb_gv_set("VERBOSE", verbose); /* The trick here is that we have to store the hash table pointer in a Ruby variable. We do not want Ruby's GC to treat this pointer as a Ruby object, so we convert it to a Ruby numeric value. */ if (trackings_value == Qnil) { /* No, it hasn't. Create one ourselves */ swig_ruby_trackings = st_init_numtable(); rb_ivar_set( _mSWIG, trackings_id, SWIG2NUM(swig_ruby_trackings) ); } else { swig_ruby_trackings = (st_table*)NUM2SWIG(trackings_value); } rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", VALUEFUNC(swig_ruby_trackings_count), SWIG_RUBY_VOID_ANYARGS_FUNC((rb_gvar_setter_t*)NULL)); } /* Add a Tracking from a C/C++ struct to a Ruby object */ SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) { /* Store the mapping to the global hash table. */ st_insert(swig_ruby_trackings, (st_data_t)ptr, object); } /* Get the Ruby object that owns the specified C/C++ struct */ SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) { /* Now lookup the value stored in the global hash table */ VALUE value; if (st_lookup(swig_ruby_trackings, (st_data_t)ptr, &value)) { return value; } else { return Qnil; } } /* Remove a Tracking from a C/C++ struct to a Ruby object. It is very important to remove objects once they are destroyed since the same memory address may be reused later to create a new object. */ SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) { /* Delete the object from the hash table */ st_delete(swig_ruby_trackings, (st_data_t *)&ptr, NULL); } /* This is a helper method that unlinks a Ruby object from its underlying C++ object. This is needed if the lifetime of the Ruby object is longer than the C++ object. */ SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) { VALUE object = SWIG_RubyInstanceFor(ptr); if (object != Qnil) { // object might have the T_ZOMBIE type, but that's just // because the GC has flagged it as such for a deferred // destruction. Until then, it's still a T_DATA object. DATA_PTR(object) = 0; } } /* This is a helper method that iterates over all the trackings passing the C++ object pointer and its related Ruby object to the passed callback function. */ /* Proxy method to abstract the internal trackings datatype */ static int swig_ruby_internal_iterate_callback(st_data_t ptr, st_data_t obj, st_data_t meth) { ((void (*) (void *, VALUE))meth)((void *)ptr, (VALUE)obj); return ST_CONTINUE; } SWIGRUNTIME void SWIG_RubyIterateTrackings( void(*meth)(void* ptr, VALUE obj) ) { st_foreach(swig_ruby_trackings, SWIG_RUBY_INT_ANYARGS_FUNC(swig_ruby_internal_iterate_callback), (st_data_t)meth); } #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * Ruby API portion that goes into the runtime * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #endif SWIGINTERN VALUE SWIG_Ruby_AppendOutput(VALUE target, VALUE o) { if (NIL_P(target)) { target = o; } else { if (TYPE(target) != T_ARRAY) { VALUE o2 = target; target = rb_ary_new(); rb_ary_push(target, o2); } rb_ary_push(target, o); } return target; } /* For ruby1.8.4 and earlier. */ #ifndef RUBY_INIT_STACK RUBY_EXTERN void Init_stack(VALUE* addr); # define RUBY_INIT_STACK \ VALUE variable_in_this_stack_frame; \ Init_stack(&variable_in_this_stack_frame); #endif #ifdef __cplusplus } #endif /* ----------------------------------------------------------------------------- * rubyrun.swg * * This file contains the runtime support for Ruby modules * and includes code for managing global variables and pointer * type checking. * ----------------------------------------------------------------------------- */ /* For backward compatibility only */ #define SWIG_POINTER_EXCEPTION 0 /* for raw pointers */ #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, 0) #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, own) #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags) #define SWIG_AcquirePtr(ptr, own) SWIG_Ruby_AcquirePtr(ptr, own) #define swig_owntype swig_ruby_owntype /* for raw packed data */ #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags) #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type) /* for class or struct pointers */ #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) /* for C or C++ function pointers */ #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0) #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0) /* for C++ member pointers, ie, member methods */ #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty) #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type) /* Runtime API */ #define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer) /* Error manipulation */ #define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code) #define SWIG_Error(code, msg) rb_raise(SWIG_Ruby_ErrorType(code), "%s", msg) #define SWIG_fail goto fail /* Ruby-specific SWIG API */ #define SWIG_InitRuntime() SWIG_Ruby_InitRuntime() #define SWIG_define_class(ty) SWIG_Ruby_define_class(ty) #define SWIG_NewClassInstance(value, ty) SWIG_Ruby_NewClassInstance(value, ty) #define SWIG_MangleStr(value) SWIG_Ruby_MangleStr(value) #define SWIG_CheckConvert(value, ty) SWIG_Ruby_CheckConvert(value, ty) #include "assert.h" /* ----------------------------------------------------------------------------- * pointers/data manipulation * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #endif typedef struct { VALUE klass; VALUE mImpl; void (*mark)(void *); void (*destroy)(void *); int trackObjects; } swig_class; /* Global pointer used to keep some internal SWIG stuff */ static VALUE _cSWIG_Pointer = Qnil; static VALUE swig_runtime_data_type_pointer = Qnil; /* Global IDs used to keep some internal SWIG stuff */ static ID swig_arity_id = 0; static ID swig_call_id = 0; static ID swig_lowerthan_id = 0; /* If your swig extension is to be run within an embedded ruby and has director callbacks, you should set -DRUBY_EMBEDDED during compilation. This will reset ruby's stack frame on each entry point from the main program the first time a virtual director function is invoked (in a non-recursive way). If this is not done, you run the risk of Ruby trashing the stack. */ #ifdef RUBY_EMBEDDED # define SWIG_INIT_STACK \ if ( !swig_virtual_calls ) { RUBY_INIT_STACK } \ ++swig_virtual_calls; # define SWIG_RELEASE_STACK --swig_virtual_calls; # define Ruby_DirectorTypeMismatchException(x) \ rb_raise( rb_eTypeError, "%s", x ); return c_result; static unsigned int swig_virtual_calls = 0; #else /* normal non-embedded extension */ # define SWIG_INIT_STACK # define SWIG_RELEASE_STACK # define Ruby_DirectorTypeMismatchException(x) \ throw Swig::DirectorTypeMismatchException( x ); #endif /* RUBY_EMBEDDED */ SWIGRUNTIME VALUE getExceptionClass(void) { static int init = 0; static VALUE rubyExceptionClass ; if (!init) { init = 1; rubyExceptionClass = rb_const_get(_mSWIG, rb_intern("Exception")); } return rubyExceptionClass; } /* This code checks to see if the Ruby object being raised as part of an exception inherits from the Ruby class Exception. If so, the object is simply returned. If not, then a new Ruby exception object is created and that will be returned to Ruby.*/ SWIGRUNTIME VALUE SWIG_Ruby_ExceptionType(swig_type_info *desc, VALUE obj) { VALUE exceptionClass = getExceptionClass(); if (rb_obj_is_kind_of(obj, exceptionClass)) { return obj; } else { return rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj)); } } /* Initialize Ruby runtime support */ SWIGRUNTIME void SWIG_Ruby_InitRuntime(void) { if (_mSWIG == Qnil) { _mSWIG = rb_define_module("SWIG"); swig_call_id = rb_intern("call"); swig_arity_id = rb_intern("arity"); swig_lowerthan_id = rb_intern("<"); } } /* Define Ruby class for C type */ SWIGRUNTIME void SWIG_Ruby_define_class(swig_type_info *type) { size_t klass_len = 4 + strlen(type->name) + 1; char *klass_name = (char *) malloc(klass_len); SWIG_snprintf(klass_name, klass_len, "TYPE%s", type->name); if (NIL_P(_cSWIG_Pointer)) { _cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject); rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new"); } rb_undef_alloc_func(rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer)); free((void *) klass_name); } /* Create a new pointer object */ SWIGRUNTIME VALUE SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags) { int own = flags & SWIG_POINTER_OWN; int track; char *klass_name; swig_class *sklass; VALUE klass; VALUE obj; if (!ptr) return Qnil; assert(type); if (type->clientdata) { sklass = (swig_class *) type->clientdata; /* Are we tracking this class and have we already returned this Ruby object? */ track = sklass->trackObjects; if (track) { obj = SWIG_RubyInstanceFor(ptr); /* Check the object's type and make sure it has the correct type. It might not in cases where methods do things like downcast methods. */ if (obj != Qnil) { VALUE value = rb_iv_get(obj, "@__swigtype__"); const char* type_name = RSTRING_PTR(value); if (strcmp(type->name, type_name) == 0) { return obj; } } } /* Create a new Ruby object */ obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), ( own ? VOIDFUNC(sklass->destroy) : (track ? VOIDFUNC(SWIG_RubyRemoveTracking) : 0 ) ), ptr); /* If tracking is on for this class then track this object. */ if (track) { SWIG_RubyAddTracking(ptr, obj); } } else { size_t klass_len = 4 + strlen(type->name) + 1; klass_name = (char *) malloc(klass_len); SWIG_snprintf(klass_name, klass_len, "TYPE%s", type->name); klass = rb_const_get(_mSWIG, rb_intern(klass_name)); free((void *) klass_name); obj = Data_Wrap_Struct(klass, 0, 0, ptr); } rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name)); return obj; } /* Create a new class instance (always owned) */ SWIGRUNTIME VALUE SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type) { VALUE obj; swig_class *sklass = (swig_class *) type->clientdata; obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0); rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name)); return obj; } /* Get type mangle from class name */ SWIGRUNTIMEINLINE char * SWIG_Ruby_MangleStr(VALUE obj) { VALUE stype = rb_iv_get(obj, "@__swigtype__"); if (NIL_P(stype)) return NULL; return StringValuePtr(stype); } /* Acquire a pointer value */ typedef struct { void (*datafree)(void *); int own; } swig_ruby_owntype; SWIGRUNTIME swig_ruby_owntype SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) { swig_ruby_owntype oldown = {0, 0}; if (TYPE(obj) == T_DATA && !RTYPEDDATA_P(obj)) { oldown.datafree = RDATA(obj)->dfree; RDATA(obj)->dfree = own.datafree; } return oldown; } /* Convert a pointer value */ SWIGRUNTIME int SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, swig_ruby_owntype *own) { char *c; swig_cast_info *tc; void *vptr = 0; /* Grab the pointer */ if (NIL_P(obj)) { if (ptr) *ptr = 0; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } else { if (TYPE(obj) != T_DATA || (TYPE(obj) == T_DATA && RTYPEDDATA_P(obj))) { return SWIG_ERROR; } Data_Get_Struct(obj, void, vptr); } if (own) { own->datafree = RDATA(obj)->dfree; own->own = 0; } if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE)) { if (!RDATA(obj)->dfree) return SWIG_ERROR_RELEASE_NOT_OWNED; } /* Check to see if the input object is giving up ownership of the underlying C struct or C++ object. If so then we need to reset the destructor since the Ruby object no longer owns the underlying C++ object.*/ if (flags & SWIG_POINTER_DISOWN) { /* Is tracking on for this class? */ int track = 0; if (ty && ty->clientdata) { swig_class *sklass = (swig_class *) ty->clientdata; track = sklass->trackObjects; } if (track) { /* We are tracking objects for this class. Thus we change the destructor * to SWIG_RubyRemoveTracking. This allows us to * remove the mapping from the C++ to Ruby object * when the Ruby object is garbage collected. If we don't * do this, then it is possible we will return a reference * to a Ruby object that no longer exists thereby crashing Ruby. */ RDATA(obj)->dfree = SWIG_RubyRemoveTracking; } else { RDATA(obj)->dfree = 0; } } if (flags & SWIG_POINTER_CLEAR) { DATA_PTR(obj) = 0; } /* Do type-checking if type info was provided */ if (ty) { if (ty->clientdata) { if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) { if (vptr == 0) { /* The object has already been deleted */ return SWIG_ObjectPreviouslyDeletedError; } } } if ((c = SWIG_MangleStr(obj)) == NULL) { return SWIG_ERROR; } tc = SWIG_TypeCheck(c, ty); if (!tc) { return SWIG_ERROR; } else { if (ptr) { if (tc->type == ty) { *ptr = vptr; } else { int newmemory = 0; *ptr = SWIG_TypeCast(tc, vptr, &newmemory); if (newmemory == SWIG_CAST_NEW_MEMORY) { assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ if (own) own->own = own->own | SWIG_CAST_NEW_MEMORY; } } } } } else { if (ptr) *ptr = vptr; } return SWIG_OK; } /* Check convert */ SWIGRUNTIMEINLINE int SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty) { char *c = SWIG_MangleStr(obj); if (!c) return 0; return SWIG_TypeCheck(c,ty) != 0; } SWIGRUNTIME VALUE SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) { char result[1024]; char *r = result; if ((2*sz + 1 + strlen(type->name)) > 1000) return 0; *(r++) = '_'; r = SWIG_PackData(r, ptr, sz); strcpy(r, type->name); return rb_str_new2(result); } /* Convert a packed pointer value */ SWIGRUNTIME int SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) { swig_cast_info *tc; const char *c; if (TYPE(obj) != T_STRING) goto type_error; c = StringValuePtr(obj); /* Pointer values must start with leading underscore */ if (*c != '_') goto type_error; c++; c = SWIG_UnpackData(c, ptr, sz); if (ty) { tc = SWIG_TypeCheck(c, ty); if (!tc) goto type_error; } return SWIG_OK; type_error: return SWIG_ERROR; } SWIGRUNTIME swig_module_info * SWIG_Ruby_GetModule(void *SWIGUNUSEDPARM(clientdata)) { VALUE pointer; swig_module_info *ret = 0; VALUE verbose = rb_gv_get("VERBOSE"); /* temporarily disable warnings, since the pointer check causes warnings with 'ruby -w' */ rb_gv_set("VERBOSE", Qfalse); /* first check if pointer already created */ pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); if (pointer != Qnil) { Data_Get_Struct(pointer, swig_module_info, ret); } /* reinstate warnings */ rb_gv_set("VERBOSE", verbose); return ret; } SWIGRUNTIME void SWIG_Ruby_SetModule(swig_module_info *pointer) { /* register a new class */ VALUE cl = rb_define_class("swig_runtime_data", rb_cObject); rb_undef_alloc_func(cl); /* create and store the structure pointer to a global variable */ swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer); rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer); } /* This function can be used to check whether a proc or method or similarly callable function has been passed. Usually used in a %typecheck, like: %typecheck(c_callback_t, precedence=SWIG_TYPECHECK_POINTER) { $result = SWIG_Ruby_isCallable( $input ); } */ SWIGINTERN int SWIG_Ruby_isCallable( VALUE proc ) { if ( rb_respond_to( proc, swig_call_id ) ) return 1; return 0; } /* This function can be used to check the arity (number of arguments) a proc or method can take. Usually used in a %typecheck. Valid arities will be that equal to minimal or those < 0 which indicate a variable number of parameters at the end. */ SWIGINTERN int SWIG_Ruby_arity( VALUE proc, int minimal ) { if ( rb_respond_to( proc, swig_arity_id ) ) { VALUE num = rb_funcall2( proc, swig_arity_id, 0, 0 ); int arity = NUM2INT(num); if ( arity < 0 && (arity+1) < -minimal ) return 1; if ( arity == minimal ) return 1; return 1; } return 0; } #ifdef __cplusplus } #endif #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) #define SWIG_contract_assert(expr, msg) do { if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } } while (0) #define SWIG_exception(code, msg) do { SWIG_Error(code, msg);; } while(0) /* -------- TYPES TABLE (BEGIN) -------- */ #define SWIGTYPE_p_char swig_types[0] #define SWIGTYPE_p_marisa__Key swig_types[1] #define SWIGTYPE_p_marisa_swig__Agent swig_types[2] #define SWIGTYPE_p_marisa_swig__Key swig_types[3] #define SWIGTYPE_p_marisa_swig__Keyset swig_types[4] #define SWIGTYPE_p_marisa_swig__Query swig_types[5] #define SWIGTYPE_p_marisa_swig__Trie swig_types[6] #define SWIGTYPE_p_p_char swig_types[7] #define SWIGTYPE_p_std__size_t swig_types[8] static swig_type_info *swig_types[10]; static swig_module_info swig_module = {swig_types, 9, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) /* -------- TYPES TABLE (END) -------- */ #define SWIG_init Init_marisa #define SWIG_name "Marisa" static VALUE mMarisa; #ifdef __cplusplus #include /* SwigValueWrapper is described in swig.swg */ template class SwigValueWrapper { struct SwigSmartPointer { T *ptr; SwigSmartPointer(T *p) : ptr(p) { } ~SwigSmartPointer() { delete ptr; } SwigSmartPointer& operator=(SwigSmartPointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } void reset(T *p) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = p; } } pointer; SwigValueWrapper& operator=(const SwigValueWrapper& rhs); SwigValueWrapper(const SwigValueWrapper& rhs); public: SwigValueWrapper() : pointer(0) { } SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; } #if __cplusplus >=201103L SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; } operator T&&() const { return std::move(*pointer.ptr); } #else operator T&() const { return *pointer.ptr; } #endif T *operator&() const { return pointer.ptr; } static void reset(SwigValueWrapper& t, T *p) { t.pointer.reset(p); } }; /* * SwigValueInit() is a generic initialisation solution as the following approach: * * T c_result = T(); * * doesn't compile for all types for example: * * unsigned int c_result = unsigned int(); */ template T SwigValueInit() { return T(); } #if __cplusplus >=201103L # define SWIG_STD_MOVE(OBJ) std::move(OBJ) #else # define SWIG_STD_MOVE(OBJ) OBJ #endif #endif #define SWIG_RUBY_THREAD_BEGIN_BLOCK #define SWIG_RUBY_THREAD_END_BLOCK #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) #include #include "marisa-swig.h" #include #if !defined(SWIG_NO_LLONG_MAX) # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) # define LLONG_MAX __LONG_LONG_MAX__ # define LLONG_MIN (-LLONG_MAX - 1LL) # define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) # endif #endif #define SWIG_From_long LONG2NUM SWIGINTERNINLINE VALUE SWIG_From_int (int value) { return SWIG_From_long (value); } SWIGINTERN swig_type_info* SWIG_pchar_descriptor(void) { static int init = 0; static swig_type_info* info = 0; if (!init) { info = SWIG_TypeQuery("_p_char"); init = 1; } return info; } SWIGINTERNINLINE VALUE SWIG_FromCharPtrAndSize(const char* carray, size_t size) { if (carray) { if (size > LONG_MAX) { swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); return pchar_descriptor ? SWIG_NewPointerObj(const_cast< char * >(carray), pchar_descriptor, 0) : Qnil; } else { return rb_str_new(carray, static_cast< long >(size)); } } else { return Qnil; } } SWIGINTERNINLINE VALUE SWIG_From_unsigned_SS_long (unsigned long value) { return ULONG2NUM(value); } #if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE) # define SWIG_LONG_LONG_AVAILABLE #endif #ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE VALUE SWIG_From_unsigned_SS_long_SS_long (unsigned long long value) { return ULL2NUM(value); } #endif SWIGINTERNINLINE VALUE SWIG_From_size_t (size_t value) { #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif return SWIG_From_unsigned_SS_long (static_cast< unsigned long >(value)); #ifdef SWIG_LONG_LONG_AVAILABLE } else { /* assume sizeof(size_t) <= sizeof(unsigned long long) */ return SWIG_From_unsigned_SS_long_SS_long (static_cast< unsigned long long >(value)); } #endif } #define SWIG_From_double rb_float_new SWIGINTERNINLINE VALUE SWIG_From_float (float value) { return SWIG_From_double (value); } SWIGINTERN int SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc) { if (TYPE(obj) == T_STRING) { char *cstr = StringValuePtr(obj); size_t size = RSTRING_LEN(obj) + 1; if (cptr) { if (alloc) { if (*alloc == SWIG_NEWOBJ) { *cptr = reinterpret_cast< char* >(memcpy(new char[size], cstr, sizeof(char)*(size))); } else { *cptr = cstr; *alloc = SWIG_OLDOBJ; } } } if (psize) *psize = size; return SWIG_OK; } else { swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); if (pchar_descriptor) { void* vptr = 0; if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { if (cptr) *cptr = (char *)vptr; if (psize) *psize = vptr ? (strlen((char*)vptr) + 1) : 0; if (alloc) *alloc = SWIG_OLDOBJ; return SWIG_OK; } } } return SWIG_TypeError; } #include #include /* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ #ifndef SWIG_isfinite /* isfinite() is a macro for C99 */ # if defined(isfinite) # define SWIG_isfinite(X) (isfinite(X)) # elif defined(__cplusplus) && __cplusplus >= 201103L /* Use a template so that this works whether isfinite() is std::isfinite() or * in the global namespace. The reality seems to vary between compiler * versions. * * Make sure namespace std exists to avoid compiler warnings. * * extern "C++" is required as this fragment can end up inside an extern "C" { } block */ namespace std { } extern "C++" template inline int SWIG_isfinite_func(T x) { using namespace std; return isfinite(x); } # define SWIG_isfinite(X) (SWIG_isfinite_func(X)) # elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) # define SWIG_isfinite(X) (__builtin_isfinite(X)) # elif defined(_MSC_VER) # define SWIG_isfinite(X) (_finite(X)) # elif defined(__sun) && defined(__SVR4) # include # define SWIG_isfinite(X) (finite(X)) # endif #endif /* Accept infinite as a valid float value unless we are unable to check if a value is finite */ #ifdef SWIG_isfinite # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX) && SWIG_isfinite(X)) #else # define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX)) #endif SWIGINTERN VALUE SWIG_ruby_failed(VALUE SWIGUNUSEDPARM(arg1), VALUE SWIGUNUSEDPARM(arg2)) { return Qnil; } /*@SWIG:/usr/share/swig4.0/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/ SWIGINTERN VALUE SWIG_AUX_NUM2DBL(VALUE arg) { VALUE *args = (VALUE *)arg; VALUE obj = args[0]; VALUE type = TYPE(obj); double *res = (double *)(args[1]); *res = NUM2DBL(obj); (void)type; return obj; } /*@SWIG@*/ SWIGINTERN int SWIG_AsVal_double (VALUE obj, double *val) { VALUE type = TYPE(obj); if ((type == T_FLOAT) || (type == T_FIXNUM) || (type == T_BIGNUM)) { double v; VALUE a[2]; a[0] = obj; a[1] = (VALUE)(&v); if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2DBL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { if (val) *val = v; return SWIG_OK; } } return SWIG_TypeError; } SWIGINTERN int SWIG_AsVal_float (VALUE obj, float *val) { double v; int res = SWIG_AsVal_double (obj, &v); if (SWIG_IsOK(res)) { if (SWIG_Float_Overflow_Check(v)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< float >(v); } } return res; } /*@SWIG:/usr/share/swig4.0/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/ SWIGINTERN VALUE SWIG_AUX_NUM2ULONG(VALUE arg) { VALUE *args = (VALUE *)arg; VALUE obj = args[0]; VALUE type = TYPE(obj); unsigned long *res = (unsigned long *)(args[1]); *res = type == T_FIXNUM ? NUM2ULONG(obj) : rb_big2ulong(obj); return obj; } /*@SWIG@*/ SWIGINTERN int SWIG_AsVal_unsigned_SS_long (VALUE obj, unsigned long *val) { VALUE type = TYPE(obj); if ((type == T_FIXNUM) || (type == T_BIGNUM)) { unsigned long v; VALUE a[2]; a[0] = obj; a[1] = (VALUE)(&v); if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { if (rb_funcall(obj, swig_lowerthan_id, 1, INT2FIX(0)) != Qfalse) return SWIG_OverflowError; if (val) *val = v; return SWIG_OK; } } return SWIG_TypeError; } #ifdef SWIG_LONG_LONG_AVAILABLE /*@SWIG:/usr/share/swig4.0/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/ SWIGINTERN VALUE SWIG_AUX_NUM2ULL(VALUE arg) { VALUE *args = (VALUE *)arg; VALUE obj = args[0]; VALUE type = TYPE(obj); long long *res = (long long *)(args[1]); *res = type == T_FIXNUM ? NUM2ULL(obj) : rb_big2ull(obj); return obj; } /*@SWIG@*/ SWIGINTERN int SWIG_AsVal_unsigned_SS_long_SS_long (VALUE obj, unsigned long long *val) { VALUE type = TYPE(obj); if ((type == T_FIXNUM) || (type == T_BIGNUM)) { unsigned long long v; VALUE a[2]; a[0] = obj; a[1] = (VALUE)(&v); if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2ULL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { if (rb_funcall(obj, swig_lowerthan_id, 1, INT2FIX(0)) != Qfalse) return SWIG_OverflowError; if (val) *val = v; return SWIG_OK; } } return SWIG_TypeError; } #endif SWIGINTERNINLINE int SWIG_AsVal_size_t (VALUE obj, size_t *val) { int res = SWIG_TypeError; #ifdef SWIG_LONG_LONG_AVAILABLE if (sizeof(size_t) <= sizeof(unsigned long)) { #endif unsigned long v; res = SWIG_AsVal_unsigned_SS_long (obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); #ifdef SWIG_LONG_LONG_AVAILABLE } else if (sizeof(size_t) <= sizeof(unsigned long long)) { unsigned long long v; res = SWIG_AsVal_unsigned_SS_long_SS_long (obj, val ? &v : 0); if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v); } #endif return res; } SWIGINTERNINLINE VALUE SWIG_From_bool (bool value) { return value ? Qtrue : Qfalse; } /*@SWIG:/usr/share/swig4.0/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/ SWIGINTERN VALUE SWIG_AUX_NUM2LONG(VALUE arg) { VALUE *args = (VALUE *)arg; VALUE obj = args[0]; VALUE type = TYPE(obj); long *res = (long *)(args[1]); *res = type == T_FIXNUM ? NUM2LONG(obj) : rb_big2long(obj); return obj; } /*@SWIG@*/ SWIGINTERN int SWIG_AsVal_long (VALUE obj, long* val) { VALUE type = TYPE(obj); if ((type == T_FIXNUM) || (type == T_BIGNUM)) { long v; VALUE a[2]; a[0] = obj; a[1] = (VALUE)(&v); if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2LONG), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { if (val) *val = v; return SWIG_OK; } } return SWIG_TypeError; } SWIGINTERN int SWIG_AsVal_int (VALUE obj, int *val) { long v; int res = SWIG_AsVal_long (obj, &v); if (SWIG_IsOK(res)) { if ((v < INT_MIN || v > INT_MAX)) { return SWIG_OverflowError; } else { if (val) *val = static_cast< int >(v); } } return res; } static swig_class SwigClassKey; SWIGINTERN VALUE _wrap_Key_str(int argc, VALUE *argv, VALUE self) { marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; VALUE vresult = Qnil; arg2 = &temp2; arg3 = &tempn2; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Key const *","str", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { ((marisa_swig::Key const *)arg1)->str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (*arg2) { vresult = SWIG_Ruby_AppendOutput(vresult, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Key_id(int argc, VALUE *argv, VALUE self) { marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Key const *","id", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = ((marisa_swig::Key const *)arg1)->id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Key_weight(int argc, VALUE *argv, VALUE self) { marisa_swig::Key *arg1 = (marisa_swig::Key *) 0 ; void *argp1 = 0 ; int res1 = 0 ; float result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Key const *","weight", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Key * >(argp1); { try { result = (float)((marisa_swig::Key const *)arg1)->weight(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_float(static_cast< float >(result)); return vresult; fail: return Qnil; } SWIGINTERN void free_marisa_swig_Key(void *self) { marisa_swig::Key *arg1 = (marisa_swig::Key *)self; delete arg1; } static swig_class SwigClassQuery; SWIGINTERN VALUE _wrap_Query_str(int argc, VALUE *argv, VALUE self) { marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; VALUE vresult = Qnil; arg2 = &temp2; arg3 = &tempn2; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Query const *","str", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { ((marisa_swig::Query const *)arg1)->str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (*arg2) { vresult = SWIG_Ruby_AppendOutput(vresult, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Query_id(int argc, VALUE *argv, VALUE self) { marisa_swig::Query *arg1 = (marisa_swig::Query *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Query const *","id", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Query * >(argp1); { try { result = ((marisa_swig::Query const *)arg1)->id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN void free_marisa_swig_Query(void *self) { marisa_swig::Query *arg1 = (marisa_swig::Query *)self; delete arg1; } static swig_class SwigClassKeyset; SWIGINTERN VALUE #ifdef HAVE_RB_DEFINE_ALLOC_FUNC _wrap_Keyset_allocate(VALUE self) #else _wrap_Keyset_allocate(int argc, VALUE *argv, VALUE self) #endif { VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE_p_marisa_swig__Keyset); #ifndef HAVE_RB_DEFINE_ALLOC_FUNC rb_obj_call_init(vresult, argc, argv); #endif return vresult; } SWIGINTERN VALUE _wrap_new_Keyset(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *result = 0 ; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } { try { result = (marisa_swig::Keyset *)new marisa_swig::Keyset(); DATA_PTR(self) = result; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return self; fail: return Qnil; } SWIGINTERN void free_marisa_swig_Keyset(void *self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *)self; delete arg1; } SWIGINTERN VALUE _wrap_Keyset_push_back__SWIG_0(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; marisa::Key *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset *","push_back", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_marisa__Key, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "marisa::Key const &","push_back", 2, argv[0] )); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "marisa::Key const &","push_back", 2, argv[0])); } arg2 = reinterpret_cast< marisa::Key * >(argp2); { try { (arg1)->push_back((marisa::Key const &)*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } SWIGINTERN VALUE _wrap_Keyset_push_back__SWIG_1(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; float arg4 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; float val4 ; int ecode4 = 0 ; if ((argc < 2) || (argc > 2)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset *","push_back", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","push_back", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); ecode4 = SWIG_AsVal_float(argv[1], &val4); if (!SWIG_IsOK(ecode4)) { SWIG_exception_fail(SWIG_ArgError(ecode4), Ruby_Format_TypeError( "", "float","push_back", 4, argv[1] )); } arg4 = static_cast< float >(val4); { try { (arg1)->push_back((char const *)arg2,arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Keyset_push_back__SWIG_2(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset *","push_back", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","push_back", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->push_back((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Keyset_push_back(int nargs, VALUE *args, VALUE self) { int argc; VALUE argv[4]; int ii; argc = nargs + 1; argv[0] = self; if (argc > 4) SWIG_fail; for (ii = 1; (ii < argc); ++ii) { argv[ii] = args[ii-1]; } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa__Key, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Keyset_push_back__SWIG_0(nargs, args, self); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Keyset_push_back__SWIG_2(nargs, args, self); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Keyset_push_back__SWIG_2(nargs, args, self); } } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Keyset, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_float(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Keyset_push_back__SWIG_1(nargs, args, self); } } } } fail: Ruby_Format_OverloadedError( argc, 4, "Keyset.push_back", " void Keyset.push_back(marisa::Key const &key)\n" " void Keyset.push_back(char const *ptr, std::size_t length, float weight)\n" " void Keyset.push_back(char const *ptr, std::size_t length)\n"); return Qnil; } SWIGINTERN VALUE _wrap_Keyset_key(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; marisa_swig::Key *result = 0 ; VALUE vresult = Qnil; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset const *","key", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(argv[0], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "std::size_t","key", 2, argv[0] )); } arg2 = static_cast< std::size_t >(val2); { try { result = (marisa_swig::Key *) &((marisa_swig::Keyset const *)arg1)->key(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Keyset_key_str(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; VALUE vresult = Qnil; arg3 = &temp3; arg4 = &tempn3; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset const *","key_str", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(argv[0], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "std::size_t","key_str", 2, argv[0] )); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Keyset const *)arg1)->key_str(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (*arg3) { vresult = SWIG_Ruby_AppendOutput(vresult, SWIG_FromCharPtrAndSize(*arg3,*arg4)); ; } return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Keyset_key_id(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset const *","key_id", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); ecode2 = SWIG_AsVal_size_t(argv[0], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "std::size_t","key_id", 2, argv[0] )); } arg2 = static_cast< std::size_t >(val2); { try { result = ((marisa_swig::Keyset const *)arg1)->key_id(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Keyset_num_keys(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset const *","num_keys", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } /* Document-method: Marisa::Keyset.empty call-seq: empty -> bool Check if Keyset is empty. */ SWIGINTERN VALUE _wrap_Keyset_empty(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; bool result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset const *","empty", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = (bool)((marisa_swig::Keyset const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_bool(static_cast< bool >(result)); return vresult; fail: return Qnil; } /* Document-method: Marisa::Keyset.size call-seq: size -> std::size_t Size or Length of the Keyset. */ SWIGINTERN VALUE _wrap_Keyset_size(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset const *","size", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Keyset_total_length(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset const *","total_length", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { result = ((marisa_swig::Keyset const *)arg1)->total_length(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Keyset_reset(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset *","reset", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->reset(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } SWIGINTERN VALUE _wrap_Keyset_clear(int argc, VALUE *argv, VALUE self) { marisa_swig::Keyset *arg1 = (marisa_swig::Keyset *) 0 ; void *argp1 = 0 ; int res1 = 0 ; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Keyset, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Keyset *","clear", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Keyset * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } static swig_class SwigClassAgent; SWIGINTERN VALUE #ifdef HAVE_RB_DEFINE_ALLOC_FUNC _wrap_Agent_allocate(VALUE self) #else _wrap_Agent_allocate(int argc, VALUE *argv, VALUE self) #endif { VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE_p_marisa_swig__Agent); #ifndef HAVE_RB_DEFINE_ALLOC_FUNC rb_obj_call_init(vresult, argc, argv); #endif return vresult; } SWIGINTERN VALUE _wrap_new_Agent(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *result = 0 ; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } { try { result = (marisa_swig::Agent *)new marisa_swig::Agent(); DATA_PTR(self) = result; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return self; fail: return Qnil; } SWIGINTERN void free_marisa_swig_Agent(void *self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *)self; delete arg1; } SWIGINTERN VALUE _wrap_Agent_set_query__SWIG_0(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent *","set_query", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","set_query", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { (arg1)->set_query((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Agent_set_query__SWIG_1(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; std::size_t arg2 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent *","set_query", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); ecode2 = SWIG_AsVal_size_t(argv[0], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "std::size_t","set_query", 2, argv[0] )); } arg2 = static_cast< std::size_t >(val2); { try { (arg1)->set_query(arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } SWIGINTERN VALUE _wrap_Agent_set_query(int nargs, VALUE *args, VALUE self) { int argc; VALUE argv[3]; int ii; argc = nargs + 1; argv[0] = self; if (argc > 3) SWIG_fail; for (ii = 1; (ii < argc); ++ii) { argv[ii] = args[ii-1]; } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_size_t(argv[1], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Agent_set_query__SWIG_1(nargs, args, self); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Agent, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Agent_set_query__SWIG_0(nargs, args, self); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Agent_set_query__SWIG_0(nargs, args, self); } } } } fail: Ruby_Format_OverloadedError( argc, 3, "Agent.set_query", " void Agent.set_query(char const *ptr, std::size_t length)\n" " void Agent.set_query(std::size_t id)\n"); return Qnil; } SWIGINTERN VALUE _wrap_Agent_key(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; marisa_swig::Key *result = 0 ; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent const *","key", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Key *) &((marisa_swig::Agent const *)arg1)->key(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Key, 0 | 0 ); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Agent_query(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; marisa_swig::Query *result = 0 ; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent const *","query", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = (marisa_swig::Query *) &((marisa_swig::Agent const *)arg1)->query(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_marisa_swig__Query, 0 | 0 ); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Agent_key_str(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; VALUE vresult = Qnil; arg2 = &temp2; arg3 = &tempn2; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent const *","key_str", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->key_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (*arg2) { vresult = SWIG_Ruby_AppendOutput(vresult, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Agent_key_id(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent const *","key_id", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->key_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Agent_query_str(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; char **arg2 = (char **) 0 ; std::size_t *arg3 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; char *temp2 = 0 ; std::size_t tempn2 ; VALUE vresult = Qnil; arg2 = &temp2; arg3 = &tempn2; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent const *","query_str", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { ((marisa_swig::Agent const *)arg1)->query_str((char const **)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (*arg2) { vresult = SWIG_Ruby_AppendOutput(vresult, SWIG_FromCharPtrAndSize(*arg2,*arg3)); ; } return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Agent_query_id(int argc, VALUE *argv, VALUE self) { marisa_swig::Agent *arg1 = (marisa_swig::Agent *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Agent, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Agent const *","query_id", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Agent * >(argp1); { try { result = ((marisa_swig::Agent const *)arg1)->query_id(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } static swig_class SwigClassTrie; SWIGINTERN VALUE #ifdef HAVE_RB_DEFINE_ALLOC_FUNC _wrap_Trie_allocate(VALUE self) #else _wrap_Trie_allocate(int argc, VALUE *argv, VALUE self) #endif { VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE_p_marisa_swig__Trie); #ifndef HAVE_RB_DEFINE_ALLOC_FUNC rb_obj_call_init(vresult, argc, argv); #endif return vresult; } SWIGINTERN VALUE _wrap_new_Trie(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *result = 0 ; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } { try { result = (marisa_swig::Trie *)new marisa_swig::Trie(); DATA_PTR(self) = result; } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return self; fail: return Qnil; } SWIGINTERN void free_marisa_swig_Trie(void *self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *)self; delete arg1; } SWIGINTERN VALUE _wrap_Trie_build__SWIG_0(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int val3 ; int ecode3 = 0 ; if ((argc < 2) || (argc > 2)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie *","build", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "marisa_swig::Keyset &","build", 2, argv[0] )); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "marisa_swig::Keyset &","build", 2, argv[0])); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); ecode3 = SWIG_AsVal_int(argv[1], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "int","build", 3, argv[1] )); } arg3 = static_cast< int >(val3); { try { (arg1)->build(*arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_build__SWIG_1(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Keyset *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie *","build", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_marisa_swig__Keyset, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "marisa_swig::Keyset &","build", 2, argv[0] )); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "marisa_swig::Keyset &","build", 2, argv[0])); } arg2 = reinterpret_cast< marisa_swig::Keyset * >(argp2); { try { (arg1)->build(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_build(int nargs, VALUE *args, VALUE self) { int argc; VALUE argv[4]; int ii; argc = nargs + 1; argv[0] = self; if (argc > 4) SWIG_fail; for (ii = 1; (ii < argc); ++ii) { argv[ii] = args[ii-1]; } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_build__SWIG_1(nargs, args, self); } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Keyset, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_int(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_build__SWIG_0(nargs, args, self); } } } } fail: Ruby_Format_OverloadedError( argc, 4, "Trie.build", " void Trie.build(marisa_swig::Keyset &keyset, int config_flags)\n" " void Trie.build(marisa_swig::Keyset &keyset)\n"); return Qnil; } SWIGINTERN VALUE _wrap_Trie_mmap__SWIG_0(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; int arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; int val3 ; int ecode3 = 0 ; if ((argc < 2) || (argc > 2)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie *","mmap", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","mmap", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); ecode3 = SWIG_AsVal_int(argv[1], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "int","mmap", 3, argv[1] )); } arg3 = static_cast< int >(val3); { try { (arg1)->mmap((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Trie_mmap__SWIG_1(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie *","mmap", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","mmap", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->mmap((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Trie_mmap(int nargs, VALUE *args, VALUE self) { int argc; VALUE argv[4]; int ii; argc = nargs + 1; argv[0] = self; if (argc > 4) SWIG_fail; for (ii = 1; (ii < argc); ++ii) { argv[ii] = args[ii-1]; } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_mmap__SWIG_1(nargs, args, self); } } } if (argc == 3) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_int(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_mmap__SWIG_0(nargs, args, self); } } } } fail: Ruby_Format_OverloadedError( argc, 4, "Trie.mmap", " void Trie.mmap(char const *filename, int flags)\n" " void Trie.mmap(char const *filename)\n"); return Qnil; } SWIGINTERN VALUE _wrap_Trie_load(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie *","load", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","load", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); { try { (arg1)->load((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Trie_save(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","save", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","save", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); { try { ((marisa_swig::Trie const *)arg1)->save((char const *)arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Trie_lookup__SWIG_0(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; bool result; VALUE vresult = Qnil; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","lookup", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "marisa_swig::Agent &","lookup", 2, argv[0] )); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "marisa_swig::Agent &","lookup", 2, argv[0])); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_bool(static_cast< bool >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_reverse_lookup__SWIG_0(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","reverse_lookup", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "marisa_swig::Agent &","reverse_lookup", 2, argv[0] )); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "marisa_swig::Agent &","reverse_lookup", 2, argv[0])); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_common_prefix_search(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; bool result; VALUE vresult = Qnil; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","common_prefix_search", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "marisa_swig::Agent &","common_prefix_search", 2, argv[0] )); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "marisa_swig::Agent &","common_prefix_search", 2, argv[0])); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->common_prefix_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_bool(static_cast< bool >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_predictive_search(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; marisa_swig::Agent *arg2 = 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; bool result; VALUE vresult = Qnil; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","predictive_search", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_marisa_swig__Agent, 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "marisa_swig::Agent &","predictive_search", 2, argv[0] )); } if (!argp2) { SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "marisa_swig::Agent &","predictive_search", 2, argv[0])); } arg2 = reinterpret_cast< marisa_swig::Agent * >(argp2); { try { result = (bool)((marisa_swig::Trie const *)arg1)->predictive_search(*arg2); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_bool(static_cast< bool >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_lookup__SWIG_1(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; char *arg2 = (char *) 0 ; std::size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; size_t size2 = 0 ; int alloc2 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","lookup", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); res2 = SWIG_AsCharPtrAndSize(argv[0], &buf2, &size2, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","lookup", 2, argv[0] )); } arg2 = reinterpret_cast< char * >(buf2); arg3 = static_cast< std::size_t >(size2 - 1); { try { result = ((marisa_swig::Trie const *)arg1)->lookup((char const *)arg2,arg3); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return vresult; fail: if (alloc2 == SWIG_NEWOBJ) delete[] buf2; return Qnil; } SWIGINTERN VALUE _wrap_Trie_lookup(int nargs, VALUE *args, VALUE self) { int argc; VALUE argv[3]; int ii; argc = nargs + 1; argv[0] = self; if (argc > 3) SWIG_fail; for (ii = 1; (ii < argc); ++ii) { argv[ii] = args[ii-1]; } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_lookup__SWIG_0(nargs, args, self); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); _v = SWIG_CheckState(res); if (_v) { if (argc <= 2) { return _wrap_Trie_lookup__SWIG_1(nargs, args, self); } { int res = SWIG_AsVal_size_t(argv[2], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_lookup__SWIG_1(nargs, args, self); } } } } fail: Ruby_Format_OverloadedError( argc, 3, "Trie.lookup", " bool Trie.lookup(marisa_swig::Agent &agent)\n" " std::size_t Trie.lookup(char const *ptr, std::size_t length)\n"); return Qnil; } SWIGINTERN VALUE _wrap_Trie_reverse_lookup__SWIG_1(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; std::size_t arg2 ; char **arg3 = (char **) 0 ; std::size_t *arg4 = (std::size_t *) 0 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; char *temp3 = 0 ; std::size_t tempn3 ; VALUE vresult = Qnil; arg3 = &temp3; arg4 = &tempn3; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","reverse_lookup", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); ecode2 = SWIG_AsVal_size_t(argv[0], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "std::size_t","reverse_lookup", 2, argv[0] )); } arg2 = static_cast< std::size_t >(val2); { try { ((marisa_swig::Trie const *)arg1)->reverse_lookup(arg2,(char const **)arg3,arg4); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } if (*arg3) { vresult = SWIG_Ruby_AppendOutput(vresult, SWIG_FromCharPtrAndSize(*arg3,*arg4)); delete [] (*arg3); } return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_reverse_lookup(int nargs, VALUE *args, VALUE self) { int argc; VALUE argv[3]; int ii; argc = nargs + 1; argv[0] = self; if (argc > 3) SWIG_fail; for (ii = 1; (ii < argc); ++ii) { argv[ii] = args[ii-1]; } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { void *vptr = 0; int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_marisa_swig__Agent, SWIG_POINTER_NO_NULL); _v = SWIG_CheckState(res); if (_v) { return _wrap_Trie_reverse_lookup__SWIG_0(nargs, args, self); } } } if (argc == 2) { int _v = 0; void *vptr = 0; int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_marisa_swig__Trie, 0); _v = SWIG_CheckState(res); if (_v) { { int res = SWIG_AsVal_size_t(argv[1], NULL); _v = SWIG_CheckState(res); } if (_v) { return _wrap_Trie_reverse_lookup__SWIG_1(nargs, args, self); } } } fail: Ruby_Format_OverloadedError( argc, 3, "Trie.reverse_lookup", " void Trie.reverse_lookup(marisa_swig::Agent &agent)\n" " void Trie.reverse_lookup(std::size_t id, char const **ptr_out_to_be_deleted, std::size_t *length_out)\n"); return Qnil; } SWIGINTERN VALUE _wrap_Trie_num_tries(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","num_tries", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_tries(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_num_keys(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","num_keys", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_keys(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_num_nodes(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","num_nodes", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->num_nodes(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_tail_mode(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; marisa_swig::TailMode result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","tail_mode", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::TailMode)((marisa_swig::Trie const *)arg1)->tail_mode(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_int(static_cast< int >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_node_order(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; marisa_swig::NodeOrder result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","node_order", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (marisa_swig::NodeOrder)((marisa_swig::Trie const *)arg1)->node_order(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_int(static_cast< int >(result)); return vresult; fail: return Qnil; } /* Document-method: Marisa::Trie.empty call-seq: empty -> bool Check if Trie is empty. */ SWIGINTERN VALUE _wrap_Trie_empty(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; bool result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","empty", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = (bool)((marisa_swig::Trie const *)arg1)->empty(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_bool(static_cast< bool >(result)); return vresult; fail: return Qnil; } /* Document-method: Marisa::Trie.size call-seq: size -> std::size_t Size or Length of the Trie. */ SWIGINTERN VALUE _wrap_Trie_size(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","size", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_total_size(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","total_size", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->total_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_io_size(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; std::size_t result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie const *","io_size", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { result = ((marisa_swig::Trie const *)arg1)->io_size(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } vresult = SWIG_From_size_t(static_cast< size_t >(result)); return vresult; fail: return Qnil; } SWIGINTERN VALUE _wrap_Trie_clear(int argc, VALUE *argv, VALUE self) { marisa_swig::Trie *arg1 = (marisa_swig::Trie *) 0 ; void *argp1 = 0 ; int res1 = 0 ; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_marisa_swig__Trie, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "marisa_swig::Trie *","clear", 1, self )); } arg1 = reinterpret_cast< marisa_swig::Trie * >(argp1); { try { (arg1)->clear(); } catch (const marisa::Exception &ex) { SWIG_exception(SWIG_RuntimeError, ex.what()); } catch (...) { SWIG_exception(SWIG_UnknownError,"Unknown exception"); } } return Qnil; fail: return Qnil; } /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa__Key = {"_p_marisa__Key", "marisa::Key *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Agent = {"_p_marisa_swig__Agent", "marisa_swig::Agent *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Key = {"_p_marisa_swig__Key", "marisa_swig::Key *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Keyset = {"_p_marisa_swig__Keyset", "marisa_swig::Keyset *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Query = {"_p_marisa_swig__Query", "marisa_swig::Query *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_marisa_swig__Trie = {"_p_marisa_swig__Trie", "marisa_swig::Trie *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_std__size_t = {"_p_std__size_t", "std::size_t *", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { &_swigt__p_char, &_swigt__p_marisa__Key, &_swigt__p_marisa_swig__Agent, &_swigt__p_marisa_swig__Key, &_swigt__p_marisa_swig__Keyset, &_swigt__p_marisa_swig__Query, &_swigt__p_marisa_swig__Trie, &_swigt__p_p_char, &_swigt__p_std__size_t, }; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa__Key[] = { {&_swigt__p_marisa__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Agent[] = { {&_swigt__p_marisa_swig__Agent, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Key[] = { {&_swigt__p_marisa_swig__Key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Keyset[] = { {&_swigt__p_marisa_swig__Keyset, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Query[] = { {&_swigt__p_marisa_swig__Query, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_marisa_swig__Trie[] = { {&_swigt__p_marisa_swig__Trie, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_std__size_t[] = { {&_swigt__p_std__size_t, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { _swigc__p_char, _swigc__p_marisa__Key, _swigc__p_marisa_swig__Agent, _swigc__p_marisa_swig__Key, _swigc__p_marisa_swig__Keyset, _swigc__p_marisa_swig__Query, _swigc__p_marisa_swig__Trie, _swigc__p_p_char, _swigc__p_std__size_t, }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ /* ----------------------------------------------------------------------------- * Type initialization: * This problem is tough by the requirement that no dynamic * memory is used. Also, since swig_type_info structures store pointers to * swig_cast_info structures and swig_cast_info structures store pointers back * to swig_type_info structures, we need some lookup code at initialization. * The idea is that swig generates all the structures that are needed. * The runtime then collects these partially filled structures. * The SWIG_InitializeModule function takes these initial arrays out of * swig_module, and does all the lookup, filling in the swig_module.types * array with the correct data and linking the correct swig_cast_info * structures together. * * The generated swig_type_info structures are assigned statically to an initial * array. We just loop through that array, and handle each type individually. * First we lookup if this type has been already loaded, and if so, use the * loaded structure instead of the generated one. Then we have to fill in the * cast linked list. The cast data is initially stored in something like a * two-dimensional array. Each row corresponds to a type (there are the same * number of rows as there are in the swig_type_initial array). Each entry in * a column is one of the swig_cast_info structures for that type. * The cast_initial array is actually an array of arrays, because each row has * a variable number of columns. So to actually build the cast linked list, * we find the array of casts associated with the type, and loop through it * adding the casts to the list. The one last trick we need to do is making * sure the type pointer in the swig_cast_info struct is correct. * * First off, we lookup the cast->type name to see if it is already loaded. * There are three cases to handle: * 1) If the cast->type has already been loaded AND the type we are adding * casting info to has not been loaded (it is in this module), THEN we * replace the cast->type pointer with the type pointer that has already * been loaded. * 2) If BOTH types (the one we are adding casting info to, and the * cast->type) are loaded, THEN the cast info has already been loaded by * the previous module so we just ignore it. * 3) Finally, if cast->type has not already been loaded, then we add that * swig_cast_info to the linked list (because the cast->type) pointer will * be correct. * ----------------------------------------------------------------------------- */ #ifdef __cplusplus extern "C" { #if 0 } /* c-mode */ #endif #endif #if 0 #define SWIGRUNTIME_DEBUG #endif #ifndef SWIG_INIT_CLIENT_DATA_TYPE #define SWIG_INIT_CLIENT_DATA_TYPE void * #endif SWIGRUNTIME void SWIG_InitializeModule(SWIG_INIT_CLIENT_DATA_TYPE clientdata) { size_t i; swig_module_info *module_head, *iter; int init; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { /* Initialize the swig_module */ swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; init = 1; } else { init = 0; } /* Try and load any already created modules */ module_head = SWIG_GetModule(clientdata); if (!module_head) { /* This is the first module loaded for this interpreter */ /* so set the swig module into the interpreter */ SWIG_SetModule(clientdata, &swig_module); } else { /* the interpreter has loaded a SWIG module, but has it loaded this one? */ iter=module_head; do { if (iter==&swig_module) { /* Our module is already in the list, so there's nothing more to do. */ return; } iter=iter->next; } while (iter!= module_head); /* otherwise we must add our module into the list */ swig_module.next = module_head->next; module_head->next = &swig_module; } /* When multiple interpreters are used, a module could have already been initialized in a different interpreter, but not yet have a pointer in this interpreter. In this case, we do not want to continue adding types... everything should be set up already */ if (init == 0) return; /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); #endif for (i = 0; i < swig_module.size; ++i) { swig_type_info *type = 0; swig_type_info *ret; swig_cast_info *cast; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); #endif /* if there is another module already loaded */ if (swig_module.next != &swig_module) { type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); } if (type) { /* Overwrite clientdata field */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found type %s\n", type->name); #endif if (swig_module.type_initial[i]->clientdata) { type->clientdata = swig_module.type_initial[i]->clientdata; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); #endif } } else { type = swig_module.type_initial[i]; } /* Insert casting types */ cast = swig_module.cast_initial[i]; while (cast->type) { /* Don't need to add information already in the list */ ret = 0; #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); #endif if (swig_module.next != &swig_module) { ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); #ifdef SWIGRUNTIME_DEBUG if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); #endif } if (ret) { if (type == swig_module.type_initial[i]) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: skip old type %s\n", ret->name); #endif cast->type = ret; ret = 0; } else { /* Check for casting already in the list */ swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); #ifdef SWIGRUNTIME_DEBUG if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); #endif if (!ocast) ret = 0; } } if (!ret) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); #endif if (type->cast) { type->cast->prev = cast; cast->next = type->cast; } type->cast = cast; } cast++; } /* Set entry in modules->types array equal to the type */ swig_module.types[i] = type; } swig_module.types[i] = 0; #ifdef SWIGRUNTIME_DEBUG printf("**** SWIG_InitializeModule: Cast List ******\n"); for (i = 0; i < swig_module.size; ++i) { int j = 0; swig_cast_info *cast = swig_module.cast_initial[i]; printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); while (cast->type) { printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); cast++; ++j; } printf("---- Total casts: %d\n",j); } printf("**** SWIG_InitializeModule: Cast List ******\n"); #endif } /* This function will propagate the clientdata field of type to * any new swig_type_info structures that have been added into the list * of equivalent types. It is like calling * SWIG_TypeClientData(type, clientdata) a second time. */ SWIGRUNTIME void SWIG_PropagateClientData(void) { size_t i; swig_cast_info *equiv; static int init_run = 0; if (init_run) return; init_run = 1; for (i = 0; i < swig_module.size; i++) { if (swig_module.types[i]->clientdata) { equiv = swig_module.types[i]->cast; while (equiv) { if (!equiv->converter) { if (equiv->type && !equiv->type->clientdata) SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); } equiv = equiv->next; } } } } #ifdef __cplusplus #if 0 { /* c-mode */ #endif } #endif /* */ #ifdef __cplusplus extern "C" #endif SWIGEXPORT void Init_marisa(void) { size_t i; SWIG_InitRuntime(); mMarisa = rb_define_module("Marisa"); SWIG_InitializeModule(0); for (i = 0; i < swig_module.size; i++) { SWIG_define_class(swig_module.types[i]); } SWIG_RubyInitializeTrackings(); rb_define_const(mMarisa, "OK", SWIG_From_int(static_cast< int >(marisa_swig::OK))); rb_define_const(mMarisa, "STATE_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::STATE_ERROR))); rb_define_const(mMarisa, "NULL_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::NULL_ERROR))); rb_define_const(mMarisa, "BOUND_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::BOUND_ERROR))); rb_define_const(mMarisa, "RANGE_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::RANGE_ERROR))); rb_define_const(mMarisa, "CODE_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::CODE_ERROR))); rb_define_const(mMarisa, "RESET_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::RESET_ERROR))); rb_define_const(mMarisa, "SIZE_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::SIZE_ERROR))); rb_define_const(mMarisa, "MEMORY_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::MEMORY_ERROR))); rb_define_const(mMarisa, "IO_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::IO_ERROR))); rb_define_const(mMarisa, "FORMAT_ERROR", SWIG_From_int(static_cast< int >(marisa_swig::FORMAT_ERROR))); rb_define_const(mMarisa, "MAP_POPULATE", SWIG_From_int(static_cast< int >(marisa_swig::MAP_POPULATE))); rb_define_const(mMarisa, "MIN_NUM_TRIES", SWIG_From_int(static_cast< int >(marisa_swig::MIN_NUM_TRIES))); rb_define_const(mMarisa, "MAX_NUM_TRIES", SWIG_From_int(static_cast< int >(marisa_swig::MAX_NUM_TRIES))); rb_define_const(mMarisa, "DEFAULT_NUM_TRIES", SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_NUM_TRIES))); rb_define_const(mMarisa, "HUGE_CACHE", SWIG_From_int(static_cast< int >(marisa_swig::HUGE_CACHE))); rb_define_const(mMarisa, "LARGE_CACHE", SWIG_From_int(static_cast< int >(marisa_swig::LARGE_CACHE))); rb_define_const(mMarisa, "NORMAL_CACHE", SWIG_From_int(static_cast< int >(marisa_swig::NORMAL_CACHE))); rb_define_const(mMarisa, "SMALL_CACHE", SWIG_From_int(static_cast< int >(marisa_swig::SMALL_CACHE))); rb_define_const(mMarisa, "TINY_CACHE", SWIG_From_int(static_cast< int >(marisa_swig::TINY_CACHE))); rb_define_const(mMarisa, "DEFAULT_CACHE", SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_CACHE))); rb_define_const(mMarisa, "TEXT_TAIL", SWIG_From_int(static_cast< int >(marisa_swig::TEXT_TAIL))); rb_define_const(mMarisa, "BINARY_TAIL", SWIG_From_int(static_cast< int >(marisa_swig::BINARY_TAIL))); rb_define_const(mMarisa, "DEFAULT_TAIL", SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_TAIL))); rb_define_const(mMarisa, "LABEL_ORDER", SWIG_From_int(static_cast< int >(marisa_swig::LABEL_ORDER))); rb_define_const(mMarisa, "WEIGHT_ORDER", SWIG_From_int(static_cast< int >(marisa_swig::WEIGHT_ORDER))); rb_define_const(mMarisa, "DEFAULT_ORDER", SWIG_From_int(static_cast< int >(marisa_swig::DEFAULT_ORDER))); SwigClassKey.klass = rb_define_class_under(mMarisa, "Key", rb_cObject); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Key, (void *) &SwigClassKey); rb_undef_alloc_func(SwigClassKey.klass); rb_define_method(SwigClassKey.klass, "str", VALUEFUNC(_wrap_Key_str), -1); rb_define_method(SwigClassKey.klass, "id", VALUEFUNC(_wrap_Key_id), -1); rb_define_method(SwigClassKey.klass, "weight", VALUEFUNC(_wrap_Key_weight), -1); SwigClassKey.mark = 0; SwigClassKey.destroy = (void (*)(void *)) free_marisa_swig_Key; SwigClassKey.trackObjects = 0; SwigClassQuery.klass = rb_define_class_under(mMarisa, "Query", rb_cObject); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Query, (void *) &SwigClassQuery); rb_undef_alloc_func(SwigClassQuery.klass); rb_define_method(SwigClassQuery.klass, "str", VALUEFUNC(_wrap_Query_str), -1); rb_define_method(SwigClassQuery.klass, "id", VALUEFUNC(_wrap_Query_id), -1); SwigClassQuery.mark = 0; SwigClassQuery.destroy = (void (*)(void *)) free_marisa_swig_Query; SwigClassQuery.trackObjects = 0; SwigClassKeyset.klass = rb_define_class_under(mMarisa, "Keyset", rb_cObject); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Keyset, (void *) &SwigClassKeyset); rb_define_alloc_func(SwigClassKeyset.klass, _wrap_Keyset_allocate); rb_define_method(SwigClassKeyset.klass, "initialize", VALUEFUNC(_wrap_new_Keyset), -1); rb_define_method(SwigClassKeyset.klass, "push_back", VALUEFUNC(_wrap_Keyset_push_back), -1); rb_define_method(SwigClassKeyset.klass, "key", VALUEFUNC(_wrap_Keyset_key), -1); rb_define_method(SwigClassKeyset.klass, "key_str", VALUEFUNC(_wrap_Keyset_key_str), -1); rb_define_method(SwigClassKeyset.klass, "key_id", VALUEFUNC(_wrap_Keyset_key_id), -1); rb_define_method(SwigClassKeyset.klass, "num_keys", VALUEFUNC(_wrap_Keyset_num_keys), -1); rb_define_method(SwigClassKeyset.klass, "empty", VALUEFUNC(_wrap_Keyset_empty), -1); rb_define_method(SwigClassKeyset.klass, "size", VALUEFUNC(_wrap_Keyset_size), -1); rb_define_method(SwigClassKeyset.klass, "total_length", VALUEFUNC(_wrap_Keyset_total_length), -1); rb_define_method(SwigClassKeyset.klass, "reset", VALUEFUNC(_wrap_Keyset_reset), -1); rb_define_method(SwigClassKeyset.klass, "clear", VALUEFUNC(_wrap_Keyset_clear), -1); SwigClassKeyset.mark = 0; SwigClassKeyset.destroy = (void (*)(void *)) free_marisa_swig_Keyset; SwigClassKeyset.trackObjects = 0; SwigClassAgent.klass = rb_define_class_under(mMarisa, "Agent", rb_cObject); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Agent, (void *) &SwigClassAgent); rb_define_alloc_func(SwigClassAgent.klass, _wrap_Agent_allocate); rb_define_method(SwigClassAgent.klass, "initialize", VALUEFUNC(_wrap_new_Agent), -1); rb_define_method(SwigClassAgent.klass, "set_query", VALUEFUNC(_wrap_Agent_set_query), -1); rb_define_method(SwigClassAgent.klass, "key", VALUEFUNC(_wrap_Agent_key), -1); rb_define_method(SwigClassAgent.klass, "query", VALUEFUNC(_wrap_Agent_query), -1); rb_define_method(SwigClassAgent.klass, "key_str", VALUEFUNC(_wrap_Agent_key_str), -1); rb_define_method(SwigClassAgent.klass, "key_id", VALUEFUNC(_wrap_Agent_key_id), -1); rb_define_method(SwigClassAgent.klass, "query_str", VALUEFUNC(_wrap_Agent_query_str), -1); rb_define_method(SwigClassAgent.klass, "query_id", VALUEFUNC(_wrap_Agent_query_id), -1); SwigClassAgent.mark = 0; SwigClassAgent.destroy = (void (*)(void *)) free_marisa_swig_Agent; SwigClassAgent.trackObjects = 0; SwigClassTrie.klass = rb_define_class_under(mMarisa, "Trie", rb_cObject); SWIG_TypeClientData(SWIGTYPE_p_marisa_swig__Trie, (void *) &SwigClassTrie); rb_define_alloc_func(SwigClassTrie.klass, _wrap_Trie_allocate); rb_define_method(SwigClassTrie.klass, "initialize", VALUEFUNC(_wrap_new_Trie), -1); rb_define_method(SwigClassTrie.klass, "build", VALUEFUNC(_wrap_Trie_build), -1); rb_define_method(SwigClassTrie.klass, "mmap", VALUEFUNC(_wrap_Trie_mmap), -1); rb_define_method(SwigClassTrie.klass, "load", VALUEFUNC(_wrap_Trie_load), -1); rb_define_method(SwigClassTrie.klass, "save", VALUEFUNC(_wrap_Trie_save), -1); rb_define_method(SwigClassTrie.klass, "common_prefix_search", VALUEFUNC(_wrap_Trie_common_prefix_search), -1); rb_define_method(SwigClassTrie.klass, "predictive_search", VALUEFUNC(_wrap_Trie_predictive_search), -1); rb_define_method(SwigClassTrie.klass, "lookup", VALUEFUNC(_wrap_Trie_lookup), -1); rb_define_method(SwigClassTrie.klass, "reverse_lookup", VALUEFUNC(_wrap_Trie_reverse_lookup), -1); rb_define_method(SwigClassTrie.klass, "num_tries", VALUEFUNC(_wrap_Trie_num_tries), -1); rb_define_method(SwigClassTrie.klass, "num_keys", VALUEFUNC(_wrap_Trie_num_keys), -1); rb_define_method(SwigClassTrie.klass, "num_nodes", VALUEFUNC(_wrap_Trie_num_nodes), -1); rb_define_method(SwigClassTrie.klass, "tail_mode", VALUEFUNC(_wrap_Trie_tail_mode), -1); rb_define_method(SwigClassTrie.klass, "node_order", VALUEFUNC(_wrap_Trie_node_order), -1); rb_define_method(SwigClassTrie.klass, "empty", VALUEFUNC(_wrap_Trie_empty), -1); rb_define_method(SwigClassTrie.klass, "size", VALUEFUNC(_wrap_Trie_size), -1); rb_define_method(SwigClassTrie.klass, "total_size", VALUEFUNC(_wrap_Trie_total_size), -1); rb_define_method(SwigClassTrie.klass, "io_size", VALUEFUNC(_wrap_Trie_io_size), -1); rb_define_method(SwigClassTrie.klass, "clear", VALUEFUNC(_wrap_Trie_clear), -1); SwigClassTrie.mark = 0; SwigClassTrie.destroy = (void (*)(void *)) free_marisa_swig_Trie; SwigClassTrie.trackObjects = 0; rb_define_const(mMarisa, "INVALID_KEY_ID", SWIG_From_size_t(static_cast< size_t >(MARISA_INVALID_KEY_ID))); } marisa-trie-master/bindings/ruby/sample.rb000066400000000000000000000027761505027263100211650ustar00rootroot00000000000000require "marisa" keyset = Marisa::Keyset.new keyset.push_back("cake") keyset.push_back("cookie") keyset.push_back("ice") keyset.push_back("ice-cream") trie = Marisa::Trie.new trie.build(keyset) print("no. keys: ", trie.num_keys(), "\n") print("no. tries: ", trie.num_tries(), "\n") print("no. nodes: ", trie.num_nodes(), "\n") print("size: ", trie.io_size(), "\n") agent = Marisa::Agent.new agent.set_query("cake") trie.lookup(agent) print(agent.query_str(), ": ", agent.key_id(), "\n") agent.set_query("cookie") trie.lookup(agent) print(agent.query_str(), ": ", agent.key_id(), "\n") agent.set_query("cockoo") if not trie.lookup(agent) print(agent.query_str(), ": not found\n") end print("ice: ", trie.lookup("ice"), "\n") print("ice-cream: ", trie.lookup("ice-cream"), "\n") if trie.lookup("ice-age") == Marisa::INVALID_KEY_ID print("ice-age: not found\n") end trie.save("sample.dic") trie.load("sample.dic") agent.set_query(0) trie.reverse_lookup(agent) print(agent.query_id(), ": ", agent.key_str(), "\n") agent.set_query(1) trie.reverse_lookup(agent) print(agent.query_id(), ": ", agent.key_str(), "\n") print("2: ", trie.reverse_lookup(2), "\n") print("3: ", trie.reverse_lookup(3), "\n") trie.mmap("sample.dic") agent.set_query("ice-cream soda") while trie.common_prefix_search(agent) print(agent.query_str(), ": ", agent.key_str(), " (", agent.key_id(), ")\n") end agent.set_query("ic") while trie.predictive_search(agent) print(agent.query_str(), ": ", agent.key_str(), " (", agent.key_id(), ")\n") end marisa-trie-master/cmake/000077500000000000000000000000001505027263100156455ustar00rootroot00000000000000marisa-trie-master/cmake/finders/000077500000000000000000000000001505027263100172775ustar00rootroot00000000000000marisa-trie-master/cmake/finders/FindGperftools.cmake000066400000000000000000000031251505027263100232270ustar00rootroot00000000000000# Based on https://github.com/baidu/braft/blob/e7776cd03ccc04f18d0f0911200617a89ac3cdf0/cmake/FindGperftools.cmake # Tries to find Gperftools. # # Usage of this module as follows: # # find_package(Gperftools) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # Gperftools_ROOT_DIR Set this variable to the root installation of # Gperftools if the module has problems finding # the proper installation path. # # Variables defined by this module: # # GPERFTOOLS_FOUND System has Gperftools libs/headers # GPERFTOOLS_LIBRARIES The Gperftools libraries (tcmalloc & profiler) # GPERFTOOLS_INCLUDE_DIR The location of Gperftools headers find_library(GPERFTOOLS_TCMALLOC NAMES tcmalloc HINTS ${Gperftools_ROOT_DIR}/lib) find_library(GPERFTOOLS_PROFILER NAMES profiler HINTS ${Gperftools_ROOT_DIR}/lib) find_library(GPERFTOOLS_TCMALLOC_AND_PROFILER NAMES tcmalloc_and_profiler HINTS ${Gperftools_ROOT_DIR}/lib) find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h HINTS ${Gperftools_ROOT_DIR}/include) set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_TCMALLOC_AND_PROFILER}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args( Gperftools DEFAULT_MSG GPERFTOOLS_LIBRARIES GPERFTOOLS_INCLUDE_DIR) mark_as_advanced( Gperftools_ROOT_DIR GPERFTOOLS_TCMALLOC GPERFTOOLS_PROFILER GPERFTOOLS_TCMALLOC_AND_PROFILER GPERFTOOLS_LIBRARIES GPERFTOOLS_INCLUDE_DIR) marisa-trie-master/docs/000077500000000000000000000000001505027263100155155ustar00rootroot00000000000000marisa-trie-master/docs/readme.en.html000066400000000000000000001136031505027263100202450ustar00rootroot00000000000000 MARISA: Matching Algorithm with Recursively Implemented StorAge

MARISA: Matching Algorithm with Recursively Implemented StorAge

Abstract: Matching Algorithm with Recursively Implemented StorAge (MARISA) is a space-efficient trie data structure. libmarisa is a C++ library for an implementation of MARISA. Users can build dictionaries and search keys from the dictionaries. The package also provides command line tools to test basic operations of libmarisa, and the tools are useful to test the performance.

Introduction

Overview

Matching Algorithm with Recursively Implemented StorAge (MARISA) is a space-efficient, fairly fast, and static trie data structure. MARISA serves as a dictionary structure, and by definition, it supports exact match lookup, which is the basic operation of dictionary. In addition, MARISA supports reverse lookup, common prefix search, and predictive search.

In most cases, MARISA is much more compact than a plain text which consists of the registered keys. This means that the traditional dictionary implementations, a binary tree (std::map<std::string, T>) and a hash table (std::unordered_map<std::string, T>), require more and more and more spaces than MARISA. Bloom Filter, a probabilistic data structure, is more space-efficient than MARISA but causes false positives and does not support reverse lookup, common prefix search, and predictive search.

libmarisa is a C++ library for an implementation of MARISA. Users can build dictionaries and search keys from the dictionaries. The package also provides command line tools to test basic operations of libmarisa, and the tools are useful to test the performance.

Functionality

libmarisa associates string keys with unique IDs, from 0 to (n - 1), where n is the number of keys. Note that users cannot specify the IDs because the mapping is automatically generated by MARISA. Every search function takes a string or an ID and returns the search result which is represented by a pair of the key and its ID.

  • Lookup
    • checks whether or not a query string is registered.
  • Reverse lookup
    • restores a key from its ID.
  • Common prefix search
    • searches keys from the possible prefixes of a query string.
  • Predictive search
    • searches keys starting with a query string.

Source

License

libmarisa and its command line tools are licensed under BSD-2-Clause OR LGPL-2.1-or-later.

Installation

GCC & Clang

$ tar zxf marisa-trie-0.3.1.tar.gz
$ cd marisa-trie-0.3.1
$ cmake -S. -Bbuild-rel -DCMAKE_BUILD_TYPE=Release
$ cmake --build build-rel
$ cmake --install build-rel

You can build and install libmarisa by using cmake. If you want to install files into directories other than the default, specify -DCMAKE_INSTALL_PREFIX to the first cmake. cmake --install may require sudo to install libmarisa as the root user. With the default settings, libmarisa is installed as a static library.

$ cmake --install build-rel --component Library

If you want to install just the library without the binaries, specify --component Library to cmake --install.

$ cmake --install build-rel --component Binaries

If you want to install just the binaries, specify --component Binaries to cmake --install.

$ cmake -S. -Bbuild-rel -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON

If you want to build and install a shared library, specify -DBUILD_SHARED_LIBS=ON to the first cmake. The remaining steps are the same. Try cmake --build and cmake --install.

$ cmake -S. -Bbuild-rel -DCMAKE_BUILD_TYPE=Release -DENABLE_NATIVE_CODE=ON

You can specify -DENABLE_NATIVE_CODE=ON to the first cmake. This option enables SIMD instructions available on your environment and improves the performance of libmarisa.

Visual Studio 2022

When you open the marisa-trie folder in the source archive via Visual Studio 2022, it detects CMakeLists.txt and creates a project for marisa-trie. The project builds a static library marisa.lib and the command line tools in debug mode by default.

Perl Bindings

$ cd bindings/perl
$ perl Makefile.PL
$ make
$ make install

Users can find a Perl bindings in bindings/perl/, in which the wrapper was generated by SWIG. To install the Perl bindings, run perl Makefile.PL and then make install. See also bindings/perl/sample.pl.

Python Bindings

$ cd bindings/python3
$ python3 setup.py build
$ python3 setup.py install

Users can find a Python bindings in bindings/python3/, in which the wrapper was generated by SWIG. To install the Python bindings, run python3 setup.py install. See also bindings/python/sample.py. bindings/python/ contains old bindngs and it is left for compatibitity.

Ruby Bindings

$ cd bindings/ruby
$ ruby extconf.rb
$ make
$ make install

Users can find a Ruby bindings in bindings/ruby/, in which the wrapper was generated by SWIG. To install the Ruby bindings, run ruby extconf.rb and then make install. See also bindings/ruby/sample.rb.

Others

There are other bindings.

Command Line Tools

marisa-build

$ marisa-build < keyset.txt > keyset.dic
#keys: 9864459
#nodes: 13473881
size: 51044424

marisa-build is a tool to build a dictionary from a set of keys. This tool takes as input newline-delimited keys and writes the dictionary to the standard output.

Users can specify parameters through command line options. See marisa-build -h for the list of options.

If an input line contains horizontal tabs, the last one serves as the delimiter between a key and its weight which is used to optimize the order of nodes. Estimated frequency of each key, given as the weight, may improve the search performance.

marisa-lookup

$ marisa-lookup keyset.dic
Marisa
915465	Marisa
What's_uuup
-1	What's_uuup

marisa-lookup is a tool to test exact match lookup. If a query string is registered, this tool prints the key and its ID. Otherwise, this tool prints the query with -1.

See marisa-lookup -h for the list of options.

marisa-reverse-lookup

$ marisa-reverse-lookup keyset.dic
1234567
1234567	Goma_International_Airport

marisa-reverse-lookup is a tool to test reverse lookup. If a given ID is not out-of-range, this tool restores the associated key and prints it. The available ID is 0 to (n - 1), where n is the number of keys. Note that an out-of-range ID causes an error.

See marisa-reverse-lookup -h for the list of options.

marisa-common-prefix-search

$ marisa-common-prefix-search keyset.dic
USA
3 found
20	U	USA
1526	US	USA
37471	USA	USA

marisa-common-prefix-search is a tool to test common prefix search. This tool searches keys from the possible prefixes of a query string and then prints the first m keys, where m is one of the parameters.

See marisa-common-prefix-search -h for the list of options.

marisa-predictive-search

$ marisa-predictive-search keyset.dic -n 2
Touhou
15 found
975378	Touhou	Touhou
5508004	Touhou_Hisotensoku	Touhou

marisa-predictive-search is a tool to test predictive search. This tool searches keys starting with a query string and then prints the first m keys, where m is one of the parameters.

See marisa-predictive-search -h for the list of options.

marisa-benchmark

$ marisa-benchmark keyset.txt
Number of tries: 1 - 5
TAIL mode: Text mode
Node order: Descending weight order
Cache level: Normal cache
Number of keys: 9864459
Total length: 191858227
------+----------+--------+--------+--------+--------+--------
#tries       size    build   lookup  reverse   prefix  predict
                                      lookup   search   search
          [bytes]    [K/s]    [K/s]    [K/s]    [K/s]    [K/s]
------+----------+--------+--------+--------+--------+--------
     1   69905816   334.84  1368.16  1304.82  1080.44   605.92
     2   53635744   284.03   762.91   773.68   662.04   244.35
     3   51044424   278.89   688.86   703.60   604.44   212.00
     4   50309000   277.01   669.23   680.78   588.57   204.23
     5   50042232   275.93   636.83   674.26   562.08   199.48
------+----------+--------+--------+--------+--------+--------

marisa-benchmark is a tool to benchmark libmarisa. This tool takes the same input as marisa-build and measures the performance of libmarisa for the given set of keys. This tool is useful to fix dictionary settings.

For the search performance, marisa-benchmark measures the time to lookup or search keys in input order. When the keys are given in lexicographic order, few cache misses will occur in the benchmark. In contrast, when the keys are given in random order, many cache misses will occur in the benchmark.

See marisa-benchmark -h for the list of options.

marisa-dump

$ marisa-dump keyset.dic | head -3
input: keyset.dic
S
St
Sta

marisa-build is a tool to dump a dictionary. This tool prints all the keys in a given dictionary.

Users can specify the delimiter through command line options. See marisa-dump -h for the list of options.

Library

How to Use

// sample.cc
#include <iostream>
#include <marisa.h>

int main() {
  marisa::Keyset keyset;
  keyset.push_back("a");
  keyset.push_back("app");
  keyset.push_back("apple");

  marisa::Trie trie;
  trie.build(keyset);

  marisa::Agent agent;
  agent.set_query("apple");
  while (trie.common_prefix_search(agent)) {
    std::cout.write(agent.key().ptr(), agent.key().length());
    std::cout << ": " << agent.key().id() << std::endl;
  }
  return 0;
}
$ g++ sample.cc -lmarisa
$ ./a.out
a: 0
app: 1
apple: 2

libmarisa provides marisa.h in which all the headers are #included. Also, libmarisa uses namespace marisa. All the classes and functions except enumeration types are given as members of this namespace. Note that using namespace marisa may cause a critical error. Finally, gcc and clang require an option, -lmarisa, to link libmarisa with an application.

The core components of libmarisa are Keyset, Agent, and Trie. In addition, libmarisa provides an exception class, Exception, and two more classes, Key and Query, as members of Keyset and Agent.

  • Keyset: A class to store a set of keys. This class is used to build a set of keys for building a dictionary. Also, this class is useful to store search results.
  • Agent: A class to store a query and a result of search operations. Every search function takes a reference to this class.
  • Trie: A dictionary class.

For more examples, you can find the source code of the command line tools in tools/. The source code is useful as an example of error handling, predicive search, etc.

Enumeration Constants

Error Codes

typedef enum marisa_error_code_ {
  MARISA_OK           = 0,
  MARISA_STATE_ERROR  = 1,
  MARISA_NULL_ERROR   = 2,
  MARISA_BOUND_ERROR  = 3,
  MARISA_RANGE_ERROR  = 4,
  MARISA_CODE_ERROR   = 5,
  MARISA_RESET_ERROR  = 6,
  MARISA_SIZE_ERROR   = 7,
  MARISA_MEMORY_ERROR = 8,
  MARISA_IO_ERROR     = 9,
  MARISA_FORMAT_ERROR = 10,
} marisa_error_code;

libmarisa throws an instance of Exception when an error occurs, such as a file I/O error (MARISA_IO_ERROR), a size limitation error (MARISA_SIZE_ERROR), etc. For details, see marisa/base.h.

Flags for memory mapping

typedef enum marisa_map_flags {
  MARISA_MAP_POPULATE = 1 << 0,
} marisa_map_flags;

libmarisa supports memory mapping for dictionaries. MARISA_MAP_POPULATE is a flag to populate (prefault) page tables for a mapping. It takes time when you open a dictionary, but it can reduce page faults later. If you heavily use the dictionary, MARISA_MAP_POPULATE may work well. If you accesses only a few keys, the overhead may be unacceptable.

Number of Tries

typedef enum marisa_num_tries_ {
  MARISA_MIN_NUM_TRIES     = 0x00001,
  MARISA_MAX_NUM_TRIES     = 0x0007F,
  MARISA_DEFAULT_NUM_TRIES = 0x00003,
} marisa_num_tries;

MARISA is a recursive data structure in which a patricia trie is used to represent another patricia trie. A deeper recursion makes a dictionary more compact but degrades the search performance. For this time-space tradeoff, libmarisa provides a parameter to limit the recursion depth, which is equivalent to the number of tries. marisa_num_tries gives the range and the default setting of this parameter.

The best setting depends on the set of keys and the applications. In most cases, libmarisa works well with the default setting, MARISA_DEFAULT_NUM_TRIES, but if the application requires better search performance, MARISA_MIN_NUM_TRIES may be a better choice. Also, if the application uses long and complicated keys, a deeper recursion may achieve much higher spece-efficiency. marisa-benchmark is useful to find the best setting.

Cache Size

typedef enum marisa_cache_level_ {
  MARISA_HUGE_CACHE    = 0x00080,
  MARISA_LARGE_CACHE   = 0x00100,
  MARISA_NORMAL_CACHE  = 0x00200,
  MARISA_SMALL_CACHE   = 0x00400,
  MARISA_TINY_CACHE    = 0x00800,
  MARISA_DEFAULT_CACHE = MARISA_NORMAL_CACHE
} marisa_cache_level;

libmarisa embeds a precomputed table to a dictionary. The table serves as transition cache which improves the search performance but increases the dictionary size. Cache size is the parameter of this time-space tradeoff.

marisa_cache_level gives a list of available cache size. Compared with MARISA_NORMAL_CACHE, MARISA_LARGE_CACHE is 2 times larger, MARISA_HUGE_CACHE is 4 times larger, MARISA_SMALL_CACHE is 2 times smaller, and MARISA_TINY_CACHE is 4 times smaller.

TAIL Mode

typedef enum marisa_tail_mode_ {
  MARISA_TEXT_TAIL    = 0x01000,
  MARISA_BINARY_TAIL  = 0x02000,
  MARISA_DEFAULT_TAIL = MARISA_TEXT_TAIL,
} marisa_tail_mode;

The last patricia trie of MARISA stores its multi-byte labels as strings and marisa_tail_mode gives a list of TAIL implementations.

MARISA_TEXT_TAIL stores labels as zero-terminated strings. If the labels contain '\0', the TAIL mode is automatically switched to MARISA_BINARY_TAIL.

On the other hand, MARISA_BINARY_TAIL uses a bit vector, instead of '\0', to detect the end of labels. This means that MARISA_TEXT_TAIL is more space-efficient than MARISA_BINARY_TAIL when the average length of multi-byte labels is longer than 8 bytes.

Node Order

typedef enum marisa_node_order_ {
  MARISA_LABEL_ORDER   = 0x10000,
  MARISA_WEIGHT_ORDER  = 0x20000,
  MARISA_DEFAULT_ORDER = MARISA_WEIGHT_ORDER,
} marisa_node_order;

A dictionary has one more parameter, which is the order of nodes. There are two choices, MARISA_LABEL_ORDER and MARISA_WEIGHT_ORDER. The former arranges nodes in ascending order of the label and the latter arranges nodes in descending order of the weight. Many trie implementations arrange nodes in the label order but libmarisa uses MARISA_WEIGHT_ORDER as the default setting.

MARISA_WEIGHT_ORDER optimizes the node order for linear search performed in exact match lookup, common prefix search, and predictive search. In practice, experiments for English words/phrases showed that MARISA_WEIGHT_ORDER halved the average search time. On the other hand, MARISA_LABEL_ORDER enables predictive search to restore keys in lexicographic order.

Aliases

namespace marisa {
  typedef ::marisa_error_code ErrorCode;
  typedef ::marisa_cache_level CacheLevel;
  typedef ::marisa_tail_mode TailMode;
  typedef ::marisa_node_order NodeOrder;
}  // namespace marisa

The above enumeration types are defined in the global namespace to avoid collisions of the enumeration constants with macros provided by other modules. libmarisa provides type aliases and users can choose the familiar one.

class Exception

class Exception {
 public:
  const char *filename() const;
  int line() const;
  ErrorCode error_code() const;
  const char *error_message() const;

  const char *what() const;
};

Exception is an exception class. libmarisa throws an instance of Exception with the file name (__FILE__), the line number (__LINE__), and an error code (ErrorCode) when an error is detected. The instance also has an error message formatted __FILE__:__LINE__: error_code: error_message.

class Key

class Key {
 public:
  char operator[](std::size_t i) const;
  std::string_view str() const;
  const char *ptr() const;
  std::size_t length() const;
  std::size_t id() const;
};

Key is a member of Keyset and Agent. Each key of Keyset is represented by this class. Also, the search result of Agent is represented by this class.

class Query

class Query {
 public:
  char operator[](std::size_t i) const;
  std::string_view str() const;
  const char *ptr() const;
  std::size_t length() const;
  std::size_t id() const;
};

Query is a member of Agent. This class stores a query string and an ID as input for search functions. Users cannot make changes directly to Query because Agent provides a special interface to update its query.

class Keyset

class Keyset {
 public:
  Keyset();

  void push_back(const Key &key);
  void push_back(const Key &key, char end_marker);

  void push_back(std::string_view str,
                 float weight = 1.0);
  void push_back(const char *str);
  void push_back(const char *ptr,
                 std::size_t length,
                 float weight = 1.0);

  const Key &operator[](std::size_t i) const;
  Key &operator[](std::size_t i);

  std::size_t num_keys();

  bool empty() const;
  std::size_t size() const;
  std::size_t total_length() const;

  void reset();

  void clear() noexcept;
  void swap(Keyset &rhs) noexcept;
};

Overview

Keyset is used to store a set of keys for dictionary construction or to save the results of search functions.

Dictionary Source

For dictionary construction, users append keys to Keyset by using push_back() and then pass the keyset to build() of Trie. weight is an argument to receive the frequency or possibility of each key. If there are same keys, the weights are accumulated in dictionary construction.

After dictionary construction, users can read the associated IDs through operator[](). Instead, the weights are overwritten by the IDs because Key uses a union to store a weight or an ID.

Search Result

Users can save a search result to Keyset by using push_back(). When key() of Agent is given, a copy of the search result is stored in Keyset. If you want to append an end marker, such as '\0', use end_marker of push_back().

If you want to reuse an instance of Keyset, reset() may be a better choice than clear() because reset() keeps allocated memory in order to reduce memory allocation overhead.

num_keys() and size() return the number of keys. empty() checks whether the number of keys is 0 or not. total_length() returns the total length in byte.

class Agent

class Agent {
 public:
  Agent();

  const Query &query() const;
  const Key &key() const;

  void set_query(std::string_view str);
  void set_query(const char *str);
  void set_query(const char *ptr,
                 std::size_t length);
  void set_query(std::size_t key_id);
};

Agent is actually a tuple of Query, Key, and State. This class is used as I/O of search functions. Also, State is an incomplete type to keep the internal state of search operation.

A lookup operation requires 3 steps as follows: 1. sets a query string by set_query() of Agent, 2. passes the agent to lookup() of Trie, and 3. gets the search result by key() of Agent. The other operations proceed in the same way.

class Trie

class Trie {
 public:
  Trie();

  void build(Keyset &keyset,
             int config_flags = 0);

  void mmap(const char *filename,
            int flags = 0);
  void map(const void *ptr,
           std::size_t size);

  void load(const char *filename);
  void read(int fd);

  void save(const char *filename) const;
  void write(int fd) const;

  bool lookup(Agent &agent) const;
  void reverse_lookup(Agent &agent) const;
  bool common_prefix_search(Agent &agent) const;
  bool predictive_search(Agent &agent) const;

  std::size_t num_tries() const;
  std::size_t num_keys() const;
  std::size_t num_nodes() const;

  TailMode tail_mode() const;
  NodeOrder node_order() const;

  bool empty() const;
  std::size_t size() const;
  std::size_t io_size() const;

  void clear() noexcept;
  void swap(Trie &rhs) noexcept;
};

Overview

Trie is a dictionary class, which is the most important component of libmarisa. All the operations are performed through this class.

In fact, Trie is a dictionary handle, and if the handle is invalid, functions other than build(), mmap(), map(), load(), read(), clear(), swap() throw an exception.

Construction

You can build a dictionary by using build(). The arguments are the above mentioned Keyset and a dictionary setting, config_flags, which is represented by a combination of flags. For example, 2 | MARISA_BINARY_TAIL specifies the maximum number of tries (2) and a TAIL mode (MARISA_BINARY_TAIL). Also, in this case, the default settings, MARISA_DEFAULT_ORDER and MARISA_DEFAULT_CACHE, are used for the node order and the cache size.

The IDs associated with the keys are available through operator[]() of keyset, and the IDs are useful to associate the keys with any data types.

File I/O

mmap() is an interface for memory mapped I/O. If an application performs a few search operations, it is unnecessary to read the whole dictionary, and in such a case, mmap() is useful. Also, memory mapped I/O is an easy way to share dictionary data among processes. On the other hand, if an application performs a lot of search operations, a memory mapped dictionary might cause a lot of random disk accesses which considerably increase the search time. In such a case, you can specify flags as MARISA_MAP_POPULATE to populate (prefault) page tables and reduces page faults in searches.

map() restores an instance of Trie from dictionary data on memory. load() and read() read a dictionary from a file or a file descriptor. save() and write() write a dictionary to a file or a file descriptor.

Search

Trie provides 4 search functions lookup(), reverse_lookup(), common_prefix_search(), and predictive_search() as follows:

  • lookup() checks whether a query string is registered or not, and if it is registered, lookup() returns true. In this case, the search result is available through agent.key(). Note that lookup() does not restore a key and agent.key().ptr() points to the query string because the two strings are the same.
  • reverse_lookup() restores a key from its ID. This function has no return value and the key is available through agent.key(). The key is actually stored in agent and it is lost when agent is reset or used for another search operation. If a given ID is out-of-range, reverse_lookup() throws an exception.
  • common_prefix_search() searches keys from the possible prefixes of a query string. If there are matching keys, this function returns true. In this case, the first key is available through agent.key(), and if there are more than one matching keys, the next key will be available after the next common_prefix_search() which returns true until there are no more matching keys. Note that agent.key().ptr() == agent.query().ptr() is always true when common_prefix_search() has returned true.
  • predictive_search() searches keys starting with a query string, and similar to common_prefix_search(), this function returns true until there are no more matching keys.

Note that agent keeps the internal state of common_prefix_search() and predictive_search() until agent is passed to another search function or agent.set_query() is called.

num_keys() and size() return the number of keys. empty() checks whether the number of keys is 0 or not. io_size() returns the dictionary size in byte.

stdio

void fread(std::FILE *file, Trie *trie);
void fwrite(std::FILE *file, const Trie &trie);

The functions for I/O using std::FILE are declared in marisa/stdio.h. If you don't want to #include <cstdio>, use marisa/trie.h instead of marisa.h.

iostream

std::istream &read(std::istream &stream, Trie *trie);
std::ostream &write(std::ostream &stream, const Trie &trie);

std::istream &operator>>(std::istream &stream, Trie &trie);
std::ostream &operator<<(std::ostream &stream, const Trie &trie);

The functions for I/O using std::iostream are declared in marisa/iostream.h. If you don't want to #include <iosfwd>, use marisa/trie.h instead of marisa.h.

Cross-architecture compatibility

The dictionary format of libmarisa depends on the architecture. Dictionaries built on a little endian architecture don't work on a big endian architecture. Also, on a big endian architecture, dictionaries built on a 32-bit machine don't work on a 64-bit machine and vise versa. On a little endian architecture, dictionaries are compatible on 32/64-bit machines.

References

Last Spell

Feel free to contact me for any questions.

marisa-trie-master/docs/readme.ja.html000066400000000000000000001325211505027263100202350ustar00rootroot00000000000000 MARISA: Matching Algorithm with Recursively Implemented StorAge

MARISA: Matching Algorithm with Recursively Implemented StorAge

Abstract: Matching Algorithm with Recursively Implemented StorAge (MARISA) は Trie をコンパクトに表現する程度の能力を持つデータ構造です.libmarisa は MARISA を C++ で実装したライブラリであり,MARISA による辞書を構築したり,辞書からの検索をおこなったりできます.libmarisa の基本的な機能に対応するコマンドラインツールを用意しているので,辞書のサイズがどのくらいになるのか,検索にどのくらい時間がかかるのか,などを手軽に試すことができます.

はじめに

概要

Matching Algorithm with Recursively Implemented StorAge (MARISA) は Trie に対するコンパクトなデータ構造であり,動的な更新には対応していないものの,高い空間効率とそれなりの時間効率を実現できます.また,Trie の特徴を引き継いでいるため,MARISA による辞書は,単純な辞書引きだけでなく,逆引き,Common Prefix Search や Predictive Search を効率良く実現できます.

ほとんどの場合,MARISA による辞書は,登録文字列の集合を連結してできるテキストと比べて,ずっとコンパクトになります.そのため,登録文字列をそのまま保持する標準的な二分探索木やハッシュ表と比べると,ずーっとコンパクトです.一方で,確率的なデータ構造である Bloom Filter と比べてみると,空間効率の面では劣りますが,False Positive がなく,逆引きに加えて Common Prefix Search や Predictive Search を効率良く実現できることが特徴になります.

libmarisa は MARISA を C++ で実装したライブラリであり,MARISA による辞書を構築したり,辞書からの検索をおこなったりできます.libmarisa の基本的な機能に対応するコマンドラインツールを用意しているので,辞書のサイズがどのくらいになるのか,検索にどのくらい時間がかかるのか,などを手軽に試すことができます.

できること

libmarisa による辞書の構築では,登録文字列に 0 から順に固有の ID を割り当てるようになっています.ID は自動的に割り当てられるので,登録文字列に任意の ID を割り当てることはできません.検索においては,文字列あるいは ID をクエリとして受け取り,適合する登録文字列と ID の組を検索結果として返すようになっています.

  • 辞書引き(Lookup)
    • 入力文字列が登録されているかどうかを確認します.
  • 逆引き(Reverse Lookup)
    • 入力された ID から登録文字列を復元します.
  • Common Prefix Search
    • 入力文字列の前半部分に一致する登録文字列を検索します.
  • Predictive Search
    • 入力文字列で始まる登録文字列を検索します.

ソースコード

ライセンス

libmarisa および付属のコマンドラインツールはフリーソフトウェアです.使用・再配布については, BSD-2-Clause OR LGPL-2.1-or-later を採用しています.

ダウンロード

プロジェクトの管理やソースコードの配布には GitHub を利用しています.

インストール

GCC & Clang

$ tar zxf marisa-trie-0.3.1.tar.gz
$ cd marisa-trie-0.3.1
$ cmake -S. -Bbuild-rel -DCMAKE_BUILD_TYPE=Release
$ cmake --build build-rel
$ cmake --install build-rel

cmake を使ってビルド,インストールできるようになっています.インストール先を変更したいときは,最初の cmake-DCMAKE_INSTALL_PREFIX で指定してください.cmake --install については,必要に応じて sudo を付けてご利用ください.特に指定がなければ libmarisa はスタティックライブラリとしてインストールされます.

$ cmake --install build-rel --component Library

ツールが不要でライブラリのみをインストールしたいときは,cmake --install--component Library を指定してください.

$ cmake --install build-rel --component Binaries

ツールのみをインストールしたいときは,cmake --install--component Binaries を指定してください.

$ cmake -S. -Bbuild-rel -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON

共有ライブラリをビルド,インストールしたいときは,最初の cmake に追加で -DBUILD_SHARED_LIBS=ON を渡します.後の手順は同様です.

$ cmake -S. -Bbuild-rel -DCMAKE_BUILD_TYPE=Release -DENABLE_NATIVE_CODE=ON

各種 SIMD 命令が使える環境では,最初の cmake に追加で -DENABLE_NATIVE_CODE=ON を渡すことで,コンパイル環境で使える命令が有効になり,libmarisa の性能が向上します.

Visual Studio 2022

アーカイブを展開して作成されたフォルダを Visual Studio 2022 で開けば,CMakeLists.txt が自動で検出されて,プロジェクトが作成されます.デフォルトではデバッグモードでスタティックライブラリ marisa.lib とコマンドラインツールをビルドするようになっています.

Perl バインディング

$ cd bindings/perl
$ perl Makefile.PL
$ make
$ make install

SWIG による Perl バインディングが bindings/perl/ にあります.perl Makefile.PL により Makefile を作成し,make install を実行することでインストールできます.使い方については,bindings/perl/sample.pl を参考にしてください.

Python バインディング

$ cd bindings/python3
$ python3 setup.py build
$ python3 setup.py install

SWIG による Python バインディングが bindings/python3/ にあります.python3 setup.py install により インストールできます.使い方については,bindings/python3/sample.py を参考にしてください. bindings/python/ には古い Python バインディングがあり,互換性のために残されています.

Ruby バインディング

$ cd bindings/ruby
$ ruby extconf.rb
$ make
$ make install

SWIG による Ruby バインディングが bindings/ruby/ にあります.ruby extconf.rb により Makefile を作成し,make install を実行することでインストールできます.使い方については,bindings/ruby/sample.rb を参考にしてください.

その他

上記以外のバインディングもあります.

コマンドラインツール

marisa-build

$ marisa-build < keyset.txt > keyset.dic
#keys: 1342099
#nodes: 1832373
size: 7841664

marisa-build は辞書を構築するツールです.改行を区切りとして文字列を受け取り,構築した辞書を標準出力に書き出すようになっています.

構築する辞書のパラメータについては,オプションを使って指定できます.オプションの一覧は marisa-build -h により確認できます.

入力は改行区切りとなっていますが,水平タブが存在する行については,最後の水平タブ以降を文字列の重みとして扱うようになっています.文字列の出現頻度や出現確率を与えることにより,検索時間を短縮できる可能性があります.

marisa-lookup

$ marisa-lookup keyset.dic
東方
174385	東方
とうほう
-1	とうほう

marisa-lookup は単純な辞書引きをおこなうツールです.入力された文字列が登録されていれば ID とともに出力し,登録されていなければ -1 とともに出力します.

オプションの一覧は marisa-lookup -h により確認できます.

marisa-reverse-lookup

$ marisa-reverse-lookup keyset.dic
800000
800000	紀元前475年

marisa-reverse-lookup は辞書に登録されている文字列を ID から復元するツールです.登録文字列には 0 から順に固有の ID が割り当てられるので,指定できる値は 0 以上で登録文字列数より小さい整数となります.範囲外の値を入力するとエラーになるので注意してください.

オプションの一覧は marisa-reverse-lookup -h により確認できます.

marisa-common-prefix-search

$ marisa-common-prefix-search keyset.dic
東方
2 found
3542	東	東方
174385	東方	東方

marisa-common-prefix-search は Common Prefix Search をおこなうツールです.入力された文字列の前半部分に一致する登録文字列を ID とともに出力します.

オプションの一覧は marisa-common-prefix-search -h により確認できます.

marisa-predictive-search

$ marisa-predictive-search keyset.dic -n 2
東方
200 found
174385	東方	東方
639679	東方文花帖	東方

marisa-predictive-search は Predictive Search をおこなうツールです.入力された文字列で始まる登録文字列を ID とともに出力します.

オプションの一覧は marisa-predictive-search -h により確認できます.

marisa-benchmark

$ marisa-benchmark keyset.txt
Number of tries: 1 - 5
TAIL mode: Text mode
Node order: Descending weight order
Cache level: Normal cache
Number of keys: 1342099
Total length: 28308027
------+----------+--------+--------+--------+--------+--------
#tries       size    build   lookup  reverse   prefix  predict
                                      lookup   search   search
          [bytes]    [K/s]    [K/s]    [K/s]    [K/s]    [K/s]
------+----------+--------+--------+--------+--------+--------
     1   11588904   506.45  1187.70  1109.17  1040.39   596.49
     2    8467920   424.71   699.01   677.83   636.07   300.25
     3    7841664   405.47   615.64   601.84   563.91   254.67
     4    7633584   399.43   593.85   583.52   545.57   242.69
     5    7548584   395.90   526.31   563.91   504.55   236.70
------+----------+--------+--------+--------+--------+--------

marisa-benchmark は,marisa-build と同様の入力を受け取り,辞書のサイズや構築・検索にかかる時間を調べるツールです.辞書を構成する Trie の数を選択するのに有用です.

検索時間については,入力された文字列を一通り検索するのに要した時間を std::clock() で計測した結果を出力します.文字列を整列してから入力とした場合はキャッシュが効きやすい状況での検索時間になり,文字列をランダムに並べ替えてから入力とした場合はキャッシュが効きにくい状況での検索時間になります.

オプションの一覧は marisa-benchmark -h により確認できます.

marisa-dump

$ marisa-dump keyset.dic | head -3
input: keyset.dic
フ
ファ
ファン

marisa-dump は辞書に登録されている文字列をすべて出力するツールです.デフォルトの区切り文字は改行(LF)ですが,オプションにより変更することができます.

オプションの一覧は marisa-dump -h により確認できます.

ライブラリ

使い方

// sample.cc
#include <iostream>
#include <marisa.h>

int main() {
  marisa::Keyset keyset;
  keyset.push_back("a");
  keyset.push_back("app");
  keyset.push_back("apple");

  marisa::Trie trie;
  trie.build(keyset);

  marisa::Agent agent;
  agent.set_query("apple");
  while (trie.common_prefix_search(agent)) {
    std::cout.write(agent.key().ptr(), agent.key().length());
    std::cout << ": " << agent.key().id() << std::endl;
  }
  return 0;
}
$ g++ sample.cc -lmarisa
$ ./a.out
a: 0
app: 1
apple: 2

libmarisa のヘッダは marisa.h です.名前空間には marisa を使っています.危険なので,using namespace marisa とするのは避けてください.最後に,gccclang によるリンクでは -lmarisa が必要となることに注意してください.

libmarisa の主要なクラスは Keyset, Agent, Trie の 3 つです.サンプルコードでは明示的に使っていませんが,例外のクラスとして Exception があるほか,Keyset, Agent のメンバとして KeyQuery が存在します.

  • Keyset: 文字列の集合を格納するクラスです.辞書を構築するときの入力として使うほか,検索結果の保存にも利用できます.
  • Agent: 検索の入出力と途中経過を格納するクラスです.検索用の関数はすべて Agent への参照を引数とします.
  • Trie: 辞書のクラスです.

コマンドラインツールのソースコードが tools/ にあり,例外処理やファイル入出力,Predictive Search などのサンプルとして利用できます.

定数

エラーコード

typedef enum marisa_error_code_ {
  MARISA_OK           = 0,
  MARISA_STATE_ERROR  = 1,
  MARISA_NULL_ERROR   = 2,
  MARISA_BOUND_ERROR  = 3,
  MARISA_RANGE_ERROR  = 4,
  MARISA_CODE_ERROR   = 5,
  MARISA_RESET_ERROR  = 6,
  MARISA_SIZE_ERROR   = 7,
  MARISA_MEMORY_ERROR = 8,
  MARISA_IO_ERROR     = 9,
  MARISA_FORMAT_ERROR = 10,
} marisa_error_code;

libmarisa では,ファイル入出力に失敗したときや辞書のサイズが上限に到達したときなどに,Exception を送出します.そして,Exception に格納される情報の 1 つが marisa_error_code です.

辞書の入出力に関するエラーコードである MARISA_IO_ERRORMARISA_FORMAT_ERROR 以外については,バグによる可能性が高いと思います.各エラーコードの詳細については,marisa/base.h をご覧ください.

メモリマッピング用のフラグ

typedef enum marisa_map_flags {
  MARISA_MAP_POPULATE = 1 << 0,
} marisa_map_flags;

libmarisa では,メモリマッピングを使用して辞書を開くことができます.MARISA_MAP_POPULATE は辞書の先読みを有効にするフラグであり,辞書を開くときに時間がかかるものの,辞書を引くときにページフォルトの発生を抑制できます.参照するキーが多いときに有効です.参照するキーが少ないキーでは逆に遅くなることもあります.

トライの数

typedef enum marisa_num_tries_ {
  MARISA_MIN_NUM_TRIES     = 0x00001,
  MARISA_MAX_NUM_TRIES     = 0x0007F,
  MARISA_DEFAULT_NUM_TRIES = 0x00003,
} marisa_num_tries;

MARISA は複数の Patricia Trie を組み合わせて 1 つの Trie を構成することが特徴の 1 つであり,Patricia Trie の数を増やすほど,辞書はコンパクトになるものの,検索が遅くなるという傾向があります.marisa_num_tries では,辞書を構成する Patricia Trie の数について,最小値・最大値とデフォルトの値を提供します.

適切な設定は登録文字列やアプリケーションによって異なります.ほとんどの場合はデフォルトの設定で問題ないと思いますが,検索時間が問題になるときは,思い切って 1 にしてください.また,登録文字列が長くて少し複雑な構成になる場合,デフォルトより大きな値にすることで,辞書のサイズをさらに小さくできることがあります.設定が気になるときは,marisa-benchmark をお試しください.

キャッシュのサイズ

typedef enum marisa_cache_level_ {
  MARISA_HUGE_CACHE    = 0x00080,
  MARISA_LARGE_CACHE   = 0x00100,
  MARISA_NORMAL_CACHE  = 0x00200,
  MARISA_SMALL_CACHE   = 0x00400,
  MARISA_TINY_CACHE    = 0x00800,
  MARISA_DEFAULT_CACHE = MARISA_NORMAL_CACHE
} marisa_cache_level;

libmarisa では,検索時間の短縮を目的として,辞書にキャッシュを埋め込むようになっています.キャッシュの内容は通過する確率の高い遷移に関する情報であり,キャッシュを大きくすることによって,辞書は大きくなるものの,検索時間を短縮できます.

marisa_cache_level は,キャッシュのサイズを制御するための定数を提供します.MARISA_NORMAL_CACHE を基準として,MARISA_LARGE_CACHE は 2 倍,MARISA_HUGE_CACHE は 4 倍になり,MARISA_SMALL_CACHE は 1/2,MARISA_TINY_CACHE は 1/4 になります.

TAIL の種類

typedef enum marisa_tail_mode_ {
  MARISA_TEXT_TAIL    = 0x01000,
  MARISA_BINARY_TAIL  = 0x02000,
  MARISA_DEFAULT_TAIL = MARISA_TEXT_TAIL,
} marisa_tail_mode;

libmarisa による辞書では,最後の Patiricia Trie について,ラベルをそのまま保存するようになっています.marisa_tail_mode はラベルの保存方法を選ぶためのパラメータです.

MARISA_TEXT_TAIL はラベルを '\0' を終端とする文字列として保存します.そのため,ラベルに '\0' が含まれるときは,自動的に MARISA_BINARY_TAIL へと切り替わるようになっています.明示的に MARISA_BINARY_TAIL を選ぶ理由はほとんどありません.

一方,MARISA_BINARY_TAIL では,ラベルの終端を検出するために,'\0' の代わりにビット列を使用します.そのため,ラベルの平均長が 8 bytes を超えるときは MARISA_TEXT_TAIL の方がコンパクトになります.

ノードの順序

typedef enum marisa_node_order_ {
  MARISA_LABEL_ORDER   = 0x10000,
  MARISA_WEIGHT_ORDER  = 0x20000,
  MARISA_DEFAULT_ORDER = MARISA_WEIGHT_ORDER,
} marisa_node_order;

libmarisa では,ノードの順序が辞書のパラメータになっています.選択肢は MARISA_LABEL_ORDERMARISA_WEIGHT_ORDER の 2 つであり,前者はラベルが昇順になるようにノードを配列し,後者は重み(出現しやすさ)が降順になるようにノードを配列します.一般的な Trie の実装では MARISA_LABEL_ORDER の順序を用いますが,libmarisa では MARISA_WEIGHT_ORDER がデフォルトになっています.

MARISA_WEIGHT_ORDER の目的は,出現しやすいノードから順に並べておくことにより,線形探索の効率を高め,検索時間を短縮することにあります.日本語の単語やフレーズを用いた実験においては,辞書引きにかかる時間を 1/2 程度に短縮できることが確認されています.一方,MARISA_LABEL_ORDER については,検索時間は長くなるものの,Predictive Search の検索結果が文字列昇順になるという特徴があります.

別名

namespace marisa {
  typedef ::marisa_error_code ErrorCode;
  typedef ::marisa_cache_level CacheLevel;
  typedef ::marisa_tail_mode TailMode;
  typedef ::marisa_node_order NodeOrder;
}  // namespace marisa

以上の列挙型については,マクロとの衝突を避けるために,グローバル名前空間にて定義しています.namespace marisa に別名を用意しているので,お好きな方をご利用ください.

class Exception

class Exception {
 public:
  const char *filename() const;
  int line() const;
  ErrorCode error_code() const;
  const char *error_message() const;

  const char *what() const;
};

Exception は libmarisa が例外として送出するクラスです.エラーが検出されたファイルの名前(__FILE__)と行番号(__LINE__),さらにエラーコードを取り出せるようになっています.what() は使いやすさのために用意した関数であり,error_message() と同じく,__FILE__:__LINE__: error_code: error_message という書式の文字列を返します.

class Key

class Key {
 public:
  char operator[](std::size_t i) const;
  std::string_view str() const;
  const char *ptr() const;
  std::size_t length() const;
  std::size_t id() const;
};

Key は後述する Keyset および Agent のメンバになっているクラスです.登録しようとしている文字列や,検索で見つけた登録文字列の情報を格納するために使われています.基本的な使い方では,既に情報が格納されたインスタンスのみを目にすることになります.

class Query

class Query {
 public:
  char operator[](std::size_t i) const;
  std::string_view str() const;
  const char *ptr() const;
  std::size_t length() const;
  std::size_t id() const;
};

Query は後述する Agent のメンバになっているクラスです.検索しようとしている文字列や参照したい登録文字列の ID を格納するようになっています.Query に対する文字列や ID の設定は Agent を介しておこなうため,基本的な使い方では,意識する必要はありません.内容を確認したいときに参照する程度です.

class Keyset

class Keyset {
 public:
  Keyset();

  void push_back(const Key &key);
  void push_back(const Key &key, char end_marker);

  void push_back(std::string_view str,
                 float weight = 1.0);
  void push_back(const char *str);
  void push_back(const char *ptr,
                 std::size_t length,
                 float weight = 1.0);

  const Key &operator[](std::size_t i) const;
  Key &operator[](std::size_t i);

  std::size_t num_keys();

  bool empty() const;
  std::size_t size() const;
  std::size_t total_length() const;

  void reset();

  void clear();
  void swap(Keyset &rhs) noexcept;
};

概要

Keyset は辞書に登録しようとしている文字列もしくは登録されている文字列を詰め込むためのクラスです.辞書を構築するときの入力として,あるいは検索結果を保存しておくために使います.

辞書の構築

辞書の構築に使う場合,push_back() で登録したい文字列を追加してから,後述する Triebuild() に渡します.weight は文字列の出現しやすさを示す重みであり,同じ文字列を繰り返し追加した場合,辞書を構築する段階で加算されるようになっています.

辞書を構築した後は,operator[]() により登録文字列の ID を確認できます.その代わり,Key は重みと ID を共用体のメンバとして持つため,辞書の構築に使用した重みを参照できなくなります.

検索結果の保存

検索結果の保存に使う場合,後述する Agent に格納されている検索結果を push_back() に渡すことで,文字列を複製し,ID を残しておくことができます.検索結果の文字列に終端記号を加えたいときは end_marker を利用してください.文字列の長さには影響を与えず,end_marker を終端文字として加えることができます.

検索結果を破棄して別の検索結果を保存するために再利用するという場合,clear() の代わりに reset() を使うことで,既に確保している領域を再利用できます.メモリの確保・解放にかかるオーバーヘッドが気になるときにご利用ください.

empty() は文字列が格納されていないかどうかを返す関数です.size()num_keys() と同じく格納されている文字列の数を返す関数であり,total_length() は格納されている文字列の合計長を byte 単位で返す関数です.

class Agent

class Agent {
 public:
  Agent();

  const Query &query() const;
  const Key &key() const;

  void set_query(std::string_view str);
  void set_query(const char *str);
  void set_query(const char *ptr,
                 std::size_t length);
  void set_query(std::size_t key_id);
};

AgentQueryKey をメンバとして持つクラスです.検索における入出力の受け渡し,および途中経過の保存に使います.後述する Trie の検索関数は,例外なく Agent への参照を引数として受け取るようになっています.

検索の手順は,set_query() を使って検索したい文字列もしくは参照したい登録文字列の ID を設定し,Trie の関数に渡した後,key() により検索結果を取り出すという流れになります.

class Trie

class Trie {
 public:
  Trie();

  void build(Keyset &keyset,
             int config_flags = 0);

  void mmap(const char *filename,
            int flags = 0);
  void map(const void *ptr,
           std::size_t size);

  void load(const char *filename);
  void read(int fd);

  void save(const char *filename) const;
  void write(int fd) const;

  bool lookup(Agent &agent) const;
  void reverse_lookup(Agent &agent) const;
  bool common_prefix_search(Agent &agent) const;
  bool predictive_search(Agent &agent) const;

  std::size_t num_tries() const;
  std::size_t num_keys() const;
  std::size_t num_nodes() const;

  TailMode tail_mode() const;
  NodeOrder node_order() const;

  bool empty() const;
  std::size_t size() const;
  std::size_t io_size() const;

  void clear();
  void swap(Trie &rhs) noexcept;
};

概要

Trie は辞書のクラスです.libmarisa において最も重要なクラスであり,辞書の構築・検索からファイル入出力にいたるまで,あらゆる操作に必要となります.

実際には,辞書のハンドルに相当するクラスであり,辞書の実体がない状況では,build(), mmap(), map(), load(), read(), clear(), swap() 以外の関数を呼び出すと例外が送出されます.

辞書の構築

辞書の構築には build() を使います.引数は,前述の Keyset と,辞書の設定を XOR(|) で組み合わせた config_flags です.config_flags については,2 | MARISA_BINARY_TAIL のように指定します.この例では,辞書を構成する Patricia Trie の数を 2 つに制限し,ラベルの保存方法を MARISA_BINARY_TAIL に固定します.省略されているノードの順序とキャッシュのサイズについては,デフォルトの設定である MARISA_DEFAULT_ORDERMARISA_DEFAULT_CACHE が採用されます.

辞書の構築において登録文字列に割り当てられた ID は,keysetoperator[]() を使って確認できます.登録文字列に対して関連付ける情報がある場合にご利用ください.

ファイル入出力

mmap() は,Memory Mapped I/O により,辞書全体をファイルから読み込むことなく検索できる状態にする関数です.少ししか検索しないのに辞書全体を読み込むのは勿体ないという状況や,異なるプロセスで同じ辞書を共有したいという状況で使うと効果的です.逆に,たくさんの文字列を検索する場合,あらかじめ辞書全体を読み込んでおかないと,外部記憶に対するランダムアクセスにより検索時間が極端に長くなる可能性があります.このような場合,flagsMARISA_MAP_POPULATE を指定すれば,ページテーブルを先読みさせて,検索時のページフォルトを抑制できます.

map() はメモリ上に展開されている辞書のバイナリを使って検索できる状態にする関数です.load()read() は辞書を入力する関数であり,save()write() は辞書を出力する関数です.

辞書からの検索

検索をおこなう関数は lookup(), reverse_lookup(), common_prefix_search(), predictive_search() の 4 種類です.

  • lookup(): 文字列が登録されているかどうかを確認します.登録されていれば true を返します.このとき,agent.key() により検索結果を取り出すことができます.ただし,agent.key().ptr() については,入力として渡された文字列を指しているだけであり,文字列の複製を持っているわけではないことに注意してください.登録されていなければ false を返して終了です.
  • reverse_lookup(): ID から登録文字列を復元します.返り値はなく,復元された文字列は agent.key() を介してアクセスできます.文字列の実体は agent 内部に保持されています.agent を使って次の検索をおこなった段階で失われるものと考えてください.ID が範囲外であれば例外を送出して終了です.
  • common_prefix_search(): 入力文字列の前半部分に一致する登録文字列を検索します.該当する登録文字列があれば true を返します.このとき,agent.key() には検索結果が格納されています.agent.key().ptr() == agent.query().ptr() が成立することに注意してください.該当する登録文字列が複数ある場合,返り値が false になるまで繰り返し common_prefix_search() を呼び出すことにより,すべての検索結果を取得できます.
  • predictive_search(): 入力文字列で始まる登録文字列を検索します.該当する登録文字列があれば true を返します.検索によって復元された文字列には,agent.key() を介してアクセスできます.文字列の実体は,agent 内部に検索の途中経過として保持されているので,agent を使って次の検索をおこなった段階で失われるものと考えてください.該当する登録文字列が複数ある場合,返り値が false になるまで繰り返し predictive_search() を呼び出すことにより,すべての検索結果を取得できます.

繰り返しにより検索が進行する common_prefix_search()predictive_search() については,agent が検索の途中経過を保持するようになっています.そのため,agent を別の関数に渡したり,agent.set_query() を呼び出したりした時点で,検索の進行はリセットされます.

empty() は登録文字列が存在するかどうかを返す関数です.size()num_keys() と同じく登録文字列の数を返す関数であり,io_size() は辞書をファイルに出力した場合のサイズを返す関数です.

stdio

void fread(std::FILE *file, Trie *trie);
void fwrite(std::FILE *file, const Trie &trie);

std::FILE を用いる関数は marisa/stdio.h で宣言されています.#include <cstdio> を入れたくないときは,marisa.h の代わりに marisa/trie.h を使ってください.

iostream

std::istream &read(std::istream &stream, Trie *trie);
std::ostream &write(std::ostream &stream, const Trie &trie);

std::istream &operator>>(std::istream &stream, Trie &trie);
std::ostream &operator<<(std::ostream &stream, const Trie &trie);

std::iostream を用いる関数は marisa/iostream.h で宣言されています.#include <iosfwd> を入れたくないときは,marisa.h の代わりに marisa/trie.h を使ってください.

辞書の互換性

libmarisa により構築される辞書の書式はアーキテクチャに依存します.Little Endian な環境で構築した辞書は,Big Endian な環境では使えません.あらためて構築しなおす必要があります.また,Little Endian 形式の辞書は 32/64-bit 環境における互換性があるのに対し,Big Endian 形式の辞書は 32/64-bit 環境における互換性がありません.

参考資料

おわりに

質問などありましたら,欄外のメールアドレス宛てに,お気軽にご連絡ください.

marisa-trie-master/docs/style.css000066400000000000000000000075231505027263100173760ustar00rootroot00000000000000@charset "utf-8"; * { line-height: 140%; margin: 0px; padding: 0px; } body { background: lightgray; color: #222; margin: 10px 20px; } a { color: inherit; text-decoration: none; } a:link { color: #066; padding: 0px 2px; } a:link:after { content: "†"; } a:visited { color: #057; padding: 0px 2px; } a:visited:after { content: "†"; } a:hover { text-decoration: underline; } a[name]:hover { color: inherit; text-decoration: none; } a:active { } a[name]:active { color: inherit; padding: 0px; } ol { list-style-position: outside; margin-left: 2em; } ol ol { list-style-position: outside; margin-left: 1em; } ul { list-style-position: outside; margin-left: 2em; } ul ul { list-style-position: outside; margin-left: 1em; } li { margin: 5px 0px; } code { color: darkblue; font-family: sans-serif; font-style: normal; padding: 0px 2px; } kbd { color: darkgreen; font-family: sans-serif; font-style: normal; padding: 0px 2px; white-space: nowrap; } var { color: darkred; font-family: sans-serif; font-style: normal; padding: 0px 2px; } sup { font-size: 75%; } div#header { font-family: "Times New Roman"; padding: 5px 10px; } div#header div.left { float: left; } div#header div.right { float: right; } div#header div.end { clear: both; } div#body { background: white; border: 1px solid black; box-shadow: 1px 1px 5px gray; -webkit-box-shadow: 1px 1px 5px gray; -moz-box-shadow: 1px 1px 5px gray; padding: 20px; } div#body h1 { font-size: 150%; margin: 10px; text-align: center; } div#body p#authors { font-weight: bold; margin: 10px; text-align: center; } div#body p#authors span.author { margin: 0px 1em; } div#body p#abstract { margin: 15px auto; text-align: auto; width: 75%; } div#body p#abstract span#heading { font-family: "Times New Roman"; font-style: italic; font-weight: bold; margin-right: 0.5em; } div#body div.section { clear: both; margin: 5px 0px; } div#body div.section h2 { background: honeydew; border-bottom: 1px dashed darkgray; color: #353; font-size: 125%; margin-top: 15px; padding: 5px; } div#body div.section p { margin: 5px 0px; text-indent: 1em; } div#body div.section div.float { box-shadow: 1px 1px 5px gray; -webkit-box-shadow: 1px 1px 5px gray; -moz-box-shadow: 1px 1px 5px gray; clear: both; float: right; margin: 5px 0px 5px 10px; max-width: 75%; } div#body div.section pre.code { background: whitesmoke; color: darkblue; line-height: 125%; overflow: auto; padding: 5px 10px; } div#body div.section pre.console { background: darkslategray; color: white; line-height: 125%; overflow: auto; padding: 5px 10px; } div#body div.section table { background: whitesmoke; border-collapse: separate; border-spacing: 5px; empty-cells: hide; padding: 5px 10px; } div#body div.section table caption { background: inherit; padding-top: 5px; } div#body div.section table th { background: white; box-shadow: 1px 1px 3px gray; -webkit-box-shadow: 1px 1px 3px gray; -moz-box-shadow: 1px 1px 3px gray; font-weight: normal; padding: 0px 5px; } div#body div.section table td { background: white; box-shadow: 1px 1px 2px gray; -webkit-box-shadow: 1px 1px 2px gray; -moz-box-shadow: 1px 1px 2px gray; padding: 0px 3px; } div#body div.section div.subsection { clear: both; margin: 5px 0px; } div#body div.section div.subsection h3 { background: aliceblue; border-bottom: 1px dashed lightgray; color: #336; font-size: 100%; margin-top: 10px; padding: 3px 5px; } div#body div.section div.subsubsection { margin: 5px; } div#body div.section div.subsubsection h4 { background: lavenderblush; border-bottom: 1px dashed lightgray; color: #336; font-size: 100%; margin-top: 10px; padding: 3px 5px; } div#footer { font-family: "Times New Roman"; padding: 5px 10px; } div#footer div.left { float: left; } div#footer div.right { float: right; } div#footer div.end { clear: both; } marisa-trie-master/include/000077500000000000000000000000001505027263100162105ustar00rootroot00000000000000marisa-trie-master/include/marisa.h000066400000000000000000000007561505027263100176450ustar00rootroot00000000000000#ifndef MARISA_H_ #define MARISA_H_ // "marisa/stdio.h" includes for I/O using std::FILE. #include "marisa/stdio.h" // IWYU pragma: export // "marisa/iostream.h" includes for I/O using std::iostream. #include "marisa/iostream.h" // IWYU pragma: export // You can use instead of if you don't need the // above I/O interfaces and don't want to include the above I/O headers. #include "marisa/trie.h" // IWYU pragma: export #endif // MARISA_H_ marisa-trie-master/include/marisa/000077500000000000000000000000001505027263100174645ustar00rootroot00000000000000marisa-trie-master/include/marisa/agent.h000066400000000000000000000031141505027263100207320ustar00rootroot00000000000000#ifndef MARISA_AGENT_H_ #define MARISA_AGENT_H_ #include #include #include #include "marisa/key.h" #include "marisa/query.h" namespace marisa { namespace grimoire::trie { class State; } // namespace grimoire::trie class Agent { public: Agent(); ~Agent(); Agent(const Agent &other); Agent &operator=(const Agent &other); Agent(Agent &&other) noexcept; Agent &operator=(Agent &&other) noexcept; const Query &query() const { return query_; } const Key &key() const { return key_; } void set_query(std::string_view str) { set_query(str.data(), str.length()); } void set_query(const char *str); void set_query(const char *ptr, std::size_t length); void set_query(std::size_t key_id); const grimoire::trie::State &state() const { return *state_; } grimoire::trie::State &state() { return *state_; } void set_key(std::string_view str) { set_key(str.data(), str.length()); } void set_key(const char *str) { assert(str != nullptr); key_.set_str(str); } void set_key(const char *ptr, std::size_t length) { assert((ptr != nullptr) || (length == 0)); assert(length <= UINT32_MAX); key_.set_str(ptr, length); } void set_key(std::size_t id) { assert(id <= UINT32_MAX); key_.set_id(id); } bool has_state() const { return state_ != nullptr; } void init_state(); void clear() noexcept; void swap(Agent &rhs) noexcept; private: Query query_; Key key_; std::unique_ptr state_; }; } // namespace marisa #endif // MARISA_AGENT_H_ marisa-trie-master/include/marisa/base.h000066400000000000000000000177071505027263100205630ustar00rootroot00000000000000#ifndef MARISA_BASE_H_ #define MARISA_BASE_H_ #include #include #include #include #include // These aliases are left for backward compatibility. using marisa_uint8 [[deprecated]] = std::uint8_t; using marisa_uint16 [[deprecated]] = std::uint16_t; using marisa_uint32 [[deprecated]] = std::uint32_t; using marisa_uint64 [[deprecated]] = std::uint64_t; #if UINTPTR_MAX == UINT64_MAX #define MARISA_WORD_SIZE 64 #elif UINTPTR_MAX == UINT32_MAX #define MARISA_WORD_SIZE 32 #else #error Failed to detect MARISA_WORD_SIZE #endif // These constant variables are left for backward compatibility. [[deprecated]] constexpr auto MARISA_UINT8_MAX = UINT8_MAX; [[deprecated]] constexpr auto MARISA_UINT16_MAX = UINT16_MAX; [[deprecated]] constexpr auto MARISA_UINT32_MAX = UINT32_MAX; [[deprecated]] constexpr auto MARISA_UINT64_MAX = UINT64_MAX; [[deprecated]] constexpr auto MARISA_SIZE_MAX = SIZE_MAX; #define MARISA_INVALID_LINK_ID UINT32_MAX #define MARISA_INVALID_KEY_ID UINT32_MAX #define MARISA_INVALID_EXTRA (UINT32_MAX >> 8) // Error codes are defined as members of marisa_error_code. This library throws // an exception with one of the error codes when an error occurs. enum marisa_error_code { // MARISA_OK means that a requested operation has succeeded. In practice, an // exception never has MARISA_OK because it is not an error. MARISA_OK = 0, // MARISA_STATE_ERROR means that an object was not ready for a requested // operation. For example, an operation to modify a fixed vector throws an // exception with MARISA_STATE_ERROR. MARISA_STATE_ERROR = 1, // MARISA_NULL_ERROR means that an invalid nullptr has been given. MARISA_NULL_ERROR = 2, // MARISA_BOUND_ERROR means that an operation has tried to access an out of // range address. MARISA_BOUND_ERROR = 3, // MARISA_RANGE_ERROR means that an out of range value has appeared in // operation. MARISA_RANGE_ERROR = 4, // MARISA_CODE_ERROR means that an undefined code has appeared in operation. MARISA_CODE_ERROR = 5, // MARISA_RESET_ERROR means that a smart pointer has tried to reset itself. MARISA_RESET_ERROR = 6, // MARISA_SIZE_ERROR means that a size has exceeded a library limitation. MARISA_SIZE_ERROR = 7, // MARISA_MEMORY_ERROR means that a memory allocation has failed. MARISA_MEMORY_ERROR = 8, // MARISA_IO_ERROR means that an I/O operation has failed. MARISA_IO_ERROR = 9, // MARISA_FORMAT_ERROR means that input was in invalid format. MARISA_FORMAT_ERROR = 10, }; // Flags for memory mapping are defined as members of marisa_map_flags. // Trie::open() accepts a combination of these flags. enum marisa_map_flags { // MARISA_MAP_POPULATE specifies MAP_POPULATE. MARISA_MAP_POPULATE = 1 << 0, }; // Min/max values, flags and masks for dictionary settings are defined below. // Please note that unspecified settings will be replaced with the default // settings. For example, 0 is equivalent to (MARISA_DEFAULT_NUM_TRIES | // MARISA_DEFAULT_TRIE | MARISA_DEFAULT_TAIL | MARISA_DEFAULT_ORDER). // A dictionary consists of 3 tries in default. Usually more tries make a // dictionary space-efficient but time-inefficient. enum marisa_num_tries { MARISA_MIN_NUM_TRIES = 0x00001, MARISA_MAX_NUM_TRIES = 0x0007F, MARISA_DEFAULT_NUM_TRIES = 0x00003, }; // This library uses a cache technique to accelerate search functions. The // following enumerated type marisa_cache_level gives a list of available cache // size options. A larger cache enables faster search but takes a more space. enum marisa_cache_level { MARISA_HUGE_CACHE = 0x00080, MARISA_LARGE_CACHE = 0x00100, MARISA_NORMAL_CACHE = 0x00200, MARISA_SMALL_CACHE = 0x00400, MARISA_TINY_CACHE = 0x00800, MARISA_DEFAULT_CACHE = MARISA_NORMAL_CACHE }; // This library provides 2 kinds of TAIL implementations. enum marisa_tail_mode { // MARISA_TEXT_TAIL merges last labels as zero-terminated strings. So, it is // available if and only if the last labels do not contain a NULL character. // If MARISA_TEXT_TAIL is specified and a NULL character exists in the last // labels, the setting is automatically switched to MARISA_BINARY_TAIL. MARISA_TEXT_TAIL = 0x01000, // MARISA_BINARY_TAIL also merges last labels but as byte sequences. It uses // a bit vector to detect the end of a sequence, instead of NULL characters. // So, MARISA_BINARY_TAIL requires a larger space if the average length of // labels is greater than 8. MARISA_BINARY_TAIL = 0x02000, MARISA_DEFAULT_TAIL = MARISA_TEXT_TAIL, }; // The arrangement of nodes affects the time cost of matching and the order of // predictive search. enum marisa_node_order { // MARISA_LABEL_ORDER arranges nodes in ascending label order. // MARISA_LABEL_ORDER is useful if an application needs to predict keys in // label order. MARISA_LABEL_ORDER = 0x10000, // MARISA_WEIGHT_ORDER arranges nodes in descending weight order. // MARISA_WEIGHT_ORDER is generally a better choice because it enables faster // matching. MARISA_WEIGHT_ORDER = 0x20000, MARISA_DEFAULT_ORDER = MARISA_WEIGHT_ORDER, }; enum marisa_config_mask { MARISA_NUM_TRIES_MASK = 0x0007F, MARISA_CACHE_LEVEL_MASK = 0x00F80, MARISA_TAIL_MODE_MASK = 0x0F000, MARISA_NODE_ORDER_MASK = 0xF0000, MARISA_CONFIG_MASK = 0xFFFFF }; namespace marisa { // These aliases are left for backward compatibility. using UInt8 [[deprecated]] = std::uint8_t; using UInt16 [[deprecated]] = std::uint16_t; using UInt32 [[deprecated]] = std::uint32_t; using UInt64 [[deprecated]] = std::uint64_t; using std::uint16_t; using std::uint32_t; using std::uint64_t; using std::uint8_t; using ErrorCode = marisa_error_code; using CacheLevel = marisa_cache_level; using TailMode = marisa_tail_mode; using NodeOrder = marisa_node_order; // This is left for backward compatibility. using std::swap; // This is left for backward compatibility. using Exception = std::exception; } // namespace marisa // These macros are used to convert a line number to a string constant. #define MARISA_INT_TO_STR(value) #value #define MARISA_LINE_TO_STR(line) MARISA_INT_TO_STR(line) #define MARISA_LINE_STR MARISA_LINE_TO_STR(__LINE__) // MARISA_THROW throws an exception with a filename, a line number, an error // code and an error message. The message format is as follows: // "__FILE__:__LINE__: error_code: error_message" #define MARISA_THROW(error_type, error_message) \ (throw (error_type)(__FILE__ ":" MARISA_LINE_STR ": " #error_type \ ": " error_message)) // MARISA_THROW_IF throws an exception if `condition' is true. #define MARISA_THROW_IF(condition, error_type) \ (void)((!(condition)) || (MARISA_THROW(error_type, #condition), 0)) // MARISA_THROW_SYSTEM_ERROR_IF throws an exception if `condition` is true. // ::GetLastError() or errno should be passed as `error_value`. #define MARISA_THROW_SYSTEM_ERROR_IF(condition, error_value, error_category, \ function_name) \ (void)((!(condition)) || \ (throw std::system_error( \ std::error_code(error_value, error_category), \ __FILE__ ":" MARISA_LINE_STR \ ": std::system_error: " function_name ": " #condition), \ false)) // #ifndef MARISA_USE_EXCEPTIONS // #if defined(__GNUC__) && !defined(__EXCEPTIONS) // #define MARISA_USE_EXCEPTIONS 0 // #elif defined(__clang__) && !defined(__cpp_exceptions) // #define MARISA_USE_EXCEPTIONS 0 // #elif defined(_MSC_VER) && !_HAS_EXCEPTIONS // #define MARISA_USE_EXCEPTIONS 0 // #else // #define MARISA_USE_EXCEPTIONS 1 // #endif // #endif // #if MARISA_USE_EXCEPTIONS // #define MARISA_TRY try // #define MARISA_CATCH(x) catch (x) // #else // #define MARISA_TRY if (true) // #define MARISA_CATCH(x) if (false) // #endif #endif // MARISA_BASE_H_ marisa-trie-master/include/marisa/iostream.h000066400000000000000000000006241505027263100214620ustar00rootroot00000000000000#ifndef MARISA_IOSTREAM_H_ #define MARISA_IOSTREAM_H_ #include namespace marisa { class Trie; std::istream &read(std::istream &stream, Trie *trie); std::ostream &write(std::ostream &stream, const Trie &trie); std::istream &operator>>(std::istream &stream, Trie &trie); std::ostream &operator<<(std::ostream &stream, const Trie &trie); } // namespace marisa #endif // MARISA_IOSTREAM_H_ marisa-trie-master/include/marisa/key.h000066400000000000000000000032741505027263100204330ustar00rootroot00000000000000#ifndef MARISA_KEY_H_ #define MARISA_KEY_H_ #include #include #include "marisa/base.h" namespace marisa { class Key { public: Key() = default; Key(const Key &key) = default; Key &operator=(const Key &key) = default; char operator[](std::size_t i) const { assert(i < length_); return ptr_[i]; } void set_str(std::string_view str) { set_str(str.data(), str.length()); } void set_str(const char *str) { assert(str != nullptr); std::size_t length = 0; while (str[length] != '\0') { ++length; } assert(length <= UINT32_MAX); ptr_ = str; length_ = static_cast(length); } void set_str(const char *ptr, std::size_t length) { assert((ptr != nullptr) || (length == 0)); assert(length <= UINT32_MAX); ptr_ = ptr; length_ = static_cast(length); } void set_id(std::size_t id) { assert(id <= UINT32_MAX); union_.id = static_cast(id); } void set_weight(float weight) { union_.weight = weight; } std::string_view str() const { return std::string_view(ptr_, length_); } const char *ptr() const { return ptr_; } std::size_t length() const { return length_; } std::size_t id() const { return union_.id; } float weight() const { return union_.weight; } void clear() noexcept { Key().swap(*this); } void swap(Key &rhs) noexcept { std::swap(ptr_, rhs.ptr_); std::swap(length_, rhs.length_); std::swap(union_.id, rhs.union_.id); } private: const char *ptr_ = nullptr; uint32_t length_ = 0; union Union { uint32_t id = 0; float weight; } union_; }; } // namespace marisa #endif // MARISA_KEY_H_ marisa-trie-master/include/marisa/keyset.h000066400000000000000000000036651505027263100211530ustar00rootroot00000000000000#ifndef MARISA_KEYSET_H_ #define MARISA_KEYSET_H_ #include #include #include #include "marisa/key.h" namespace marisa { class Keyset { public: enum { BASE_BLOCK_SIZE = 4096, EXTRA_BLOCK_SIZE = 1024, KEY_BLOCK_SIZE = 256 }; Keyset(); Keyset(const Keyset &) = delete; Keyset &operator=(const Keyset &) = delete; void push_back(const Key &key); void push_back(const Key &key, char end_marker); void push_back(std::string_view str, float weight = 1.0) { push_back(str.data(), str.length(), weight); } void push_back(const char *str); void push_back(const char *ptr, std::size_t length, float weight = 1.0); const Key &operator[](std::size_t i) const { assert(i < size_); return key_blocks_[i / KEY_BLOCK_SIZE][i % KEY_BLOCK_SIZE]; } Key &operator[](std::size_t i) { assert(i < size_); return key_blocks_[i / KEY_BLOCK_SIZE][i % KEY_BLOCK_SIZE]; } std::size_t num_keys() const { return size_; } bool empty() const { return size_ == 0; } std::size_t size() const { return size_; } std::size_t total_length() const { return total_length_; } void reset(); void clear() noexcept; void swap(Keyset &rhs) noexcept; private: std::unique_ptr[]> base_blocks_; std::size_t base_blocks_size_ = 0; std::size_t base_blocks_capacity_ = 0; std::unique_ptr[]> extra_blocks_; std::size_t extra_blocks_size_ = 0; std::size_t extra_blocks_capacity_ = 0; std::unique_ptr[]> key_blocks_; std::size_t key_blocks_size_ = 0; std::size_t key_blocks_capacity_ = 0; char *ptr_ = nullptr; std::size_t avail_ = 0; std::size_t size_ = 0; std::size_t total_length_ = 0; char *reserve(std::size_t size); void append_base_block(); void append_extra_block(std::size_t size); void append_key_block(); }; } // namespace marisa #endif // MARISA_KEYSET_H_ marisa-trie-master/include/marisa/query.h000066400000000000000000000025661505027263100210130ustar00rootroot00000000000000#ifndef MARISA_QUERY_H_ #define MARISA_QUERY_H_ #include #include #include "marisa/base.h" namespace marisa { class Query { public: Query() = default; Query(const Query &query) = default; Query &operator=(const Query &query) = default; char operator[](std::size_t i) const { assert(i < length_); return ptr_[i]; } void set_str(std::string_view str) { set_str(str.data(), str.length()); } void set_str(const char *str) { assert(str != nullptr); std::size_t length = 0; while (str[length] != '\0') { ++length; } ptr_ = str; length_ = length; } void set_str(const char *ptr, std::size_t length) { assert((ptr != nullptr) || (length == 0)); ptr_ = ptr; length_ = length; } void set_id(std::size_t id) { id_ = id; } std::string_view str() const { return std::string_view(ptr_, length_); } const char *ptr() const { return ptr_; } std::size_t length() const { return length_; } std::size_t id() const { return id_; } void clear() noexcept { Query().swap(*this); } void swap(Query &rhs) noexcept { std::swap(ptr_, rhs.ptr_); std::swap(length_, rhs.length_); std::swap(id_, rhs.id_); } private: const char *ptr_ = nullptr; std::size_t length_ = 0; std::size_t id_ = 0; }; } // namespace marisa #endif // MARISA_QUERY_H_ marisa-trie-master/include/marisa/stdio.h000066400000000000000000000003701505027263100207570ustar00rootroot00000000000000#ifndef MARISA_MYSTDIO_H_ #define MARISA_MYSTDIO_H_ #include namespace marisa { class Trie; void fread(std::FILE *file, Trie *trie); void fwrite(std::FILE *file, const Trie &trie); } // namespace marisa #endif // MARISA_MYSTDIO_H_ marisa-trie-master/include/marisa/trie.h000066400000000000000000000025411505027263100206020ustar00rootroot00000000000000#ifndef MARISA_TRIE_H_ #define MARISA_TRIE_H_ #include #include "marisa/agent.h" // IWYU pragma: export #include "marisa/keyset.h" // IWYU pragma: export namespace marisa { namespace grimoire::trie { class LoudsTrie; } // namespace grimoire::trie class Trie { friend class TrieIO; public: Trie(); ~Trie(); Trie(const Trie &) = delete; Trie &operator=(const Trie &) = delete; Trie(Trie &&) noexcept; Trie &operator=(Trie &&) noexcept; void build(Keyset &keyset, int config_flags = 0); void mmap(const char *filename, int flags = 0); void map(const void *ptr, std::size_t size); void load(const char *filename); void read(int fd); void save(const char *filename) const; void write(int fd) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t num_tries() const; std::size_t num_keys() const; std::size_t num_nodes() const; TailMode tail_mode() const; NodeOrder node_order() const; bool empty() const; std::size_t size() const; std::size_t total_size() const; std::size_t io_size() const; void clear() noexcept; void swap(Trie &rhs) noexcept; private: std::unique_ptr trie_; }; } // namespace marisa #endif // MARISA_TRIE_H_ marisa-trie-master/lib/000077500000000000000000000000001505027263100153335ustar00rootroot00000000000000marisa-trie-master/lib/marisa/000077500000000000000000000000001505027263100166075ustar00rootroot00000000000000marisa-trie-master/lib/marisa/agent.cc000066400000000000000000000047601505027263100202230ustar00rootroot00000000000000#include "marisa/agent.h" #include #include #include #include "marisa/grimoire/trie.h" #include "marisa/grimoire/trie/state.h" #include "marisa/key.h" namespace marisa { namespace { void UpdateAgentAfterCopyingState(const grimoire::trie::State &state, Agent &agent) { // Point the agent's key to the newly copied buffer if necessary. switch (state.status_code()) { case grimoire::trie::MARISA_READY_TO_PREDICTIVE_SEARCH: case grimoire::trie::MARISA_END_OF_PREDICTIVE_SEARCH: // In states corresponding to predictive_search, the agent's // key points into the state key buffer. We need to repoint // after copying the state. agent.set_key(state.key_buf().data(), state.key_buf().size()); break; default: // In other states, they key is either null, or points to the // query, so we do not need to repoint it. break; } } } // namespace Agent::Agent() = default; Agent::~Agent() = default; Agent::Agent(const Agent &other) : query_(other.query_), key_(other.key_), state_(other.has_state() ? new grimoire::trie::State(other.state()) : nullptr) { if (other.has_state()) { UpdateAgentAfterCopyingState(*state_, *this); } } Agent &Agent::operator=(const Agent &other) { query_ = other.query_; key_ = other.key_; if (other.has_state()) { state_.reset(new grimoire::trie::State(other.state())); UpdateAgentAfterCopyingState(*state_, *this); } else { state_ = nullptr; } return *this; } Agent::Agent(Agent &&other) noexcept = default; Agent &Agent::operator=(Agent &&other) noexcept = default; void Agent::set_query(const char *str) { MARISA_THROW_IF(str == nullptr, std::invalid_argument); if (state_ != nullptr) { state_->reset(); } query_.set_str(str); } void Agent::set_query(const char *ptr, std::size_t length) { MARISA_THROW_IF((ptr == nullptr) && (length != 0), std::invalid_argument); if (state_ != nullptr) { state_->reset(); } query_.set_str(ptr, length); } void Agent::set_query(std::size_t key_id) { if (state_ != nullptr) { state_->reset(); } query_.set_id(key_id); } void Agent::init_state() { MARISA_THROW_IF(state_ != nullptr, std::logic_error); state_.reset(new grimoire::State); } void Agent::clear() noexcept { Agent().swap(*this); } void Agent::swap(Agent &rhs) noexcept { query_.swap(rhs.query_); key_.swap(rhs.key_); state_.swap(rhs.state_); } } // namespace marisa marisa-trie-master/lib/marisa/grimoire/000077500000000000000000000000001505027263100204245ustar00rootroot00000000000000marisa-trie-master/lib/marisa/grimoire/algorithm/000077500000000000000000000000001505027263100224125ustar00rootroot00000000000000marisa-trie-master/lib/marisa/grimoire/algorithm/sort.h000066400000000000000000000101661505027263100235560ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_ALGORITHM_SORT_H_ #define MARISA_GRIMOIRE_ALGORITHM_SORT_H_ #include #include "marisa/base.h" namespace marisa::grimoire::algorithm { namespace details { enum { MARISA_INSERTION_SORT_THRESHOLD = 10 }; template int get_label(const T &unit, std::size_t depth) { assert(depth <= unit.length()); return (depth < unit.length()) ? int{static_cast(unit[depth])} : -1; } template int median(const T &a, const T &b, const T &c, std::size_t depth) { const int x = get_label(a, depth); const int y = get_label(b, depth); const int z = get_label(c, depth); if (x < y) { if (y < z) { return y; } else if (x < z) { return z; } return x; } else if (x < z) { return x; } else if (y < z) { return z; } return y; } template int compare(const T &lhs, const T &rhs, std::size_t depth) { for (std::size_t i = depth; i < lhs.length(); ++i) { if (i == rhs.length()) { return 1; } if (lhs[i] != rhs[i]) { return static_cast(lhs[i]) - static_cast(rhs[i]); } } if (lhs.length() == rhs.length()) { return 0; } return (lhs.length() < rhs.length()) ? -1 : 1; } template std::size_t insertion_sort(Iterator l, Iterator r, std::size_t depth) { assert(l <= r); std::size_t count = 1; for (Iterator i = l + 1; i < r; ++i) { int result = 0; for (Iterator j = i; j > l; --j) { result = compare(*(j - 1), *j, depth); if (result <= 0) { break; } std::swap(*(j - 1), *j); } if (result != 0) { ++count; } } return count; } template std::size_t sort(Iterator l, Iterator r, std::size_t depth) { assert(l <= r); std::size_t count = 0; while ((r - l) > MARISA_INSERTION_SORT_THRESHOLD) { Iterator pl = l; Iterator pr = r; Iterator pivot_l = l; Iterator pivot_r = r; const int pivot = median(*l, *(l + (r - l) / 2), *(r - 1), depth); for (;;) { while (pl < pr) { const int label = get_label(*pl, depth); if (label > pivot) { break; } else if (label == pivot) { std::swap(*pl, *pivot_l); ++pivot_l; } ++pl; } while (pl < pr) { const int label = get_label(*--pr, depth); if (label < pivot) { break; } else if (label == pivot) { std::swap(*pr, *--pivot_r); } } if (pl >= pr) { break; } std::swap(*pl, *pr); ++pl; } while (pivot_l > l) { std::swap(*--pivot_l, *--pl); } while (pivot_r < r) { std::swap(*pivot_r, *pr); ++pivot_r; ++pr; } if (((pl - l) > (pr - pl)) || ((r - pr) > (pr - pl))) { if ((pr - pl) == 1) { ++count; } else if ((pr - pl) > 1) { if (pivot == -1) { ++count; } else { count += sort(pl, pr, depth + 1); } } if ((pl - l) < (r - pr)) { if ((pl - l) == 1) { ++count; } else if ((pl - l) > 1) { count += sort(l, pl, depth); } l = pr; } else { if ((r - pr) == 1) { ++count; } else if ((r - pr) > 1) { count += sort(pr, r, depth); } r = pl; } } else { if ((pl - l) == 1) { ++count; } else if ((pl - l) > 1) { count += sort(l, pl, depth); } if ((r - pr) == 1) { ++count; } else if ((r - pr) > 1) { count += sort(pr, r, depth); } l = pl, r = pr; if ((pr - pl) == 1) { ++count; } else if ((pr - pl) > 1) { if (pivot == -1) { l = r; ++count; } else { ++depth; } } } } if ((r - l) > 1) { count += insertion_sort(l, r, depth); } return count; } } // namespace details template std::size_t sort(Iterator begin, Iterator end) { assert(begin <= end); return details::sort(begin, end, 0); } } // namespace marisa::grimoire::algorithm #endif // MARISA_GRIMOIRE_ALGORITHM_SORT_H_ marisa-trie-master/lib/marisa/grimoire/intrin.h000066400000000000000000000065171505027263100221110ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_INTRIN_H_ #define MARISA_GRIMOIRE_INTRIN_H_ #include "marisa/base.h" #if defined(__x86_64__) || defined(_M_X64) #define MARISA_X64 #elif defined(__i386__) || defined(_M_IX86) #define MARISA_X86 #else // defined(__i386__) || defined(_M_IX86) #ifdef MARISA_USE_BMI2 #undef MARISA_USE_BMI2 #endif // MARISA_USE_BMI2 #ifdef MARISA_USE_BMI #undef MARISA_USE_BMI #endif // MARISA_USE_BMI #ifdef MARISA_USE_POPCNT #undef MARISA_USE_POPCNT #endif // MARISA_USE_POPCNT #ifdef MARISA_USE_SSE4A #undef MARISA_USE_SSE4A #endif // MARISA_USE_SSE4A #ifdef MARISA_USE_SSE4 #undef MARISA_USE_SSE4 #endif // MARISA_USE_SSE4 #ifdef MARISA_USE_SSE4_2 #undef MARISA_USE_SSE4_2 #endif // MARISA_USE_SSE4_2 #ifdef MARISA_USE_SSE4_1 #undef MARISA_USE_SSE4_1 #endif // MARISA_USE_SSE4_1 #ifdef MARISA_USE_SSSE3 #undef MARISA_USE_SSSE3 #endif // MARISA_USE_SSSE3 #ifdef MARISA_USE_SSE3 #undef MARISA_USE_SSE3 #endif // MARISA_USE_SSE3 #ifdef MARISA_USE_SSE2 #undef MARISA_USE_SSE2 #endif // MARISA_USE_SSE2 #endif // defined(__i386__) || defined(_M_IX86) #ifdef MARISA_USE_BMI2 #ifndef MARISA_USE_BMI #define MARISA_USE_BMI #endif // MARISA_USE_BMI #ifdef _MSC_VER #include #else // _MSC_VER #include #endif // _MSC_VER #endif // MARISA_USE_BMI2 #ifdef MARISA_USE_BMI #ifndef MARISA_USE_SSE4 #define MARISA_USE_SSE4 #endif // MARISA_USE_SSE4 #endif // MARISA_USE_BMI #ifdef MARISA_USE_SSE4A #ifndef MARISA_USE_SSE3 #define MARISA_USE_SSE3 #endif // MARISA_USE_SSE3 #ifndef MARISA_USE_POPCNT #define MARISA_USE_POPCNT #endif // MARISA_USE_POPCNT #endif // MARISA_USE_SSE4A #ifdef MARISA_USE_SSE4 #ifndef MARISA_USE_SSE4_2 #define MARISA_USE_SSE4_2 #endif // MARISA_USE_SSE4_2 #endif // MARISA_USE_SSE4 #ifdef MARISA_USE_SSE4_2 #ifndef MARISA_USE_SSE4_1 #define MARISA_USE_SSE4_1 #endif // MARISA_USE_SSE4_1 #ifndef MARISA_USE_POPCNT #define MARISA_USE_POPCNT #endif // MARISA_USE_POPCNT #endif // MARISA_USE_SSE4_2 #ifdef MARISA_USE_SSE4_1 #ifndef MARISA_USE_SSSE3 #define MARISA_USE_SSSE3 #endif // MARISA_USE_SSSE3 #endif // MARISA_USE_SSE4_1 #ifdef MARISA_USE_POPCNT #ifndef MARISA_USE_SSE3 #define MARISA_USE_SSE3 #endif // MARISA_USE_SSE3 #ifdef _MSC_VER #include #else // _MSC_VER #include #endif // _MSC_VER #endif // MARISA_USE_POPCNT #ifdef MARISA_USE_SSSE3 #ifndef MARISA_USE_SSE3 #define MARISA_USE_SSE3 #endif // MARISA_USE_SSE3 #ifdef MARISA_X64 #define MARISA_X64_SSSE3 #else // MARISA_X64 #define MARISA_X86_SSSE3 #endif // MAIRSA_X64 #include #endif // MARISA_USE_SSSE3 #ifdef MARISA_USE_SSE3 #ifndef MARISA_USE_SSE2 #define MARISA_USE_SSE2 #endif // MARISA_USE_SSE2 #endif // MARISA_USE_SSE3 #ifdef MARISA_USE_SSE2 #ifdef MARISA_X64 #define MARISA_X64_SSE2 #else // MARISA_X64 #define MARISA_X86_SSE2 #endif // MAIRSA_X64 #include #endif // MARISA_USE_SSE2 #ifdef _MSC_VER #if MARISA_WORD_SIZE == 64 #include #pragma intrinsic(_BitScanForward64) #else // MARISA_WORD_SIZE == 64 #include #pragma intrinsic(_BitScanForward) #endif // MARISA_WORD_SIZE == 64 #endif // _MSC_VER #if defined(__aarch64__) #define MARISA_AARCH64 #include #endif #endif // MARISA_GRIMOIRE_INTRIN_H_ marisa-trie-master/lib/marisa/grimoire/io.h000066400000000000000000000005131505027263100212030ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_IO_H_ #define MARISA_GRIMOIRE_IO_H_ #include "marisa/grimoire/io/mapper.h" #include "marisa/grimoire/io/reader.h" #include "marisa/grimoire/io/writer.h" namespace marisa::grimoire { using io::Mapper; using io::Reader; using io::Writer; } // namespace marisa::grimoire #endif // MARISA_GRIMOIRE_IO_H_ marisa-trie-master/lib/marisa/grimoire/io/000077500000000000000000000000001505027263100210335ustar00rootroot00000000000000marisa-trie-master/lib/marisa/grimoire/io/mapper.cc000066400000000000000000000122711505027263100226310ustar00rootroot00000000000000#if (defined _WIN32) || (defined _WIN64) #include #include #include #else // (defined _WIN32) || (defined _WIN64) #include #include #include #include #include #endif // (defined _WIN32) || (defined _WIN64) #include #include #include "marisa/grimoire/io/mapper.h" namespace marisa::grimoire::io { #if (defined _WIN32) || (defined _WIN64) Mapper::Mapper() = default; #else // (defined _WIN32) || (defined _WIN64) // mmap() returns MAP_FAILED on failure. Mapper::Mapper() : origin_(MAP_FAILED) {} #endif // (defined _WIN32) || (defined _WIN64) #if (defined _WIN32) || (defined _WIN64) Mapper::~Mapper() { if (origin_ != nullptr) { ::UnmapViewOfFile(origin_); } if (map_ != nullptr) { ::CloseHandle(map_); } if (file_ != nullptr) { ::CloseHandle(file_); } } #else // (defined _WIN32) || (defined _WIN64) Mapper::~Mapper() { if (origin_ != MAP_FAILED) { ::munmap(origin_, size_); } if (fd_ != -1) { ::close(fd_); } } #endif // (defined _WIN32) || (defined _WIN64) void Mapper::open(const char *filename, int flags) { MARISA_THROW_IF(filename == nullptr, std::invalid_argument); Mapper temp; temp.open_(filename, flags); swap(temp); } void Mapper::open(const void *ptr, std::size_t size) { MARISA_THROW_IF((ptr == nullptr) && (size != 0), std::invalid_argument); Mapper temp; temp.open_(ptr, size); swap(temp); } void Mapper::seek(std::size_t size) { MARISA_THROW_IF(!is_open(), std::logic_error); MARISA_THROW_IF(size > avail_, std::runtime_error); map_data(size); } bool Mapper::is_open() const { return ptr_ != nullptr; } void Mapper::clear() noexcept { Mapper().swap(*this); } void Mapper::swap(Mapper &rhs) noexcept { std::swap(ptr_, rhs.ptr_); std::swap(avail_, rhs.avail_); std::swap(origin_, rhs.origin_); std::swap(size_, rhs.size_); #if (defined _WIN32) || (defined _WIN64) std::swap(file_, rhs.file_); std::swap(map_, rhs.map_); #else // (defined _WIN32) || (defined _WIN64) std::swap(fd_, rhs.fd_); #endif // (defined _WIN32) || (defined _WIN64) } const void *Mapper::map_data(std::size_t size) { MARISA_THROW_IF(!is_open(), std::logic_error); MARISA_THROW_IF(size > avail_, std::runtime_error); const char *const data = static_cast(ptr_); ptr_ = data + size; avail_ -= size; return data; } #if (defined _WIN32) || (defined _WIN64) #ifdef __MSVCRT_VERSION__ #if __MSVCRT_VERSION__ >= 0x0601 #define MARISA_HAS_STAT64 #endif // __MSVCRT_VERSION__ >= 0x0601 #endif // __MSVCRT_VERSION__ void Mapper::open_(const char *filename, int flags) { file_ = ::CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); MARISA_THROW_SYSTEM_ERROR_IF(file_ == INVALID_HANDLE_VALUE, ::GetLastError(), std::system_category(), "CreateFileA"); DWORD size_high, size_low; size_low = ::GetFileSize(file_, &size_high); MARISA_THROW_SYSTEM_ERROR_IF(size_low == INVALID_FILE_SIZE, ::GetLastError(), std::system_category(), "GetFileSize"); size_ = (std::size_t{size_high} << 32) | size_low; map_ = ::CreateFileMapping(file_, nullptr, PAGE_READONLY, 0, 0, nullptr); MARISA_THROW_SYSTEM_ERROR_IF(map_ == nullptr, ::GetLastError(), std::system_category(), "CreateFileMapping"); origin_ = ::MapViewOfFile(map_, FILE_MAP_READ, 0, 0, 0); MARISA_THROW_SYSTEM_ERROR_IF(origin_ == nullptr, ::GetLastError(), std::system_category(), "MapViewOfFile"); if (flags & MARISA_MAP_POPULATE) { WIN32_MEMORY_RANGE_ENTRY range_entry; range_entry.VirtualAddress = origin_; range_entry.NumberOfBytes = size_; ::PrefetchVirtualMemory(GetCurrentProcess(), 1, &range_entry, 0); } ptr_ = static_cast(origin_); avail_ = size_; } #else // (defined _WIN32) || (defined _WIN64) void Mapper::open_(const char *filename, int flags) { fd_ = ::open(filename, O_RDONLY); MARISA_THROW_SYSTEM_ERROR_IF(fd_ == -1, errno, std::generic_category(), "open"); struct stat st; MARISA_THROW_SYSTEM_ERROR_IF(::fstat(fd_, &st) != 0, errno, std::generic_category(), "fstat"); MARISA_THROW_IF(static_cast(st.st_size) > SIZE_MAX, std::runtime_error); size_ = static_cast(st.st_size); int map_flags = MAP_SHARED; if (flags & MARISA_MAP_POPULATE) { #if defined(MAP_POPULATE) // `MAP_POPULATE` is Linux-specific. map_flags |= MAP_POPULATE; #elif defined(MAP_PREFAULT_READ) // `MAP_PREFAULT_READ` is FreeBSD-specific. map_flags |= MAP_PREFAULT_READ; #endif } origin_ = ::mmap(nullptr, size_, PROT_READ, map_flags, fd_, 0); MARISA_THROW_SYSTEM_ERROR_IF(origin_ == MAP_FAILED, errno, std::generic_category(), "mmap"); ptr_ = static_cast(origin_); avail_ = size_; } #endif // (defined _WIN32) || (defined _WIN64) void Mapper::open_(const void *ptr, std::size_t size) { ptr_ = ptr; avail_ = size; } } // namespace marisa::grimoire::io marisa-trie-master/lib/marisa/grimoire/io/mapper.h000066400000000000000000000030321505027263100224660ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_IO_MAPPER_H_ #define MARISA_GRIMOIRE_IO_MAPPER_H_ #include #include #include "marisa/base.h" namespace marisa::grimoire::io { class Mapper { public: Mapper(); ~Mapper(); Mapper(const Mapper &) = delete; Mapper &operator=(const Mapper &) = delete; void open(const char *filename, int flags = 0); void open(const void *ptr, std::size_t size); template void map(T *obj) { MARISA_THROW_IF(obj == nullptr, std::invalid_argument); *obj = *static_cast(map_data(sizeof(T))); } template void map(const T **objs, std::size_t num_objs) { MARISA_THROW_IF((objs == nullptr) && (num_objs != 0), std::invalid_argument); MARISA_THROW_IF(num_objs > (SIZE_MAX / sizeof(T)), std::invalid_argument); *objs = static_cast(map_data(sizeof(T) * num_objs)); } void seek(std::size_t size); bool is_open() const; void clear() noexcept; void swap(Mapper &rhs) noexcept; private: const void *ptr_ = nullptr; void *origin_ = nullptr; std::size_t avail_ = 0; std::size_t size_ = 0; #if (defined _WIN32) || (defined _WIN64) void *file_ = nullptr; void *map_ = nullptr; #else // (defined _WIN32) || (defined _WIN64) int fd_ = -1; #endif // (defined _WIN32) || (defined _WIN64) void open_(const char *filename, int flags); void open_(const void *ptr, std::size_t size); const void *map_data(std::size_t size); }; } // namespace marisa::grimoire::io #endif // MARISA_GRIMOIRE_IO_MAPPER_H_ marisa-trie-master/lib/marisa/grimoire/io/reader.cc000066400000000000000000000072171505027263100226130ustar00rootroot00000000000000#ifdef _WIN32 #include #else // _WIN32 #include #endif // _WIN32 #include #include #include #include "marisa/grimoire/io/reader.h" namespace marisa::grimoire::io { Reader::Reader() = default; Reader::~Reader() { if (needs_fclose_) { std::fclose(file_); } } void Reader::open(const char *filename) { MARISA_THROW_IF(filename == nullptr, std::invalid_argument); Reader temp; temp.open_(filename); swap(temp); } void Reader::open(std::FILE *file) { MARISA_THROW_IF(file == nullptr, std::invalid_argument); Reader temp; temp.open_(file); swap(temp); } void Reader::open(int fd) { MARISA_THROW_IF(fd == -1, std::invalid_argument); Reader temp; temp.open_(fd); swap(temp); } void Reader::open(std::istream &stream) { Reader temp; temp.open_(stream); swap(temp); } void Reader::clear() noexcept { Reader().swap(*this); } void Reader::swap(Reader &rhs) noexcept { std::swap(file_, rhs.file_); std::swap(fd_, rhs.fd_); std::swap(stream_, rhs.stream_); std::swap(needs_fclose_, rhs.needs_fclose_); } void Reader::seek(std::size_t size) { MARISA_THROW_IF(!is_open(), std::logic_error); if (size == 0) { return; } if (size <= 16) { char buf[16]; read_data(buf, size); } else { char buf[1024]; while (size != 0) { const std::size_t count = (size < sizeof(buf)) ? size : sizeof(buf); read_data(buf, count); size -= count; } } } bool Reader::is_open() const { return (file_ != nullptr) || (fd_ != -1) || (stream_ != nullptr); } void Reader::open_(const char *filename) { std::FILE *file = nullptr; #ifdef _MSC_VER const errno_t error_value = ::fopen_s(&file, filename, "rb"); MARISA_THROW_SYSTEM_ERROR_IF(error_value != 0, error_value, std::generic_category(), "fopen_s"); #else // _MSC_VER file = std::fopen(filename, "rb"); MARISA_THROW_SYSTEM_ERROR_IF(file == nullptr, errno, std::generic_category(), "std::fopen"); #endif // _MSC_VER file_ = file; needs_fclose_ = true; } void Reader::open_(std::FILE *file) { file_ = file; } void Reader::open_(int fd) { fd_ = fd; } void Reader::open_(std::istream &stream) { stream_ = &stream; } void Reader::read_data(void *buf, std::size_t size) { MARISA_THROW_IF(!is_open(), std::logic_error); if (size == 0) { return; } if (fd_ != -1) { while (size != 0) { #ifdef _WIN32 constexpr std::size_t CHUNK_SIZE = std::numeric_limits::max(); const unsigned int count = (size < CHUNK_SIZE) ? size : CHUNK_SIZE; const int size_read = ::_read(fd_, buf, count); MARISA_THROW_SYSTEM_ERROR_IF(size_read <= 0, errno, std::generic_category(), "_read"); #else // _WIN32 constexpr std::size_t CHUNK_SIZE = std::numeric_limits< ::ssize_t>::max(); const ::size_t count = (size < CHUNK_SIZE) ? size : CHUNK_SIZE; const ::ssize_t size_read = ::read(fd_, buf, count); MARISA_THROW_SYSTEM_ERROR_IF(size_read <= 0, errno, std::generic_category(), "read"); #endif // _WIN32 buf = static_cast(buf) + size_read; size -= static_cast(size_read); } } else if (file_ != nullptr) { MARISA_THROW_SYSTEM_ERROR_IF(std::fread(buf, 1, size, file_) != size, errno, std::generic_category(), "std::fread"); } else if (stream_ != nullptr) { MARISA_THROW_IF(!stream_->read(static_cast(buf), static_cast(size)), std::runtime_error); } } } // namespace marisa::grimoire::io marisa-trie-master/lib/marisa/grimoire/io/reader.h000066400000000000000000000025501505027263100224500ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_IO_READER_H_ #define MARISA_GRIMOIRE_IO_READER_H_ #include #include #include #include "marisa/base.h" namespace marisa::grimoire::io { class Reader { public: Reader(); ~Reader(); Reader(const Reader &) = delete; Reader &operator=(const Reader &) = delete; void open(const char *filename); void open(std::FILE *file); void open(int fd); void open(std::istream &stream); template void read(T *obj) { MARISA_THROW_IF(obj == nullptr, std::invalid_argument); read_data(obj, sizeof(T)); } template void read(T *objs, std::size_t num_objs) { MARISA_THROW_IF((objs == nullptr) && (num_objs != 0), std::invalid_argument); MARISA_THROW_IF(num_objs > (SIZE_MAX / sizeof(T)), std::invalid_argument); read_data(objs, sizeof(T) * num_objs); } void seek(std::size_t size); bool is_open() const; void clear() noexcept; void swap(Reader &rhs) noexcept; private: std::FILE *file_ = nullptr; int fd_ = -1; std::istream *stream_ = nullptr; bool needs_fclose_ = false; void open_(const char *filename); void open_(std::FILE *file); void open_(int fd); void open_(std::istream &stream); void read_data(void *buf, std::size_t size); }; } // namespace marisa::grimoire::io #endif // MARISA_GRIMOIRE_IO_READER_H_ marisa-trie-master/lib/marisa/grimoire/io/writer.cc000066400000000000000000000076461505027263100226730ustar00rootroot00000000000000#ifdef _WIN32 #include #else // _WIN32 #include #endif // _WIN32 #include #include #include #include "marisa/grimoire/io/writer.h" namespace marisa::grimoire::io { Writer::Writer() = default; Writer::~Writer() { if (needs_fclose_) { std::fclose(file_); } } void Writer::open(const char *filename) { MARISA_THROW_IF(filename == nullptr, std::invalid_argument); Writer temp; temp.open_(filename); swap(temp); } void Writer::open(std::FILE *file) { MARISA_THROW_IF(file == nullptr, std::invalid_argument); Writer temp; temp.open_(file); swap(temp); } void Writer::open(int fd) { MARISA_THROW_IF(fd == -1, std::invalid_argument); Writer temp; temp.open_(fd); swap(temp); } void Writer::open(std::ostream &stream) { Writer temp; temp.open_(stream); swap(temp); } void Writer::clear() noexcept { Writer().swap(*this); } void Writer::swap(Writer &rhs) noexcept { std::swap(file_, rhs.file_); std::swap(fd_, rhs.fd_); std::swap(stream_, rhs.stream_); std::swap(needs_fclose_, rhs.needs_fclose_); } void Writer::seek(std::size_t size) { MARISA_THROW_IF(!is_open(), std::logic_error); if (size == 0) { return; } if (size <= 16) { const char buf[16] = {}; write_data(buf, size); } else { const char buf[1024] = {}; do { const std::size_t count = (size < sizeof(buf)) ? size : sizeof(buf); write_data(buf, count); size -= count; } while (size != 0); } } bool Writer::is_open() const { return (file_ != nullptr) || (fd_ != -1) || (stream_ != nullptr); } void Writer::open_(const char *filename) { std::FILE *file = nullptr; #ifdef _MSC_VER const errno_t error_value = ::fopen_s(&file, filename, "wb"); MARISA_THROW_SYSTEM_ERROR_IF(error_value != 0, error_value, std::generic_category(), "fopen_s"); #else // _MSC_VER file = std::fopen(filename, "wb"); MARISA_THROW_SYSTEM_ERROR_IF(file == nullptr, errno, std::generic_category(), "std::fopen"); #endif // _MSC_VER file_ = file; needs_fclose_ = true; } void Writer::open_(std::FILE *file) { file_ = file; } void Writer::open_(int fd) { fd_ = fd; } void Writer::open_(std::ostream &stream) { stream_ = &stream; } void Writer::write_data(const void *data, std::size_t size) { MARISA_THROW_IF(!is_open(), std::logic_error); if (size == 0) { return; } if (fd_ != -1) { while (size != 0) { #ifdef _WIN32 constexpr std::size_t CHUNK_SIZE = std::numeric_limits::max(); const unsigned int count = (size < CHUNK_SIZE) ? size : CHUNK_SIZE; const int size_written = ::_write(fd_, data, count); MARISA_THROW_SYSTEM_ERROR_IF(size_written <= 0, errno, std::generic_category(), "_write"); #else // _WIN32 constexpr std::size_t CHUNK_SIZE = std::numeric_limits< ::ssize_t>::max(); const ::size_t count = (size < CHUNK_SIZE) ? size : CHUNK_SIZE; const ::ssize_t size_written = ::write(fd_, data, count); MARISA_THROW_SYSTEM_ERROR_IF(size_written <= 0, errno, std::generic_category(), "write"); #endif // _WIN32 data = static_cast(data) + size_written; size -= static_cast(size_written); } } else if (file_ != nullptr) { MARISA_THROW_SYSTEM_ERROR_IF(std::fwrite(data, 1, size, file_) != size, errno, std::generic_category(), "std::fwrite"); MARISA_THROW_SYSTEM_ERROR_IF(std::fflush(file_) != 0, errno, std::generic_category(), "std::fflush"); } else if (stream_ != nullptr) { MARISA_THROW_IF(!stream_->write(static_cast(data), static_cast(size)), std::runtime_error); MARISA_THROW_IF(!stream_->flush(), std::runtime_error); } } } // namespace marisa::grimoire::io marisa-trie-master/lib/marisa/grimoire/io/writer.h000066400000000000000000000025051505027263100225220ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_IO_WRITER_H_ #define MARISA_GRIMOIRE_IO_WRITER_H_ #include #include #include #include "marisa/base.h" namespace marisa::grimoire::io { class Writer { public: Writer(); ~Writer(); Writer(const Writer &) = delete; Writer &operator=(const Writer &) = delete; void open(const char *filename); void open(std::FILE *file); void open(int fd); void open(std::ostream &stream); template void write(const T &obj) { write_data(&obj, sizeof(T)); } template void write(const T *objs, std::size_t num_objs) { MARISA_THROW_IF((objs == nullptr) && (num_objs != 0), std::invalid_argument); MARISA_THROW_IF(num_objs > (SIZE_MAX / sizeof(T)), std::invalid_argument); write_data(objs, sizeof(T) * num_objs); } void seek(std::size_t size); bool is_open() const; void clear() noexcept; void swap(Writer &rhs) noexcept; private: std::FILE *file_ = nullptr; int fd_ = -1; std::ostream *stream_ = nullptr; bool needs_fclose_ = false; void open_(const char *filename); void open_(std::FILE *file); void open_(int fd); void open_(std::ostream &stream); void write_data(const void *data, std::size_t size); }; } // namespace marisa::grimoire::io #endif // MARISA_GRIMOIRE_IO_WRITER_H_ marisa-trie-master/lib/marisa/grimoire/trie.h000066400000000000000000000004451505027263100215430ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_H_ #define MARISA_GRIMOIRE_TRIE_H_ #include "marisa/grimoire/trie/louds-trie.h" #include "marisa/grimoire/trie/state.h" namespace marisa::grimoire { using trie::LoudsTrie; using trie::State; } // namespace marisa::grimoire #endif // MARISA_GRIMOIRE_TRIE_H_ marisa-trie-master/lib/marisa/grimoire/trie/000077500000000000000000000000001505027263100213675ustar00rootroot00000000000000marisa-trie-master/lib/marisa/grimoire/trie/cache.h000066400000000000000000000027521505027263100226110ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_CACHE_H_ #define MARISA_GRIMOIRE_TRIE_CACHE_H_ #include #include #include "marisa/base.h" namespace marisa::grimoire::trie { class Cache { public: Cache() = default; Cache(const Cache &cache) = default; Cache &operator=(const Cache &cache) = default; void set_parent(std::size_t parent) { assert(parent <= UINT32_MAX); parent_ = static_cast(parent); } void set_child(std::size_t child) { assert(child <= UINT32_MAX); child_ = static_cast(child); } void set_base(uint8_t base) { union_.link = (union_.link & ~0xFFU) | base; } void set_extra(std::size_t extra) { assert(extra <= (UINT32_MAX >> 8)); union_.link = static_cast((union_.link & 0xFFU) | (extra << 8)); } void set_weight(float weight) { union_.weight = weight; } std::size_t parent() const { return parent_; } std::size_t child() const { return child_; } uint8_t base() const { return static_cast(union_.link & 0xFFU); } std::size_t extra() const { return union_.link >> 8; } char label() const { return static_cast(base()); } std::size_t link() const { return union_.link; } float weight() const { return union_.weight; } private: uint32_t parent_ = 0; uint32_t child_ = 0; union Union { uint32_t link; float weight = FLT_MIN; } union_; }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_CACHE_H_ marisa-trie-master/lib/marisa/grimoire/trie/config.h000066400000000000000000000067061505027263100230160ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_CONFIG_H_ #define MARISA_GRIMOIRE_TRIE_CONFIG_H_ #include #include "marisa/base.h" namespace marisa::grimoire::trie { class Config { public: Config() = default; Config(const Config &) = delete; Config &operator=(const Config &) = delete; void parse(int config_flags) { Config temp; temp.parse_(config_flags); swap(temp); } int flags() const { return static_cast(num_tries_) | tail_mode_ | node_order_; } std::size_t num_tries() const { return num_tries_; } CacheLevel cache_level() const { return cache_level_; } TailMode tail_mode() const { return tail_mode_; } NodeOrder node_order() const { return node_order_; } void clear() noexcept { Config().swap(*this); } void swap(Config &rhs) noexcept { std::swap(num_tries_, rhs.num_tries_); std::swap(cache_level_, rhs.cache_level_); std::swap(tail_mode_, rhs.tail_mode_); std::swap(node_order_, rhs.node_order_); } private: std::size_t num_tries_ = MARISA_DEFAULT_NUM_TRIES; CacheLevel cache_level_ = MARISA_DEFAULT_CACHE; TailMode tail_mode_ = MARISA_DEFAULT_TAIL; NodeOrder node_order_ = MARISA_DEFAULT_ORDER; void parse_(int config_flags) { MARISA_THROW_IF((config_flags & ~MARISA_CONFIG_MASK) != 0, std::invalid_argument); parse_num_tries(config_flags); parse_cache_level(config_flags); parse_tail_mode(config_flags); parse_node_order(config_flags); } void parse_num_tries(int config_flags) { const int num_tries = config_flags & MARISA_NUM_TRIES_MASK; if (num_tries != 0) { num_tries_ = static_cast(num_tries); } } void parse_cache_level(int config_flags) { switch (config_flags & MARISA_CACHE_LEVEL_MASK) { case 0: { cache_level_ = MARISA_DEFAULT_CACHE; break; } case MARISA_HUGE_CACHE: { cache_level_ = MARISA_HUGE_CACHE; break; } case MARISA_LARGE_CACHE: { cache_level_ = MARISA_LARGE_CACHE; break; } case MARISA_NORMAL_CACHE: { cache_level_ = MARISA_NORMAL_CACHE; break; } case MARISA_SMALL_CACHE: { cache_level_ = MARISA_SMALL_CACHE; break; } case MARISA_TINY_CACHE: { cache_level_ = MARISA_TINY_CACHE; break; } default: { MARISA_THROW(std::invalid_argument, "undefined cache level"); } } } void parse_tail_mode(int config_flags) { switch (config_flags & MARISA_TAIL_MODE_MASK) { case 0: { tail_mode_ = MARISA_DEFAULT_TAIL; break; } case MARISA_TEXT_TAIL: { tail_mode_ = MARISA_TEXT_TAIL; break; } case MARISA_BINARY_TAIL: { tail_mode_ = MARISA_BINARY_TAIL; break; } default: { MARISA_THROW(std::invalid_argument, "undefined tail mode"); } } } void parse_node_order(int config_flags) { switch (config_flags & MARISA_NODE_ORDER_MASK) { case 0: { node_order_ = MARISA_DEFAULT_ORDER; break; } case MARISA_LABEL_ORDER: { node_order_ = MARISA_LABEL_ORDER; break; } case MARISA_WEIGHT_ORDER: { node_order_ = MARISA_WEIGHT_ORDER; break; } default: { MARISA_THROW(std::invalid_argument, "undefined node order"); } } } }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_CONFIG_H_ marisa-trie-master/lib/marisa/grimoire/trie/entry.h000066400000000000000000000030571505027263100227060ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_ENTRY_H_ #define MARISA_GRIMOIRE_TRIE_ENTRY_H_ #include #include "marisa/base.h" namespace marisa::grimoire::trie { class Entry { public: Entry() = default; Entry(const Entry &entry) = default; Entry &operator=(const Entry &entry) = default; char operator[](std::size_t i) const { assert(i < length_); return *(ptr_ - i); } void set_str(const char *ptr, std::size_t length) { assert((ptr != nullptr) || (length == 0)); assert(length <= UINT32_MAX); ptr_ = ptr + length - 1; length_ = static_cast(length); } void set_id(std::size_t id) { assert(id <= UINT32_MAX); id_ = static_cast(id); } const char *ptr() const { return ptr_ - length_ + 1; } std::size_t length() const { return length_; } std::size_t id() const { return id_; } class StringComparer { public: bool operator()(const Entry &lhs, const Entry &rhs) const { for (std::size_t i = 0; i < lhs.length(); ++i) { if (i == rhs.length()) { return true; } if (lhs[i] != rhs[i]) { return static_cast(lhs[i]) > static_cast(rhs[i]); } } return lhs.length() > rhs.length(); } }; class IDComparer { public: bool operator()(const Entry &lhs, const Entry &rhs) const { return lhs.id_ < rhs.id_; } }; private: const char *ptr_ = nullptr; uint32_t length_ = 0; uint32_t id_ = 0; }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_ENTRY_H_ marisa-trie-master/lib/marisa/grimoire/trie/header.h000066400000000000000000000022521505027263100227710ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_HEADER_H_ #define MARISA_GRIMOIRE_TRIE_HEADER_H_ #include #include "marisa/grimoire/io.h" namespace marisa::grimoire::trie { class Header { public: enum { HEADER_SIZE = 16 }; Header() = default; Header(const Header &) = delete; Header &operator=(const Header &) = delete; void map(Mapper &mapper) { const char *ptr; mapper.map(&ptr, HEADER_SIZE); MARISA_THROW_IF(!test_header(ptr), std::runtime_error); } void read(Reader &reader) { char buf[HEADER_SIZE]; reader.read(buf, HEADER_SIZE); MARISA_THROW_IF(!test_header(buf), std::runtime_error); } void write(Writer &writer) const { writer.write(get_header(), HEADER_SIZE); } std::size_t io_size() const { return HEADER_SIZE; } private: static const char *get_header() { static const char buf[HEADER_SIZE] = "We love Marisa."; return buf; } static bool test_header(const char *ptr) { for (std::size_t i = 0; i < HEADER_SIZE; ++i) { if (ptr[i] != get_header()[i]) { return false; } } return true; } }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_HEADER_H_ marisa-trie-master/lib/marisa/grimoire/trie/history.h000066400000000000000000000026241505027263100232450ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_STATE_HISTORY_H_ #define MARISA_GRIMOIRE_TRIE_STATE_HISTORY_H_ #include #include "marisa/base.h" namespace marisa::grimoire::trie { class History { public: History() = default; void set_node_id(std::size_t node_id) { assert(node_id <= UINT32_MAX); node_id_ = static_cast(node_id); } void set_louds_pos(std::size_t louds_pos) { assert(louds_pos <= UINT32_MAX); louds_pos_ = static_cast(louds_pos); } void set_key_pos(std::size_t key_pos) { assert(key_pos <= UINT32_MAX); key_pos_ = static_cast(key_pos); } void set_link_id(std::size_t link_id) { assert(link_id <= UINT32_MAX); link_id_ = static_cast(link_id); } void set_key_id(std::size_t key_id) { assert(key_id <= UINT32_MAX); key_id_ = static_cast(key_id); } std::size_t node_id() const { return node_id_; } std::size_t louds_pos() const { return louds_pos_; } std::size_t key_pos() const { return key_pos_; } std::size_t link_id() const { return link_id_; } std::size_t key_id() const { return key_id_; } private: uint32_t node_id_ = 0; uint32_t louds_pos_ = 0; uint32_t key_pos_ = 0; uint32_t link_id_ = MARISA_INVALID_LINK_ID; uint32_t key_id_ = MARISA_INVALID_KEY_ID; }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_STATE_HISTORY_H_ marisa-trie-master/lib/marisa/grimoire/trie/key.h000066400000000000000000000107051505027263100223330ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_KEY_H_ #define MARISA_GRIMOIRE_TRIE_KEY_H_ #include #include "marisa/base.h" namespace marisa::grimoire::trie { class Key { public: Key() = default; Key(const Key &entry) = default; Key &operator=(const Key &entry) = default; char operator[](std::size_t i) const { assert(i < length_); return ptr_[i]; } void substr(std::size_t pos, std::size_t length) { assert(pos <= length_); assert(length <= length_); assert(pos <= (length_ - length)); ptr_ += pos; length_ = static_cast(length); } void set_str(const char *ptr, std::size_t length) { assert((ptr != nullptr) || (length == 0)); assert(length <= UINT32_MAX); ptr_ = ptr; length_ = static_cast(length); } void set_weight(float weight) { union_.weight = weight; } void set_terminal(std::size_t terminal) { assert(terminal <= UINT32_MAX); union_.terminal = static_cast(terminal); } void set_id(std::size_t id) { assert(id <= UINT32_MAX); id_ = static_cast(id); } const char *ptr() const { return ptr_; } std::size_t length() const { return length_; } float weight() const { return union_.weight; } std::size_t terminal() const { return union_.terminal; } std::size_t id() const { return id_; } private: const char *ptr_ = nullptr; uint32_t length_ = 0; union Union { float weight; uint32_t terminal = 0; } union_; uint32_t id_ = 0; }; inline bool operator==(const Key &lhs, const Key &rhs) { if (lhs.length() != rhs.length()) { return false; } for (std::size_t i = 0; i < lhs.length(); ++i) { if (lhs[i] != rhs[i]) { return false; } } return true; } inline bool operator!=(const Key &lhs, const Key &rhs) { return !(lhs == rhs); } inline bool operator<(const Key &lhs, const Key &rhs) { for (std::size_t i = 0; i < lhs.length(); ++i) { if (i == rhs.length()) { return false; } if (lhs[i] != rhs[i]) { return static_cast(lhs[i]) < static_cast(rhs[i]); } } return lhs.length() < rhs.length(); } inline bool operator>(const Key &lhs, const Key &rhs) { return rhs < lhs; } class ReverseKey { public: ReverseKey() = default; ReverseKey(const ReverseKey &entry) = default; ReverseKey &operator=(const ReverseKey &entry) = default; char operator[](std::size_t i) const { assert(i < length_); return *(ptr_ - i - 1); } void substr(std::size_t pos, std::size_t length) { assert(pos <= length_); assert(length <= length_); assert(pos <= (length_ - length)); ptr_ -= pos; length_ = static_cast(length); } void set_str(const char *ptr, std::size_t length) { assert((ptr != nullptr) || (length == 0)); assert(length <= UINT32_MAX); ptr_ = ptr + length; length_ = static_cast(length); } void set_weight(float weight) { union_.weight = weight; } void set_terminal(std::size_t terminal) { assert(terminal <= UINT32_MAX); union_.terminal = static_cast(terminal); } void set_id(std::size_t id) { assert(id <= UINT32_MAX); id_ = static_cast(id); } const char *ptr() const { return ptr_ - length_; } std::size_t length() const { return length_; } float weight() const { return union_.weight; } std::size_t terminal() const { return union_.terminal; } std::size_t id() const { return id_; } private: const char *ptr_ = nullptr; uint32_t length_ = 0; union Union { float weight; uint32_t terminal = 0; } union_; uint32_t id_ = 0; }; inline bool operator==(const ReverseKey &lhs, const ReverseKey &rhs) { if (lhs.length() != rhs.length()) { return false; } for (std::size_t i = 0; i < lhs.length(); ++i) { if (lhs[i] != rhs[i]) { return false; } } return true; } inline bool operator!=(const ReverseKey &lhs, const ReverseKey &rhs) { return !(lhs == rhs); } inline bool operator<(const ReverseKey &lhs, const ReverseKey &rhs) { for (std::size_t i = 0; i < lhs.length(); ++i) { if (i == rhs.length()) { return false; } if (lhs[i] != rhs[i]) { return static_cast(lhs[i]) < static_cast(rhs[i]); } } return lhs.length() < rhs.length(); } inline bool operator>(const ReverseKey &lhs, const ReverseKey &rhs) { return rhs < lhs; } } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_KEY_H_ marisa-trie-master/lib/marisa/grimoire/trie/louds-trie.cc000066400000000000000000000632761505027263100240030ustar00rootroot00000000000000#include "marisa/grimoire/trie/louds-trie.h" #include #include #include #include #include #include "marisa/grimoire/algorithm/sort.h" #include "marisa/grimoire/trie/header.h" #include "marisa/grimoire/trie/range.h" #include "marisa/grimoire/trie/state.h" namespace marisa::grimoire::trie { LoudsTrie::LoudsTrie() = default; LoudsTrie::~LoudsTrie() = default; void LoudsTrie::build(Keyset &keyset, int flags) { Config config; config.parse(flags); LoudsTrie temp; temp.build_(keyset, config); swap(temp); } void LoudsTrie::map(Mapper &mapper) { Header().map(mapper); LoudsTrie temp; temp.map_(mapper); temp.mapper_.swap(mapper); swap(temp); } void LoudsTrie::read(Reader &reader) { Header().read(reader); LoudsTrie temp; temp.read_(reader); swap(temp); } void LoudsTrie::write(Writer &writer) const { Header().write(writer); write_(writer); } bool LoudsTrie::lookup(Agent &agent) const { assert(agent.has_state()); State &state = agent.state(); state.lookup_init(); while (state.query_pos() < agent.query().length()) { if (!find_child(agent)) { return false; } } if (!terminal_flags_[state.node_id()]) { return false; } agent.set_key(agent.query().ptr(), agent.query().length()); agent.set_key(terminal_flags_.rank1(state.node_id())); return true; } void LoudsTrie::reverse_lookup(Agent &agent) const { assert(agent.has_state()); MARISA_THROW_IF(agent.query().id() >= size(), std::out_of_range); State &state = agent.state(); state.reverse_lookup_init(); state.set_node_id(terminal_flags_.select1(agent.query().id())); if (state.node_id() == 0) { agent.set_key(state.key_buf().data(), state.key_buf().size()); agent.set_key(agent.query().id()); return; } for (;;) { if (link_flags_[state.node_id()]) { const std::size_t prev_key_pos = state.key_buf().size(); restore(agent, get_link(state.node_id())); std::reverse( state.key_buf().begin() + static_cast(prev_key_pos), state.key_buf().end()); } else { state.key_buf().push_back(static_cast(bases_[state.node_id()])); } if (state.node_id() <= num_l1_nodes_) { std::reverse(state.key_buf().begin(), state.key_buf().end()); agent.set_key(state.key_buf().data(), state.key_buf().size()); agent.set_key(agent.query().id()); return; } state.set_node_id(louds_.select1(state.node_id()) - state.node_id() - 1); } } bool LoudsTrie::common_prefix_search(Agent &agent) const { assert(agent.has_state()); State &state = agent.state(); if (state.status_code() == MARISA_END_OF_COMMON_PREFIX_SEARCH) { return false; } if (state.status_code() != MARISA_READY_TO_COMMON_PREFIX_SEARCH) { state.common_prefix_search_init(); if (terminal_flags_[state.node_id()]) { agent.set_key(agent.query().ptr(), state.query_pos()); agent.set_key(terminal_flags_.rank1(state.node_id())); return true; } } while (state.query_pos() < agent.query().length()) { if (!find_child(agent)) { state.set_status_code(MARISA_END_OF_COMMON_PREFIX_SEARCH); return false; } if (terminal_flags_[state.node_id()]) { agent.set_key(agent.query().ptr(), state.query_pos()); agent.set_key(terminal_flags_.rank1(state.node_id())); return true; } } state.set_status_code(MARISA_END_OF_COMMON_PREFIX_SEARCH); return false; } bool LoudsTrie::predictive_search(Agent &agent) const { assert(agent.has_state()); State &state = agent.state(); if (state.status_code() == MARISA_END_OF_PREDICTIVE_SEARCH) { return false; } if (state.status_code() != MARISA_READY_TO_PREDICTIVE_SEARCH) { state.predictive_search_init(); while (state.query_pos() < agent.query().length()) { if (!predictive_find_child(agent)) { state.set_status_code(MARISA_END_OF_PREDICTIVE_SEARCH); return false; } } History history; history.set_node_id(state.node_id()); history.set_key_pos(state.key_buf().size()); state.history().push_back(history); state.set_history_pos(1); if (terminal_flags_[state.node_id()]) { agent.set_key(state.key_buf().data(), state.key_buf().size()); agent.set_key(terminal_flags_.rank1(state.node_id())); return true; } } for (;;) { if (state.history_pos() == state.history().size()) { const History ¤t = state.history().back(); History next; next.set_louds_pos(louds_.select0(current.node_id()) + 1); next.set_node_id(next.louds_pos() - current.node_id() - 1); state.history().push_back(next); } History &next = state.history()[state.history_pos()]; const bool link_flag = louds_[next.louds_pos()]; next.set_louds_pos(next.louds_pos() + 1); if (link_flag) { state.set_history_pos(state.history_pos() + 1); if (link_flags_[next.node_id()]) { next.set_link_id(update_link_id(next.link_id(), next.node_id())); restore(agent, get_link(next.node_id(), next.link_id())); } else { state.key_buf().push_back(static_cast(bases_[next.node_id()])); } next.set_key_pos(state.key_buf().size()); if (terminal_flags_[next.node_id()]) { if (next.key_id() == MARISA_INVALID_KEY_ID) { next.set_key_id(terminal_flags_.rank1(next.node_id())); } else { next.set_key_id(next.key_id() + 1); } agent.set_key(state.key_buf().data(), state.key_buf().size()); agent.set_key(next.key_id()); return true; } } else if (state.history_pos() != 1) { History ¤t = state.history()[state.history_pos() - 1]; current.set_node_id(current.node_id() + 1); const History &prev = state.history()[state.history_pos() - 2]; state.key_buf().resize(prev.key_pos()); state.set_history_pos(state.history_pos() - 1); } else { state.set_status_code(MARISA_END_OF_PREDICTIVE_SEARCH); return false; } } } std::size_t LoudsTrie::total_size() const { return louds_.total_size() + terminal_flags_.total_size() + link_flags_.total_size() + bases_.total_size() + extras_.total_size() + tail_.total_size() + ((next_trie_ != nullptr) ? next_trie_->total_size() : 0) + cache_.total_size(); } std::size_t LoudsTrie::io_size() const { return Header().io_size() + louds_.io_size() + terminal_flags_.io_size() + link_flags_.io_size() + bases_.io_size() + extras_.io_size() + tail_.io_size() + ((next_trie_ != nullptr) ? (next_trie_->io_size() - Header().io_size()) : 0) + cache_.io_size() + (sizeof(uint32_t) * 2); } void LoudsTrie::clear() noexcept { LoudsTrie().swap(*this); } void LoudsTrie::swap(LoudsTrie &rhs) noexcept { louds_.swap(rhs.louds_); terminal_flags_.swap(rhs.terminal_flags_); link_flags_.swap(rhs.link_flags_); bases_.swap(rhs.bases_); extras_.swap(rhs.extras_); tail_.swap(rhs.tail_); next_trie_.swap(rhs.next_trie_); cache_.swap(rhs.cache_); std::swap(cache_mask_, rhs.cache_mask_); std::swap(num_l1_nodes_, rhs.num_l1_nodes_); config_.swap(rhs.config_); mapper_.swap(rhs.mapper_); } void LoudsTrie::build_(Keyset &keyset, const Config &config) { Vector keys; keys.resize(keyset.size()); for (std::size_t i = 0; i < keyset.size(); ++i) { keys[i].set_str(keyset[i].ptr(), keyset[i].length()); keys[i].set_weight(keyset[i].weight()); } Vector terminals; build_trie(keys, &terminals, config, 1); using TerminalIdPair = std::pair; const std::size_t pairs_size = terminals.size(); std::unique_ptr pairs(new TerminalIdPair[pairs_size]); for (std::size_t i = 0; i < pairs_size; ++i) { pairs[i].first = terminals[i]; pairs[i].second = static_cast(i); } terminals.clear(); std::sort(pairs.get(), pairs.get() + pairs_size); std::size_t node_id = 0; for (std::size_t i = 0; i < pairs_size; ++i) { while (node_id < pairs[i].first) { terminal_flags_.push_back(false); ++node_id; } if (node_id == pairs[i].first) { terminal_flags_.push_back(true); ++node_id; } } while (node_id < bases_.size()) { terminal_flags_.push_back(false); ++node_id; } terminal_flags_.push_back(false); terminal_flags_.build(false, true); for (std::size_t i = 0; i < keyset.size(); ++i) { keyset[pairs[i].second].set_id(terminal_flags_.rank1(pairs[i].first)); } } template void LoudsTrie::build_trie(Vector &keys, Vector *terminals, const Config &config, std::size_t trie_id) { build_current_trie(keys, terminals, config, trie_id); Vector next_terminals; if (!keys.empty()) { build_next_trie(keys, &next_terminals, config, trie_id); } if (next_trie_ != nullptr) { config_.parse(static_cast((next_trie_->num_tries() + 1)) | next_trie_->tail_mode() | next_trie_->node_order()); } else { config_.parse(1 | tail_.mode() | config.node_order() | config.cache_level()); } link_flags_.build(false, false); std::size_t node_id = 0; for (std::size_t i = 0; i < next_terminals.size(); ++i) { while (!link_flags_[node_id]) { ++node_id; } bases_[node_id] = static_cast(next_terminals[i] % 256); next_terminals[i] /= 256; ++node_id; } extras_.build(next_terminals); fill_cache(); } template void LoudsTrie::build_current_trie(Vector &keys, Vector *terminals, const Config &config, std::size_t trie_id) { for (std::size_t i = 0; i < keys.size(); ++i) { keys[i].set_id(i); } const std::size_t num_keys = algorithm::sort(keys.begin(), keys.end()); reserve_cache(config, trie_id, num_keys); louds_.push_back(true); louds_.push_back(false); bases_.push_back('\0'); link_flags_.push_back(false); Vector next_keys; std::queue queue; Vector w_ranges; queue.push(make_range(0, keys.size(), 0)); while (!queue.empty()) { const std::size_t node_id = link_flags_.size() - queue.size(); Range range = queue.front(); queue.pop(); while ((range.begin() < range.end()) && (keys[range.begin()].length() == range.key_pos())) { keys[range.begin()].set_terminal(node_id); range.set_begin(range.begin() + 1); } if (range.begin() == range.end()) { louds_.push_back(false); continue; } w_ranges.clear(); double weight = double{keys[range.begin()].weight()}; for (std::size_t i = range.begin() + 1; i < range.end(); ++i) { if (keys[i - 1][range.key_pos()] != keys[i][range.key_pos()]) { w_ranges.push_back(make_weighted_range( range.begin(), i, range.key_pos(), static_cast(weight))); range.set_begin(i); weight = 0.0; } weight += double{keys[i].weight()}; } w_ranges.push_back(make_weighted_range(range.begin(), range.end(), range.key_pos(), static_cast(weight))); if (config.node_order() == MARISA_WEIGHT_ORDER) { std::stable_sort(w_ranges.begin(), w_ranges.end(), std::greater()); } if (node_id == 0) { num_l1_nodes_ = w_ranges.size(); } for (std::size_t i = 0; i < w_ranges.size(); ++i) { WeightedRange &w_range = w_ranges[i]; std::size_t key_pos = w_range.key_pos() + 1; while (key_pos < keys[w_range.begin()].length()) { std::size_t j; for (j = w_range.begin() + 1; j < w_range.end(); ++j) { if (keys[j - 1][key_pos] != keys[j][key_pos]) { break; } } if (j < w_range.end()) { break; } ++key_pos; } cache(node_id, bases_.size(), w_range.weight(), keys[w_range.begin()][w_range.key_pos()]); if (key_pos == w_range.key_pos() + 1) { bases_.push_back(static_cast( keys[w_range.begin()][w_range.key_pos()])); link_flags_.push_back(false); } else { bases_.push_back('\0'); link_flags_.push_back(true); T next_key; next_key.set_str(keys[w_range.begin()].ptr(), keys[w_range.begin()].length()); next_key.substr(w_range.key_pos(), key_pos - w_range.key_pos()); next_key.set_weight(w_range.weight()); next_keys.push_back(next_key); } w_range.set_key_pos(key_pos); queue.push(w_range.range()); louds_.push_back(true); } louds_.push_back(false); } louds_.push_back(false); louds_.build(trie_id == 1, true); bases_.shrink(); build_terminals(keys, terminals); keys.swap(next_keys); } template <> void LoudsTrie::build_next_trie(Vector &keys, Vector *terminals, const Config &config, std::size_t trie_id) { if (trie_id == config.num_tries()) { Vector entries; entries.resize(keys.size()); for (std::size_t i = 0; i < keys.size(); ++i) { entries[i].set_str(keys[i].ptr(), keys[i].length()); } tail_.build(entries, terminals, config.tail_mode()); return; } Vector reverse_keys; reverse_keys.resize(keys.size()); for (std::size_t i = 0; i < keys.size(); ++i) { reverse_keys[i].set_str(keys[i].ptr(), keys[i].length()); reverse_keys[i].set_weight(keys[i].weight()); } keys.clear(); next_trie_.reset(new LoudsTrie); next_trie_->build_trie(reverse_keys, terminals, config, trie_id + 1); } template <> void LoudsTrie::build_next_trie(Vector &keys, Vector *terminals, const Config &config, std::size_t trie_id) { if (trie_id == config.num_tries()) { Vector entries; entries.resize(keys.size()); for (std::size_t i = 0; i < keys.size(); ++i) { entries[i].set_str(keys[i].ptr(), keys[i].length()); } tail_.build(entries, terminals, config.tail_mode()); return; } next_trie_.reset(new LoudsTrie); next_trie_->build_trie(keys, terminals, config, trie_id + 1); } template void LoudsTrie::build_terminals(const Vector &keys, Vector *terminals) const { Vector temp; temp.resize(keys.size()); for (std::size_t i = 0; i < keys.size(); ++i) { temp[keys[i].id()] = static_cast(keys[i].terminal()); } terminals->swap(temp); } template <> void LoudsTrie::cache(std::size_t parent, std::size_t child, float weight, char label) { assert(parent < child); const std::size_t cache_id = get_cache_id(parent, label); if (weight > cache_[cache_id].weight()) { cache_[cache_id].set_parent(parent); cache_[cache_id].set_child(child); cache_[cache_id].set_weight(weight); } } void LoudsTrie::reserve_cache(const Config &config, std::size_t trie_id, std::size_t num_keys) { std::size_t cache_size = (trie_id == 1) ? 256 : 1; while (cache_size < (num_keys / config.cache_level())) { cache_size *= 2; } cache_.resize(cache_size); cache_mask_ = cache_size - 1; } template <> void LoudsTrie::cache(std::size_t parent, std::size_t child, float weight, char) { assert(parent < child); const std::size_t cache_id = get_cache_id(child); if (weight > cache_[cache_id].weight()) { cache_[cache_id].set_parent(parent); cache_[cache_id].set_child(child); cache_[cache_id].set_weight(weight); } } void LoudsTrie::fill_cache() { for (std::size_t i = 0; i < cache_.size(); ++i) { const std::size_t node_id = cache_[i].child(); if (node_id != 0) { cache_[i].set_base(bases_[node_id]); cache_[i].set_extra(!link_flags_[node_id] ? MARISA_INVALID_EXTRA : extras_[link_flags_.rank1(node_id)]); } else { cache_[i].set_parent(UINT32_MAX); cache_[i].set_child(UINT32_MAX); } } } void LoudsTrie::map_(Mapper &mapper) { louds_.map(mapper); terminal_flags_.map(mapper); link_flags_.map(mapper); bases_.map(mapper); extras_.map(mapper); tail_.map(mapper); if ((link_flags_.num_1s() != 0) && tail_.empty()) { next_trie_.reset(new LoudsTrie); next_trie_->map_(mapper); } cache_.map(mapper); cache_mask_ = cache_.size() - 1; { uint32_t temp_num_l1_nodes; mapper.map(&temp_num_l1_nodes); num_l1_nodes_ = temp_num_l1_nodes; } { uint32_t temp_config_flags; mapper.map(&temp_config_flags); config_.parse(static_cast(temp_config_flags)); } } void LoudsTrie::read_(Reader &reader) { louds_.read(reader); terminal_flags_.read(reader); link_flags_.read(reader); bases_.read(reader); extras_.read(reader); tail_.read(reader); if ((link_flags_.num_1s() != 0) && tail_.empty()) { next_trie_.reset(new LoudsTrie); next_trie_->read_(reader); } cache_.read(reader); cache_mask_ = cache_.size() - 1; { uint32_t temp_num_l1_nodes; reader.read(&temp_num_l1_nodes); num_l1_nodes_ = temp_num_l1_nodes; } { uint32_t temp_config_flags; reader.read(&temp_config_flags); config_.parse(static_cast(temp_config_flags)); } } void LoudsTrie::write_(Writer &writer) const { louds_.write(writer); terminal_flags_.write(writer); link_flags_.write(writer); bases_.write(writer); extras_.write(writer); tail_.write(writer); if (next_trie_ != nullptr) { next_trie_->write_(writer); } cache_.write(writer); writer.write(static_cast(num_l1_nodes_)); writer.write(static_cast(config_.flags())); } bool LoudsTrie::find_child(Agent &agent) const { assert(agent.state().query_pos() < agent.query().length()); State &state = agent.state(); const std::size_t cache_id = get_cache_id(state.node_id(), agent.query()[state.query_pos()]); if (state.node_id() == cache_[cache_id].parent()) { if (cache_[cache_id].extra() != MARISA_INVALID_EXTRA) { if (!match(agent, cache_[cache_id].link())) { return false; } } else { state.set_query_pos(state.query_pos() + 1); } state.set_node_id(cache_[cache_id].child()); return true; } std::size_t louds_pos = louds_.select0(state.node_id()) + 1; if (!louds_[louds_pos]) { return false; } state.set_node_id(louds_pos - state.node_id() - 1); std::size_t link_id = MARISA_INVALID_LINK_ID; do { if (link_flags_[state.node_id()]) { link_id = update_link_id(link_id, state.node_id()); const std::size_t prev_query_pos = state.query_pos(); if (match(agent, get_link(state.node_id(), link_id))) { return true; } if (state.query_pos() != prev_query_pos) { return false; } } else if (bases_[state.node_id()] == static_cast(agent.query()[state.query_pos()])) { state.set_query_pos(state.query_pos() + 1); return true; } state.set_node_id(state.node_id() + 1); ++louds_pos; } while (louds_[louds_pos]); return false; } bool LoudsTrie::predictive_find_child(Agent &agent) const { assert(agent.state().query_pos() < agent.query().length()); State &state = agent.state(); const std::size_t cache_id = get_cache_id(state.node_id(), agent.query()[state.query_pos()]); if (state.node_id() == cache_[cache_id].parent()) { if (cache_[cache_id].extra() != MARISA_INVALID_EXTRA) { if (!prefix_match(agent, cache_[cache_id].link())) { return false; } } else { state.key_buf().push_back(cache_[cache_id].label()); state.set_query_pos(state.query_pos() + 1); } state.set_node_id(cache_[cache_id].child()); return true; } std::size_t louds_pos = louds_.select0(state.node_id()) + 1; if (!louds_[louds_pos]) { return false; } state.set_node_id(louds_pos - state.node_id() - 1); std::size_t link_id = MARISA_INVALID_LINK_ID; do { if (link_flags_[state.node_id()]) { link_id = update_link_id(link_id, state.node_id()); const std::size_t prev_query_pos = state.query_pos(); if (prefix_match(agent, get_link(state.node_id(), link_id))) { return true; } if (state.query_pos() != prev_query_pos) { return false; } } else if (bases_[state.node_id()] == static_cast(agent.query()[state.query_pos()])) { state.key_buf().push_back(static_cast(bases_[state.node_id()])); state.set_query_pos(state.query_pos() + 1); return true; } state.set_node_id(state.node_id() + 1); ++louds_pos; } while (louds_[louds_pos]); return false; } void LoudsTrie::restore(Agent &agent, std::size_t link) const { if (next_trie_ != nullptr) { next_trie_->restore_(agent, link); } else { tail_.restore(agent, link); } } bool LoudsTrie::match(Agent &agent, std::size_t link) const { if (next_trie_ != nullptr) { return next_trie_->match_(agent, link); } return tail_.match(agent, link); } bool LoudsTrie::prefix_match(Agent &agent, std::size_t link) const { if (next_trie_ != nullptr) { return next_trie_->prefix_match_(agent, link); } return tail_.prefix_match(agent, link); } void LoudsTrie::restore_(Agent &agent, std::size_t node_id) const { assert(node_id != 0); State &state = agent.state(); for (;;) { const std::size_t cache_id = get_cache_id(node_id); if (node_id == cache_[cache_id].child()) { if (cache_[cache_id].extra() != MARISA_INVALID_EXTRA) { restore(agent, cache_[cache_id].link()); } else { state.key_buf().push_back(cache_[cache_id].label()); } node_id = cache_[cache_id].parent(); if (node_id == 0) { return; } continue; } if (link_flags_[node_id]) { restore(agent, get_link(node_id)); } else { state.key_buf().push_back(static_cast(bases_[node_id])); } if (node_id <= num_l1_nodes_) { return; } node_id = louds_.select1(node_id) - node_id - 1; } } bool LoudsTrie::match_(Agent &agent, std::size_t node_id) const { assert(agent.state().query_pos() < agent.query().length()); assert(node_id != 0); State &state = agent.state(); for (;;) { const std::size_t cache_id = get_cache_id(node_id); if (node_id == cache_[cache_id].child()) { if (cache_[cache_id].extra() != MARISA_INVALID_EXTRA) { if (!match(agent, cache_[cache_id].link())) { return false; } } else if (cache_[cache_id].label() == agent.query()[state.query_pos()]) { state.set_query_pos(state.query_pos() + 1); } else { return false; } node_id = cache_[cache_id].parent(); if (node_id == 0) { return true; } if (state.query_pos() >= agent.query().length()) { return false; } continue; } if (link_flags_[node_id]) { if (next_trie_ != nullptr) { if (!match(agent, get_link(node_id))) { return false; } } else if (!tail_.match(agent, get_link(node_id))) { return false; } } else if (bases_[node_id] == static_cast(agent.query()[state.query_pos()])) { state.set_query_pos(state.query_pos() + 1); } else { return false; } if (node_id <= num_l1_nodes_) { return true; } if (state.query_pos() >= agent.query().length()) { return false; } node_id = louds_.select1(node_id) - node_id - 1; } } bool LoudsTrie::prefix_match_(Agent &agent, std::size_t node_id) const { assert(agent.state().query_pos() < agent.query().length()); assert(node_id != 0); State &state = agent.state(); for (;;) { const std::size_t cache_id = get_cache_id(node_id); if (node_id == cache_[cache_id].child()) { if (cache_[cache_id].extra() != MARISA_INVALID_EXTRA) { if (!prefix_match(agent, cache_[cache_id].link())) { return false; } } else if (cache_[cache_id].label() == agent.query()[state.query_pos()]) { state.key_buf().push_back(cache_[cache_id].label()); state.set_query_pos(state.query_pos() + 1); } else { return false; } node_id = cache_[cache_id].parent(); if (node_id == 0) { return true; } } else { if (link_flags_[node_id]) { if (!prefix_match(agent, get_link(node_id))) { return false; } } else if (bases_[node_id] == static_cast(agent.query()[state.query_pos()])) { state.key_buf().push_back(static_cast(bases_[node_id])); state.set_query_pos(state.query_pos() + 1); } else { return false; } if (node_id <= num_l1_nodes_) { return true; } node_id = louds_.select1(node_id) - node_id - 1; } if (state.query_pos() >= agent.query().length()) { restore_(agent, node_id); return true; } } } std::size_t LoudsTrie::get_cache_id(std::size_t node_id, char label) const { return (node_id ^ (node_id << 5) ^ static_cast(label)) & cache_mask_; } std::size_t LoudsTrie::get_cache_id(std::size_t node_id) const { return node_id & cache_mask_; } std::size_t LoudsTrie::get_link(std::size_t node_id) const { return bases_[node_id] | (extras_[link_flags_.rank1(node_id)] * 256); } std::size_t LoudsTrie::get_link(std::size_t node_id, std::size_t link_id) const { return bases_[node_id] | (extras_[link_id] * 256); } std::size_t LoudsTrie::update_link_id(std::size_t link_id, std::size_t node_id) const { return (link_id == MARISA_INVALID_LINK_ID) ? link_flags_.rank1(node_id) : (link_id + 1); } } // namespace marisa::grimoire::trie marisa-trie-master/lib/marisa/grimoire/trie/louds-trie.h000066400000000000000000000073061505027263100236350ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_LOUDS_TRIE_H_ #define MARISA_GRIMOIRE_TRIE_LOUDS_TRIE_H_ #include #include "marisa/agent.h" #include "marisa/grimoire/trie/cache.h" #include "marisa/grimoire/trie/config.h" #include "marisa/grimoire/trie/key.h" #include "marisa/grimoire/trie/tail.h" #include "marisa/grimoire/vector.h" #include "marisa/keyset.h" namespace marisa::grimoire::trie { class LoudsTrie { public: LoudsTrie(); ~LoudsTrie(); LoudsTrie(const LoudsTrie &) = delete; LoudsTrie &operator=(const LoudsTrie &) = delete; void build(Keyset &keyset, int flags); void map(Mapper &mapper); void read(Reader &reader); void write(Writer &writer) const; bool lookup(Agent &agent) const; void reverse_lookup(Agent &agent) const; bool common_prefix_search(Agent &agent) const; bool predictive_search(Agent &agent) const; std::size_t num_tries() const { return config_.num_tries(); } std::size_t num_keys() const { return size(); } std::size_t num_nodes() const { return (louds_.size() / 2) - 1; } CacheLevel cache_level() const { return config_.cache_level(); } TailMode tail_mode() const { return config_.tail_mode(); } NodeOrder node_order() const { return config_.node_order(); } bool empty() const { return size() == 0; } std::size_t size() const { return terminal_flags_.num_1s(); } std::size_t total_size() const; std::size_t io_size() const; void clear() noexcept; void swap(LoudsTrie &rhs) noexcept; private: BitVector louds_; BitVector terminal_flags_; BitVector link_flags_; Vector bases_; FlatVector extras_; Tail tail_; std::unique_ptr next_trie_; Vector cache_; std::size_t cache_mask_ = 0; std::size_t num_l1_nodes_ = 0; Config config_; Mapper mapper_; void build_(Keyset &keyset, const Config &config); template void build_trie(Vector &keys, Vector *terminals, const Config &config, std::size_t trie_id); template void build_current_trie(Vector &keys, Vector *terminals, const Config &config, std::size_t trie_id); template void build_next_trie(Vector &keys, Vector *terminals, const Config &config, std::size_t trie_id); template void build_terminals(const Vector &keys, Vector *terminals) const; void reserve_cache(const Config &config, std::size_t trie_id, std::size_t num_keys); template void cache(std::size_t parent, std::size_t child, float weight, char label); void fill_cache(); void map_(Mapper &mapper); void read_(Reader &reader); void write_(Writer &writer) const; inline bool find_child(Agent &agent) const; inline bool predictive_find_child(Agent &agent) const; inline void restore(Agent &agent, std::size_t node_id) const; inline bool match(Agent &agent, std::size_t node_id) const; inline bool prefix_match(Agent &agent, std::size_t node_id) const; void restore_(Agent &agent, std::size_t node_id) const; bool match_(Agent &agent, std::size_t node_id) const; bool prefix_match_(Agent &agent, std::size_t node_id) const; inline std::size_t get_cache_id(std::size_t node_id, char label) const; inline std::size_t get_cache_id(std::size_t node_id) const; inline std::size_t get_link(std::size_t node_id) const; inline std::size_t get_link(std::size_t node_id, std::size_t link_id) const; inline std::size_t update_link_id(std::size_t link_id, std::size_t node_id) const; }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_LOUDS_TRIE_H_ marisa-trie-master/lib/marisa/grimoire/trie/range.h000066400000000000000000000045121505027263100226360ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_RANGE_H_ #define MARISA_GRIMOIRE_TRIE_RANGE_H_ #include #include "marisa/base.h" namespace marisa::grimoire::trie { class Range { public: Range() = default; void set_begin(std::size_t begin) { assert(begin <= UINT32_MAX); begin_ = static_cast(begin); } void set_end(std::size_t end) { assert(end <= UINT32_MAX); end_ = static_cast(end); } void set_key_pos(std::size_t key_pos) { assert(key_pos <= UINT32_MAX); key_pos_ = static_cast(key_pos); } std::size_t begin() const { return begin_; } std::size_t end() const { return end_; } std::size_t key_pos() const { return key_pos_; } private: uint32_t begin_ = 0; uint32_t end_ = 0; uint32_t key_pos_ = 0; }; inline Range make_range(std::size_t begin, std::size_t end, std::size_t key_pos) { Range range; range.set_begin(begin); range.set_end(end); range.set_key_pos(key_pos); return range; } class WeightedRange { public: WeightedRange() = default; void set_range(const Range &range) { range_ = range; } void set_begin(std::size_t begin) { range_.set_begin(begin); } void set_end(std::size_t end) { range_.set_end(end); } void set_key_pos(std::size_t key_pos) { range_.set_key_pos(key_pos); } void set_weight(float weight) { weight_ = weight; } const Range &range() const { return range_; } std::size_t begin() const { return range_.begin(); } std::size_t end() const { return range_.end(); } std::size_t key_pos() const { return range_.key_pos(); } float weight() const { return weight_; } private: Range range_; float weight_ = 0.0F; }; inline bool operator<(const WeightedRange &lhs, const WeightedRange &rhs) { return lhs.weight() < rhs.weight(); } inline bool operator>(const WeightedRange &lhs, const WeightedRange &rhs) { return lhs.weight() > rhs.weight(); } inline WeightedRange make_weighted_range(std::size_t begin, std::size_t end, std::size_t key_pos, float weight) { WeightedRange range; range.set_begin(begin); range.set_end(end); range.set_key_pos(key_pos); range.set_weight(weight); return range; } } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_RANGE_H_ marisa-trie-master/lib/marisa/grimoire/trie/state.h000066400000000000000000000051511505027263100226620ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_STATE_H_ #define MARISA_GRIMOIRE_TRIE_STATE_H_ #include #include #include "marisa/grimoire/trie/history.h" namespace marisa::grimoire::trie { // A search agent has its internal state and the status codes are defined // below. enum StatusCode { MARISA_READY_TO_ALL, MARISA_READY_TO_COMMON_PREFIX_SEARCH, MARISA_READY_TO_PREDICTIVE_SEARCH, MARISA_END_OF_COMMON_PREFIX_SEARCH, MARISA_END_OF_PREDICTIVE_SEARCH, }; class State { public: State() = default; State(const State &) = default; State &operator=(const State &) = default; State(State &&) noexcept = default; State &operator=(State &&) noexcept = default; void set_node_id(std::size_t node_id) { assert(node_id <= UINT32_MAX); node_id_ = static_cast(node_id); } void set_query_pos(std::size_t query_pos) { assert(query_pos <= UINT32_MAX); query_pos_ = static_cast(query_pos); } void set_history_pos(std::size_t history_pos) { assert(history_pos <= UINT32_MAX); history_pos_ = static_cast(history_pos); } void set_status_code(StatusCode status_code) { status_code_ = status_code; } std::size_t node_id() const { return node_id_; } std::size_t query_pos() const { return query_pos_; } std::size_t history_pos() const { return history_pos_; } StatusCode status_code() const { return status_code_; } const std::vector &key_buf() const { return key_buf_; } const std::vector &history() const { return history_; } std::vector &key_buf() { return key_buf_; } std::vector &history() { return history_; } void reset() { status_code_ = MARISA_READY_TO_ALL; } void lookup_init() { node_id_ = 0; query_pos_ = 0; status_code_ = MARISA_READY_TO_ALL; } void reverse_lookup_init() { key_buf_.resize(0); key_buf_.reserve(32); status_code_ = MARISA_READY_TO_ALL; } void common_prefix_search_init() { node_id_ = 0; query_pos_ = 0; status_code_ = MARISA_READY_TO_COMMON_PREFIX_SEARCH; } void predictive_search_init() { key_buf_.resize(0); key_buf_.reserve(64); history_.resize(0); history_.reserve(4); node_id_ = 0; query_pos_ = 0; history_pos_ = 0; status_code_ = MARISA_READY_TO_PREDICTIVE_SEARCH; } private: std::vector key_buf_; std::vector history_; uint32_t node_id_ = 0; uint32_t query_pos_ = 0; uint32_t history_pos_ = 0; StatusCode status_code_ = MARISA_READY_TO_ALL; }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_STATE_H_ marisa-trie-master/lib/marisa/grimoire/trie/tail.cc000066400000000000000000000126571505027263100226420ustar00rootroot00000000000000#include "marisa/grimoire/trie/tail.h" #include #include #include "marisa/grimoire/algorithm/sort.h" #include "marisa/grimoire/trie/state.h" namespace marisa::grimoire::trie { Tail::Tail() = default; void Tail::build(Vector &entries, Vector *offsets, TailMode mode) { MARISA_THROW_IF(offsets == nullptr, std::invalid_argument); switch (mode) { case MARISA_TEXT_TAIL: { for (std::size_t i = 0; i < entries.size(); ++i) { const char *const ptr = entries[i].ptr(); const std::size_t length = entries[i].length(); for (std::size_t j = 0; j < length; ++j) { if (ptr[j] == '\0') { mode = MARISA_BINARY_TAIL; break; } } if (mode == MARISA_BINARY_TAIL) { break; } } break; } case MARISA_BINARY_TAIL: { break; } default: { MARISA_THROW(std::invalid_argument, "undefined tail mode"); } } Tail temp; temp.build_(entries, offsets, mode); swap(temp); } void Tail::map(Mapper &mapper) { Tail temp; temp.map_(mapper); swap(temp); } void Tail::read(Reader &reader) { Tail temp; temp.read_(reader); swap(temp); } void Tail::write(Writer &writer) const { write_(writer); } void Tail::restore(Agent &agent, std::size_t offset) const { assert(!buf_.empty()); State &state = agent.state(); if (end_flags_.empty()) { for (const char *ptr = &buf_[offset]; *ptr != '\0'; ++ptr) { state.key_buf().push_back(*ptr); } } else { do { state.key_buf().push_back(buf_[offset]); } while (!end_flags_[offset++]); } } bool Tail::match(Agent &agent, std::size_t offset) const { assert(!buf_.empty()); assert(agent.state().query_pos() < agent.query().length()); State &state = agent.state(); if (end_flags_.empty()) { const char *const ptr = &buf_[offset] - state.query_pos(); do { if (ptr[state.query_pos()] != agent.query()[state.query_pos()]) { return false; } state.set_query_pos(state.query_pos() + 1); if (ptr[state.query_pos()] == '\0') { return true; } } while (state.query_pos() < agent.query().length()); return false; } do { if (buf_[offset] != agent.query()[state.query_pos()]) { return false; } state.set_query_pos(state.query_pos() + 1); if (end_flags_[offset++]) { return true; } } while (state.query_pos() < agent.query().length()); return false; } bool Tail::prefix_match(Agent &agent, std::size_t offset) const { assert(!buf_.empty()); State &state = agent.state(); if (end_flags_.empty()) { const char *ptr = &buf_[offset] - state.query_pos(); do { if (ptr[state.query_pos()] != agent.query()[state.query_pos()]) { return false; } state.key_buf().push_back(ptr[state.query_pos()]); state.set_query_pos(state.query_pos() + 1); if (ptr[state.query_pos()] == '\0') { return true; } } while (state.query_pos() < agent.query().length()); ptr += state.query_pos(); do { state.key_buf().push_back(*ptr); } while (*++ptr != '\0'); return true; } do { if (buf_[offset] != agent.query()[state.query_pos()]) { return false; } state.key_buf().push_back(buf_[offset]); state.set_query_pos(state.query_pos() + 1); if (end_flags_[offset++]) { return true; } } while (state.query_pos() < agent.query().length()); do { state.key_buf().push_back(buf_[offset]); } while (!end_flags_[offset++]); return true; } void Tail::clear() noexcept { Tail().swap(*this); } void Tail::swap(Tail &rhs) noexcept { buf_.swap(rhs.buf_); end_flags_.swap(rhs.end_flags_); } void Tail::build_(Vector &entries, Vector *offsets, TailMode mode) { for (std::size_t i = 0; i < entries.size(); ++i) { entries[i].set_id(i); } algorithm::sort(entries.begin(), entries.end()); Vector temp_offsets; temp_offsets.resize(entries.size(), 0); const Entry dummy; const Entry *last = &dummy; for (std::size_t i = entries.size(); i > 0; --i) { const Entry ¤t = entries[i - 1]; MARISA_THROW_IF(current.length() == 0, std::out_of_range); std::size_t match = 0; while ((match < current.length()) && (match < last->length()) && ((*last)[match] == current[match])) { ++match; } if ((match == current.length()) && (last->length() != 0)) { temp_offsets[current.id()] = static_cast( temp_offsets[last->id()] + (last->length() - match)); } else { temp_offsets[current.id()] = static_cast(buf_.size()); for (std::size_t j = 1; j <= current.length(); ++j) { buf_.push_back(current[current.length() - j]); } if (mode == MARISA_TEXT_TAIL) { buf_.push_back('\0'); } else { for (std::size_t j = 1; j < current.length(); ++j) { end_flags_.push_back(false); } end_flags_.push_back(true); } MARISA_THROW_IF(buf_.size() > UINT32_MAX, std::length_error); } last = ¤t; } buf_.shrink(); offsets->swap(temp_offsets); } void Tail::map_(Mapper &mapper) { buf_.map(mapper); end_flags_.map(mapper); } void Tail::read_(Reader &reader) { buf_.read(reader); end_flags_.read(reader); } void Tail::write_(Writer &writer) const { buf_.write(writer); end_flags_.write(writer); } } // namespace marisa::grimoire::trie marisa-trie-master/lib/marisa/grimoire/trie/tail.h000066400000000000000000000030471505027263100224750ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_TRIE_TAIL_H_ #define MARISA_GRIMOIRE_TRIE_TAIL_H_ #include #include "marisa/agent.h" #include "marisa/grimoire/trie/entry.h" #include "marisa/grimoire/vector.h" namespace marisa::grimoire::trie { class Tail { public: Tail(); Tail(const Tail &) = delete; Tail &operator=(const Tail &) = delete; void build(Vector &entries, Vector *offsets, TailMode mode); void map(Mapper &mapper); void read(Reader &reader); void write(Writer &writer) const; void restore(Agent &agent, std::size_t offset) const; bool match(Agent &agent, std::size_t offset) const; bool prefix_match(Agent &agent, std::size_t offset) const; const char &operator[](std::size_t offset) const { assert(offset < buf_.size()); return buf_[offset]; } TailMode mode() const { return end_flags_.empty() ? MARISA_TEXT_TAIL : MARISA_BINARY_TAIL; } bool empty() const { return buf_.empty(); } std::size_t size() const { return buf_.size(); } std::size_t total_size() const { return buf_.total_size() + end_flags_.total_size(); } std::size_t io_size() const { return buf_.io_size() + end_flags_.io_size(); } void clear() noexcept; void swap(Tail &rhs) noexcept; private: Vector buf_; BitVector end_flags_; void build_(Vector &entries, Vector *offsets, TailMode mode); void map_(Mapper &mapper); void read_(Reader &reader); void write_(Writer &writer) const; }; } // namespace marisa::grimoire::trie #endif // MARISA_GRIMOIRE_TRIE_TAIL_H_ marisa-trie-master/lib/marisa/grimoire/vector.h000066400000000000000000000005771505027263100221100ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_VECTOR_H_ #define MARISA_GRIMOIRE_VECTOR_H_ #include "marisa/grimoire/vector/bit-vector.h" #include "marisa/grimoire/vector/flat-vector.h" #include "marisa/grimoire/vector/vector.h" namespace marisa::grimoire { using vector::BitVector; using vector::FlatVector; using vector::Vector; } // namespace marisa::grimoire #endif // MARISA_GRIMOIRE_VECTOR_H_ marisa-trie-master/lib/marisa/grimoire/vector/000077500000000000000000000000001505027263100217265ustar00rootroot00000000000000marisa-trie-master/lib/marisa/grimoire/vector/bit-vector.cc000066400000000000000000000743741505027263100243320ustar00rootroot00000000000000#include "marisa/grimoire/vector/bit-vector.h" #include #if __cplusplus >= 202002L #include #endif #include #include "marisa/grimoire/vector/pop-count.h" namespace marisa::grimoire::vector { namespace { #if defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L inline std::size_t countr_zero(uint64_t x) { return static_cast(std::countr_zero(x)); } #else // c++17 inline std::size_t countr_zero(uint64_t x) { #ifdef _MSC_VER unsigned long pos; ::_BitScanForward64(&pos, x); return pos; #else // _MSC_VER return __builtin_ctzll(x); #endif // _MSC_VER } #endif // c++17 #ifdef MARISA_USE_BMI2 inline std::size_t select_bit(std::size_t i, std::size_t bit_id, uint64_t unit) { return bit_id + countr_zero(_pdep_u64(1ULL << i, unit)); } #else // MARISA_USE_BMI2 // clang-format off const uint8_t SELECT_TABLE[8][256] = { { 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 }, { 7, 7, 7, 1, 7, 2, 2, 1, 7, 3, 3, 1, 3, 2, 2, 1, 7, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 7, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1, 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 7, 6, 6, 1, 6, 2, 2, 1, 6, 3, 3, 1, 3, 2, 2, 1, 6, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 6, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1, 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 7, 7, 7, 1, 7, 2, 2, 1, 7, 3, 3, 1, 3, 2, 2, 1, 7, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 7, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1, 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 7, 6, 6, 1, 6, 2, 2, 1, 6, 3, 3, 1, 3, 2, 2, 1, 6, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 6, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1, 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1 }, { 7, 7, 7, 7, 7, 7, 7, 2, 7, 7, 7, 3, 7, 3, 3, 2, 7, 7, 7, 4, 7, 4, 4, 2, 7, 4, 4, 3, 4, 3, 3, 2, 7, 7, 7, 5, 7, 5, 5, 2, 7, 5, 5, 3, 5, 3, 3, 2, 7, 5, 5, 4, 5, 4, 4, 2, 5, 4, 4, 3, 4, 3, 3, 2, 7, 7, 7, 6, 7, 6, 6, 2, 7, 6, 6, 3, 6, 3, 3, 2, 7, 6, 6, 4, 6, 4, 4, 2, 6, 4, 4, 3, 4, 3, 3, 2, 7, 6, 6, 5, 6, 5, 5, 2, 6, 5, 5, 3, 5, 3, 3, 2, 6, 5, 5, 4, 5, 4, 4, 2, 5, 4, 4, 3, 4, 3, 3, 2, 7, 7, 7, 7, 7, 7, 7, 2, 7, 7, 7, 3, 7, 3, 3, 2, 7, 7, 7, 4, 7, 4, 4, 2, 7, 4, 4, 3, 4, 3, 3, 2, 7, 7, 7, 5, 7, 5, 5, 2, 7, 5, 5, 3, 5, 3, 3, 2, 7, 5, 5, 4, 5, 4, 4, 2, 5, 4, 4, 3, 4, 3, 3, 2, 7, 7, 7, 6, 7, 6, 6, 2, 7, 6, 6, 3, 6, 3, 3, 2, 7, 6, 6, 4, 6, 4, 4, 2, 6, 4, 4, 3, 4, 3, 3, 2, 7, 6, 6, 5, 6, 5, 5, 2, 6, 5, 5, 3, 5, 3, 3, 2, 6, 5, 5, 4, 5, 4, 4, 2, 5, 4, 4, 3, 4, 3, 3, 2 }, { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, 7, 7, 7, 7, 7, 7, 7, 4, 7, 7, 7, 4, 7, 4, 4, 3, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 5, 7, 5, 5, 3, 7, 7, 7, 5, 7, 5, 5, 4, 7, 5, 5, 4, 5, 4, 4, 3, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 3, 7, 7, 7, 6, 7, 6, 6, 4, 7, 6, 6, 4, 6, 4, 4, 3, 7, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 3, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, 7, 7, 7, 7, 7, 7, 7, 4, 7, 7, 7, 4, 7, 4, 4, 3, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 5, 7, 5, 5, 3, 7, 7, 7, 5, 7, 5, 5, 4, 7, 5, 5, 4, 5, 4, 4, 3, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 3, 7, 7, 7, 6, 7, 6, 6, 4, 7, 6, 6, 4, 6, 4, 4, 3, 7, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 3, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3 }, { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 5, 7, 5, 5, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 4, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 5, 7, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 5, 7, 5, 5, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 4, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 5, 7, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4 }, { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 6, 7, 6, 6, 5 }, { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6 }, { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 } }; // clang-format on #if MARISA_WORD_SIZE == 64 constexpr uint64_t MASK_01 = 0x0101010101010101ULL; // Pre-computed lookup table trick from Gog, Simon and Matthias Petri. // "Optimized succinct data structures for massive data." Software: // Practice and Experience 44 (2014): 1287 - 1314. // PREFIX_SUM_OVERFLOW[i] = (0x7F - i) * MASK_01. const uint64_t PREFIX_SUM_OVERFLOW[64] = { // clang-format off 0x7F * MASK_01, 0x7E * MASK_01, 0x7D * MASK_01, 0x7C * MASK_01, 0x7B * MASK_01, 0x7A * MASK_01, 0x79 * MASK_01, 0x78 * MASK_01, 0x77 * MASK_01, 0x76 * MASK_01, 0x75 * MASK_01, 0x74 * MASK_01, 0x73 * MASK_01, 0x72 * MASK_01, 0x71 * MASK_01, 0x70 * MASK_01, 0x6F * MASK_01, 0x6E * MASK_01, 0x6D * MASK_01, 0x6C * MASK_01, 0x6B * MASK_01, 0x6A * MASK_01, 0x69 * MASK_01, 0x68 * MASK_01, 0x67 * MASK_01, 0x66 * MASK_01, 0x65 * MASK_01, 0x64 * MASK_01, 0x63 * MASK_01, 0x62 * MASK_01, 0x61 * MASK_01, 0x60 * MASK_01, 0x5F * MASK_01, 0x5E * MASK_01, 0x5D * MASK_01, 0x5C * MASK_01, 0x5B * MASK_01, 0x5A * MASK_01, 0x59 * MASK_01, 0x58 * MASK_01, 0x57 * MASK_01, 0x56 * MASK_01, 0x55 * MASK_01, 0x54 * MASK_01, 0x53 * MASK_01, 0x52 * MASK_01, 0x51 * MASK_01, 0x50 * MASK_01, 0x4F * MASK_01, 0x4E * MASK_01, 0x4D * MASK_01, 0x4C * MASK_01, 0x4B * MASK_01, 0x4A * MASK_01, 0x49 * MASK_01, 0x48 * MASK_01, 0x47 * MASK_01, 0x46 * MASK_01, 0x45 * MASK_01, 0x44 * MASK_01, 0x43 * MASK_01, 0x42 * MASK_01, 0x41 * MASK_01, 0x40 * MASK_01 // clang-format on }; std::size_t select_bit(std::size_t i, std::size_t bit_id, uint64_t unit) { uint64_t counts; { #if defined(MARISA_X64) && defined(MARISA_USE_SSSE3) __m128i lower_nibbles = _mm_cvtsi64_si128(static_cast(unit & 0x0F0F0F0F0F0F0F0FULL)); __m128i upper_nibbles = _mm_cvtsi64_si128(static_cast(unit & 0xF0F0F0F0F0F0F0F0ULL)); upper_nibbles = _mm_srli_epi32(upper_nibbles, 4); __m128i lower_counts = _mm_set_epi8(4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0); lower_counts = _mm_shuffle_epi8(lower_counts, lower_nibbles); __m128i upper_counts = _mm_set_epi8(4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0); upper_counts = _mm_shuffle_epi8(upper_counts, upper_nibbles); counts = static_cast( _mm_cvtsi128_si64(_mm_add_epi8(lower_counts, upper_counts))); #elif defined(MARISA_AARCH64) // Byte-wise popcount using CNT (plus a lot of conversion noise). // This actually only requires NEON, not AArch64, but we are already // in a 64-bit `#ifdef`. counts = vget_lane_u64(vreinterpret_u64_u8(vcnt_u8(vcreate_u8(unit))), 0); #else // defined(MARISA_AARCH64) constexpr uint64_t MASK_0F = 0x0F0F0F0F0F0F0F0FULL; constexpr uint64_t MASK_33 = 0x3333333333333333ULL; constexpr uint64_t MASK_55 = 0x5555555555555555ULL; counts = unit - ((unit >> 1) & MASK_55); counts = (counts & MASK_33) + ((counts >> 2) & MASK_33); counts = (counts + (counts >> 4)) & MASK_0F; #endif // defined(MARISA_AARCH64) counts *= MASK_01; } #if defined(MARISA_X64) && defined(MARISA_USE_POPCNT) uint8_t skip; { __m128i x = _mm_cvtsi64_si128(static_cast((i + 1) * MASK_01)); __m128i y = _mm_cvtsi64_si128(static_cast(counts)); x = _mm_cmpgt_epi8(x, y); skip = (uint8_t)popcount(static_cast(_mm_cvtsi128_si64(x))); } #else // defined(MARISA_X64) && defined(MARISA_USE_POPCNT) constexpr uint64_t MASK_80 = 0x8080808080808080ULL; const uint64_t x = (counts + PREFIX_SUM_OVERFLOW[i]) & MASK_80; // We masked with `MASK_80`, so the first bit set is the high bit in the // byte, therefore `num_trailing_zeros == 8 * byte_nr + 7` and the byte // number is the number of trailing zeros divided by 8. We just shift off // the low 7 bits, so `CTZ` gives us the `skip` value we want for the // number of bits of `counts` to shift. const int skip = countr_zero(x >> 7); #endif // defined(MARISA_X64) && defined(MARISA_USE_POPCNT) bit_id += static_cast(skip); unit >>= skip; i -= ((counts << 8) >> skip) & 0xFF; return bit_id + SELECT_TABLE[i][unit & 0xFF]; } #else // MARISA_WORD_SIZE == 64 #ifdef MARISA_USE_SSE2 // Popcount of the byte times eight. const uint8_t POPCNT_X8_TABLE[256] = { // clang-format off 0, 8, 8, 16, 8, 16, 16, 24, 8, 16, 16, 24, 16, 24, 24, 32, 8, 16, 16, 24, 16, 24, 24, 32, 16, 24, 24, 32, 24, 32, 32, 40, 8, 16, 16, 24, 16, 24, 24, 32, 16, 24, 24, 32, 24, 32, 32, 40, 16, 24, 24, 32, 24, 32, 32, 40, 24, 32, 32, 40, 32, 40, 40, 48, 8, 16, 16, 24, 16, 24, 24, 32, 16, 24, 24, 32, 24, 32, 32, 40, 16, 24, 24, 32, 24, 32, 32, 40, 24, 32, 32, 40, 32, 40, 40, 48, 16, 24, 24, 32, 24, 32, 32, 40, 24, 32, 32, 40, 32, 40, 40, 48, 24, 32, 32, 40, 32, 40, 40, 48, 32, 40, 40, 48, 40, 48, 48, 56, 8, 16, 16, 24, 16, 24, 24, 32, 16, 24, 24, 32, 24, 32, 32, 40, 16, 24, 24, 32, 24, 32, 32, 40, 24, 32, 32, 40, 32, 40, 40, 48, 16, 24, 24, 32, 24, 32, 32, 40, 24, 32, 32, 40, 32, 40, 40, 48, 24, 32, 32, 40, 32, 40, 40, 48, 32, 40, 40, 48, 40, 48, 48, 56, 16, 24, 24, 32, 24, 32, 32, 40, 24, 32, 32, 40, 32, 40, 40, 48, 24, 32, 32, 40, 32, 40, 40, 48, 32, 40, 40, 48, 40, 48, 48, 56, 24, 32, 32, 40, 32, 40, 40, 48, 32, 40, 40, 48, 40, 48, 48, 56, 32, 40, 40, 48, 40, 48, 48, 56, 40, 48, 48, 56, 48, 56, 56, 64 // clang-format on }; std::size_t select_bit(std::size_t i, std::size_t bit_id, uint32_t unit_lo, uint32_t unit_hi) { __m128i unit; { __m128i lower_dword = _mm_cvtsi32_si128(unit_lo); __m128i upper_dword = _mm_cvtsi32_si128(unit_hi); upper_dword = _mm_slli_si128(upper_dword, 4); unit = _mm_or_si128(lower_dword, upper_dword); } __m128i counts; { #ifdef MARISA_USE_SSSE3 __m128i lower_nibbles = _mm_set1_epi8(0x0F); lower_nibbles = _mm_and_si128(lower_nibbles, unit); __m128i upper_nibbles = _mm_set1_epi8((uint8_t)0xF0); upper_nibbles = _mm_and_si128(upper_nibbles, unit); upper_nibbles = _mm_srli_epi32(upper_nibbles, 4); __m128i lower_counts = _mm_set_epi8(4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0); lower_counts = _mm_shuffle_epi8(lower_counts, lower_nibbles); __m128i upper_counts = _mm_set_epi8(4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0); upper_counts = _mm_shuffle_epi8(upper_counts, upper_nibbles); counts = _mm_add_epi8(lower_counts, upper_counts); #else // MARISA_USE_SSSE3 __m128i x = _mm_srli_epi32(unit, 1); x = _mm_and_si128(x, _mm_set1_epi8(0x55)); x = _mm_sub_epi8(unit, x); __m128i y = _mm_srli_epi32(x, 2); y = _mm_and_si128(y, _mm_set1_epi8(0x33)); x = _mm_and_si128(x, _mm_set1_epi8(0x33)); x = _mm_add_epi8(x, y); y = _mm_srli_epi32(x, 4); x = _mm_add_epi8(x, y); counts = _mm_and_si128(x, _mm_set1_epi8(0x0F)); #endif // MARISA_USE_SSSE3 } __m128i accumulated_counts; { __m128i x = counts; x = _mm_slli_si128(x, 1); __m128i y = counts; y = _mm_add_epi32(y, x); x = y; y = _mm_slli_si128(y, 2); x = _mm_add_epi32(x, y); y = x; x = _mm_slli_si128(x, 4); y = _mm_add_epi32(y, x); accumulated_counts = _mm_set_epi32(0x7F7F7F7FU, 0x7F7F7F7FU, 0, 0); accumulated_counts = _mm_or_si128(accumulated_counts, y); } uint8_t skip; { __m128i x = _mm_set1_epi8((uint8_t)(i + 1)); x = _mm_cmpgt_epi8(x, accumulated_counts); // Since we use `_mm_movemask_epi8`, to move the top bit of every byte, // popcount times eight gives the original popcount of `x` before the // movemask. (`_mm_cmpgt_epi8` sets all bits in a byte to 0 or 1.) skip = POPCNT_X8_TABLE[_mm_movemask_epi8(x)]; } uint8_t byte; { alignas(16) uint8_t unit_bytes[16]; alignas(16) uint8_t accumulated_counts_bytes[16]; accumulated_counts = _mm_slli_si128(accumulated_counts, 1); _mm_store_si128(reinterpret_cast<__m128i *>(unit_bytes), unit); _mm_store_si128(reinterpret_cast<__m128i *>(accumulated_counts_bytes), accumulated_counts); bit_id += skip; byte = unit_bytes[skip / 8]; i -= accumulated_counts_bytes[skip / 8]; } return bit_id + SELECT_TABLE[i][byte]; } #else // MARISA_USE_SSE2 const uint8_t POPCNT_TABLE[256] = { // clang-format off 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 // clang-format on }; std::size_t select_bit(std::size_t i, std::size_t bit_id, uint32_t unit_lo, uint32_t unit_hi) { uint32_t next_byte = unit_lo & 0xFF; uint32_t byte_popcount = POPCNT_TABLE[next_byte]; // Assuming the desired bit is in a random byte, branches are not // taken 7/8 of the time, so this is branch-predictor friendly, // unlike binary search. if (i < byte_popcount) return bit_id + SELECT_TABLE[i][next_byte]; i -= byte_popcount; next_byte = (unit_lo >> 8) & 0xFF; byte_popcount = POPCNT_TABLE[next_byte]; if (i < byte_popcount) return bit_id + 8 + SELECT_TABLE[i][next_byte]; i -= byte_popcount; next_byte = (unit_lo >> 16) & 0xFF; byte_popcount = POPCNT_TABLE[next_byte]; if (i < byte_popcount) return bit_id + 16 + SELECT_TABLE[i][next_byte]; i -= byte_popcount; next_byte = unit_lo >> 24; byte_popcount = POPCNT_TABLE[next_byte]; if (i < byte_popcount) return bit_id + 24 + SELECT_TABLE[i][next_byte]; i -= byte_popcount; next_byte = unit_hi & 0xFF; byte_popcount = POPCNT_TABLE[next_byte]; if (i < byte_popcount) return bit_id + 32 + SELECT_TABLE[i][next_byte]; i -= byte_popcount; next_byte = (unit_hi >> 8) & 0xFF; byte_popcount = POPCNT_TABLE[next_byte]; if (i < byte_popcount) return bit_id + 40 + SELECT_TABLE[i][next_byte]; i -= byte_popcount; next_byte = (unit_hi >> 16) & 0xFF; byte_popcount = POPCNT_TABLE[next_byte]; if (i < byte_popcount) return bit_id + 48 + SELECT_TABLE[i][next_byte]; i -= byte_popcount; next_byte = unit_hi >> 24; // Assume `i < POPCNT_TABLE[next_byte]`. return bit_id + 56 + SELECT_TABLE[i][next_byte]; } #endif // MARISA_USE_SSE2 // This is only used by build_index, so don't worry about the small performance // penalty from not having version taking only a uint32_t. inline std::size_t select_bit(std::size_t i, std::size_t bit_id, uint32_t unit) { return select_bit(i, bit_id, /*unit_lo=*/unit, /*unit_hi=*/0); } #endif // MARISA_WORD_SIZE == 64 #endif // MARISA_USE_BMI2 } // namespace #if MARISA_WORD_SIZE == 64 std::size_t BitVector::rank1(std::size_t i) const { assert(!ranks_.empty()); assert(i <= size_); const RankIndex &rank = ranks_[i / 512]; std::size_t offset = rank.abs(); switch ((i / 64) % 8) { case 1: { offset += rank.rel1(); break; } case 2: { offset += rank.rel2(); break; } case 3: { offset += rank.rel3(); break; } case 4: { offset += rank.rel4(); break; } case 5: { offset += rank.rel5(); break; } case 6: { offset += rank.rel6(); break; } case 7: { offset += rank.rel7(); break; } } offset += popcount(units_[i / 64] & ((1ULL << (i % 64)) - 1)); return offset; } std::size_t BitVector::select0(std::size_t i) const { assert(!select0s_.empty()); assert(i < num_0s()); const std::size_t select_id = i / 512; assert((select_id + 1) < select0s_.size()); if ((i % 512) == 0) { return select0s_[select_id]; } std::size_t begin = select0s_[select_id] / 512; std::size_t end = (select0s_[select_id + 1] + 511) / 512; if (begin + 10 >= end) { while (i >= ((begin + 1) * 512) - ranks_[begin + 1].abs()) { ++begin; } } else { while (begin + 1 < end) { const std::size_t middle = (begin + end) / 2; if (i < (middle * 512) - ranks_[middle].abs()) { end = middle; } else { begin = middle; } } } const std::size_t rank_id = begin; i -= (rank_id * 512) - ranks_[rank_id].abs(); const RankIndex &rank = ranks_[rank_id]; std::size_t unit_id = rank_id * 8; if (i < (256U - rank.rel4())) { if (i < (128U - rank.rel2())) { if (i >= (64U - rank.rel1())) { unit_id += 1; i -= 64 - rank.rel1(); } } else if (i < (192U - rank.rel3())) { unit_id += 2; i -= 128 - rank.rel2(); } else { unit_id += 3; i -= 192 - rank.rel3(); } } else if (i < (384U - rank.rel6())) { if (i < (320U - rank.rel5())) { unit_id += 4; i -= 256 - rank.rel4(); } else { unit_id += 5; i -= 320 - rank.rel5(); } } else if (i < (448U - rank.rel7())) { unit_id += 6; i -= 384 - rank.rel6(); } else { unit_id += 7; i -= 448 - rank.rel7(); } return select_bit(i, unit_id * 64, ~units_[unit_id]); } std::size_t BitVector::select1(std::size_t i) const { assert(!select1s_.empty()); assert(i < num_1s()); const std::size_t select_id = i / 512; assert((select_id + 1) < select1s_.size()); if ((i % 512) == 0) { return select1s_[select_id]; } std::size_t begin = select1s_[select_id] / 512; std::size_t end = (select1s_[select_id + 1] + 511) / 512; if (begin + 10 >= end) { while (i >= ranks_[begin + 1].abs()) { ++begin; } } else { while (begin + 1 < end) { const std::size_t middle = (begin + end) / 2; if (i < ranks_[middle].abs()) { end = middle; } else { begin = middle; } } } const std::size_t rank_id = begin; i -= ranks_[rank_id].abs(); const RankIndex &rank = ranks_[rank_id]; std::size_t unit_id = rank_id * 8; if (i < rank.rel4()) { if (i < rank.rel2()) { if (i >= rank.rel1()) { unit_id += 1; i -= rank.rel1(); } } else if (i < rank.rel3()) { unit_id += 2; i -= rank.rel2(); } else { unit_id += 3; i -= rank.rel3(); } } else if (i < rank.rel6()) { if (i < rank.rel5()) { unit_id += 4; i -= rank.rel4(); } else { unit_id += 5; i -= rank.rel5(); } } else if (i < rank.rel7()) { unit_id += 6; i -= rank.rel6(); } else { unit_id += 7; i -= rank.rel7(); } return select_bit(i, unit_id * 64, units_[unit_id]); } #else // MARISA_WORD_SIZE == 64 std::size_t BitVector::rank1(std::size_t i) const { assert(!ranks_.empty()); assert(i <= size_); const RankIndex &rank = ranks_[i / 512]; std::size_t offset = rank.abs(); switch ((i / 64) % 8) { case 1: { offset += rank.rel1(); break; } case 2: { offset += rank.rel2(); break; } case 3: { offset += rank.rel3(); break; } case 4: { offset += rank.rel4(); break; } case 5: { offset += rank.rel5(); break; } case 6: { offset += rank.rel6(); break; } case 7: { offset += rank.rel7(); break; } } if (((i / 32) & 1) == 1) { offset += popcount(units_[(i / 32) - 1]); } offset += popcount(units_[i / 32] & ((1U << (i % 32)) - 1)); return offset; } std::size_t BitVector::select0(std::size_t i) const { assert(!select0s_.empty()); assert(i < num_0s()); const std::size_t select_id = i / 512; assert((select_id + 1) < select0s_.size()); if ((i % 512) == 0) { return select0s_[select_id]; } std::size_t begin = select0s_[select_id] / 512; std::size_t end = (select0s_[select_id + 1] + 511) / 512; if (begin + 10 >= end) { while (i >= ((begin + 1) * 512) - ranks_[begin + 1].abs()) { ++begin; } } else { while (begin + 1 < end) { const std::size_t middle = (begin + end) / 2; if (i < (middle * 512) - ranks_[middle].abs()) { end = middle; } else { begin = middle; } } } const std::size_t rank_id = begin; i -= (rank_id * 512) - ranks_[rank_id].abs(); const RankIndex &rank = ranks_[rank_id]; std::size_t unit_id = rank_id * 16; if (i < (256U - rank.rel4())) { if (i < (128U - rank.rel2())) { if (i >= (64U - rank.rel1())) { unit_id += 2; i -= 64 - rank.rel1(); } } else if (i < (192U - rank.rel3())) { unit_id += 4; i -= 128 - rank.rel2(); } else { unit_id += 6; i -= 192 - rank.rel3(); } } else if (i < (384U - rank.rel6())) { if (i < (320U - rank.rel5())) { unit_id += 8; i -= 256 - rank.rel4(); } else { unit_id += 10; i -= 320 - rank.rel5(); } } else if (i < (448U - rank.rel7())) { unit_id += 12; i -= 384 - rank.rel6(); } else { unit_id += 14; i -= 448 - rank.rel7(); } return select_bit(i, unit_id * 32, ~units_[unit_id], ~units_[unit_id + 1]); } std::size_t BitVector::select1(std::size_t i) const { assert(!select1s_.empty()); assert(i < num_1s()); const std::size_t select_id = i / 512; assert((select_id + 1) < select1s_.size()); if ((i % 512) == 0) { return select1s_[select_id]; } std::size_t begin = select1s_[select_id] / 512; std::size_t end = (select1s_[select_id + 1] + 511) / 512; if (begin + 10 >= end) { while (i >= ranks_[begin + 1].abs()) { ++begin; } } else { while (begin + 1 < end) { const std::size_t middle = (begin + end) / 2; if (i < ranks_[middle].abs()) { end = middle; } else { begin = middle; } } } const std::size_t rank_id = begin; i -= ranks_[rank_id].abs(); const RankIndex &rank = ranks_[rank_id]; std::size_t unit_id = rank_id * 16; if (i < rank.rel4()) { if (i < rank.rel2()) { if (i >= rank.rel1()) { unit_id += 2; i -= rank.rel1(); } } else if (i < rank.rel3()) { unit_id += 4; i -= rank.rel2(); } else { unit_id += 6; i -= rank.rel3(); } } else if (i < rank.rel6()) { if (i < rank.rel5()) { unit_id += 8; i -= rank.rel4(); } else { unit_id += 10; i -= rank.rel5(); } } else if (i < rank.rel7()) { unit_id += 12; i -= rank.rel6(); } else { unit_id += 14; i -= rank.rel7(); } return select_bit(i, unit_id * 32, units_[unit_id], units_[unit_id + 1]); } #endif // MARISA_WORD_SIZE == 64 void BitVector::build_index(const BitVector &bv, bool enables_select0, bool enables_select1) { const std::size_t num_bits = bv.size(); ranks_.resize((num_bits / 512) + (((num_bits % 512) != 0) ? 1 : 0) + 1); std::size_t num_0s = 0; // Only updated if enables_select0 is true. std::size_t num_1s = 0; const std::size_t num_units = bv.units_.size(); for (std::size_t unit_id = 0; unit_id < num_units; ++unit_id) { const std::size_t bit_id = unit_id * MARISA_WORD_SIZE; if ((bit_id % 64) == 0) { const std::size_t rank_id = bit_id / 512; switch ((bit_id / 64) % 8) { case 0: { ranks_[rank_id].set_abs(num_1s); break; } case 1: { ranks_[rank_id].set_rel1(num_1s - ranks_[rank_id].abs()); break; } case 2: { ranks_[rank_id].set_rel2(num_1s - ranks_[rank_id].abs()); break; } case 3: { ranks_[rank_id].set_rel3(num_1s - ranks_[rank_id].abs()); break; } case 4: { ranks_[rank_id].set_rel4(num_1s - ranks_[rank_id].abs()); break; } case 5: { ranks_[rank_id].set_rel5(num_1s - ranks_[rank_id].abs()); break; } case 6: { ranks_[rank_id].set_rel6(num_1s - ranks_[rank_id].abs()); break; } case 7: { ranks_[rank_id].set_rel7(num_1s - ranks_[rank_id].abs()); break; } } } const Unit unit = bv.units_[unit_id]; // push_back resizes with 0, so the high bits of the last unit are 0 and // do not affect the 1s count. const std::size_t unit_num_1s = popcount(unit); if (enables_select0) { // num_0s is somewhat move involved to compute, so only do it if we // need it. The last word has zeros in the high bits, so that needs // to be accounted for when computing the unit_num_0s from unit_num_1s. const std::size_t bits_remaining = num_bits - bit_id; const std::size_t unit_num_0s = std::min(bits_remaining, MARISA_WORD_SIZE) - unit_num_1s; // Note: MSVC rejects unary minus operator applied to unsigned type. const std::size_t zero_bit_id = (0 - num_0s) % 512; if (unit_num_0s > zero_bit_id) { // select0s_ is uint32_t, but select_bit returns size_t, so cast to // suppress narrowing conversion warning. push_back checks the // size, so there is no truncation here. select0s_.push_back( static_cast(select_bit(zero_bit_id, bit_id, ~unit))); } num_0s += unit_num_0s; } if (enables_select1) { // Note: MSVC rejects unary minus operator applied to unsigned type. const std::size_t one_bit_id = (0 - num_1s) % 512; if (unit_num_1s > one_bit_id) { select1s_.push_back( static_cast(select_bit(one_bit_id, bit_id, unit))); } } num_1s += unit_num_1s; } if ((num_bits % 512) != 0) { const std::size_t rank_id = (num_bits - 1) / 512; switch (((num_bits - 1) / 64) % 8) { case 0: { ranks_[rank_id].set_rel1(num_1s - ranks_[rank_id].abs()); } [[fallthrough]]; case 1: { ranks_[rank_id].set_rel2(num_1s - ranks_[rank_id].abs()); } [[fallthrough]]; case 2: { ranks_[rank_id].set_rel3(num_1s - ranks_[rank_id].abs()); } [[fallthrough]]; case 3: { ranks_[rank_id].set_rel4(num_1s - ranks_[rank_id].abs()); } [[fallthrough]]; case 4: { ranks_[rank_id].set_rel5(num_1s - ranks_[rank_id].abs()); } [[fallthrough]]; case 5: { ranks_[rank_id].set_rel6(num_1s - ranks_[rank_id].abs()); } [[fallthrough]]; case 6: { ranks_[rank_id].set_rel7(num_1s - ranks_[rank_id].abs()); break; } } } size_ = num_bits; num_1s_ = bv.num_1s(); ranks_.back().set_abs(num_1s); if (enables_select0) { select0s_.push_back(static_cast(num_bits)); select0s_.shrink(); } if (enables_select1) { select1s_.push_back(static_cast(num_bits)); select1s_.shrink(); } } } // namespace marisa::grimoire::vector marisa-trie-master/lib/marisa/grimoire/vector/bit-vector.h000066400000000000000000000101021505027263100241470ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_VECTOR_BIT_VECTOR_H_ #define MARISA_GRIMOIRE_VECTOR_BIT_VECTOR_H_ #include #include #include "marisa/grimoire/vector/rank-index.h" #include "marisa/grimoire/vector/vector.h" namespace marisa::grimoire::vector { class BitVector { public: #if MARISA_WORD_SIZE == 64 using Unit = uint64_t; #else // MARISA_WORD_SIZE == 64 using Unit = uint32_t; #endif // MARISA_WORD_SIZE == 64 BitVector() = default; BitVector(const BitVector &) = delete; BitVector &operator=(const BitVector &) = delete; void build(bool enables_select0, bool enables_select1) { BitVector temp; temp.build_index(*this, enables_select0, enables_select1); units_.shrink(); temp.units_.swap(units_); swap(temp); } void map(Mapper &mapper) { BitVector temp; temp.map_(mapper); swap(temp); } void read(Reader &reader) { BitVector temp; temp.read_(reader); swap(temp); } void write(Writer &writer) const { write_(writer); } void disable_select0() { select0s_.clear(); } void disable_select1() { select1s_.clear(); } void push_back(bool bit) { MARISA_THROW_IF(size_ == UINT32_MAX, std::length_error); if (size_ == (MARISA_WORD_SIZE * units_.size())) { units_.resize(units_.size() + (64 / MARISA_WORD_SIZE), 0); } if (bit) { units_[size_ / MARISA_WORD_SIZE] |= Unit{1} << (size_ % MARISA_WORD_SIZE); ++num_1s_; } ++size_; } bool operator[](std::size_t i) const { assert(i < size_); return (units_[i / MARISA_WORD_SIZE] & (Unit{1} << (i % MARISA_WORD_SIZE))) != 0; } std::size_t rank0(std::size_t i) const { assert(!ranks_.empty()); assert(i <= size_); return i - rank1(i); } std::size_t rank1(std::size_t i) const; std::size_t select0(std::size_t i) const; std::size_t select1(std::size_t i) const; std::size_t num_0s() const { return size_ - num_1s_; } std::size_t num_1s() const { return num_1s_; } bool empty() const { return size_ == 0; } std::size_t size() const { return size_; } std::size_t total_size() const { return units_.total_size() + ranks_.total_size() + select0s_.total_size() + select1s_.total_size(); } std::size_t io_size() const { return units_.io_size() + (sizeof(uint32_t) * 2) + ranks_.io_size() + select0s_.io_size() + select1s_.io_size(); } void clear() noexcept { BitVector().swap(*this); } void swap(BitVector &rhs) noexcept { units_.swap(rhs.units_); std::swap(size_, rhs.size_); std::swap(num_1s_, rhs.num_1s_); ranks_.swap(rhs.ranks_); select0s_.swap(rhs.select0s_); select1s_.swap(rhs.select1s_); } private: Vector units_; std::size_t size_ = 0; std::size_t num_1s_ = 0; Vector ranks_; Vector select0s_; Vector select1s_; void build_index(const BitVector &bv, bool enables_select0, bool enables_select1); void map_(Mapper &mapper) { units_.map(mapper); { uint32_t temp_size; mapper.map(&temp_size); size_ = temp_size; } { uint32_t temp_num_1s; mapper.map(&temp_num_1s); MARISA_THROW_IF(temp_num_1s > size_, std::runtime_error); num_1s_ = temp_num_1s; } ranks_.map(mapper); select0s_.map(mapper); select1s_.map(mapper); } void read_(Reader &reader) { units_.read(reader); { uint32_t temp_size; reader.read(&temp_size); size_ = temp_size; } { uint32_t temp_num_1s; reader.read(&temp_num_1s); MARISA_THROW_IF(temp_num_1s > size_, std::runtime_error); num_1s_ = temp_num_1s; } ranks_.read(reader); select0s_.read(reader); select1s_.read(reader); } void write_(Writer &writer) const { units_.write(writer); writer.write(static_cast(size_)); writer.write(static_cast(num_1s_)); ranks_.write(writer); select0s_.write(writer); select1s_.write(writer); } }; } // namespace marisa::grimoire::vector #endif // MARISA_GRIMOIRE_VECTOR_BIT_VECTOR_H_ marisa-trie-master/lib/marisa/grimoire/vector/flat-vector.h000066400000000000000000000121371505027263100243310ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_VECTOR_FLAT_VECTOR_H_ #define MARISA_GRIMOIRE_VECTOR_FLAT_VECTOR_H_ #include #include #include "marisa/grimoire/vector/vector.h" namespace marisa::grimoire::vector { class FlatVector { public: #if MARISA_WORD_SIZE == 64 using Unit = uint64_t; #else // MARISA_WORD_SIZE == 64 using Unit = uint32_t; #endif // MARISA_WORD_SIZE == 64 FlatVector() = default; FlatVector(const FlatVector &) = delete; FlatVector &operator=(const FlatVector &) = delete; void build(const Vector &values) { FlatVector temp; temp.build_(values); swap(temp); } void map(Mapper &mapper) { FlatVector temp; temp.map_(mapper); swap(temp); } void read(Reader &reader) { FlatVector temp; temp.read_(reader); swap(temp); } void write(Writer &writer) const { write_(writer); } uint32_t operator[](std::size_t i) const { assert(i < size_); const std::size_t pos = i * value_size_; const std::size_t unit_id = pos / MARISA_WORD_SIZE; const std::size_t unit_offset = pos % MARISA_WORD_SIZE; if ((unit_offset + value_size_) <= MARISA_WORD_SIZE) { return static_cast(units_[unit_id] >> unit_offset) & mask_; } else { return static_cast( (units_[unit_id] >> unit_offset) | (units_[unit_id + 1] << (MARISA_WORD_SIZE - unit_offset))) & mask_; } } std::size_t value_size() const { return value_size_; } uint32_t mask() const { return mask_; } bool empty() const { return size_ == 0; } std::size_t size() const { return size_; } std::size_t total_size() const { return units_.total_size(); } std::size_t io_size() const { return units_.io_size() + (sizeof(uint32_t) * 2) + sizeof(uint64_t); } void clear() noexcept { FlatVector().swap(*this); } void swap(FlatVector &rhs) noexcept { units_.swap(rhs.units_); std::swap(value_size_, rhs.value_size_); std::swap(mask_, rhs.mask_); std::swap(size_, rhs.size_); } private: Vector units_; std::size_t value_size_ = 0; uint32_t mask_ = 0; std::size_t size_ = 0; void build_(const Vector &values) { uint32_t max_value = 0; for (std::size_t i = 0; i < values.size(); ++i) { if (values[i] > max_value) { max_value = values[i]; } } std::size_t value_size = 0; while (max_value != 0) { ++value_size; max_value >>= 1; } std::size_t num_units = values.empty() ? 0 : (64 / MARISA_WORD_SIZE); if (value_size != 0) { num_units = static_cast( ((static_cast(value_size) * values.size()) + (MARISA_WORD_SIZE - 1)) / MARISA_WORD_SIZE); num_units += num_units % (64 / MARISA_WORD_SIZE); } units_.resize(num_units); if (num_units > 0) { units_.back() = 0; } value_size_ = value_size; if (value_size != 0) { mask_ = UINT32_MAX >> (32 - value_size); } size_ = values.size(); for (std::size_t i = 0; i < values.size(); ++i) { set(i, values[i]); } } void map_(Mapper &mapper) { units_.map(mapper); { uint32_t temp_value_size; mapper.map(&temp_value_size); MARISA_THROW_IF(temp_value_size > 32, std::runtime_error); value_size_ = temp_value_size; } { uint32_t temp_mask; mapper.map(&temp_mask); mask_ = temp_mask; } { uint64_t temp_size; mapper.map(&temp_size); MARISA_THROW_IF(temp_size > SIZE_MAX, std::runtime_error); size_ = static_cast(temp_size); } } void read_(Reader &reader) { units_.read(reader); { uint32_t temp_value_size; reader.read(&temp_value_size); MARISA_THROW_IF(temp_value_size > 32, std::runtime_error); value_size_ = temp_value_size; } { uint32_t temp_mask; reader.read(&temp_mask); mask_ = temp_mask; } { uint64_t temp_size; reader.read(&temp_size); MARISA_THROW_IF(temp_size > SIZE_MAX, std::runtime_error); size_ = static_cast(temp_size); } } void write_(Writer &writer) const { units_.write(writer); writer.write(static_cast(value_size_)); writer.write(static_cast(mask_)); writer.write(static_cast(size_)); } void set(std::size_t i, uint32_t value) { assert(i < size_); assert(value <= mask_); const std::size_t pos = i * value_size_; const std::size_t unit_id = pos / MARISA_WORD_SIZE; const std::size_t unit_offset = pos % MARISA_WORD_SIZE; units_[unit_id] &= ~(static_cast(mask_) << unit_offset); units_[unit_id] |= static_cast(value & mask_) << unit_offset; if ((unit_offset + value_size_) > MARISA_WORD_SIZE) { units_[unit_id + 1] &= ~(static_cast(mask_) >> (MARISA_WORD_SIZE - unit_offset)); units_[unit_id + 1] |= static_cast(value & mask_) >> (MARISA_WORD_SIZE - unit_offset); } } }; } // namespace marisa::grimoire::vector #endif // MARISA_GRIMOIRE_VECTOR_FLAT_VECTOR_H_ marisa-trie-master/lib/marisa/grimoire/vector/pop-count.h000066400000000000000000000044041505027263100240250ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_VECTOR_POP_COUNT_H_ #define MARISA_GRIMOIRE_VECTOR_POP_COUNT_H_ #if __cplusplus >= 202002L #include #endif #include "marisa/grimoire/intrin.h" namespace marisa::grimoire::vector { #if defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L inline std::size_t popcount(uint64_t x) { return static_cast(std::popcount(x)); } #else // c++17 #ifdef __has_builtin #define MARISA_HAS_BUILTIN(x) __has_builtin(x) #else #define MARISA_HAS_BUILTIN(x) 0 #endif #if MARISA_WORD_SIZE == 64 inline std::size_t popcount(uint64_t x) { #if MARISA_HAS_BUILTIN(__builtin_popcountll) static_assert(sizeof(x) == sizeof(unsigned long long), "__builtin_popcountll does not take 64-bit arg"); return __builtin_popcountll(x); #elif defined(MARISA_X64) && defined(MARISA_USE_POPCNT) #ifdef _MSC_VER return __popcnt64(x); #else // _MSC_VER return static_cast(_mm_popcnt_u64(x)); #endif // _MSC_VER #elif defined(MARISA_AARCH64) // Byte-wise popcount followed by horizontal add. return vaddv_u8(vcnt_u8(vcreate_u8(x))); #else // defined(MARISA_AARCH64) x = (x & 0x5555555555555555ULL) + ((x & 0xAAAAAAAAAAAAAAAAULL) >> 1); x = (x & 0x3333333333333333ULL) + ((x & 0xCCCCCCCCCCCCCCCCULL) >> 2); x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x & 0xF0F0F0F0F0F0F0F0ULL) >> 4); x *= 0x0101010101010101ULL; return x >> 56; #endif // defined(MARISA_AARCH64) } #else // MARISA_WORD_SIZE == 64 inline std::size_t popcount(uint32_t x) { #if MARISA_HAS_BUILTIN(__builtin_popcount) static_assert(sizeof(x) == sizeof(unsigned int), "__builtin_popcount does not take 32-bit arg"); return __builtin_popcount(x); #elif defined(MARISA_USE_POPCNT) #ifdef _MSC_VER return __popcnt(x); #else // _MSC_VER return _mm_popcnt_u32(x); #endif // _MSC_VER #else // MARISA_USE_POPCNT x = (x & 0x55555555U) + ((x & 0xAAAAAAAAU) >> 1); x = (x & 0x33333333U) + ((x & 0xCCCCCCCCU) >> 2); x = (x & 0x0F0F0F0FU) + ((x & 0xF0F0F0F0U) >> 4); x *= 0x01010101U; return x >> 24; #endif // MARISA_USE_POPCNT } #endif // MARISA_WORD_SIZE == 64 #undef MARISA_HAS_BUILTIN #endif // c++17 } // namespace marisa::grimoire::vector #endif // MARISA_GRIMOIRE_VECTOR_POP_COUNT_H_ marisa-trie-master/lib/marisa/grimoire/vector/rank-index.h000066400000000000000000000043641505027263100241460ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_VECTOR_RANK_INDEX_H_ #define MARISA_GRIMOIRE_VECTOR_RANK_INDEX_H_ #include #include "marisa/base.h" namespace marisa::grimoire::vector { class RankIndex { public: RankIndex() = default; void set_abs(std::size_t value) { assert(value <= UINT32_MAX); abs_ = static_cast(value); } void set_rel1(std::size_t value) { assert(value <= 64); rel_lo_ = static_cast((rel_lo_ & ~0x7FU) | (value & 0x7FU)); } void set_rel2(std::size_t value) { assert(value <= 128); rel_lo_ = static_cast((rel_lo_ & ~(0xFFU << 7)) | ((value & 0xFFU) << 7)); } void set_rel3(std::size_t value) { assert(value <= 192); rel_lo_ = static_cast((rel_lo_ & ~(0xFFU << 15)) | ((value & 0xFFU) << 15)); } void set_rel4(std::size_t value) { assert(value <= 256); rel_lo_ = static_cast((rel_lo_ & ~(0x1FFU << 23)) | ((value & 0x1FFU) << 23)); } void set_rel5(std::size_t value) { assert(value <= 320); rel_hi_ = static_cast((rel_hi_ & ~0x1FFU) | (value & 0x1FFU)); } void set_rel6(std::size_t value) { assert(value <= 384); rel_hi_ = static_cast((rel_hi_ & ~(0x1FFU << 9)) | ((value & 0x1FFU) << 9)); } void set_rel7(std::size_t value) { assert(value <= 448); rel_hi_ = static_cast((rel_hi_ & ~(0x1FFU << 18)) | ((value & 0x1FFU) << 18)); } std::size_t abs() const { return abs_; } std::size_t rel1() const { return rel_lo_ & 0x7FU; } std::size_t rel2() const { return (rel_lo_ >> 7) & 0xFFU; } std::size_t rel3() const { return (rel_lo_ >> 15) & 0xFFU; } std::size_t rel4() const { return (rel_lo_ >> 23) & 0x1FFU; } std::size_t rel5() const { return rel_hi_ & 0x1FFU; } std::size_t rel6() const { return (rel_hi_ >> 9) & 0x1FFU; } std::size_t rel7() const { return (rel_hi_ >> 18) & 0x1FFU; } private: uint32_t abs_ = 0; uint32_t rel_lo_ = 0; uint32_t rel_hi_ = 0; }; } // namespace marisa::grimoire::vector #endif // MARISA_GRIMOIRE_VECTOR_RANK_INDEX_H_ marisa-trie-master/lib/marisa/grimoire/vector/vector.h000066400000000000000000000160711505027263100234060ustar00rootroot00000000000000#ifndef MARISA_GRIMOIRE_VECTOR_VECTOR_H_ #define MARISA_GRIMOIRE_VECTOR_VECTOR_H_ #include #include #include #include #include #include #include #include "marisa/grimoire/io.h" namespace marisa::grimoire::vector { template class Vector { public: // These assertions are repeated for clarity/robustness where the property // is used. static_assert(std::is_trivially_copyable_v); static_assert(std::is_trivially_destructible_v); Vector() = default; // `T` is trivially destructible, so default destructor is ok. ~Vector() = default; Vector(const Vector &other) : fixed_(other.fixed_) { if (other.buf_ == nullptr) { objs_ = other.objs_; const_objs_ = other.const_objs_; size_ = other.size_; capacity_ = other.capacity_; } else { copyInit(other.const_objs_, other.size_, other.capacity_); } } Vector &operator=(const Vector &other) { clear(); fixed_ = other.fixed_; if (other.buf_ == nullptr) { objs_ = other.objs_; const_objs_ = other.const_objs_; size_ = other.size_; capacity_ = other.capacity_; } else { copyInit(other.const_objs_, other.size_, other.capacity_); } return *this; } Vector(Vector &&) noexcept = default; Vector &operator=(Vector &&) noexcept = default; void map(Mapper &mapper) { Vector temp; temp.map_(mapper); swap(temp); } void read(Reader &reader) { Vector temp; temp.read_(reader); swap(temp); } void write(Writer &writer) const { write_(writer); } void push_back(const T &x) { assert(!fixed_); assert(size_ < max_size()); reserve(size_ + 1); new (&objs_[size_]) T(x); ++size_; } void pop_back() { assert(!fixed_); assert(size_ != 0); --size_; static_assert(std::is_trivially_destructible_v); } // resize() assumes that T's placement new does not throw an exception. void resize(std::size_t size) { assert(!fixed_); reserve(size); for (std::size_t i = size_; i < size; ++i) { new (&objs_[i]) T; } static_assert(std::is_trivially_destructible_v); size_ = size; } // resize() assumes that T's placement new does not throw an exception. void resize(std::size_t size, const T &x) { assert(!fixed_); reserve(size); if (size > size_) { std::fill_n(&objs_[size_], size - size_, x); } // No need to destroy old elements. static_assert(std::is_trivially_destructible_v); size_ = size; } void reserve(std::size_t capacity) { assert(!fixed_); if (capacity <= capacity_) { return; } assert(capacity <= max_size()); std::size_t new_capacity = capacity; if (capacity_ > (capacity / 2)) { if (capacity_ > (max_size() / 2)) { new_capacity = max_size(); } else { new_capacity = capacity_ * 2; } } realloc(new_capacity); } void shrink() { MARISA_THROW_IF(fixed_, std::logic_error); if (size_ != capacity_) { realloc(size_); } } void fix() { MARISA_THROW_IF(fixed_, std::logic_error); fixed_ = true; } const T *begin() const { return const_objs_; } const T *end() const { return const_objs_ + size_; } const T &operator[](std::size_t i) const { assert(i < size_); return const_objs_[i]; } const T &front() const { assert(size_ != 0); return const_objs_[0]; } const T &back() const { assert(size_ != 0); return const_objs_[size_ - 1]; } T *begin() { assert(!fixed_); return objs_; } T *end() { assert(!fixed_); return objs_ + size_; } T &operator[](std::size_t i) { assert(!fixed_); assert(i < size_); return objs_[i]; } T &front() { assert(!fixed_); assert(size_ != 0); return objs_[0]; } T &back() { assert(!fixed_); assert(size_ != 0); return objs_[size_ - 1]; } std::size_t size() const { return size_; } std::size_t capacity() const { return capacity_; } bool fixed() const { return fixed_; } bool empty() const { return size_ == 0; } std::size_t total_size() const { return sizeof(T) * size_; } std::size_t io_size() const { return sizeof(uint64_t) + ((total_size() + 7) & ~0x07U); } void clear() noexcept { Vector().swap(*this); } void swap(Vector &rhs) noexcept { buf_.swap(rhs.buf_); std::swap(objs_, rhs.objs_); std::swap(const_objs_, rhs.const_objs_); std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(fixed_, rhs.fixed_); } static std::size_t max_size() { return SIZE_MAX / sizeof(T); } private: std::unique_ptr buf_; T *objs_ = nullptr; const T *const_objs_ = nullptr; std::size_t size_ = 0; std::size_t capacity_ = 0; bool fixed_ = false; void map_(Mapper &mapper) { uint64_t total_size; mapper.map(&total_size); MARISA_THROW_IF(total_size > SIZE_MAX, std::runtime_error); MARISA_THROW_IF((total_size % sizeof(T)) != 0, std::runtime_error); const std::size_t size = static_cast(total_size / sizeof(T)); mapper.map(&const_objs_, size); mapper.seek(static_cast((8 - (total_size % 8)) % 8)); size_ = size; fix(); } void read_(Reader &reader) { uint64_t total_size; reader.read(&total_size); MARISA_THROW_IF(total_size > SIZE_MAX, std::runtime_error); MARISA_THROW_IF((total_size % sizeof(T)) != 0, std::runtime_error); const std::size_t size = static_cast(total_size / sizeof(T)); resize(size); reader.read(objs_, size); reader.seek(static_cast((8 - (total_size % 8)) % 8)); } void write_(Writer &writer) const { writer.write(static_cast(total_size())); writer.write(const_objs_, size_); writer.seek((8 - (total_size() % 8)) % 8); } // Copies current elements to new buffer of size `new_capacity`. // Requires `new_capacity >= size_`. void realloc(std::size_t new_capacity) { assert(new_capacity >= size_); assert(new_capacity <= max_size()); std::unique_ptr new_buf(new char[sizeof(T) * new_capacity]); T *new_objs = reinterpret_cast(new_buf.get()); static_assert(std::is_trivially_copyable_v); std::memcpy(new_objs, objs_, sizeof(T) * size_); buf_ = std::move(new_buf); objs_ = new_objs; const_objs_ = new_objs; capacity_ = new_capacity; } // copyInit() assumes that T's placement new does not throw an exception. // Requires the vector to be empty. void copyInit(const T *src, std::size_t size, std::size_t capacity) { assert(size_ == 0); std::unique_ptr new_buf(new char[sizeof(T) * capacity]); T *new_objs = reinterpret_cast(new_buf.get()); static_assert(std::is_trivially_copyable_v); std::memcpy(new_objs, src, sizeof(T) * size); buf_ = std::move(new_buf); objs_ = new_objs; const_objs_ = new_objs; size_ = size; capacity_ = capacity; } }; } // namespace marisa::grimoire::vector #endif // MARISA_GRIMOIRE_VECTOR_VECTOR_H_ marisa-trie-master/lib/marisa/keyset.cc000066400000000000000000000115541505027263100204300ustar00rootroot00000000000000#include "marisa/keyset.h" #include #include #include #include #include namespace marisa { Keyset::Keyset() = default; void Keyset::push_back(const Key &key) { assert(size_ < SIZE_MAX); char *const key_ptr = reserve(key.length()); std::memcpy(key_ptr, key.ptr(), key.length()); Key &new_key = key_blocks_[size_ / KEY_BLOCK_SIZE][size_ % KEY_BLOCK_SIZE]; new_key.set_str(key_ptr, key.length()); new_key.set_id(key.id()); ++size_; total_length_ += new_key.length(); } void Keyset::push_back(const Key &key, char end_marker) { assert(size_ < SIZE_MAX); if ((size_ / KEY_BLOCK_SIZE) == key_blocks_size_) { append_key_block(); } char *const key_ptr = reserve(key.length() + 1); std::memcpy(key_ptr, key.ptr(), key.length()); key_ptr[key.length()] = end_marker; Key &new_key = key_blocks_[size_ / KEY_BLOCK_SIZE][size_ % KEY_BLOCK_SIZE]; new_key.set_str(key_ptr, key.length()); new_key.set_id(key.id()); ++size_; total_length_ += new_key.length(); } void Keyset::push_back(const char *str) { assert(size_ < SIZE_MAX); MARISA_THROW_IF(str == nullptr, std::invalid_argument); std::size_t length = 0; while (str[length] != '\0') { ++length; } push_back(str, length); } void Keyset::push_back(const char *ptr, std::size_t length, float weight) { assert(size_ < SIZE_MAX); MARISA_THROW_IF((ptr == nullptr) && (length != 0), std::invalid_argument); MARISA_THROW_IF(length > UINT32_MAX, std::invalid_argument); char *const key_ptr = reserve(length); std::memcpy(key_ptr, ptr, length); Key &key = key_blocks_[size_ / KEY_BLOCK_SIZE][size_ % KEY_BLOCK_SIZE]; key.set_str(key_ptr, length); key.set_weight(weight); ++size_; total_length_ += length; } void Keyset::reset() { base_blocks_size_ = 0; extra_blocks_size_ = 0; ptr_ = nullptr; avail_ = 0; size_ = 0; total_length_ = 0; } void Keyset::clear() noexcept { Keyset().swap(*this); } void Keyset::swap(Keyset &rhs) noexcept { base_blocks_.swap(rhs.base_blocks_); std::swap(base_blocks_size_, rhs.base_blocks_size_); std::swap(base_blocks_capacity_, rhs.base_blocks_capacity_); extra_blocks_.swap(rhs.extra_blocks_); std::swap(extra_blocks_size_, rhs.extra_blocks_size_); std::swap(extra_blocks_capacity_, rhs.extra_blocks_capacity_); key_blocks_.swap(rhs.key_blocks_); std::swap(key_blocks_size_, rhs.key_blocks_size_); std::swap(key_blocks_capacity_, rhs.key_blocks_capacity_); std::swap(ptr_, rhs.ptr_); std::swap(avail_, rhs.avail_); std::swap(size_, rhs.size_); std::swap(total_length_, rhs.total_length_); } char *Keyset::reserve(std::size_t size) { if ((size_ / KEY_BLOCK_SIZE) == key_blocks_size_) { append_key_block(); } if (size > EXTRA_BLOCK_SIZE) { append_extra_block(size); return extra_blocks_[extra_blocks_size_ - 1].get(); } if (size > avail_) { append_base_block(); } ptr_ += size; avail_ -= size; return ptr_ - size; } void Keyset::append_base_block() { if (base_blocks_size_ == base_blocks_capacity_) { const std::size_t new_capacity = (base_blocks_size_ != 0) ? (base_blocks_size_ * 2) : 1; std::unique_ptr[]> new_blocks( new std::unique_ptr[new_capacity]); for (std::size_t i = 0; i < base_blocks_size_; ++i) { base_blocks_[i].swap(new_blocks[i]); } base_blocks_.swap(new_blocks); base_blocks_capacity_ = new_capacity; } if (base_blocks_[base_blocks_size_] == nullptr) { std::unique_ptr new_block(new char[BASE_BLOCK_SIZE]); base_blocks_[base_blocks_size_].swap(new_block); } ptr_ = base_blocks_[base_blocks_size_++].get(); avail_ = BASE_BLOCK_SIZE; } void Keyset::append_extra_block(std::size_t size) { if (extra_blocks_size_ == extra_blocks_capacity_) { const std::size_t new_capacity = (extra_blocks_size_ != 0) ? (extra_blocks_size_ * 2) : 1; std::unique_ptr[]> new_blocks( new std::unique_ptr[new_capacity]); for (std::size_t i = 0; i < extra_blocks_size_; ++i) { extra_blocks_[i].swap(new_blocks[i]); } extra_blocks_.swap(new_blocks); extra_blocks_capacity_ = new_capacity; } std::unique_ptr new_block(new char[size]); extra_blocks_[extra_blocks_size_++].swap(new_block); } void Keyset::append_key_block() { if (key_blocks_size_ == key_blocks_capacity_) { const std::size_t new_capacity = (key_blocks_size_ != 0) ? (key_blocks_size_ * 2) : 1; std::unique_ptr[]> new_blocks( new std::unique_ptr[new_capacity]); for (std::size_t i = 0; i < key_blocks_size_; ++i) { key_blocks_[i].swap(new_blocks[i]); } key_blocks_.swap(new_blocks); key_blocks_capacity_ = new_capacity; } std::unique_ptr new_block(new Key[KEY_BLOCK_SIZE]); key_blocks_[key_blocks_size_++].swap(new_block); } } // namespace marisa marisa-trie-master/lib/marisa/trie.cc000066400000000000000000000137431505027263100200710ustar00rootroot00000000000000#include "marisa/trie.h" #include #include #include "marisa/grimoire/trie.h" #include "marisa/iostream.h" #include "marisa/stdio.h" namespace marisa { Trie::Trie() = default; Trie::~Trie() = default; Trie::Trie(Trie &&other) noexcept = default; Trie &Trie::operator=(Trie &&other) noexcept = default; void Trie::build(Keyset &keyset, int config_flags) { std::unique_ptr temp(new grimoire::LoudsTrie); temp->build(keyset, config_flags); trie_.swap(temp); } void Trie::mmap(const char *filename, int flags) { MARISA_THROW_IF(filename == nullptr, std::invalid_argument); std::unique_ptr temp(new grimoire::LoudsTrie); grimoire::Mapper mapper; mapper.open(filename, flags); temp->map(mapper); trie_.swap(temp); } void Trie::map(const void *ptr, std::size_t size) { MARISA_THROW_IF((ptr == nullptr) && (size != 0), std::invalid_argument); std::unique_ptr temp(new grimoire::LoudsTrie); grimoire::Mapper mapper; mapper.open(ptr, size); temp->map(mapper); trie_.swap(temp); } void Trie::load(const char *filename) { MARISA_THROW_IF(filename == nullptr, std::invalid_argument); std::unique_ptr temp(new grimoire::LoudsTrie); grimoire::Reader reader; reader.open(filename); temp->read(reader); trie_.swap(temp); } void Trie::read(int fd) { MARISA_THROW_IF(fd == -1, std::invalid_argument); std::unique_ptr temp(new grimoire::LoudsTrie); grimoire::Reader reader; reader.open(fd); temp->read(reader); trie_.swap(temp); } void Trie::save(const char *filename) const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); MARISA_THROW_IF(filename == nullptr, std::invalid_argument); grimoire::Writer writer; writer.open(filename); trie_->write(writer); } void Trie::write(int fd) const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); MARISA_THROW_IF(fd == -1, std::invalid_argument); grimoire::Writer writer; writer.open(fd); trie_->write(writer); } bool Trie::lookup(Agent &agent) const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); if (!agent.has_state()) { agent.init_state(); } return trie_->lookup(agent); } void Trie::reverse_lookup(Agent &agent) const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); if (!agent.has_state()) { agent.init_state(); } trie_->reverse_lookup(agent); } bool Trie::common_prefix_search(Agent &agent) const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); if (!agent.has_state()) { agent.init_state(); } return trie_->common_prefix_search(agent); } bool Trie::predictive_search(Agent &agent) const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); if (!agent.has_state()) { agent.init_state(); } return trie_->predictive_search(agent); } std::size_t Trie::num_tries() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->num_tries(); } std::size_t Trie::num_keys() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->num_keys(); } std::size_t Trie::num_nodes() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->num_nodes(); } TailMode Trie::tail_mode() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->tail_mode(); } NodeOrder Trie::node_order() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->node_order(); } bool Trie::empty() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->empty(); } std::size_t Trie::size() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->size(); } std::size_t Trie::total_size() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->total_size(); } std::size_t Trie::io_size() const { MARISA_THROW_IF(trie_ == nullptr, std::logic_error); return trie_->io_size(); } void Trie::clear() noexcept { Trie().swap(*this); } void Trie::swap(Trie &rhs) noexcept { trie_.swap(rhs.trie_); } } // namespace marisa #include namespace marisa { class TrieIO { public: static void fread(std::FILE *file, Trie *trie) { MARISA_THROW_IF(trie == nullptr, std::invalid_argument); std::unique_ptr temp(new grimoire::LoudsTrie); grimoire::Reader reader; reader.open(file); temp->read(reader); trie->trie_.swap(temp); } static void fwrite(std::FILE *file, const Trie &trie) { MARISA_THROW_IF(file == nullptr, std::invalid_argument); MARISA_THROW_IF(trie.trie_ == nullptr, std::logic_error); grimoire::Writer writer; writer.open(file); trie.trie_->write(writer); } static std::istream &read(std::istream &stream, Trie *trie) { MARISA_THROW_IF(trie == nullptr, std::invalid_argument); std::unique_ptr temp(new grimoire::LoudsTrie); grimoire::Reader reader; reader.open(stream); temp->read(reader); trie->trie_.swap(temp); return stream; } static std::ostream &write(std::ostream &stream, const Trie &trie) { MARISA_THROW_IF(trie.trie_ == nullptr, std::logic_error); grimoire::Writer writer; writer.open(stream); trie.trie_->write(writer); return stream; } }; void fread(std::FILE *file, Trie *trie) { MARISA_THROW_IF(file == nullptr, std::invalid_argument); MARISA_THROW_IF(trie == nullptr, std::invalid_argument); TrieIO::fread(file, trie); } void fwrite(std::FILE *file, const Trie &trie) { MARISA_THROW_IF(file == nullptr, std::invalid_argument); TrieIO::fwrite(file, trie); } std::istream &read(std::istream &stream, Trie *trie) { MARISA_THROW_IF(trie == nullptr, std::invalid_argument); return TrieIO::read(stream, trie); } std::ostream &write(std::ostream &stream, const Trie &trie) { return TrieIO::write(stream, trie); } std::istream &operator>>(std::istream &stream, Trie &trie) { return read(stream, &trie); } std::ostream &operator<<(std::ostream &stream, const Trie &trie) { return write(stream, trie); } } // namespace marisa marisa-trie-master/marisa.pc.in000066400000000000000000000003731505027263100167750ustar00rootroot00000000000000libdir=@CMAKE_INSTALL_PREFIX@/@LIB_INSTALL_DIR@ includedir=@CMAKE_INSTALL_PREFIX@/include Name: Marisa Description: Matching Algorithm with Recursively Implemented StorAge Version: @PROJECT_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -lmarisa marisa-trie-master/tests/000077500000000000000000000000001505027263100157275ustar00rootroot00000000000000marisa-trie-master/tests/base-test.cc000066400000000000000000000202201505027263100201210ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include "marisa-assert.h" namespace { std::random_device seed_gen; std::mt19937 random_engine(seed_gen()); void TestSwap() { TEST_START(); int x = 100, y = 200; std::swap(x, y); ASSERT(x == 200); ASSERT(y == 100); double a = 1.23, b = 2.34; std::swap(a, b); ASSERT(a == 2.34); ASSERT(b == 1.23); TEST_END(); } void TestException() { TEST_START(); try { MARISA_THROW(std::runtime_error, "Message"); } catch (const std::exception &ex) { std::stringstream s; s << __FILE__ << ":" << (__LINE__ - 3) << ": std::runtime_error: Message"; ASSERT(ex.what() == s.str()); } EXCEPT(MARISA_THROW(std::runtime_error, "OK"), std::runtime_error); EXCEPT(MARISA_THROW(std::invalid_argument, "NULL"), std::invalid_argument); TEST_END(); } void TestKey() { TEST_START(); const char *const str = "apple"; marisa::Key key; ASSERT(key.ptr() == nullptr); ASSERT(key.length() == 0); key.set_str(str); ASSERT(key.ptr() == str); ASSERT(key.length() == std::strlen(str)); key.set_str(str, 4); ASSERT(key.ptr() == str); ASSERT(key.length() == 4); const std::string_view view = "orange"; key.set_str(view); ASSERT(key.ptr() == view.data()); ASSERT(key.length() == 6); // Compare string_view, emphasizing that it is not a pointer comparison. ASSERT(key.str() == std::string("orange")); key.set_weight(1.0); ASSERT(key.weight() == 1.0F); key.set_id(100); ASSERT(key.id() == 100); TEST_END(); } void TestKeyset() { TEST_START(); marisa::Keyset keyset; ASSERT(keyset.size() == 0); ASSERT(keyset.empty()); ASSERT(keyset.total_length() == 0); std::vector keys; keys.push_back("apple"); keys.push_back("orange"); keys.push_back("banana"); std::size_t total_length = 0; for (std::size_t i = 0; i < keys.size(); ++i) { keyset.push_back(keys[i].c_str()); ASSERT(keyset.size() == (i + 1)); ASSERT(!keyset.empty()); total_length += keys[i].length(); ASSERT(keyset.total_length() == total_length); ASSERT(keyset[i].length() == keys[i].length()); ASSERT(std::memcmp(keyset[i].ptr(), keys[i].c_str(), keyset[i].length()) == 0); ASSERT(keyset[i].weight() == 1.0F); } keyset.clear(); total_length = 0; // Same thing again, but now via string_view, and with a weight. for (std::size_t i = 0; i < keys.size(); ++i) { keyset.push_back(keys[i], 2.0); ASSERT(keyset.size() == (i + 1)); ASSERT(!keyset.empty()); total_length += keys[i].length(); ASSERT(keyset.total_length() == total_length); ASSERT(keyset[i].length() == keys[i].length()); ASSERT(keyset[i].str().length() == keys[i].length()); ASSERT(std::memcmp(keyset[i].ptr(), keys[i].c_str(), keyset[i].length()) == 0); ASSERT(keyset[i].str() == keys[i]); ASSERT(keyset[i].weight() == 2.0F); } keyset.clear(); marisa::Key key; key.set_str("123"); keyset.push_back(key); ASSERT(keyset[0].length() == 3); ASSERT(std::memcmp(keyset[0].ptr(), "123", 3) == 0); key.set_str("456"); keyset.push_back(key, '\0'); ASSERT(keyset[1].length() == 3); ASSERT(std::memcmp(keyset[1].ptr(), "456", 3) == 0); ASSERT(std::strcmp(keyset[1].ptr(), "456") == 0); key.set_str("789"); keyset.push_back(key, '0'); ASSERT(keyset[2].length() == 3); ASSERT(std::memcmp(keyset[2].ptr(), "789", 3) == 0); ASSERT(std::memcmp(keyset[2].ptr(), "7890", 4) == 0); ASSERT(keyset.size() == 3); keyset.clear(); ASSERT(keyset.size() == 0); ASSERT(keyset.total_length() == 0); keys.resize(1000); std::vector weights(keys.size()); total_length = 0; for (std::size_t i = 0; i < keys.size(); ++i) { keys[i].resize(random_engine() % (marisa::Keyset::EXTRA_BLOCK_SIZE * 2)); for (std::size_t j = 0; j < keys[i].length(); ++j) { keys[i][j] = static_cast(random_engine() & 0xFF); } double weight = 100.0 * static_cast(random_engine()) / static_cast(RAND_MAX); weights[i] = static_cast(weight); keyset.push_back(keys[i].c_str(), keys[i].length(), weights[i]); total_length += keys[i].length(); ASSERT(keyset.total_length() == total_length); } ASSERT(keyset.size() == keys.size()); for (std::size_t i = 0; i < keys.size(); ++i) { ASSERT(keyset[i].length() == keys[i].length()); ASSERT(std::memcmp(keyset[i].ptr(), keys[i].c_str(), keyset[i].length()) == 0); ASSERT(keyset[i].weight() == weights[i]); } keyset.reset(); ASSERT(keyset.size() == 0); ASSERT(keyset.total_length() == 0); total_length = 0; for (std::size_t i = 0; i < keys.size(); ++i) { keys[i].resize(random_engine() % (marisa::Keyset::EXTRA_BLOCK_SIZE * 2)); for (std::size_t j = 0; j < keys[i].length(); ++j) { keys[i][j] = static_cast(random_engine() & 0xFF); } double weight = 100.0 * static_cast(random_engine()) / static_cast(RAND_MAX); weights[i] = static_cast(weight); keyset.push_back(keys[i].c_str(), keys[i].length(), weights[i]); total_length += keys[i].length(); ASSERT(keyset.total_length() == total_length); } ASSERT(keyset.size() == keys.size()); for (std::size_t i = 0; i < keys.size(); ++i) { ASSERT(keyset[i].length() == keys[i].length()); ASSERT(std::memcmp(keyset[i].ptr(), keys[i].c_str(), keyset[i].length()) == 0); ASSERT(keyset[i].weight() == weights[i]); } TEST_END(); } void TestQuery() { TEST_START(); marisa::Query query; ASSERT(query.ptr() == nullptr); ASSERT(query.length() == 0); ASSERT(query.id() == 0); const char *str = "apple"; query.set_str(str); ASSERT(query.ptr() == str); ASSERT(query.length() == std::strlen(str)); query.set_str(str, 3); ASSERT(query.ptr() == str); ASSERT(query.length() == 3); const std::string_view view = "orange"; query.set_str(view); ASSERT(query.ptr() == view.data()); ASSERT(query.length() == 6); // Compare string_view, emphasizing that it is not a pointer comparison. ASSERT(query.str() == std::string("orange")); query.set_id(100); ASSERT(query.id() == 100); query.clear(); ASSERT(query.ptr() == nullptr); ASSERT(query.length() == 0); ASSERT(query.id() == 0); TEST_END(); } void TestAgent() { TEST_START(); marisa::Agent agent; ASSERT(agent.query().ptr() == nullptr); ASSERT(agent.query().length() == 0); ASSERT(agent.query().id() == 0); ASSERT(agent.key().ptr() == nullptr); ASSERT(agent.key().length() == 0); ASSERT(!agent.has_state()); const char *query_str = "query"; const char *key_str = "key"; agent.set_query(query_str); agent.set_query(123); agent.set_key(key_str); agent.set_key(234); ASSERT(agent.query().ptr() == query_str); ASSERT(agent.query().length() == std::strlen(query_str)); ASSERT(agent.query().id() == 123); ASSERT(agent.key().ptr() == key_str); ASSERT(agent.key().length() == std::strlen(key_str)); ASSERT(agent.key().id() == 234); const std::string_view query_view = "query2"; const std::string_view key_view = "key2"; agent.set_query(query_view); agent.set_key(key_view); ASSERT(agent.query().ptr() == query_view.data()); ASSERT(agent.query().length() == 6); // Compare string_view, emphasizing that it is not a pointer comparison. ASSERT(agent.query().str() == std::string("query2")); ASSERT(agent.key().ptr() == key_view.data()); ASSERT(agent.key().length() == 4); ASSERT(agent.key().str() == std::string("key2")); agent.init_state(); ASSERT(agent.has_state()); EXCEPT(agent.init_state(), std::logic_error); agent.clear(); ASSERT(agent.query().ptr() == nullptr); ASSERT(agent.query().length() == 0); ASSERT(agent.query().id() == 0); ASSERT(agent.key().ptr() == nullptr); ASSERT(agent.key().length() == 0); ASSERT(!agent.has_state()); TEST_END(); } } // namespace int main() try { TestSwap(); TestException(); TestKey(); TestKeyset(); TestQuery(); TestAgent(); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << "\n"; throw; } marisa-trie-master/tests/io-test.cc000066400000000000000000000122451505027263100176260ustar00rootroot00000000000000#ifdef _MSC_VER #include #else #include #endif // _MSC_VER #include #include #include #include #include #include #include #include #include "marisa-assert.h" namespace { void TestFilename() { TEST_START(); { marisa::grimoire::Writer writer; writer.open("io-test.dat"); writer.write(std::uint32_t{123}); writer.write(std::uint32_t{234}); double values[] = {3.45, 4.56}; writer.write(values, 2); EXCEPT(writer.write(values, SIZE_MAX), std::invalid_argument); } { marisa::grimoire::Reader reader; reader.open("io-test.dat"); std::uint32_t value; reader.read(&value); ASSERT(value == 123); reader.read(&value); ASSERT(value == 234); double values[2]; reader.read(values, 2); ASSERT(values[0] == 3.45); ASSERT(values[1] == 4.56); char byte; EXCEPT(reader.read(&byte), std::runtime_error); } { marisa::grimoire::Mapper mapper; mapper.open("io-test.dat"); std::uint32_t value; mapper.map(&value); ASSERT(value == 123); mapper.map(&value); ASSERT(value == 234); const double *values; mapper.map(&values, 2); ASSERT(values[0] == 3.45); ASSERT(values[1] == 4.56); char byte; EXCEPT(mapper.map(&byte), std::runtime_error); } { marisa::grimoire::Mapper mapper; mapper.open("io-test.dat", MARISA_MAP_POPULATE); std::uint32_t value; mapper.map(&value); ASSERT(value == 123); mapper.map(&value); ASSERT(value == 234); const double *values; mapper.map(&values, 2); ASSERT(values[0] == 3.45); ASSERT(values[1] == 4.56); char byte; EXCEPT(mapper.map(&byte), std::runtime_error); } { marisa::grimoire::Writer writer; writer.open("io-test.dat"); } { marisa::grimoire::Reader reader; reader.open("io-test.dat"); char byte; EXCEPT(reader.read(&byte), std::runtime_error); } TEST_END(); } void TestFd() { TEST_START(); { #ifdef _MSC_VER int fd = -1; ASSERT(::_sopen_s(&fd, "io-test.dat", _O_BINARY | _O_CREAT | _O_WRONLY | _O_TRUNC, _SH_DENYRW, _S_IREAD | _S_IWRITE) == 0); #else // _MSC_VER int fd = ::creat("io-test.dat", 0644); ASSERT(fd != -1); #endif // _MSC_VER marisa::grimoire::Writer writer; writer.open(fd); std::uint32_t value = 234; writer.write(value); double values[] = {34.5, 67.8}; writer.write(values, 2); #ifdef _MSC_VER ASSERT(::_close(fd) == 0); #else // _MSC_VER ASSERT(::close(fd) == 0); #endif // _MSC_VER } { #ifdef _MSC_VER int fd = -1; ASSERT(::_sopen_s(&fd, "io-test.dat", _O_BINARY | _O_RDONLY, _SH_DENYRW, _S_IREAD) == 0); #else // _MSC_VER int fd = ::open("io-test.dat", O_RDONLY); ASSERT(fd != -1); #endif // _MSC_VER marisa::grimoire::Reader reader; reader.open(fd); std::uint32_t value; reader.read(&value); ASSERT(value == 234); double values[2]; reader.read(values, 2); ASSERT(values[0] == 34.5); ASSERT(values[1] == 67.8); char byte; EXCEPT(reader.read(&byte), std::runtime_error); #ifdef _MSC_VER ASSERT(::_close(fd) == 0); #else // _MSC_VER ASSERT(::close(fd) == 0); #endif // _MSC_VER } TEST_END(); } void TestFile() { TEST_START(); { #ifdef _MSC_VER FILE *file = nullptr; ASSERT(::fopen_s(&file, "io-test.dat", "wb") == 0); #else // _MSC_VER FILE *file = std::fopen("io-test.dat", "wb"); ASSERT(file != nullptr); #endif // _MSC_VER marisa::grimoire::Writer writer; writer.open(file); std::uint32_t value = 10; writer.write(value); double values[2] = {0.1, 0.2}; writer.write(values, 2); ASSERT(std::fclose(file) == 0); } { #ifdef _MSC_VER FILE *file = nullptr; ASSERT(::fopen_s(&file, "io-test.dat", "rb") == 0); #else // _MSC_VER FILE *file = std::fopen("io-test.dat", "rb"); ASSERT(file != nullptr); #endif // _MSC_VER marisa::grimoire::Reader reader; reader.open(file); std::uint32_t value; reader.read(&value); ASSERT(value == 10); double values[2]; reader.read(values, 2); ASSERT(values[0] == 0.1); ASSERT(values[1] == 0.2); char byte; EXCEPT(reader.read(&byte), std::runtime_error); ASSERT(std::fclose(file) == 0); } TEST_END(); } void TestStream() { TEST_START(); std::stringstream stream; { marisa::grimoire::Writer writer; writer.open(stream); std::uint32_t value = 12; writer.write(value); double values[2] = {3.4, 5.6}; writer.write(values, 2); } { marisa::grimoire::Reader reader; reader.open(stream); std::uint32_t value; reader.read(&value); ASSERT(value == 12); double values[2]; reader.read(values, 2); ASSERT(values[0] == 3.4); ASSERT(values[1] == 5.6); char byte; EXCEPT(reader.read(&byte), std::runtime_error); } TEST_END(); } } // namespace int main() try { TestFilename(); TestFd(); TestFile(); TestStream(); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << "\n"; throw; } marisa-trie-master/tests/marisa-assert.h000066400000000000000000000021601505027263100206520ustar00rootroot00000000000000#ifndef MARISA_ASSERT_H_ #define MARISA_ASSERT_H_ #include #include #define ASSERT(cond) \ (void)((!!(cond)) || ((std::cout << __LINE__ << ": Assertion `" << #cond \ << "' failed.\n"), \ std::exit(-1), 0)) #define EXCEPT(code, expected_error_type) \ try { \ code; \ std::cout << __LINE__ << ": Exception `" << #code << "' failed.\n"; \ std::exit(-1); \ } catch (const expected_error_type &) { \ } catch (...) { \ ASSERT(false); \ } #define TEST_START() \ (std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION__ << "(): ") #define TEST_END() (std::cout << "ok\n") #endif // MARISA_ASSERT_H_ marisa-trie-master/tests/marisa-test.cc000066400000000000000000000333651505027263100205010ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include #include "marisa-assert.h" namespace { std::random_device seed_gen; std::mt19937 random_engine(seed_gen()); void TestEmptyTrie() { TEST_START(); marisa::Trie trie; EXCEPT(trie.save("marisa-test.dat"), std::logic_error); #ifdef _MSC_VER EXCEPT(trie.write(::_fileno(stdout)), std::logic_error); #else // _MSC_VER EXCEPT(trie.write(::fileno(stdout)), std::logic_error); #endif // _MSC_VER EXCEPT(std::cout << trie, std::logic_error); EXCEPT(marisa::fwrite(stdout, trie), std::logic_error); marisa::Agent agent; EXCEPT(trie.lookup(agent), std::logic_error); EXCEPT(trie.reverse_lookup(agent), std::logic_error); EXCEPT(trie.common_prefix_search(agent), std::logic_error); EXCEPT(trie.predictive_search(agent), std::logic_error); EXCEPT(trie.num_tries(), std::logic_error); EXCEPT(trie.num_keys(), std::logic_error); EXCEPT(trie.num_nodes(), std::logic_error); EXCEPT(trie.tail_mode(), std::logic_error); EXCEPT(trie.node_order(), std::logic_error); EXCEPT(trie.empty(), std::logic_error); EXCEPT(trie.size(), std::logic_error); EXCEPT(trie.total_size(), std::logic_error); EXCEPT(trie.io_size(), std::logic_error); marisa::Keyset keyset; trie.build(keyset); ASSERT(!trie.lookup(agent)); EXCEPT(trie.reverse_lookup(agent), std::out_of_range); ASSERT(!trie.common_prefix_search(agent)); ASSERT(!trie.predictive_search(agent)); ASSERT(trie.num_tries() == 1); ASSERT(trie.num_keys() == 0); ASSERT(trie.num_nodes() == 1); ASSERT(trie.tail_mode() == MARISA_DEFAULT_TAIL); ASSERT(trie.node_order() == MARISA_DEFAULT_ORDER); ASSERT(trie.empty()); ASSERT(trie.size() == 0); ASSERT(trie.total_size() != 0); ASSERT(trie.io_size() != 0); keyset.push_back(""); trie.build(keyset); ASSERT(trie.lookup(agent)); trie.reverse_lookup(agent); ASSERT(trie.common_prefix_search(agent)); ASSERT(!trie.common_prefix_search(agent)); ASSERT(trie.predictive_search(agent)); ASSERT(!trie.predictive_search(agent)); ASSERT(trie.num_keys() == 1); ASSERT(trie.num_nodes() == 1); ASSERT(!trie.empty()); ASSERT(trie.size() == 1); ASSERT(trie.total_size() != 0); ASSERT(trie.io_size() != 0); TEST_END(); } void TestTinyTrie() { TEST_START(); marisa::Keyset keyset; keyset.push_back("bach"); keyset.push_back("bet"); keyset.push_back("chat"); keyset.push_back("check"); keyset.push_back("check"); marisa::Trie trie; trie.build(keyset, 1); ASSERT(trie.num_tries() == 1); ASSERT(trie.num_keys() == 4); ASSERT(trie.num_nodes() == 7); ASSERT(trie.tail_mode() == MARISA_DEFAULT_TAIL); ASSERT(trie.node_order() == MARISA_DEFAULT_ORDER); ASSERT(keyset[0].id() == 2); ASSERT(keyset[1].id() == 3); ASSERT(keyset[2].id() == 1); ASSERT(keyset[3].id() == 0); ASSERT(keyset[4].id() == 0); marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); ASSERT(trie.lookup(agent)); ASSERT(agent.key().id() == keyset[i].id()); agent.set_query(keyset[i].id()); trie.reverse_lookup(agent); ASSERT(agent.key().length() == keyset[i].length()); ASSERT(std::memcmp(agent.key().ptr(), keyset[i].ptr(), agent.key().length()) == 0); } agent.set_query("be"); ASSERT(!trie.common_prefix_search(agent)); agent.set_query("beX"); ASSERT(!trie.common_prefix_search(agent)); agent.set_query("bet"); ASSERT(trie.common_prefix_search(agent)); ASSERT(!trie.common_prefix_search(agent)); agent.set_query("betX"); ASSERT(trie.common_prefix_search(agent)); ASSERT(!trie.common_prefix_search(agent)); agent.set_query("chatX"); ASSERT(!trie.predictive_search(agent)); agent.set_query("chat"); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().length() == 4); ASSERT(!trie.predictive_search(agent)); agent.set_query("cha"); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().length() == 4); ASSERT(!trie.predictive_search(agent)); agent.set_query("c"); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().length() == 5); ASSERT(std::memcmp(agent.key().ptr(), "check", 5) == 0); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().length() == 4); ASSERT(std::memcmp(agent.key().ptr(), "chat", 4) == 0); ASSERT(!trie.predictive_search(agent)); agent.set_query("ch"); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().length() == 5); ASSERT(std::memcmp(agent.key().ptr(), "check", 5) == 0); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().length() == 4); ASSERT(std::memcmp(agent.key().ptr(), "chat", 4) == 0); ASSERT(!trie.predictive_search(agent)); trie.build(keyset, 1 | MARISA_LABEL_ORDER); ASSERT(trie.num_tries() == 1); ASSERT(trie.num_keys() == 4); ASSERT(trie.num_nodes() == 7); ASSERT(trie.tail_mode() == MARISA_DEFAULT_TAIL); ASSERT(trie.node_order() == MARISA_LABEL_ORDER); ASSERT(keyset[0].id() == 0); ASSERT(keyset[1].id() == 1); ASSERT(keyset[2].id() == 2); ASSERT(keyset[3].id() == 3); ASSERT(keyset[4].id() == 3); for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); ASSERT(trie.lookup(agent)); ASSERT(agent.key().id() == keyset[i].id()); agent.set_query(keyset[i].id()); trie.reverse_lookup(agent); ASSERT(agent.key().length() == keyset[i].length()); ASSERT(std::memcmp(agent.key().ptr(), keyset[i].ptr(), agent.key().length()) == 0); } agent.set_query(""); for (std::size_t i = 0; i < trie.size(); ++i) { ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().id() == i); } ASSERT(!trie.predictive_search(agent)); TEST_END(); } void MakeKeyset(std::size_t num_keys, marisa::TailMode tail_mode, marisa::Keyset *keyset) { char key_buf[16]; for (std::size_t i = 0; i < num_keys; ++i) { const std::size_t length = static_cast(random_engine()) % sizeof(key_buf); for (std::size_t j = 0; j < length; ++j) { key_buf[j] = static_cast(random_engine() % 10); if (tail_mode == MARISA_TEXT_TAIL) { key_buf[j] = static_cast(key_buf[j] + '0'); } } keyset->push_back(key_buf, length); } } void TestLookup(const marisa::Trie &trie, const marisa::Keyset &keyset) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); ASSERT(trie.lookup(agent)); ASSERT(agent.key().id() == keyset[i].id()); agent.set_query(keyset[i].id()); trie.reverse_lookup(agent); ASSERT(agent.key().length() == keyset[i].length()); ASSERT(std::memcmp(agent.key().ptr(), keyset[i].ptr(), agent.key().length()) == 0); } } void TestCommonPrefixSearch(const marisa::Trie &trie, const marisa::Keyset &keyset) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); ASSERT(trie.common_prefix_search(agent)); ASSERT(agent.key().id() <= keyset[i].id()); while (trie.common_prefix_search(agent)) { ASSERT(agent.key().id() <= keyset[i].id()); } ASSERT(agent.key().id() == keyset[i].id()); } } void TestCommonPrefixSearchAgentCopy(const marisa::Trie &trie, const marisa::Keyset &keyset) { if (keyset.empty()) return; marisa::Agent agent; agent.set_query(keyset[0].ptr(), keyset[0].length()); ASSERT(trie.common_prefix_search(agent)); const std::string original_agent_key(agent.key().ptr(), agent.key().length()); marisa::Agent agent_copy = agent; trie.common_prefix_search(agent); ASSERT(std::string(agent_copy.key().ptr(), agent_copy.key().length()) == original_agent_key); } void TestPredictiveSearch(const marisa::Trie &trie, const marisa::Keyset &keyset) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().id() == keyset[i].id()); while (trie.predictive_search(agent)) { ASSERT(agent.key().id() > keyset[i].id()); } } } void TestPredictiveSearchAgentCopy(const marisa::Trie &trie, const marisa::Keyset &keyset) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); ASSERT(trie.predictive_search(agent)); ASSERT(agent.key().id() == keyset[i].id()); std::vector agent_copies; std::vector ids; std::vector keys; while (trie.predictive_search(agent)) { ASSERT(agent.key().id() > keyset[i].id()); ids.push_back(agent.key().id()); keys.emplace_back(agent.key().ptr(), agent.key().length()); // Tests copy constructor. agent_copies.push_back(agent); } for (std::size_t j = 0; j < agent_copies.size(); ++j) { marisa::Agent agent_copy; // Tests copy assignment. agent_copy = agent_copies[j]; ASSERT(agent_copy.key().id() == ids[j]); ASSERT(std::string(agent_copy.key().ptr(), agent_copy.key().length()) == keys[j]); if (j + 1 < agent_copies.size()) { ASSERT(trie.predictive_search(agent_copy)); ASSERT(agent_copy.key().id() == ids[j + 1]); ASSERT(std::string(agent_copy.key().ptr(), agent_copy.key().length()) == keys[j + 1]); } else { ASSERT(!trie.predictive_search(agent_copy)); } } } } void TestPredictiveSearchAgentMove(const marisa::Trie &trie, const marisa::Keyset &keyset) { marisa::Agent agents[2]; std::size_t current_agent = 0; const auto move_agent = [&]() { const std::size_t other_agent = (current_agent + 1) % 2; agents[other_agent] = std::move(agents[current_agent]); agents[current_agent] = {}; current_agent = other_agent; }; for (std::size_t i = 0; i < keyset.size(); ++i) { agents[current_agent].set_query(keyset[i].ptr(), keyset[i].length()); move_agent(); ASSERT(trie.predictive_search(agents[current_agent])); move_agent(); ASSERT(agents[current_agent].key().id() == keyset[i].id()); while (trie.predictive_search(agents[current_agent])) { move_agent(); ASSERT(agents[current_agent].key().id() > keyset[i].id()); } } } void TestTrie(int num_tries, marisa::TailMode tail_mode, marisa::NodeOrder node_order, marisa::Keyset &keyset) { for (std::size_t i = 0; i < keyset.size(); ++i) { keyset[i].set_weight(1.0F); } marisa::Trie trie; trie.build(keyset, num_tries | tail_mode | node_order); ASSERT(trie.num_tries() == static_cast(num_tries)); ASSERT(trie.num_keys() <= keyset.size()); ASSERT(trie.tail_mode() == tail_mode); ASSERT(trie.node_order() == node_order); TestLookup(trie, keyset); TestCommonPrefixSearch(trie, keyset); TestCommonPrefixSearchAgentCopy(trie, keyset); TestPredictiveSearch(trie, keyset); TestPredictiveSearchAgentCopy(trie, keyset); TestPredictiveSearchAgentMove(trie, keyset); trie.save("marisa-test.dat"); trie.clear(); trie.load("marisa-test.dat"); ASSERT(trie.num_tries() == static_cast(num_tries)); ASSERT(trie.num_keys() <= keyset.size()); ASSERT(trie.tail_mode() == tail_mode); ASSERT(trie.node_order() == node_order); TestLookup(trie, keyset); { std::FILE *file; #ifdef _MSC_VER ASSERT(::fopen_s(&file, "marisa-test.dat", "wb") == 0); #else // _MSC_VER file = std::fopen("marisa-test.dat", "wb"); ASSERT(file != nullptr); #endif // _MSC_VER marisa::fwrite(file, trie); std::fclose(file); trie.clear(); #ifdef _MSC_VER ASSERT(::fopen_s(&file, "marisa-test.dat", "rb") == 0); #else // _MSC_VER file = std::fopen("marisa-test.dat", "rb"); ASSERT(file != nullptr); #endif // _MSC_VER marisa::fread(file, &trie); std::fclose(file); } ASSERT(trie.num_tries() == static_cast(num_tries)); ASSERT(trie.num_keys() <= keyset.size()); ASSERT(trie.tail_mode() == tail_mode); ASSERT(trie.node_order() == node_order); TestLookup(trie, keyset); trie.clear(); trie.mmap("marisa-test.dat"); ASSERT(trie.num_tries() == static_cast(num_tries)); ASSERT(trie.num_keys() <= keyset.size()); ASSERT(trie.tail_mode() == tail_mode); ASSERT(trie.node_order() == node_order); TestLookup(trie, keyset); { std::stringstream stream; stream << trie; trie.clear(); stream >> trie; } ASSERT(trie.num_tries() == static_cast(num_tries)); ASSERT(trie.num_keys() <= keyset.size()); ASSERT(trie.tail_mode() == tail_mode); ASSERT(trie.node_order() == node_order); TestLookup(trie, keyset); } void TestTrie(marisa::TailMode tail_mode, marisa::NodeOrder node_order, marisa::Keyset &keyset) { TEST_START(); std::cout << ((tail_mode == MARISA_TEXT_TAIL) ? "TEXT" : "BINARY") << ", "; std::cout << ((node_order == MARISA_WEIGHT_ORDER) ? "WEIGHT" : "LABEL") << ": "; for (int i = 1; i < 5; ++i) { TestTrie(i, tail_mode, node_order, keyset); } TEST_END(); } void TestTrie(marisa::TailMode tail_mode) { marisa::Keyset keyset; MakeKeyset(1000, tail_mode, &keyset); TestTrie(tail_mode, MARISA_WEIGHT_ORDER, keyset); TestTrie(tail_mode, MARISA_LABEL_ORDER, keyset); } void TestTrie() { TestTrie(MARISA_TEXT_TAIL); TestTrie(MARISA_BINARY_TAIL); } } // namespace int main() try { TestEmptyTrie(); TestTinyTrie(); TestTrie(); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << "\n"; throw; } marisa-trie-master/tests/trie-test.cc000066400000000000000000000302351505027263100201610ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include #include "marisa-assert.h" namespace { void TestConfig() { TEST_START(); marisa::grimoire::trie::Config config; ASSERT(config.num_tries() == MARISA_DEFAULT_NUM_TRIES); ASSERT(config.tail_mode() == MARISA_DEFAULT_TAIL); ASSERT(config.node_order() == MARISA_DEFAULT_ORDER); ASSERT(config.cache_level() == MARISA_DEFAULT_CACHE); config.parse(10 | MARISA_BINARY_TAIL | MARISA_LABEL_ORDER | MARISA_TINY_CACHE); ASSERT(config.num_tries() == 10); ASSERT(config.tail_mode() == MARISA_BINARY_TAIL); ASSERT(config.node_order() == MARISA_LABEL_ORDER); ASSERT(config.cache_level() == MARISA_TINY_CACHE); config.parse(0); ASSERT(config.num_tries() == MARISA_DEFAULT_NUM_TRIES); ASSERT(config.tail_mode() == MARISA_DEFAULT_TAIL); ASSERT(config.node_order() == MARISA_DEFAULT_ORDER); ASSERT(config.cache_level() == MARISA_DEFAULT_CACHE); TEST_END(); } void TestHeader() { TEST_START(); marisa::grimoire::trie::Header header; { marisa::grimoire::Writer writer; writer.open("trie-test.dat"); header.write(writer); } { marisa::grimoire::Mapper mapper; mapper.open("trie-test.dat"); header.map(mapper); } { marisa::grimoire::Reader reader; reader.open("trie-test.dat"); header.read(reader); } TEST_END(); } void TestKey() { TEST_START(); marisa::grimoire::trie::Key key; ASSERT(key.ptr() == nullptr); ASSERT(key.length() == 0); ASSERT(key.id() == 0); ASSERT(key.terminal() == 0); const char *str = "xyz"; key.set_str(str, 3); key.set_weight(10.0F); key.set_id(20); ASSERT(key.ptr() == str); ASSERT(key.length() == 3); ASSERT(key[0] == 'x'); ASSERT(key[1] == 'y'); ASSERT(key[2] == 'z'); ASSERT(key.weight() == 10.0F); ASSERT(key.id() == 20); key.set_terminal(30); ASSERT(key.terminal() == 30); key.substr(1, 2); ASSERT(key.ptr() == str + 1); ASSERT(key.length() == 2); ASSERT(key[0] == 'y'); ASSERT(key[1] == 'z'); marisa::grimoire::trie::Key key2; key2.set_str("abc", 3); ASSERT(key == key); ASSERT(key != key2); ASSERT(key > key2); ASSERT(key2 < key); marisa::grimoire::trie::ReverseKey r_key; ASSERT(r_key.ptr() == nullptr); ASSERT(r_key.length() == 0); ASSERT(r_key.id() == 0); ASSERT(r_key.terminal() == 0); r_key.set_str(str, 3); r_key.set_weight(100.0F); r_key.set_id(200); ASSERT(r_key.ptr() == str); ASSERT(r_key.length() == 3); ASSERT(r_key[0] == 'z'); ASSERT(r_key[1] == 'y'); ASSERT(r_key[2] == 'x'); ASSERT(r_key.weight() == 100.0F); ASSERT(r_key.id() == 200); r_key.set_terminal(300); ASSERT(r_key.terminal() == 300); r_key.substr(1, 2); ASSERT(r_key.ptr() == str); ASSERT(r_key.length() == 2); ASSERT(r_key[0] == 'y'); ASSERT(r_key[1] == 'x'); marisa::grimoire::trie::ReverseKey r_key2; r_key2.set_str("abc", 3); ASSERT(r_key == r_key); ASSERT(r_key != r_key2); ASSERT(r_key > r_key2); ASSERT(r_key2 < r_key); TEST_END(); } void TestRange() { TEST_START(); marisa::grimoire::trie::Range range; ASSERT(range.begin() == 0); ASSERT(range.end() == 0); ASSERT(range.key_pos() == 0); range.set_begin(1); range.set_end(2); range.set_key_pos(3); ASSERT(range.begin() == 1); ASSERT(range.end() == 2); ASSERT(range.key_pos() == 3); range = marisa::grimoire::trie::make_range(10, 20, 30); ASSERT(range.begin() == 10); ASSERT(range.end() == 20); ASSERT(range.key_pos() == 30); marisa::grimoire::trie::WeightedRange w_range; ASSERT(w_range.begin() == 0); ASSERT(w_range.end() == 0); ASSERT(w_range.key_pos() == 0); ASSERT(w_range.weight() == 0.0F); w_range.set_begin(10); w_range.set_end(20); w_range.set_key_pos(30); w_range.set_weight(40.0F); ASSERT(w_range.begin() == 10); ASSERT(w_range.end() == 20); ASSERT(w_range.key_pos() == 30); ASSERT(w_range.weight() == 40.0F); marisa::grimoire::trie::WeightedRange w_range2 = marisa::grimoire::trie::make_weighted_range(100, 200, 300, 400.0F); ASSERT(w_range2.begin() == 100); ASSERT(w_range2.end() == 200); ASSERT(w_range2.key_pos() == 300); ASSERT(w_range2.weight() == 400.0F); ASSERT(w_range < w_range2); ASSERT(w_range2 > w_range); TEST_END(); } void TestEntry() { TEST_START(); marisa::grimoire::trie::Entry entry; ASSERT(entry.length() == 0); ASSERT(entry.id() == 0); const char *str = "XYZ"; entry.set_str(str, 3); entry.set_id(123); ASSERT(entry.ptr() == str); ASSERT(entry.length() == 3); ASSERT(entry[0] == 'Z'); ASSERT(entry[1] == 'Y'); ASSERT(entry[2] == 'X'); ASSERT(entry.id() == 123); TEST_END(); } void TestTextTail() { TEST_START(); marisa::grimoire::trie::Tail tail; marisa::grimoire::Vector entries; marisa::grimoire::Vector offsets; tail.build(entries, &offsets, MARISA_TEXT_TAIL); ASSERT(tail.mode() == MARISA_TEXT_TAIL); ASSERT(tail.size() == 0); ASSERT(tail.empty()); ASSERT(tail.total_size() == tail.size()); ASSERT(tail.io_size() == (sizeof(std::uint64_t) * 6)); ASSERT(offsets.empty()); marisa::grimoire::trie::Entry entry; entry.set_str("X", 1); entries.push_back(entry); tail.build(entries, &offsets, MARISA_TEXT_TAIL); ASSERT(tail.mode() == MARISA_TEXT_TAIL); ASSERT(tail.size() == 2); ASSERT(!tail.empty()); ASSERT(tail.total_size() == tail.size()); ASSERT(tail.io_size() == (sizeof(std::uint64_t) * 7)); ASSERT(offsets.size() == entries.size()); ASSERT(offsets[0] == 0); ASSERT(tail[offsets[0]] == 'X'); ASSERT(tail[offsets[0] + 1] == '\0'); entries.clear(); entry.set_str("abc", 3); entries.push_back(entry); entry.set_str("bc", 2); entries.push_back(entry); entry.set_str("abc", 3); entries.push_back(entry); entry.set_str("c", 1); entries.push_back(entry); entry.set_str("ABC", 3); entries.push_back(entry); entry.set_str("AB", 2); entries.push_back(entry); tail.build(entries, &offsets, MARISA_TEXT_TAIL); std::sort(entries.begin(), entries.end(), marisa::grimoire::trie::Entry::IDComparer()); ASSERT(tail.size() == 11); ASSERT(offsets.size() == entries.size()); for (std::size_t i = 0; i < entries.size(); ++i) { const char *const ptr = &tail[offsets[i]]; ASSERT(std::strlen(ptr) == entries[i].length()); ASSERT(std::strcmp(ptr, entries[i].ptr()) == 0); } { marisa::grimoire::Writer writer; writer.open("trie-test.dat"); tail.write(writer); } tail.clear(); ASSERT(tail.size() == 0); ASSERT(tail.total_size() == tail.size()); { marisa::grimoire::Mapper mapper; mapper.open("trie-test.dat"); tail.map(mapper); ASSERT(tail.mode() == MARISA_TEXT_TAIL); ASSERT(tail.size() == 11); for (std::size_t i = 0; i < entries.size(); ++i) { const char *const ptr = &tail[offsets[i]]; ASSERT(std::strlen(ptr) == entries[i].length()); ASSERT(std::strcmp(ptr, entries[i].ptr()) == 0); } tail.clear(); } { marisa::grimoire::Reader reader; reader.open("trie-test.dat"); tail.read(reader); } ASSERT(tail.size() == 11); ASSERT(offsets.size() == entries.size()); for (std::size_t i = 0; i < entries.size(); ++i) { const char *const ptr = &tail[offsets[i]]; ASSERT(std::strlen(ptr) == entries[i].length()); ASSERT(std::strcmp(ptr, entries[i].ptr()) == 0); } { std::stringstream stream; marisa::grimoire::Writer writer; writer.open(stream); tail.write(writer); tail.clear(); marisa::grimoire::Reader reader; reader.open(stream); tail.read(reader); } ASSERT(tail.size() == 11); ASSERT(offsets.size() == entries.size()); for (std::size_t i = 0; i < entries.size(); ++i) { const char *const ptr = &tail[offsets[i]]; ASSERT(std::strlen(ptr) == entries[i].length()); ASSERT(std::strcmp(ptr, entries[i].ptr()) == 0); } TEST_END(); } void TestBinaryTail() { TEST_START(); marisa::grimoire::trie::Tail tail; marisa::grimoire::Vector entries; marisa::grimoire::Vector offsets; tail.build(entries, &offsets, MARISA_BINARY_TAIL); ASSERT(tail.mode() == MARISA_TEXT_TAIL); ASSERT(tail.size() == 0); ASSERT(tail.empty()); ASSERT(tail.total_size() == tail.size()); ASSERT(tail.io_size() == (sizeof(std::uint64_t) * 6)); ASSERT(offsets.empty()); marisa::grimoire::trie::Entry entry; entry.set_str("X", 1); entries.push_back(entry); tail.build(entries, &offsets, MARISA_BINARY_TAIL); ASSERT(tail.mode() == MARISA_BINARY_TAIL); ASSERT(tail.size() == 1); ASSERT(!tail.empty()); ASSERT(tail.total_size() == (tail.size() + sizeof(std::uint64_t))); ASSERT(tail.io_size() == (sizeof(std::uint64_t) * 8)); ASSERT(offsets.size() == entries.size()); ASSERT(offsets[0] == 0); const char binary_entry[] = {'N', 'P', '\0', 'T', 'r', 'i', 'e'}; entries[0].set_str(binary_entry, sizeof(binary_entry)); tail.build(entries, &offsets, MARISA_TEXT_TAIL); ASSERT(tail.mode() == MARISA_BINARY_TAIL); ASSERT(tail.size() == entries[0].length()); ASSERT(offsets.size() == entries.size()); ASSERT(offsets[0] == 0); entries.clear(); entry.set_str("abc", 3); entries.push_back(entry); entry.set_str("bc", 2); entries.push_back(entry); entry.set_str("abc", 3); entries.push_back(entry); entry.set_str("c", 1); entries.push_back(entry); entry.set_str("ABC", 3); entries.push_back(entry); entry.set_str("AB", 2); entries.push_back(entry); tail.build(entries, &offsets, MARISA_BINARY_TAIL); std::sort(entries.begin(), entries.end(), marisa::grimoire::trie::Entry::IDComparer()); ASSERT(tail.mode() == MARISA_BINARY_TAIL); ASSERT(tail.size() == 8); ASSERT(offsets.size() == entries.size()); for (std::size_t i = 0; i < entries.size(); ++i) { const char *const ptr = &tail[offsets[i]]; ASSERT(std::memcmp(ptr, entries[i].ptr(), entries[i].length()) == 0); } TEST_END(); } void TestHistory() { TEST_START(); marisa::grimoire::trie::History history; ASSERT(history.node_id() == 0); ASSERT(history.louds_pos() == 0); ASSERT(history.key_pos() == 0); ASSERT(history.link_id() == MARISA_INVALID_LINK_ID); ASSERT(history.key_id() == MARISA_INVALID_KEY_ID); history.set_node_id(100); history.set_louds_pos(200); history.set_key_pos(300); history.set_link_id(400); history.set_key_id(500); ASSERT(history.node_id() == 100); ASSERT(history.louds_pos() == 200); ASSERT(history.key_pos() == 300); ASSERT(history.link_id() == 400); ASSERT(history.key_id() == 500); TEST_END(); } void TestState() { TEST_START(); marisa::grimoire::trie::State state; ASSERT(state.key_buf().empty()); ASSERT(state.history().empty()); ASSERT(state.node_id() == 0); ASSERT(state.query_pos() == 0); ASSERT(state.history_pos() == 0); ASSERT(state.status_code() == marisa::grimoire::trie::MARISA_READY_TO_ALL); state.set_node_id(10); state.set_query_pos(100); state.set_history_pos(1000); state.set_status_code( marisa::grimoire::trie::MARISA_END_OF_PREDICTIVE_SEARCH); ASSERT(state.node_id() == 10); ASSERT(state.query_pos() == 100); ASSERT(state.history_pos() == 1000); ASSERT(state.status_code() == marisa::grimoire::trie::MARISA_END_OF_PREDICTIVE_SEARCH); state.lookup_init(); ASSERT(state.status_code() == marisa::grimoire::trie::MARISA_READY_TO_ALL); state.reverse_lookup_init(); ASSERT(state.status_code() == marisa::grimoire::trie::MARISA_READY_TO_ALL); state.common_prefix_search_init(); ASSERT(state.status_code() == marisa::grimoire::trie::MARISA_READY_TO_COMMON_PREFIX_SEARCH); state.predictive_search_init(); ASSERT(state.status_code() == marisa::grimoire::trie::MARISA_READY_TO_PREDICTIVE_SEARCH); TEST_END(); } } // namespace int main() try { TestConfig(); TestHeader(); TestKey(); TestRange(); TestEntry(); TestTextTail(); TestBinaryTail(); TestHistory(); TestState(); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << "\n"; throw; } marisa-trie-master/tests/vector-test.cc000066400000000000000000000225301505027263100205170ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include #include #include "marisa-assert.h" namespace { using marisa::grimoire::vector::popcount; std::random_device seed_gen; std::mt19937 random_engine(seed_gen()); #if MARISA_WORD_SIZE == 64 void TestPopcount() { TEST_START(); ASSERT(popcount(0U) == 0); ASSERT(popcount(~0ULL) == 64); ASSERT(popcount(0xFF7F3F1F0F070301ULL) == 36); TEST_END(); } #else // MARISA_WORD_SIZE == 64 void TestPopcount() { TEST_START(); ASSERT(popcount(0U) == 0); ASSERT(popcount(~0U) == 32); ASSERT(popcount(0xFF3F0F03U) == 20); TEST_END(); } #endif // MARISA_WORD_SIZE == 64 void TestRankIndex() { TEST_START(); marisa::grimoire::vector::RankIndex rank; ASSERT(rank.abs() == 0); ASSERT(rank.rel1() == 0); ASSERT(rank.rel2() == 0); ASSERT(rank.rel3() == 0); ASSERT(rank.rel4() == 0); ASSERT(rank.rel5() == 0); ASSERT(rank.rel6() == 0); ASSERT(rank.rel7() == 0); rank.set_abs(10000); rank.set_rel1(64); rank.set_rel2(128); rank.set_rel3(192); rank.set_rel4(256); rank.set_rel5(320); rank.set_rel6(384); rank.set_rel7(448); ASSERT(rank.abs() == 10000); ASSERT(rank.rel1() == 64); ASSERT(rank.rel2() == 128); ASSERT(rank.rel3() == 192); ASSERT(rank.rel4() == 256); ASSERT(rank.rel5() == 320); ASSERT(rank.rel6() == 384); ASSERT(rank.rel7() == 448); TEST_END(); } void TestVector() { TEST_START(); std::vector values; for (std::size_t i = 0; i < 10000; ++i) { values.push_back(static_cast(random_engine())); } marisa::grimoire::Vector vec; ASSERT(vec.max_size() == (SIZE_MAX / sizeof(int))); ASSERT(vec.size() == 0); ASSERT(vec.capacity() == 0); ASSERT(!vec.fixed()); ASSERT(vec.empty()); ASSERT(vec.total_size() == 0); ASSERT(vec.io_size() == sizeof(std::uint64_t)); for (std::size_t i = 0; i < values.size(); ++i) { vec.push_back(values[i]); ASSERT(vec[i] == values[i]); ASSERT(static_cast &>(vec)[i] == values[i]); } ASSERT(vec.size() == values.size()); ASSERT(vec.capacity() >= vec.size()); ASSERT(!vec.empty()); ASSERT(vec.total_size() == (sizeof(int) * values.size())); ASSERT(vec.io_size() == sizeof(std::uint64_t) + ((sizeof(int) * values.size()))); ASSERT(static_cast &>(vec).front() == values.front()); ASSERT(static_cast &>(vec).back() == values.back()); ASSERT(vec.front() == values.front()); ASSERT(vec.back() == values.back()); vec.shrink(); ASSERT(vec.size() == values.size()); ASSERT(vec.capacity() == vec.size()); for (std::size_t i = 0; i < values.size(); ++i) { ASSERT(vec[i] == values[i]); ASSERT(static_cast &>(vec)[i] == values[i]); } { marisa::grimoire::Writer writer; writer.open("vector-test.dat"); vec.write(writer); } vec.clear(); ASSERT(vec.empty()); ASSERT(vec.capacity() == 0); { marisa::grimoire::Mapper mapper; mapper.open("vector-test.dat"); vec.map(mapper); ASSERT(vec.size() == values.size()); ASSERT(vec.capacity() == 0); ASSERT(vec.fixed()); ASSERT(!vec.empty()); ASSERT(vec.total_size() == (sizeof(int) * values.size())); ASSERT(vec.io_size() == sizeof(std::uint64_t) + ((sizeof(int) * values.size()))); for (std::size_t i = 0; i < values.size(); ++i) { ASSERT(static_cast &>(vec)[i] == values[i]); } vec.clear(); } { marisa::grimoire::Reader reader; reader.open("vector-test.dat"); vec.read(reader); } ASSERT(vec.size() == values.size()); ASSERT(vec.capacity() == vec.size()); ASSERT(!vec.fixed()); ASSERT(!vec.empty()); ASSERT(vec.total_size() == (sizeof(int) * values.size())); ASSERT(vec.io_size() == sizeof(std::uint64_t) + ((sizeof(int) * values.size()))); for (std::size_t i = 0; i < values.size(); ++i) { ASSERT(vec[i] == values[i]); ASSERT(static_cast &>(vec)[i] == values[i]); } vec.clear(); vec.push_back(0); ASSERT(vec.capacity() == 1); vec.push_back(1); ASSERT(vec.capacity() == 2); vec.push_back(2); ASSERT(vec.capacity() == 4); vec.resize(5); ASSERT(vec.capacity() == 8); vec.resize(100); ASSERT(vec.capacity() == 100); vec.fix(); ASSERT(vec.fixed()); EXCEPT(vec.fix(), std::logic_error); TEST_END(); } void TestFlatVector() { TEST_START(); marisa::grimoire::FlatVector vec; ASSERT(vec.value_size() == 0); ASSERT(vec.mask() == 0); ASSERT(vec.size() == 0); ASSERT(vec.empty()); ASSERT(vec.total_size() == 0); ASSERT(vec.io_size() == (sizeof(std::uint64_t) * 3)); marisa::grimoire::Vector values; vec.build(values); ASSERT(vec.value_size() == 0); ASSERT(vec.mask() == 0); ASSERT(vec.size() == 0); ASSERT(vec.empty()); ASSERT(vec.total_size() == 0); ASSERT(vec.io_size() == (sizeof(std::uint64_t) * 3)); values.push_back(0); vec.build(values); ASSERT(vec.value_size() == 0); ASSERT(vec.mask() == 0); ASSERT(vec.size() == 1); ASSERT(!vec.empty()); ASSERT(vec.total_size() == 8); ASSERT(vec.io_size() == (sizeof(std::uint64_t) * 4)); ASSERT(vec[0] == 0); values.push_back(255); vec.build(values); ASSERT(vec.value_size() == 8); ASSERT(vec.mask() == 0xFF); ASSERT(vec.size() == 2); ASSERT(vec[0] == 0); ASSERT(vec[1] == 255); values.push_back(65536); vec.build(values); ASSERT(vec.value_size() == 17); ASSERT(vec.mask() == 0x1FFFF); ASSERT(vec.size() == 3); ASSERT(vec[0] == 0); ASSERT(vec[1] == 255); ASSERT(vec[2] == 65536); { marisa::grimoire::Writer writer; writer.open("vector-test.dat"); vec.write(writer); } vec.clear(); ASSERT(vec.value_size() == 0); ASSERT(vec.mask() == 0); ASSERT(vec.size() == 0); { marisa::grimoire::Mapper mapper; mapper.open("vector-test.dat"); vec.map(mapper); ASSERT(vec.value_size() == 17); ASSERT(vec.mask() == 0x1FFFF); ASSERT(vec.size() == 3); ASSERT(vec[0] == 0); ASSERT(vec[1] == 255); ASSERT(vec[2] == 65536); vec.clear(); } { marisa::grimoire::Reader reader; reader.open("vector-test.dat"); vec.read(reader); } ASSERT(vec.value_size() == 17); ASSERT(vec.mask() == 0x1FFFF); ASSERT(vec.size() == 3); ASSERT(vec[0] == 0); ASSERT(vec[1] == 255); ASSERT(vec[2] == 65536); values.clear(); for (std::size_t i = 0; i < 10000; ++i) { values.push_back(static_cast(random_engine())); } vec.build(values); ASSERT(vec.size() == values.size()); for (std::size_t i = 0; i < vec.size(); ++i) { ASSERT(vec[i] == values[i]); } TEST_END(); } void TestBitVector(std::size_t size) { marisa::grimoire::BitVector bv; ASSERT(bv.size() == 0); ASSERT(bv.empty()); ASSERT(bv.total_size() == 0); ASSERT(bv.io_size() == sizeof(std::uint64_t) * 5); std::vector bits(size); std::vector zeros, ones; for (std::size_t i = 0; i < size; ++i) { const bool bit = (random_engine() % 2) == 0; bits[i] = bit; bv.push_back(bit); (bit ? ones : zeros).push_back(i); ASSERT(bv[i] == bits[i]); } ASSERT(bv.size() == bits.size()); ASSERT((size == 0) || !bv.empty()); bv.build(true, true); std::size_t num_zeros = 0, num_ones = 0; for (std::size_t i = 0; i < bits.size(); ++i) { ASSERT(bv[i] == bits[i]); ASSERT(bv.rank0(i) == num_zeros); ASSERT(bv.rank1(i) == num_ones); ++(bv[i] ? num_ones : num_zeros); } for (std::size_t i = 0; i < zeros.size(); ++i) { ASSERT(bv.select0(i) == zeros[i]); } for (std::size_t i = 0; i < ones.size(); ++i) { ASSERT(bv.select1(i) == ones[i]); } ASSERT(bv.num_0s() == num_zeros); ASSERT(bv.num_1s() == num_ones); std::stringstream stream; { marisa::grimoire::Writer writer; writer.open(stream); bv.write(writer); } bv.clear(); ASSERT(bv.size() == 0); ASSERT(bv.empty()); ASSERT(bv.total_size() == 0); ASSERT(bv.io_size() == sizeof(std::uint64_t) * 5); { marisa::grimoire::Reader reader; reader.open(stream); bv.read(reader); } ASSERT(bv.size() == bits.size()); num_zeros = 0, num_ones = 0; for (std::size_t i = 0; i < bits.size(); ++i) { ASSERT(bv[i] == bits[i]); ASSERT(bv.rank0(i) == num_zeros); ASSERT(bv.rank1(i) == num_ones); ++(bv[i] ? num_ones : num_zeros); } for (std::size_t i = 0; i < zeros.size(); ++i) { ASSERT(bv.select0(i) == zeros[i]); } for (std::size_t i = 0; i < ones.size(); ++i) { ASSERT(bv.select1(i) == ones[i]); } ASSERT(bv.num_0s() == num_zeros); ASSERT(bv.num_1s() == num_ones); } void TestBitVector() { TEST_START(); TestBitVector(0); TestBitVector(1); TestBitVector(511); TestBitVector(512); TestBitVector(513); for (int i = 0; i < 100; ++i) { TestBitVector(static_cast(random_engine()) % 4096); } TEST_END(); } } // namespace int main() try { TestPopcount(); TestRankIndex(); TestVector(); TestFlatVector(); TestBitVector(); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << "\n"; throw; } marisa-trie-master/tools/000077500000000000000000000000001505027263100157255ustar00rootroot00000000000000marisa-trie-master/tools/cmdopt.cc000066400000000000000000000151101505027263100175200ustar00rootroot00000000000000#include "cmdopt.h" #include namespace { // Moves `optind' to the end and shifts other arguments. void cmdopt_shift(cmdopt_t *h) { int i; char *tmp; tmp = h->argv[h->optind]; for (i = h->optind; i < h->argc - 1; i++) { h->argv[i] = h->argv[i + 1]; } h->argv[i] = tmp; h->nextchar = nullptr; h->optnum--; } // Moves to the next argument. void cmdopt_next(cmdopt_t *h) { h->optind++; h->nextchar = nullptr; } // Checks if the current argument is an option or not. int cmdopt_check(cmdopt_t *h) { int ret = 1; const char *arg = h->argv[h->optind]; if (*arg++ != '-') { return 0; } if (*arg == '-') { arg++; ret++; } return ret - (*arg == '\0'); } // Gets an argument of the current option. void cmdopt_getopt(cmdopt_t *h) { // Moves to the next argument if the current argument has no more characters. if (*h->nextchar == '\0') { cmdopt_next(h); h->nextchar = h->argv[h->optind]; } // Checks whether the current option has an argument or not. if (h->optind < h->optnum) { h->optarg = h->nextchar; cmdopt_next(h); } else { h->optarg = nullptr; } } // Searches an option. int cmdopt_search(cmdopt_t *h) { const char *ptr; // Updates an option character. h->optopt = *h->nextchar++; for (ptr = h->optstring; *ptr != '\0'; ptr++) { if (*ptr == h->optopt) { // Gets an option argument if required. if (ptr[1] == ':') { cmdopt_getopt(h); // Returns ':' if there is no argument. if (h->optarg == nullptr && ptr[2] != ':') { return ':'; } } return h->optopt; } } if (h->optopt == '-') { cmdopt_next(h); while (h->optind < h->optnum) { cmdopt_shift(h); } return -1; } // Returns '?' if the option character is undefined. return '?'; } // Compares a long option with an argument and returns the length of the // matched prefix. int cmdopt_match_len(const char *opt, const char *arg) { int len = 0; // Returns 0 if there is a mismatch. while ((*arg != '\0') && (*arg != '=')) { if (*arg++ != *opt++) { return 0; } len++; } // Returns a negative value in case of a perfect match. if ((*arg == '\0') || (*arg == '=')) { return -len; } return len; } // Checks long options. int cmdopt_match(cmdopt_t *h) { int i, len; int max = 0, max_optind = -1; // Returns -1 if there are no long options. if (h->longopts == nullptr) { return max_optind; } for (i = 0; h->longopts[i].name != nullptr; i++) { len = cmdopt_match_len(h->longopts[i].name, h->nextchar); if (len < 0) { // In case of a perfect match. h->nextchar -= len; return i; } if (len > max) { // In case of a prefix match. max = len; max_optind = i; } else if (len == max) { // There are other candidates. max_optind = -1; } } // If there is no perfect match, adopts the longest one. h->nextchar += max; return max_optind; } // Gets an argument of a long option. void cmdopt_getopt_long(cmdopt_t *h) { if (*h->nextchar == '=') { h->optarg = h->nextchar + 1; cmdopt_next(h); } else { cmdopt_next(h); // Checks whether there are more options or not. if (h->optind < h->optnum) { h->optarg = h->argv[h->optind]; cmdopt_next(h); } else { h->optarg = nullptr; } } } // Searches long options. int cmdopt_search_long(cmdopt_t *h) { const cmdopt_option *option; // Keeps the long option. h->optlong = h->argv[h->optind]; // Gets the next option. h->longindex = cmdopt_match(h); if (h->longindex < 0) { cmdopt_next(h); return '?'; } // Gets an argument if required. option = h->longopts + h->longindex; if (option->has_arg) { cmdopt_getopt_long(h); // Return ':' if there are no more arguments. if (h->optarg == nullptr) { return ':'; } } else if (*h->nextchar == '=') { // Returns '?' for an extra option argument. cmdopt_getopt_long(h); return '?'; } // Overwrites a variable if specified in settings. if (option->flag != nullptr) { *option->flag = option->val; return 0; } return option->val; } // Analyze command line option. int cmdopt_main(cmdopt_t *h) { int type; // Initializes the internal state. h->optopt = 0; h->optlong = nullptr; h->optarg = nullptr; h->longindex = 0; while (h->optind < h->optnum) { if (h->nextchar == nullptr) { // Checks whether the next argument is an option or not. type = cmdopt_check(h); if (type == 0) { cmdopt_shift(h); } else { h->nextchar = h->argv[h->optind] + type; if (type == 2) { return cmdopt_search_long(h); } } } else { if (*h->nextchar == '\0') { cmdopt_next(h); continue; } // Searches an option string. return cmdopt_search(h); } } return -1; } } // namespace // cmdopt_init() initializes a cmdopt_t for successive cmdopt_get()s. void cmdopt_init(cmdopt_t *h, int argc, char **argv, const char *optstring, const cmdopt_option *longopts) { static const char empty_optstring[] = ""; h->argc = argc; h->argv = argv; h->optnum = h->argc; h->longopts = longopts; h->optstring = (optstring != nullptr) ? optstring : empty_optstring; h->optind = 1; h->nextchar = nullptr; h->optarg = nullptr; h->optopt = 0; h->optlong = nullptr; h->opterr = 1; h->longindex = 0; } // cmdopt_get() analyzes command line arguments and gets the next option. int cmdopt_get(cmdopt_t *h) { int value = cmdopt_main(h); // Prints a warning to the standard error stream if enabled. if (h->opterr) { if (value == ':') { // Warning for a lack of an option argument. if (h->optlong == nullptr) { fprintf(stderr, "option requires an argument -- %c\n", h->optopt); } else { fprintf(stderr, "option `--%s' requires an argument\n", h->longopts[h->longindex].name); } } else if (value == '?') { // Warning for an invalid option. if (h->optlong == nullptr) { fprintf(stderr, "invalid option -- %c\n", h->optopt); } else { fprintf(stderr, "unrecognized option `%s'\n", h->optlong); } } else if ((value != -1) && (h->opterr == 2)) { // Actually this is not for warning, but for debugging. if (h->optlong == nullptr) { fprintf(stderr, "option with `%s' -- %c\n", h->optarg, h->optopt); } else { fprintf(stderr, "option `--%s' with `%s'\n", h->longopts[h->longindex].name, h->optarg); } } } return value; } marisa-trie-master/tools/cmdopt.h000066400000000000000000000031351505027263100173660ustar00rootroot00000000000000#ifndef MARISA_CMDOPT_H_ #define MARISA_CMDOPT_H_ struct cmdopt_option { // `name' specifies the name of this option. // An array of options must be terminated with an option whose name == NULL. const char *name; // `has_name' specifies whether an option takes an argument or not. // 0 specifies that this option does not have any argument. // 1 specifies that this option has an argument. // 2 specifies that this option may have an argument. int has_arg; // `flag' specifies an integer variable which is overwritten by cmdopt_next() // with its return value. int *flag; // `val' specifies a return value of cmdopt_next(). This value is returned // when cmdopt_next() finds this option. int val; }; struct cmdopt_t { // Command line arguments. int argc; char **argv; // Option settings. const cmdopt_option *longopts; const char *optstring; int optind; // Index of the next argument. char *nextchar; // Next character. char *optarg; // Argument of the last option. int optopt; // Label of the last option. char *optlong; // Long option. int opterr; // Warning level (0: nothing, 1: warning, 2: all). int longindex; // Index of the last long option. int optnum; // Number of options. }; // cmdopt_init() initializes a cmdopt_t for successive cmdopt_next()s. extern void cmdopt_init(cmdopt_t *h, int argc, char **argv, const char *optstring, const cmdopt_option *longopts); // cmdopt_get() analyzes command line arguments and gets the next option. extern int cmdopt_get(cmdopt_t *h); #endif // MARISA_CMDOPT_H_ marisa-trie-master/tools/marisa-benchmark.cc000066400000000000000000000362341505027263100214500ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include "cmdopt.h" namespace { int param_min_num_tries = 1; int param_max_num_tries = 5; marisa::TailMode param_tail_mode = MARISA_DEFAULT_TAIL; marisa::NodeOrder param_node_order = MARISA_DEFAULT_ORDER; marisa::CacheLevel param_cache_level = MARISA_DEFAULT_CACHE; bool param_predict_on = true; bool param_reuse_on = true; bool param_print_speed = true; class Clock { public: Clock() : cl_(std::clock()) {} void reset() { cl_ = std::clock(); } double elasped() const { std::clock_t cur = std::clock(); return static_cast(cur - cl_) / static_cast(CLOCKS_PER_SEC); } private: std::clock_t cl_; }; void print_help(const char *cmd) { std::cerr << "Usage: " << cmd << " [OPTION]... [FILE]...\n\n" "Options:\n" " -N, --min-num-tries=[N] limit the number of tries [" << MARISA_MIN_NUM_TRIES << ", " << MARISA_MAX_NUM_TRIES << "] (default: 1)\n" " -n, --max-num-tries=[N] limit the number of tries [" << MARISA_MIN_NUM_TRIES << ", " << MARISA_MAX_NUM_TRIES << "] (default: 5)\n" " -t, --text-tail build a dictionary with text TAIL (default)\n" " -b, --binary-tail build a dictionary with binary TAIL\n" " -w, --weight-order arrange siblings in weight order (default)\n" " -l, --label-order arrange siblings in label order\n" " -c, --cache-level=[N] specify the cache size" " [1, 5] (default: 3)\n" " -P, --predict-on include predictive search (default)\n" " -p, --predict-off skip predictive search\n" " -R, --reuse-on reuse agents (default)\n" " -r, --reuse-off don't reuse agents\n" " -S, --print-speed print speed [1000 keys/s] (default)\n" " -s, --print-time print time [ns/key]\n" " -h, --help print this help\n" "\n"; } void print_config() { std::cout << "Number of tries: " << param_min_num_tries << " - " << param_max_num_tries << "\n"; std::cout << "TAIL mode: "; switch (param_tail_mode) { case MARISA_TEXT_TAIL: { std::cout << "Text mode\n"; break; } case MARISA_BINARY_TAIL: { std::cout << "Binary mode\n"; break; } } std::cout << "Node order: "; switch (param_node_order) { case MARISA_LABEL_ORDER: { std::cout << "Ascending label order\n"; break; } case MARISA_WEIGHT_ORDER: { std::cout << "Descending weight order\n"; break; } } std::cout << "Cache level: "; switch (param_cache_level) { case MARISA_HUGE_CACHE: { std::cout << "Huge cache\n"; break; } case MARISA_LARGE_CACHE: { std::cout << "Large cache\n"; break; } case MARISA_NORMAL_CACHE: { std::cout << "Normal cache\n"; break; } case MARISA_SMALL_CACHE: { std::cout << "Small cache\n"; break; } case MARISA_TINY_CACHE: { std::cout << "Tiny cache\n"; break; } } } void print_time_info(std::size_t num_keys, double elasped) { if (param_print_speed) { if (elasped == 0.0) { std::printf(" %8s", "-"); } else { std::printf(" %8.2f", static_cast(num_keys) / elasped / 1000.0); } } else { if ((elasped == 0.0) || (num_keys == 0)) { std::printf(" %8s", "-"); } else { std::printf(" %8.1f", 1000000000.0 * elasped / static_cast(num_keys)); } } } void read_keys(std::istream &input, marisa::Keyset *keyset, std::vector *weights) { std::string line; while (std::getline(input, line)) { const std::string::size_type delim_pos = line.find_last_of('\t'); float weight = 1.0F; if (delim_pos != line.npos) { char *end_of_value; weight = static_cast(std::strtod(&line[delim_pos + 1], &end_of_value)); if (*end_of_value == '\0') { line.resize(delim_pos); } } keyset->push_back(line.c_str(), line.length()); weights->push_back(weight); } } int read_keys(const char *const *args, std::size_t num_args, marisa::Keyset *keyset, std::vector *weights) { if (num_args == 0) { read_keys(std::cin, keyset, weights); } for (std::size_t i = 0; i < num_args; ++i) { std::ifstream input_file(args[i], std::ios::binary); if (!input_file) { std::cerr << "error: failed to open: " << args[i] << "\n"; return 10; } read_keys(input_file, keyset, weights); } std::cout << "Number of keys: " << keyset->size() << "\n"; std::cout << "Total length: " << keyset->total_length() << "\n" << std::flush; return 0; } void benchmark_build(marisa::Keyset &keyset, const std::vector &weights, int num_tries, marisa::Trie *trie) { for (std::size_t i = 0; i < keyset.size(); ++i) { keyset[i].set_weight(weights[i]); } Clock cl; trie->build(keyset, num_tries | param_tail_mode | param_node_order | param_cache_level); std::printf(" %10lu", static_cast(trie->io_size())); print_time_info(keyset.size(), cl.elasped()); } void benchmark_lookup(const marisa::Trie &trie, const marisa::Keyset &keyset) { Clock cl; if (param_reuse_on) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); if (!trie.lookup(agent) || (agent.key().id() != keyset[i].id())) { std::cerr << "error: lookup() failed\n"; return; } } } else { for (std::size_t i = 0; i < keyset.size(); ++i) { marisa::Agent agent; agent.set_query(keyset[i].ptr(), keyset[i].length()); if (!trie.lookup(agent) || (agent.key().id() != keyset[i].id())) { std::cerr << "error: lookup() failed\n"; return; } } } print_time_info(keyset.size(), cl.elasped()); } void benchmark_reverse_lookup(const marisa::Trie &trie, const marisa::Keyset &keyset) { Clock cl; if (param_reuse_on) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].id()); trie.reverse_lookup(agent); if ((agent.key().id() != keyset[i].id()) || (agent.key().length() != keyset[i].length()) || (std::memcmp(agent.key().ptr(), keyset[i].ptr(), agent.key().length()) != 0)) { std::cerr << "error: reverse_lookup() failed\n"; return; } } } else { for (std::size_t i = 0; i < keyset.size(); ++i) { marisa::Agent agent; agent.set_query(keyset[i].id()); trie.reverse_lookup(agent); if ((agent.key().id() != keyset[i].id()) || (agent.key().length() != keyset[i].length()) || (std::memcmp(agent.key().ptr(), keyset[i].ptr(), agent.key().length()) != 0)) { std::cerr << "error: reverse_lookup() failed\n"; return; } } } print_time_info(keyset.size(), cl.elasped()); } void benchmark_common_prefix_search(const marisa::Trie &trie, const marisa::Keyset &keyset) { Clock cl; if (param_reuse_on) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); while (trie.common_prefix_search(agent)) { if (agent.key().id() > keyset[i].id()) { std::cerr << "error: common_prefix_search() failed\n"; return; } } if (agent.key().id() != keyset[i].id()) { std::cerr << "error: common_prefix_search() failed\n"; return; } } } else { for (std::size_t i = 0; i < keyset.size(); ++i) { marisa::Agent agent; agent.set_query(keyset[i].ptr(), keyset[i].length()); while (trie.common_prefix_search(agent)) { if (agent.key().id() > keyset[i].id()) { std::cerr << "error: common_prefix_search() failed\n"; return; } } if (agent.key().id() != keyset[i].id()) { std::cerr << "error: common_prefix_search() failed\n"; return; } } } print_time_info(keyset.size(), cl.elasped()); } void benchmark_predictive_search(const marisa::Trie &trie, const marisa::Keyset &keyset) { if (!param_predict_on) { print_time_info(keyset.size(), 0.0); return; } Clock cl; if (param_reuse_on) { marisa::Agent agent; for (std::size_t i = 0; i < keyset.size(); ++i) { agent.set_query(keyset[i].ptr(), keyset[i].length()); if (!trie.predictive_search(agent) || (agent.key().id() != keyset[i].id())) { std::cerr << "error: predictive_search() failed\n"; return; } while (trie.predictive_search(agent)) { if (agent.key().id() <= keyset[i].id()) { std::cerr << "error: predictive_search() failed\n"; return; } } } } else { for (std::size_t i = 0; i < keyset.size(); ++i) { marisa::Agent agent; agent.set_query(keyset[i].ptr(), keyset[i].length()); if (!trie.predictive_search(agent) || (agent.key().id() != keyset[i].id())) { std::cerr << "error: predictive_search() failed\n"; return; } while (trie.predictive_search(agent)) { if (agent.key().id() <= keyset[i].id()) { std::cerr << "error: predictive_search() failed\n"; return; } } } } print_time_info(keyset.size(), cl.elasped()); } void benchmark(marisa::Keyset &keyset, const std::vector &weights, int num_tries) { std::printf("%6d", num_tries); marisa::Trie trie; benchmark_build(keyset, weights, num_tries, &trie); if (!trie.empty()) { benchmark_lookup(trie, keyset); benchmark_reverse_lookup(trie, keyset); benchmark_common_prefix_search(trie, keyset); benchmark_predictive_search(trie, keyset); } std::printf("\n"); } int benchmark(const char *const *args, std::size_t num_args) try { marisa::Keyset keyset; std::vector weights; const int ret = read_keys(args, num_args, &keyset, &weights); if (ret != 0) { return ret; } std::printf( "------+----------+--------+--------+--------+--------+--------\n"); std::printf("%6s %10s %8s %8s %8s %8s %8s\n", "#tries", "size", "build", "lookup", "reverse", "prefix", "predict"); std::printf("%6s %10s %8s %8s %8s %8s %8s\n", "", "", "", "", "lookup", "search", "search"); if (param_print_speed) { std::printf("%6s %10s %8s %8s %8s %8s %8s\n", "", "[bytes]", "[K/s]", "[K/s]", "[K/s]", "[K/s]", "[K/s]"); } else { std::printf("%6s %10s %8s %8s %8s %8s %8s\n", "", "[bytes]", "[ns]", "[ns]", "[ns]", "[ns]", "[ns]"); } std::printf( "------+----------+--------+--------+--------+--------+--------\n"); for (int i = param_min_num_tries; i <= param_max_num_tries; ++i) { benchmark(keyset, weights, i); } std::printf( "------+----------+--------+--------+--------+--------+--------\n"); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << "\n"; return -1; } } // namespace int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); ::cmdopt_option long_options[] = {{"min-num-tries", 1, nullptr, 'N'}, {"max-num-tries", 1, nullptr, 'n'}, {"text-tail", 0, nullptr, 't'}, {"binary-tail", 0, nullptr, 'b'}, {"weight-order", 0, nullptr, 'w'}, {"label-order", 0, nullptr, 'l'}, {"cache-level", 1, nullptr, 'c'}, {"predict-on", 0, nullptr, 'P'}, {"predict-off", 0, nullptr, 'p'}, {"reuse-on", 0, nullptr, 'R'}, {"reuse-off", 0, nullptr, 'r'}, {"print-speed", 0, nullptr, 'S'}, {"print-time", 0, nullptr, 's'}, {"help", 0, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; ::cmdopt_t cmdopt; ::cmdopt_init(&cmdopt, argc, argv, "N:n:tbwlc:PpRrSsh", long_options); int label; while ((label = ::cmdopt_get(&cmdopt)) != -1) { switch (label) { case 'N': { char *end_of_value; const long value = std::strtol(cmdopt.optarg, &end_of_value, 10); if ((*end_of_value != '\0') || (value <= 0) || (value > MARISA_MAX_NUM_TRIES)) { std::cerr << "error: option `-n' with an invalid argument: " << cmdopt.optarg << "\n"; return 1; } param_min_num_tries = static_cast(value); break; } case 'n': { char *end_of_value; const long value = std::strtol(cmdopt.optarg, &end_of_value, 10); if ((*end_of_value != '\0') || (value <= 0) || (value > MARISA_MAX_NUM_TRIES)) { std::cerr << "error: option `-n' with an invalid argument: " << cmdopt.optarg << "\n"; return 2; } param_max_num_tries = static_cast(value); break; } case 't': { param_tail_mode = MARISA_TEXT_TAIL; break; } case 'b': { param_tail_mode = MARISA_BINARY_TAIL; break; } case 'w': { param_node_order = MARISA_WEIGHT_ORDER; break; } case 'l': { param_node_order = MARISA_LABEL_ORDER; break; } case 'c': { char *end_of_value; const long value = std::strtol(cmdopt.optarg, &end_of_value, 10); if ((*end_of_value != '\0') || (value < 1) || (value > 5)) { std::cerr << "error: option `-c' with an invalid argument: " << cmdopt.optarg << "\n"; return 3; } if (value == 1) { param_cache_level = MARISA_TINY_CACHE; } else if (value == 2) { param_cache_level = MARISA_SMALL_CACHE; } else if (value == 3) { param_cache_level = MARISA_NORMAL_CACHE; } else if (value == 4) { param_cache_level = MARISA_LARGE_CACHE; } else if (value == 5) { param_cache_level = MARISA_HUGE_CACHE; } break; } case 'P': { param_predict_on = true; break; } case 'p': { param_predict_on = false; break; } case 'R': { param_reuse_on = true; break; } case 'r': { param_reuse_on = false; break; } case 'S': { param_print_speed = true; break; } case 's': { param_print_speed = false; break; } case 'h': { print_help(argv[0]); return 0; } default: { return 1; } } } print_config(); return benchmark(cmdopt.argv + cmdopt.optind, static_cast(cmdopt.argc - cmdopt.optind)); } marisa-trie-master/tools/marisa-build.cc000066400000000000000000000144431505027263100206130ustar00rootroot00000000000000#ifdef _WIN32 #include #include #include #endif // _WIN32 #include #include #include #include #include #include #include "cmdopt.h" namespace { int param_num_tries = MARISA_DEFAULT_NUM_TRIES; marisa::TailMode param_tail_mode = MARISA_DEFAULT_TAIL; marisa::NodeOrder param_node_order = MARISA_DEFAULT_ORDER; marisa::CacheLevel param_cache_level = MARISA_DEFAULT_CACHE; const char *output_filename = nullptr; void print_help(const char *cmd) { std::cerr << "Usage: " << cmd << " [OPTION]... [FILE]...\n\n" "Options:\n" " -n, --num-tries=[N] limit the number of tries [" << MARISA_MIN_NUM_TRIES << ", " << MARISA_MAX_NUM_TRIES << "] (default: 3)\n" " -t, --text-tail build a dictionary with text TAIL (default)\n" " -b, --binary-tail build a dictionary with binary TAIL\n" " -w, --weight-order arrange siblings in weight order (default)\n" " -l, --label-order arrange siblings in label order\n" " -c, --cache-level=[N] specify the cache size" " [1, 5] (default: 3)\n" " -o, --output=[FILE] write tries to FILE (default: stdout)\n" " -h, --help print this help\n" "\n"; } void read_keys(std::istream &input, marisa::Keyset *keyset) { std::string line; while (std::getline(input, line)) { const std::string::size_type delim_pos = line.find_last_of('\t'); float weight = 1.0F; if (delim_pos != line.npos) { char *end_of_value; weight = static_cast(std::strtod(&line[delim_pos + 1], &end_of_value)); if (*end_of_value == '\0') { line.resize(delim_pos); } } keyset->push_back(line.c_str(), line.length(), weight); } } int build(const char *const *args, std::size_t num_args) { marisa::Keyset keyset; if (num_args == 0) try { read_keys(std::cin, &keyset); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to read keys\n"; return 10; } for (std::size_t i = 0; i < num_args; ++i) try { std::ifstream input_file(args[i], std::ios::binary); if (!input_file) { std::cerr << "error: failed to open: " << args[i] << "\n"; return 11; } read_keys(input_file, &keyset); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to read keys\n"; return 12; } marisa::Trie trie; try { trie.build(keyset, param_num_tries | param_tail_mode | param_node_order | param_cache_level); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to build a dictionary\n"; return 20; } std::cerr << "#keys: " << trie.num_keys() << "\n"; std::cerr << "#nodes: " << trie.num_nodes() << "\n"; std::cerr << "size: " << trie.io_size() << "\n"; if (output_filename != nullptr) { try { trie.save(output_filename); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to write a dictionary to file: " << output_filename << "\n"; return 30; } } else { #ifdef _WIN32 const int stdout_fileno = ::_fileno(stdout); if (stdout_fileno < 0) { std::cerr << "error: failed to get the file descriptor of " "standard output\n"; return 31; } if (::_setmode(stdout_fileno, _O_BINARY) == -1) { std::cerr << "error: failed to set binary mode\n"; return 32; } #endif // _WIN32 try { std::cout << trie; } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to write a dictionary to standard output\n"; return 33; } } return 0; } } // namespace int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); ::cmdopt_option long_options[] = { {"max-num-tries", 1, nullptr, 'n'}, // For backward compatibility. {"num-tries", 1, nullptr, 'n'}, {"text-tail", 0, nullptr, 't'}, {"binary-tail", 0, nullptr, 'b'}, {"weight-order", 0, nullptr, 'w'}, {"label-order", 0, nullptr, 'l'}, {"cache-level", 1, nullptr, 'c'}, {"output", 1, nullptr, 'o'}, {"help", 0, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; ::cmdopt_t cmdopt; ::cmdopt_init(&cmdopt, argc, argv, "n:tbwlc:o:h", long_options); int label; while ((label = ::cmdopt_get(&cmdopt)) != -1) { switch (label) { case 'n': { char *end_of_value; const long value = std::strtol(cmdopt.optarg, &end_of_value, 10); if ((*end_of_value != '\0') || (value <= 0) || (value > MARISA_MAX_NUM_TRIES)) { std::cerr << "error: option `-n' with an invalid argument: " << cmdopt.optarg << "\n"; return 1; } param_num_tries = static_cast(value); break; } case 't': { param_tail_mode = MARISA_TEXT_TAIL; break; } case 'b': { param_tail_mode = MARISA_BINARY_TAIL; break; } case 'w': { param_node_order = MARISA_WEIGHT_ORDER; break; } case 'l': { param_node_order = MARISA_LABEL_ORDER; break; } case 'c': { char *end_of_value; const long value = std::strtol(cmdopt.optarg, &end_of_value, 10); if ((*end_of_value != '\0') || (value < 1) || (value > 5)) { std::cerr << "error: option `-c' with an invalid argument: " << cmdopt.optarg << "\n"; return 2; } if (value == 1) { param_cache_level = MARISA_TINY_CACHE; } else if (value == 2) { param_cache_level = MARISA_SMALL_CACHE; } else if (value == 3) { param_cache_level = MARISA_NORMAL_CACHE; } else if (value == 4) { param_cache_level = MARISA_LARGE_CACHE; } else if (value == 5) { param_cache_level = MARISA_HUGE_CACHE; } break; } case 'o': { output_filename = cmdopt.optarg; break; } case 'h': { print_help(argv[0]); return 0; } default: { return 1; } } } return build(cmdopt.argv + cmdopt.optind, static_cast(cmdopt.argc - cmdopt.optind)); } marisa-trie-master/tools/marisa-common-prefix-search.cc000066400000000000000000000100061505027263100235310ustar00rootroot00000000000000#include #include #include #include #include #include "cmdopt.h" namespace { std::size_t max_num_results = 10; bool mmap_flag = true; void print_help(const char *cmd) { std::cerr << "Usage: " << cmd << " [OPTION]... DIC\n\n" "Options:\n" " -n, --max-num-results=[N] limit the number of results to N" " (default: 10)\n" " 0: no limit\n" " -m, --mmap-dictionary use memory-mapped I/O to load a dictionary" " (default)\n" " -r, --read-dictionary read an entire dictionary into memory\n" " -h, --help print this help\n" "\n"; } int common_prefix_search(const char *const *args, std::size_t num_args) { if (num_args == 0) { std::cerr << "error: dictionary is not specified\n"; return 10; } if (num_args > 1) { std::cerr << "error: more than one dictionaries are specified\n"; return 11; } marisa::Trie trie; if (mmap_flag) { try { trie.mmap(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to mmap a dictionary file: " << args[0] << "\n"; return 20; } } else { try { trie.load(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to load a dictionary file: " << args[0] << "\n"; return 21; } } marisa::Agent agent; marisa::Keyset keyset; std::string str; while (std::getline(std::cin, str)) { try { agent.set_query(str.c_str(), str.length()); while (trie.common_prefix_search(agent)) { keyset.push_back(agent.key()); } if (keyset.empty()) { std::cout << "not found\n"; } else { std::cout << keyset.size() << " found\n"; const std::size_t end = std::min(max_num_results, keyset.size()); for (std::size_t i = 0; i < end; ++i) { std::cout << keyset[i].id() << '\t'; std::cout.write(keyset[i].ptr(), static_cast(keyset[i].length())) << '\t'; std::cout << str << '\n'; } } keyset.reset(); } catch (const std::exception &ex) { std::cerr << ex.what() << ": common_prefix_search() failed: " << str << "\n"; return 30; } if (!std::cout) { std::cerr << "error: failed to write results to standard output\n"; return 31; } } return 0; } } // namespace int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); ::cmdopt_option long_options[] = {{"max-num-results", 1, nullptr, 'n'}, {"mmap-dictionary", 0, nullptr, 'm'}, {"read-dictionary", 0, nullptr, 'r'}, {"help", 0, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; ::cmdopt_t cmdopt; ::cmdopt_init(&cmdopt, argc, argv, "n:mrh", long_options); int label; while ((label = ::cmdopt_get(&cmdopt)) != -1) { switch (label) { case 'n': { char *end_of_value; const long value = std::strtol(cmdopt.optarg, &end_of_value, 10); if ((*end_of_value != '\0') || (value < 0)) { std::cerr << "error: option `-n' with an invalid argument: " << cmdopt.optarg << "\n"; } if ((value == 0) || (static_cast(value) > SIZE_MAX)) { max_num_results = SIZE_MAX; } else { max_num_results = static_cast(value); } break; } case 'm': { mmap_flag = true; break; } case 'r': { mmap_flag = false; break; } case 'h': { print_help(argv[0]); return 0; } default: { return 1; } } } return common_prefix_search( cmdopt.argv + cmdopt.optind, static_cast(cmdopt.argc - cmdopt.optind)); } marisa-trie-master/tools/marisa-dump.cc000066400000000000000000000075551505027263100204670ustar00rootroot00000000000000#ifdef _WIN32 #include #include #include #endif // _WIN32 #include #include #include #include #include #include "cmdopt.h" namespace { const char *delimiter = "\n"; bool mmap_flag = true; void print_help(const char *cmd) { std::cerr << "Usage: " << cmd << " [OPTION]... DIC...\n\n" "Options:\n" " -d, --delimiter=[S] specify the delimier (default: \"\\n\")\n" " -m, --mmap-dictionary use memory-mapped I/O to load a dictionary" " (default)\n" " -r, --read-dictionary read an entire dictionary into memory\n" " -h, --help print this help\n" "\n"; } int dump(const marisa::Trie &trie) { std::size_t num_keys = 0; marisa::Agent agent; agent.set_query(""); try { while (trie.predictive_search(agent)) { std::cout.write(agent.key().ptr(), static_cast(agent.key().length())) << delimiter; if (!std::cout) { std::cerr << "error: failed to write results to standard output\n"; return 20; } ++num_keys; } } catch (const std::exception &ex) { std::cerr << ex.what() << ": predictive_search() failed\n"; return 21; } std::cerr << "#keys: " << num_keys << "\n"; return 0; } int dump(const char *filename) { marisa::Trie trie; if (filename != nullptr) { std::cerr << "input: " << filename << "\n"; if (mmap_flag) { try { trie.mmap(filename); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to mmap a dictionary file: " << filename << "\n"; return 10; } } else { try { trie.load(filename); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to load a dictionary file: " << filename << "\n"; return 11; } } } else { std::cerr << "input: \n"; #ifdef _WIN32 const int stdin_fileno = ::_fileno(stdin); if (stdin_fileno < 0) { std::cerr << "error: failed to get the file descriptor of " "standard input\n"; return 20; } if (::_setmode(stdin_fileno, _O_BINARY) == -1) { std::cerr << "error: failed to set binary mode\n"; return 21; } #endif // _WIN32 try { std::cin >> trie; } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to read a dictionary from standard input\n"; return 22; } } return dump(trie); } int dump(const char *const *args, std::size_t num_args) { if (num_args == 0) { return dump(nullptr); } for (std::size_t i = 0; i < num_args; ++i) { const int result = dump(args[i]); if (result != 0) { return result; } } return 0; } } // namespace int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); ::cmdopt_option long_options[] = {{"delimiter", 1, nullptr, 'd'}, {"mmap-dictionary", 0, nullptr, 'm'}, {"read-dictionary", 0, nullptr, 'r'}, {"help", 0, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; ::cmdopt_t cmdopt; ::cmdopt_init(&cmdopt, argc, argv, "d:mrh", long_options); int label; while ((label = ::cmdopt_get(&cmdopt)) != -1) { switch (label) { case 'd': { delimiter = cmdopt.optarg; break; } case 'm': { mmap_flag = true; break; } case 'r': { mmap_flag = false; break; } case 'h': { print_help(argv[0]); return 0; } default: { return 1; } } } return dump(cmdopt.argv + cmdopt.optind, static_cast(cmdopt.argc - cmdopt.optind)); } marisa-trie-master/tools/marisa-lookup.cc000066400000000000000000000052661505027263100210300ustar00rootroot00000000000000#include #include #include #include #include "cmdopt.h" namespace { bool mmap_flag = true; void print_help(const char *cmd) { std::cerr << "Usage: " << cmd << " [OPTION]... DIC\n\n" "Options:\n" " -m, --mmap-dictionary use memory-mapped I/O to load a dictionary" " (default)\n" " -r, --read-dictionary read an entire dictionary into memory\n" " -h, --help print this help\n" "\n"; } int lookup(const char *const *args, std::size_t num_args) { if (num_args == 0) { std::cerr << "error: dictionary is not specified\n"; return 10; } if (num_args > 1) { std::cerr << "error: more than one dictionaries are specified\n"; return 11; } marisa::Trie trie; if (mmap_flag) { try { trie.mmap(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to mmap a dictionary file: " << args[0] << "\n"; return 20; } } else { try { trie.load(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to load a dictionary file: " << args[0] << "\n"; return 21; } } marisa::Agent agent; std::string str; while (std::getline(std::cin, str)) { try { agent.set_query(str.c_str(), str.length()); if (trie.lookup(agent)) { std::cout << agent.key().id() << '\t' << str << '\n'; } else { std::cout << "-1\t" << str << '\n'; } } catch (const std::exception &ex) { std::cerr << ex.what() << ": lookup() failed: " << str << "\n"; return 30; } if (!std::cout) { std::cerr << "error: failed to write results to standard output\n"; return 30; } } return 0; } } // namespace int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); ::cmdopt_option long_options[] = {{"mmap-dictionary", 0, nullptr, 'm'}, {"read-dictionary", 0, nullptr, 'r'}, {"help", 0, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; ::cmdopt_t cmdopt; ::cmdopt_init(&cmdopt, argc, argv, "mrh", long_options); int label; while ((label = ::cmdopt_get(&cmdopt)) != -1) { switch (label) { case 'm': { mmap_flag = true; break; } case 'r': { mmap_flag = false; break; } case 'h': { print_help(argv[0]); return 0; } default: { return 1; } } } return lookup(cmdopt.argv + cmdopt.optind, static_cast(cmdopt.argc - cmdopt.optind)); } marisa-trie-master/tools/marisa-predictive-search.cc000066400000000000000000000077521505027263100231220ustar00rootroot00000000000000#include #include #include #include #include #include "cmdopt.h" namespace { std::size_t max_num_results = 10; bool mmap_flag = true; void print_help(const char *cmd) { std::cerr << "Usage: " << cmd << " [OPTION]... DIC\n\n" "Options:\n" " -n, --max-num-results=[N] limit the number of outputs to N" " (default: 10)\n" " 0: no limit\n" " -m, --mmap-dictionary use memory-mapped I/O to load a dictionary" " (default)\n" " -r, --read-dictionary read an entire dictionary into memory\n" " -h, --help print this help\n" "\n"; } int predictive_search(const char *const *args, std::size_t num_args) { if (num_args == 0) { std::cerr << "error: dictionary is not specified\n"; return 10; } if (num_args > 1) { std::cerr << "error: more than one dictionaries are specified\n"; return 11; } marisa::Trie trie; if (mmap_flag) { try { trie.mmap(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to mmap a dictionary file: " << args[0] << "\n"; return 20; } } else { try { trie.load(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to load a dictionary file: " << args[0] << "\n"; return 21; } } marisa::Agent agent; marisa::Keyset keyset; std::string str; while (std::getline(std::cin, str)) { try { agent.set_query(str.c_str(), str.length()); while (trie.predictive_search(agent)) { keyset.push_back(agent.key()); } if (keyset.empty()) { std::cout << "not found\n"; } else { std::cout << keyset.size() << " found\n"; const std::size_t end = std::min(max_num_results, keyset.size()); for (std::size_t i = 0; i < end; ++i) { std::cout << keyset[i].id() << '\t'; std::cout.write(keyset[i].ptr(), static_cast(keyset[i].length())) << '\t'; std::cout << str << '\n'; } } keyset.reset(); } catch (const std::exception &ex) { std::cerr << ex.what() << ": predictive_search() failed: " << str << "\n"; return 30; } if (!std::cout) { std::cerr << "error: failed to write results to standard output\n"; return 31; } } return 0; } } // namespace int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); ::cmdopt_option long_options[] = {{"max-num-results", 1, nullptr, 'n'}, {"mmap-dictionary", 0, nullptr, 'm'}, {"read-dictionary", 0, nullptr, 'r'}, {"help", 0, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; ::cmdopt_t cmdopt; ::cmdopt_init(&cmdopt, argc, argv, "n:mrh", long_options); int label; while ((label = ::cmdopt_get(&cmdopt)) != -1) { switch (label) { case 'n': { char *end_of_value; const long value = std::strtol(cmdopt.optarg, &end_of_value, 10); if ((*end_of_value != '\0') || (value < 0)) { std::cerr << "error: option `-n' with an invalid argument: " << cmdopt.optarg << "\n"; } if ((value == 0) || (static_cast(value) > SIZE_MAX)) { max_num_results = SIZE_MAX; } else { max_num_results = static_cast(value); } break; } case 'm': { mmap_flag = true; break; } case 'r': { mmap_flag = false; break; } case 'h': { print_help(argv[0]); return 0; } default: { return 1; } } } return predictive_search( cmdopt.argv + cmdopt.optind, static_cast(cmdopt.argc - cmdopt.optind)); } marisa-trie-master/tools/marisa-reverse-lookup.cc000066400000000000000000000053641505027263100225000ustar00rootroot00000000000000#include #include #include #include #include "cmdopt.h" namespace { bool mmap_flag = true; void print_help(const char *cmd) { std::cerr << "Usage: " << cmd << " [OPTION]... DIC\n\n" "Options:\n" " -m, --mmap-dictionary use memory-mapped I/O to load a dictionary" " (default)\n" " -r, --read-dictionary read an entire dictionary into memory\n" " -h, --help print this help\n" "\n"; } int reverse_lookup(const char *const *args, std::size_t num_args) { if (num_args == 0) { std::cerr << "error: dictionary is not specified\n"; return 10; } if (num_args > 1) { std::cerr << "error: more than one dictionaries are specified\n"; return 11; } marisa::Trie trie; if (mmap_flag) { try { trie.mmap(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to mmap a dictionary file: " << args[0] << "\n"; return 20; } } else { try { trie.load(args[0]); } catch (const std::exception &ex) { std::cerr << ex.what() << ": failed to load a dictionary file: " << args[0] << "\n"; return 21; } } marisa::Agent agent; std::size_t key_id; while (std::cin >> key_id) { try { agent.set_query(key_id); trie.reverse_lookup(agent); std::cout << agent.key().id() << '\t'; std::cout.write(agent.key().ptr(), static_cast(agent.key().length())) << '\n'; } catch (const std::exception &ex) { std::cerr << ex.what() << ": reverse_lookup() failed: " << key_id << "\n"; return 30; } if (!std::cout) { std::cerr << "error: failed to write results to standard output\n"; return 30; } } return 0; } } // namespace int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); ::cmdopt_option long_options[] = {{"mmap-dictionary", 0, nullptr, 'm'}, {"read-dictionary", 0, nullptr, 'r'}, {"help", 0, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; ::cmdopt_t cmdopt; ::cmdopt_init(&cmdopt, argc, argv, "mrh", long_options); int label; while ((label = ::cmdopt_get(&cmdopt)) != -1) { switch (label) { case 'm': { mmap_flag = true; break; } case 'r': { mmap_flag = false; break; } case 'h': { print_help(argv[0]); return 0; } default: { return 1; } } } return reverse_lookup(cmdopt.argv + cmdopt.optind, static_cast(cmdopt.argc - cmdopt.optind)); }