edit_distance 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2daa552a74d2843c27c497a5e137e8cb0574a5302d7926baae080f8f6c405680
4
+ data.tar.gz: 991a8bc44b8638584ba8b74690fce2448fe3b22d9d6e81c7d6dafd2cf1aac73b
5
+ SHA512:
6
+ metadata.gz: 424551c09bcdd20ffdba898b5f7b1e04472f6a9cb74a668fc6102202bc18a235ac7353eb4c841089a10b9cd1221aae7e56c2b90a991460203403f771086a811e
7
+ data.tar.gz: ec0bbc672a216c50c4c9460e6470cb5e96daf1bd1de66b1611c10554a4a4f332d4b871932a73a18374e08d31770cce55daf4d743bd9d6ba5e8d60a6ef48720a4
data/.clang-format ADDED
@@ -0,0 +1,115 @@
1
+ ---
2
+ Language: Cpp
3
+ # BasedOnStyle: LLVM
4
+ AccessModifierOffset: -2
5
+ AlignAfterOpenBracket: Align
6
+ AlignConsecutiveAssignments: false
7
+ AlignConsecutiveDeclarations: false
8
+ AlignEscapedNewlines: Right
9
+ AlignOperands: true
10
+ AlignTrailingComments: true
11
+ AllowAllParametersOfDeclarationOnNextLine: true
12
+ AllowShortBlocksOnASingleLine: false
13
+ AllowShortCaseLabelsOnASingleLine: true
14
+ AllowShortFunctionsOnASingleLine: All
15
+ AllowShortIfStatementsOnASingleLine: false
16
+ AllowShortLoopsOnASingleLine: false
17
+ AlwaysBreakAfterDefinitionReturnType: None
18
+ AlwaysBreakAfterReturnType: TopLevel
19
+ AlwaysBreakBeforeMultilineStrings: false
20
+ AlwaysBreakTemplateDeclarations: false
21
+ BinPackArguments: true
22
+ BinPackParameters: true
23
+ BraceWrapping:
24
+ AfterClass: false
25
+ AfterControlStatement: false
26
+ AfterEnum: false
27
+ AfterFunction: true
28
+ AfterNamespace: false
29
+ AfterObjCDeclaration: false
30
+ AfterStruct: false
31
+ AfterUnion: false
32
+ AfterExternBlock: false
33
+ BeforeCatch: false
34
+ BeforeElse: false
35
+ IndentBraces: false
36
+ SplitEmptyFunction: true
37
+ SplitEmptyRecord: true
38
+ SplitEmptyNamespace: true
39
+ BreakBeforeBinaryOperators: None
40
+ BreakBeforeBraces: Custom
41
+ BreakBeforeInheritanceComma: false
42
+ BreakBeforeTernaryOperators: true
43
+ BreakConstructorInitializersBeforeComma: false
44
+ BreakConstructorInitializers: BeforeColon
45
+ BreakAfterJavaFieldAnnotations: false
46
+ BreakStringLiterals: true
47
+ ColumnLimit: 81
48
+ CommentPragmas: '^ IWYU pragma:'
49
+ CompactNamespaces: false
50
+ ConstructorInitializerAllOnOneLineOrOnePerLine: false
51
+ ConstructorInitializerIndentWidth: 4
52
+ ContinuationIndentWidth: 4
53
+ Cpp11BracedListStyle: true
54
+ DerivePointerAlignment: false
55
+ DisableFormat: false
56
+ ExperimentalAutoDetectBinPacking: false
57
+ FixNamespaceComments: true
58
+ ForEachMacros:
59
+ - foreach
60
+ - Q_FOREACH
61
+ - BOOST_FOREACH
62
+ IncludeBlocks: Preserve
63
+ IncludeCategories:
64
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
65
+ Priority: 2
66
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
67
+ Priority: 3
68
+ - Regex: '.*'
69
+ Priority: 1
70
+ IncludeIsMainRegex: '(Test)?$'
71
+ IndentCaseLabels: false
72
+ IndentPPDirectives: None
73
+ IndentWidth: 2
74
+ IndentWrappedFunctionNames: false
75
+ JavaScriptQuotes: Leave
76
+ JavaScriptWrapImports: true
77
+ KeepEmptyLinesAtTheStartOfBlocks: true
78
+ MacroBlockBegin: ''
79
+ MacroBlockEnd: ''
80
+ MaxEmptyLinesToKeep: 1
81
+ NamespaceIndentation: None
82
+ ObjCBlockIndentWidth: 2
83
+ ObjCSpaceAfterProperty: false
84
+ ObjCSpaceBeforeProtocolList: true
85
+ PenaltyBreakAssignment: 2
86
+ PenaltyBreakBeforeFirstCallParameter: 19
87
+ PenaltyBreakComment: 300
88
+ PenaltyBreakFirstLessLess: 120
89
+ PenaltyBreakString: 1000
90
+ PenaltyExcessCharacter: 1000000
91
+ PenaltyReturnTypeOnItsOwnLine: 60
92
+ PointerAlignment: Right
93
+ RawStringFormats:
94
+ - Delimiter: pb
95
+ Language: TextProto
96
+ BasedOnStyle: google
97
+ ReflowComments: true
98
+ SortIncludes: true
99
+ SortUsingDeclarations: true
100
+ SpaceAfterCStyleCast: false
101
+ SpaceAfterTemplateKeyword: true
102
+ SpaceBeforeAssignmentOperators: true
103
+ SpaceBeforeParens: ControlStatements
104
+ SpaceInEmptyParentheses: false
105
+ SpacesBeforeTrailingComments: 1
106
+ SpacesInAngles: false
107
+ SpacesInContainerLiterals: true
108
+ SpacesInCStyleCastParentheses: false
109
+ SpacesInParentheses: false
110
+ SpacesInSquareBrackets: false
111
+ Standard: Cpp11
112
+ TabWidth: 8
113
+ UseTab: Never
114
+ ...
115
+
data/.color_coded ADDED
@@ -0,0 +1,45 @@
1
+ -x
2
+ c++
3
+ -D_DARWIN_C_SOURCE
4
+ -D_DARWIN_UNLIMITED_SELECT
5
+ -D_REENTRANT
6
+ -D_XOPEN_SOURCE
7
+ -I/Users/morgan/projects/ruby/edit_distance/tmp/x86_64-darwin16/edit_distance/2.5.1
8
+ -I/Users/morgan/projects/ruby/edit_distance/ext/edit_distance
9
+ -I/Users/morgan/.rvm/rubies/ruby-2.5.1/include/ruby-2.5.0
10
+ -I/Users/morgan/.rvm/rubies/ruby-2.5.1/include/ruby-2.5.0/ruby/backward
11
+ -I/Users/morgan/.rvm/rubies/ruby-2.5.1/include/ruby-2.5.0/x86_64-darwin16
12
+ -I/usr/local/opt/libksba/include
13
+ -I/usr/local/opt/libyaml/include
14
+ -I/usr/local/opt/openssl@1.1/include
15
+ -I/usr/local/opt/readline/include
16
+ -isystem
17
+ Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
18
+ -isystem
19
+ /usr/local/include
20
+ -isystem
21
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.1.0/include
22
+ -isystem
23
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
24
+ -isystem
25
+ /usr/include
26
+ -Wall
27
+ -Wdeclaration-after-statement
28
+ -Wdeprecated-declarations
29
+ -Wdivision-by-zero
30
+ -Wextra
31
+ -Wextra-tokens
32
+ -Wimplicit-function-declaration
33
+ -Wimplicit-int
34
+ -Wno-constant-logical-operand
35
+ -Wno-long-long
36
+ -Wno-missing-field-initializers
37
+ -Wno-parentheses
38
+ -Wno-parentheses-equality
39
+ -Wno-self-assign
40
+ -Wno-tautological-compare
41
+ -Wno-unused-parameter
42
+ -Wpointer-arith
43
+ -Wshorten-64-to-32
44
+ -Wunused-variable
45
+ -Wwrite-strings
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ edit-distance
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,176 @@
1
+ # Generated by YCM Generator at 2017-10-20 01:27:37.246835
2
+
3
+ # This file is NOT licensed under the GPLv3, which is the license for the rest
4
+ # of YouCompleteMe.
5
+ #
6
+ # Here's the license text for this file:
7
+ #
8
+ # This is free and unencumbered software released into the public domain.
9
+ #
10
+ # Anyone is free to copy, modify, publish, use, compile, sell, or
11
+ # distribute this software, either in source code form or as a compiled
12
+ # binary, for any purpose, commercial or non-commercial, and by any
13
+ # means.
14
+ #
15
+ # In jurisdictions that recognize copyright laws, the author or authors
16
+ # of this software dedicate any and all copyright interest in the
17
+ # software to the public domain. We make this dedication for the benefit
18
+ # of the public at large and to the detriment of our heirs and
19
+ # successors. We intend this dedication to be an overt act of
20
+ # relinquishment in perpetuity of all present and future rights to this
21
+ # software under copyright law.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27
+ # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29
+ # OTHER DEALINGS IN THE SOFTWARE.
30
+ #
31
+ # For more information, please refer to <http://unlicense.org/>
32
+
33
+ import os
34
+ import ycm_core
35
+
36
+ PROJECT_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
37
+ RVM_RUBY_DIR = '/Users/morgan/.rvm/rubies/ruby-2.5.1/include/ruby-2.5.0'
38
+ XCTOOLCHAIN_DIR = '/Applications/Xcode.app/Contents/Developer' \
39
+ '/Toolchains/XcodeDefault.xctoolchain'
40
+
41
+ BASE_FLAGS = [
42
+ '-D_DARWIN_C_SOURCE',
43
+ '-D_DARWIN_UNLIMITED_SELECT',
44
+ '-D_REENTRANT',
45
+ '-D_XOPEN_SOURCE',
46
+ '-I{0}/tmp/x86_64-darwin16/edit_distance/2.5.1'.format(PROJECT_ROOT_DIR),
47
+ '-I{0}/ext/edit_distance'.format(PROJECT_ROOT_DIR),
48
+ '-I{0}'.format(RVM_RUBY_DIR),
49
+ '-I{0}/ruby/backward'.format(RVM_RUBY_DIR),
50
+ '-I{0}/x86_64-darwin16'.format(RVM_RUBY_DIR),
51
+ '-I/usr/local/opt/libksba/include',
52
+ '-I/usr/local/opt/libyaml/include',
53
+ '-I/usr/local/opt/openssl@1.1/include',
54
+ '-I/usr/local/opt/readline/include',
55
+ '-isystem',
56
+ '{0}/usr/include/c++/v1'.format(XCTOOLCHAIN_DIR),
57
+ '-isystem',
58
+ '/usr/local/include'.format(XCTOOLCHAIN_DIR),
59
+ '-isystem',
60
+ '{0}/usr/lib/clang/9.1.0/include'.format(XCTOOLCHAIN_DIR),
61
+ '-isystem',
62
+ '{0}/usr/include'.format(XCTOOLCHAIN_DIR),
63
+ '-isystem',
64
+ '/usr/include',
65
+ '-Wall',
66
+ '-Wdeclaration-after-statement',
67
+ '-Wdeprecated-declarations',
68
+ '-Wdivision-by-zero',
69
+ '-Wextra',
70
+ '-Wextra-tokens',
71
+ '-Wimplicit-function-declaration',
72
+ '-Wimplicit-int',
73
+ '-Wno-constant-logical-operand',
74
+ '-Wno-long-long',
75
+ '-Wno-missing-field-initializers',
76
+ '-Wno-parentheses',
77
+ '-Wno-parentheses-equality',
78
+ '-Wno-self-assign',
79
+ '-Wno-tautological-compare',
80
+ '-Wno-unused-parameter',
81
+ '-Wpointer-arith',
82
+ '-Wshorten-64-to-32',
83
+ '-Wunused-variable',
84
+ '-Wwrite-strings',
85
+ ]
86
+
87
+
88
+ def DirectoryOfThisScript():
89
+ return os.path.dirname(os.path.abspath(__file__))
90
+
91
+
92
+ # Set this to the absolute path to the folder (NOT the file!) containing the
93
+ # compile_commands.json file to use that instead of 'BASE_FLAGS'. See here for
94
+ # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
95
+ #
96
+ # You can get CMake to generate this file for you by adding:
97
+ # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
98
+ # to your CMakeLists.txt file.
99
+ #
100
+ # Most projects will NOT need to set this to anything; you can just change the
101
+ # 'BASE_FLAGS' list of compilation flags. Notice that YCM itself uses that
102
+ # approach.
103
+ compilation_database_folder = os.path.join(DirectoryOfThisScript(), 'tmp')
104
+
105
+ SOURCE_EXTENSIONS = ['.cpp', '.cxx', '.cc', '.c', '.m', '.mm']
106
+
107
+ if os.path.exists(compilation_database_folder):
108
+ database = ycm_core.CompilationDatabase(compilation_database_folder)
109
+ else:
110
+ database = None
111
+
112
+
113
+ def IsHeaderFile(filename):
114
+ extension = os.path.splitext(filename)[1]
115
+ return extension in ['.h', '.hxx', '.hpp', '.hh']
116
+
117
+
118
+ def GetLanguageAndStandardFlagsForFile(filename):
119
+ extension = os.path.splitext(filename)[1]
120
+
121
+ if IsHeaderFile(filename) or extension in ['.cpp', '.cxx', '.cc']:
122
+ return (['-x', 'c++'], ['-std=c++14'])
123
+ elif extension == '.m':
124
+ return (['-ObjC'], [])
125
+ elif extension == '.mm':
126
+ return (['-ObjC++'], [])
127
+ else:
128
+ return (['-x', 'c'], ['-std=gnu11'])
129
+
130
+
131
+ def BuildFlagListForFile(filename):
132
+ (lang_flags, std_flags) = GetLanguageAndStandardFlagsForFile(filename)
133
+ final_flags = lang_flags + BASE_FLAGS + std_flags
134
+ return final_flags
135
+
136
+
137
+ def GetCompilationInfoForFile(filename):
138
+ # The compilation_commands.json file generated by CMake does not have
139
+ # entries for header files. So we do our best by asking the db for flags
140
+ # for a corresponding source file, if any. If one exists, the flags for
141
+ # that file should be good enough.
142
+ if IsHeaderFile(filename):
143
+ basename = os.path.splitext(filename)[0]
144
+ for extension in SOURCE_EXTENSIONS:
145
+ replacement_file = basename + extension
146
+ if os.path.exists(replacement_file):
147
+ compilation_info = database.GetCompilationInfoForFile(
148
+ replacement_file)
149
+ if compilation_info.compiler_flags_:
150
+ return compilation_info
151
+ return None
152
+ return database.GetCompilationInfoForFile(filename)
153
+
154
+
155
+ def FlagsForFile(filename, **kwargs):
156
+ if not database:
157
+ return {
158
+ 'flags': BuildFlagListForFile(filename),
159
+ 'include_paths_relative_to_dir': DirectoryOfThisScript()
160
+ }
161
+
162
+ compilation_info = GetCompilationInfoForFile(filename)
163
+ if not compilation_info:
164
+ return {
165
+ 'flags': BuildFlagListForFile(filename),
166
+ 'include_paths_relative_to_dir': DirectoryOfThisScript()
167
+ }
168
+
169
+ # Bear in mind that compilation_info.compiler_flags_ does NOT return a
170
+ # python list, but a "list-like" StringVec object.
171
+ final_flags = list(compilation_info.compiler_flags_)
172
+
173
+ return {
174
+ 'flags': final_flags,
175
+ 'include_paths_relative_to_dir': compilation_info.compiler_working_dir_
176
+ }
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at j.morgan.lieberthal@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in edit_distance.gemspec
8
+ gemspec
9
+
10
+ group :development, :test do
11
+ gem 'rubocop', '>= 0.52', require: false
12
+ gem 'rubocop-rspec', '>= 1.21', require: false
13
+
14
+ gem 'colorize', require: false # for pry prompt support
15
+
16
+ gem 'pry', require: false
17
+ gem 'pry-theme', require: false
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ edit_distance (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ colorize (0.8.1)
12
+ diff-lcs (1.3)
13
+ method_source (0.9.0)
14
+ parallel (1.12.1)
15
+ parser (2.5.1.0)
16
+ ast (~> 2.4.0)
17
+ powerpack (0.1.1)
18
+ pry (0.11.3)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.9.0)
21
+ pry-theme (1.2.0)
22
+ coderay (~> 1.1)
23
+ rainbow (3.0.0)
24
+ rake (10.5.0)
25
+ rake-compiler (1.0.4)
26
+ rake
27
+ rspec (3.7.0)
28
+ rspec-core (~> 3.7.0)
29
+ rspec-expectations (~> 3.7.0)
30
+ rspec-mocks (~> 3.7.0)
31
+ rspec-core (3.7.1)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-expectations (3.7.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.7.0)
36
+ rspec-mocks (3.7.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.7.0)
39
+ rspec-support (3.7.1)
40
+ rubocop (0.54.0)
41
+ parallel (~> 1.10)
42
+ parser (>= 2.5)
43
+ powerpack (~> 0.1)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (~> 1.0, >= 1.0.1)
47
+ rubocop-rspec (1.25.1)
48
+ rubocop (>= 0.53.0)
49
+ ruby-progressbar (1.9.0)
50
+ unicode-display_width (1.3.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ bundler (~> 1.16)
57
+ colorize
58
+ edit_distance!
59
+ pry
60
+ pry-theme
61
+ rake (~> 10.0)
62
+ rake-compiler
63
+ rspec (~> 3.0)
64
+ rubocop (>= 0.52)
65
+ rubocop-rspec (>= 1.21)
66
+
67
+ BUNDLED WITH
68
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 J. Morgan Lieberthal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # EditDistance
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/edit_distance`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'edit_distance'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install edit_distance
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/baberthal/edit_distance. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the EditDistance project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/baberthal/edit_distance/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ desc 'The default task'
6
+ task default: %i[clobber compile spec lint]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'edit_distance'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $:.unshift(lib) unless $:.include?(lib)
5
+ require 'edit_distance/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'edit_distance'
9
+ spec.version = EditDistance::VERSION
10
+ spec.authors = ['J. Morgan Lieberthal']
11
+ spec.email = ['j.morgan.lieberthal@gmail.com']
12
+
13
+ spec.summary = 'Calculate edit distance (levenshtein distance)'
14
+ spec.homepage = 'https://github.com/baberthal/ruby-edit_distance'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = %x(git ls-files -z).split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+ spec.extensions = ['ext/edit_distance/extconf.rb']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rake-compiler'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ end
@@ -0,0 +1,82 @@
1
+ //===- edit_distance.c - Ruby Edit Distance Native Extension ------*- C -*-===//
2
+ //
3
+ // This source file is part of the edit_distance open source project.
4
+ //
5
+ // Copyright (c) 2018 J. Morgan Lieberthal
6
+ // Licensed under Apache License, Version 2.0
7
+ //
8
+ //===----------------------------------------------------------------------===//
9
+
10
+ #include <ruby.h>
11
+
12
+ #include <algorithm>
13
+ #include <memory>
14
+
15
+ static VALUE mEditDistance;
16
+
17
+ static VALUE
18
+ f_compute_edit_distance(VALUE self, VALUE v_str1, VALUE v_str2,
19
+ VALUE v_allow_replacements, VALUE v_max)
20
+ {
21
+ bool AllowReplacements = RTEST(v_allow_replacements);
22
+ unsigned MaxEditDistance = NUM2UINT(v_max);
23
+
24
+ // Get the length of each string
25
+ size_t m = RSTRING_LEN(v_str1);
26
+ size_t n = RSTRING_LEN(v_str2);
27
+
28
+ // Get pointers to the string data
29
+ const char *FromStr = RSTRING_PTR(v_str1);
30
+ const char *ToStr = RSTRING_PTR(v_str2);
31
+
32
+ // Set up other variables
33
+ const unsigned SmallBufferSize = 64;
34
+ unsigned SmallBuffer[SmallBufferSize];
35
+ std::unique_ptr<unsigned[]> Allocated;
36
+ unsigned *Row = SmallBuffer;
37
+
38
+ // allocate storage if we need more than 64 chars
39
+ if (n + 1 > SmallBufferSize) {
40
+ Row = new unsigned[n + 1];
41
+ Allocated.reset(Row);
42
+ }
43
+
44
+ // Fill in the row
45
+ for (unsigned i = 1; i <= n; ++i)
46
+ Row[i] = i;
47
+
48
+ for (size_t y = 1; y <= m; ++y) {
49
+ Row[0] = static_cast<unsigned>(y);
50
+ unsigned BestThisRow = Row[0];
51
+
52
+ unsigned Previous = static_cast<unsigned>(y - 1);
53
+ for (size_t x = 1; x <= n; ++x) {
54
+ int OldRow = Row[x];
55
+ if (AllowReplacements) {
56
+ Row[x] = std::min(Previous + (FromStr[y - 1] == ToStr[x - 1] ? 0u : 1u),
57
+ std::min(Row[x - 1], Row[x]) + 1);
58
+ } else {
59
+ if (FromStr[y - 1] == ToStr[x - 1])
60
+ Row[x] = Previous;
61
+ else
62
+ Row[x] = std::min(Row[x - 1], Row[x]) + 1;
63
+ }
64
+ Previous = OldRow;
65
+ BestThisRow = std::min(BestThisRow, Row[x]);
66
+ }
67
+
68
+ if (MaxEditDistance && BestThisRow > MaxEditDistance)
69
+ return UINT2NUM(MaxEditDistance + 1);
70
+ }
71
+
72
+ unsigned Result = Row[n];
73
+ return UINT2NUM(Result);
74
+ }
75
+
76
+ extern "C" void
77
+ Init_edit_distance(void)
78
+ {
79
+ mEditDistance = rb_define_module("EditDistance");
80
+ rb_define_module_function(mEditDistance, "_compute_edit_distance",
81
+ (VALUE(*)(...))f_compute_edit_distance, 4);
82
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+
5
+ create_makefile('edit_distance/edit_distance')
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'edit_distance/version'
4
+ require 'edit_distance/edit_distance'
5
+
6
+ module EditDistance
7
+ module_function
8
+
9
+ def compute_edit_distance(str1, str2, **options)
10
+ allow_replacements = options.fetch(:allow_replacements, true)
11
+ max_edit_distance = options.fetch(:max_edit_distance, 0)
12
+ _compute_edit_distance(str1, str2, allow_replacements, max_edit_distance)
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EditDistance
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake/extensiontask'
4
+ require_relative 'constants'
5
+
6
+ task build: :compile
7
+
8
+ Rake::ExtensionTask.new('edit_distance') do |ext|
9
+ ext.lib_dir = 'lib/edit_distance'
10
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ TMP_COMPILE_COMMANDS = 'tmp/compile_commands.json'
4
+ TMP_COMPDB = File.expand_path("../#{TMP_COMPILE_COMMANDS}", __dir__).freeze
5
+
6
+ ENV['MAKE'] = "bear -o #{TMP_COMPDB} make"
data/rakelib/ide.rake ADDED
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require_relative 'constants'
5
+
6
+ module IDE
7
+ def self.db_path
8
+ TMP_COMPILE_COMMANDS
9
+ end
10
+
11
+ def self.compile_commands
12
+ @compile_commands ||= begin
13
+ require 'json'
14
+ JSON.parse(File.read(db_path))
15
+ end
16
+ end
17
+
18
+ class CompilationDatabase
19
+ def initialize(data)
20
+ @data = data
21
+ end
22
+ end
23
+
24
+ class CompileCommand
25
+ attr_reader :file, :directory, :arguments
26
+
27
+ def initialize(data)
28
+ @file = Pathname.new(data['file'])
29
+ @directory = Pathname.new(data['directory'])
30
+ @arguments = data['arguments']
31
+ end
32
+
33
+ def absolute_file_path
34
+ @absolute_file_path ||= file.expand_path(directory)
35
+ end
36
+
37
+ def include_flags; end
38
+
39
+ def warning_flags
40
+ @warning_flags ||= arguments.grep(/^-W/)
41
+ end
42
+
43
+ private
44
+
45
+ def include_flag?(flag)
46
+ flag.start_with? '-I', '-isystem'
47
+ end
48
+
49
+ def warning_flag?(flag)
50
+ flag.start_with? '-W'
51
+ end
52
+
53
+ def feature_flag?(flag)
54
+ flag.start_with? '-f'
55
+ end
56
+
57
+ def def_flag?(flag)
58
+ flag.start_with? '-D', '-U'
59
+ end
60
+ end
61
+ end
62
+
63
+ namespace :ide do
64
+ directory 'tmp'
65
+
66
+ file TMP_COMPILE_COMMANDS => :compile
67
+ end
data/rakelib/lint.rake ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new(:rubocop) do |task|
6
+ task.patterns = %w[lib/**/*.rb spec/**/*.rb]
7
+ task.formatters = ['files']
8
+ task.fail_on_error = true
9
+ end
10
+
11
+ desc 'Run linters and static analysis tools'
12
+ task lint: [:rubocop]
data/rakelib/spec.rake ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edit_distance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - J. Morgan Lieberthal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - j.morgan.lieberthal@gmail.com
72
+ executables: []
73
+ extensions:
74
+ - ext/edit_distance/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".clang-format"
78
+ - ".color_coded"
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".ruby-gemset"
82
+ - ".ruby-version"
83
+ - ".travis.yml"
84
+ - ".ycm_extra_conf.py"
85
+ - CODE_OF_CONDUCT.md
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - edit_distance.gemspec
94
+ - ext/edit_distance/edit_distance.cpp
95
+ - ext/edit_distance/extconf.rb
96
+ - lib/edit_distance.rb
97
+ - lib/edit_distance/version.rb
98
+ - rakelib/compile.rake
99
+ - rakelib/constants.rb
100
+ - rakelib/ide.rake
101
+ - rakelib/lint.rake
102
+ - rakelib/spec.rake
103
+ homepage: https://github.com/baberthal/ruby-edit_distance
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.7.6
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Calculate edit distance (levenshtein distance)
127
+ test_files: []