Created
May 1, 2024 11:18
-
-
Save tompng/044f09e7d2b1ae31cf02de0af8a19bc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files_rbreadline = Dir.glob('rb-readline/lib/**/*.rb') | |
files_reline = Dir.glob('reline/lib/**/*.rb') | |
K = 123456789 | |
P = (1 << 81) | 17 | |
def hashes(text, n) | |
output = {} | |
hash = 0 | |
hash2 = 0 | |
chars = [] | |
q = K.pow(n, P) | |
text.chars.each_with_index.select do |c, i| | |
next if c =~ /\s/ | |
chars << [c, i] | |
hash = (hash * K + c.ord) % P | |
if chars.size >= n | |
idx = chars.first.last | |
yield (hash - hash2 * q) % P, idx..i | |
hash2 = (hash2 * K + chars.shift.first.ord) % P | |
end | |
end | |
end | |
MATCH_LEN = 30 | |
file_codes = {} | |
hash_code_indices = {} | |
files_rbreadline.each do |file| | |
code = File.read(file) | |
file_codes[file] = code | |
hashes(code, MATCH_LEN) do |hash, range| | |
hash_code_indices[hash] = [file, range] | |
end | |
end | |
files_reline.each do |file| | |
code = File.read(file) | |
duplicates = [] | |
hashes(code, MATCH_LEN) do |hash, range| | |
src_file, src_range = hash_code_indices[hash] | |
next unless src_file | |
prev = duplicates.last | |
if prev && prev[0] == src_file && prev[1].end >= src_range.begin && prev[2].end >= range.begin | |
prev[2] = prev[2].begin..range.end | |
else | |
duplicates << [src_file, src_range, range] | |
end | |
end | |
next if duplicates.empty? | |
puts "\e[31mFile: #{file}\e[m" | |
puts | |
duplicates.each do |src_file, src_range, dst_range| | |
puts "From: #{src_file} #{src_range}" | |
puts | |
puts code[dst_range] | |
puts | |
end | |
4.times { puts } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File: reline/lib/reline/config.rb | |
From: rb-readline/lib/rbreadline.rb 75858..75887 | |
print-completions-horizontally | |
From: rb-readline/lib/rbreadline.rb 76698..76729 | |
completion_query_items = value.to_i | |
when | |
From: rb-readline/lib/rbreadline.rb 76247..76281 | |
value.nil? || value == '1' || value == 'on' | |
File: reline/lib/reline/line_editor.rb | |
From: rb-readline/lib/rbreadline.rb 34552..34584 | |
completion_append_character = '' | |
From: rb-readline/lib/rbreadline.rb 272273..272302 | |
r.dup.force_encoding(@encoding | |
From: rb-readline/lib/rbreadline.rb 272273..272302 | |
r.dup.force_encoding(@encoding | |
From: rb-readline/lib/readline.rb 6879..6908 | |
.completer_word_break_characte | |
From: rb-readline/lib/readline.rb 7011..7040 | |
completer_word_break_characters | |
File: reline/lib/reline/windows.rb | |
From: rb-readline/lib/rbreadline.rb 147764..147816 | |
class Win32API | |
DLL = {} | |
TYPEMAP = {"0" => Fiddle::TYPE_VOID, "S" => Fid | |
From: rb-readline/lib/rbreadline.rb 147817..147851 | |
" => Fiddle::TYPE_VOID, "S" => Fiddle::TYPE_VOIDP, "I" => Fiddle::T | |
From: rb-readline/lib/rbreadline.rb 147852..147884 | |
le::TYPE_VOIDP, "I" => Fiddle::TYPE_LONG} | |
From: rb-readline/lib/rbreadline.rb 147998..148030 | |
def initialize(dllname, func, import, export = "0", calltype = :stdc | |
From: rb-readline/lib/rbreadline.rb 148031..148066 | |
ort, export = "0", calltype = :stdcall) | |
@proto = | |
From: rb-readline/lib/rbreadline.rb 148216..148247 | |
@func = Fiddle::Function.new(handle[func], | |
From: rb-readline/lib/rbreadline.rb 148350..148406 | |
) | |
args.each_with_index do |x, i| | |
args[i], = [x == 0 ? nil : x].pack("p") | |
From: rb-readline/lib/rbreadline.rb 148407..148444 | |
gs[i], = [x == 0 ? nil : x].pack("p").unpack( | |
From: rb-readline/lib/rbreadline.rb 148520..148551 | |
args[i], = [x].pack("I").unpack("i") if | |
From: rb-readline/lib/rbreadline.rb 149278..149309 | |
@GetConsoleScreenBufferInfo = Win32API.new( | |
From: rb-readline/lib/rbreadline.rb 149180..149211 | |
@SetConsoleCursorPosition = Win32API.new( | |
From: rb-readline/lib/rbreadline.rb 149380..149411 | |
@FillConsoleOutputCharacter = Win32API.new( | |
From: rb-readline/lib/rbreadline.rb 149494..149525 | |
@ReadConsoleInput = Win32API.new( | |
From: rb-readline/lib/rbreadline.rb 150474..150505 | |
@GetKeyState.call(VK_LMENU) & 0x80) != 0 | |
From: rb-readline/lib/rbreadline.rb 154438..154475 | |
= csbi[4, 4].unpack('L').first | |
written = | |
File: reline/lib/reline.rb | |
From: rb-readline/lib/readline.rb 7011..7040 | |
completer_word_break_characters | |
From: rb-readline/lib/readline.rb 7011..7040 | |
completer_word_break_characters=( | |
From: rb-readline/lib/readline.rb 7011..7040 | |
completer_word_break_characters = | |
From: rb-readline/lib/rbreadline.rb 30740..30772 | |
basic_word_break_characters = " \t\n | |
From: rb-readline/lib/readline.rb 6879..6908 | |
.completer_word_break_characte | |
From: rb-readline/lib/readline.rb 7011..7040 | |
completer_word_break_characters = | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment