• Stars
    star
    286
  • Rank 143,588 (Top 3 %)
  • Language
    Ruby
  • License
    Other
  • Created about 13 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate difference sets between Ruby sequences.

Diff::LCS

home

github.com/halostatue/diff-lcs

code

github.com/halostatue/diff-lcs

bugs

github.com/halostatue/diff-lcs/issues

rdoc

rubydoc.info/github/halostatue/diff-lcs

continuous integration

<img src=“https://github.com/halostatue/diff-lcs/workflows/CI/badge.svg” />

Description

Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities to create a simple HTML diff output format and a standard diff-like tool.

This is release 1.4.3, providing a simple extension that allows for Diff::LCS::Change objects to be treated implicitly as arrays and fixes a number of formatting issues.

Ruby versions below 2.5 are soft-deprecated, which means that older versions are no longer part of the CI test suite. If any changes have been introduced that break those versions, bug reports and patches will be accepted, but it will be up to the reporter to verify any fixes prior to release. The next major release will completely break compatibility.

Synopsis

Using this module is quite simple. By default, Diff::LCS does not extend objects with the Diff::LCS interface, but will be called as if it were a function:

require 'diff/lcs'

seq1 = %w(a b c e h j l m n p)
seq2 = %w(b c d e f j k l m r s t)

lcs = Diff::LCS.LCS(seq1, seq2)
diffs = Diff::LCS.diff(seq1, seq2)
sdiff = Diff::LCS.sdiff(seq1, seq2)
seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj)
bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj)
seq2 == Diff::LCS.patch!(seq1, diffs)
seq1 == Diff::LCS.unpatch!(seq2, diffs)
seq2 == Diff::LCS.patch!(seq1, sdiff)
seq1 == Diff::LCS.unpatch!(seq2, sdiff)

Objects can be extended with Diff::LCS:

seq1.extend(Diff::LCS)
lcs = seq1.lcs(seq2)
diffs = seq1.diff(seq2)
sdiff = seq1.sdiff(seq2)
seq = seq1.traverse_sequences(seq2, callback_obj)
bal = seq1.traverse_balanced(seq2, callback_obj)
seq2 == seq1.patch!(diffs)
seq1 == seq2.unpatch!(diffs)
seq2 == seq1.patch!(sdiff)
seq1 == seq2.unpatch!(sdiff)

By requiring ‘diff/lcs/array’ or ‘diff/lcs/string’, Array or String will be extended for use this way.

Note that Diff::LCS requires a sequenced enumerable container, which means that the order of enumeration is both predictable and consistent for the same set of data. While it is theoretically possible to generate a diff for an unordered hash, it will only be meaningful if the enumeration of the hashes is consistent. In general, this will mean that containers that behave like String or Array will perform best.

History

Diff::LCS is a port of Perl’s Algorithm::Diff that uses the McIlroy-Hunt longest common subsequence (LCS) algorithm to compute intelligent differences between two sequenced enumerable containers. The implementation is based on Mario I. Wolczko’s Smalltalk version 1.2 (1993) and Ned Konz’s Perl version Algorithm::Diff 1.15. Diff::LCS#sdiff and Diff::LCS#traverse_balanced were originally written for the Perl version by Mike Schilli.

The algorithm is described in A Fast Algorithm for Computing Longest Common Subsequences, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor improvements to improve the speed. A simplified description of the algorithm, originally written for the Perl version, was written by Mark-Jason Dominus.

More Repositories

1

rubypython

An in-process between Ruby and Python 2.
Ruby
254
star
2

color

Color tools for Ruby.
Ruby
133
star
3

coredata-easyfetch

A fast fetch based on example code by Matt Gallagher
Objective-C
81
star
4

text-hyphen

Text::Hyphen will hyphenate words using modified versions of TeX hyphenation patterns.
Ruby
48
star
5

minitar

Minimal pure-ruby support for POSIX tar(1) archives.
Ruby
38
star
6

fish-docker

Docker and Docker Compose completions for the Fish Shell
Shell
37
star
7

fish-macos

MacOS functions for Fish
Shell
25
star
8

transaction-simple

Transaction::Simple for Ruby
Ruby
19
star
9

fish-rust

Rust/Cargo configuration for Fish
Shell
15
star
10

dotfiles

Dotfiles for 2023, Managed with chezmoi
Shell
12
star
11

fish-haskell

Haskell configuration for Fish
Shell
10
star
12

fish-go

Golang configuration discovery for Fish
Shell
10
star
13

fish-brew

Homebrew utility functions for Fish
Shell
9
star
14

fish-direnv

A very basic direnv configuration for fish
Shell
9
star
15

i18n-tasks-csv

Ruby
8
star
16

xcode-git-version

A script that I use for versioning builds using git. Supports both sharef and version-tag numbering.
Ruby
7
star
17

dsym-archiver

A simple bash script to archive your .dSYM bundles. Based originally on http://furbo.org/stuff/dSYM_Archive.txt.
7
star
18

fish-elixir

Fish meets Elixir
Shell
7
star
19

fish-fzf

FZF Helpers for Fish
Shell
6
star
20

minitest-bonus-assertions

Useful Minitest assertions, and assertions for testing Minitest assertions
Ruby
6
star
21

fish-utils

Fish utility functions
Shell
6
star
22

stockpile

Stockpile: a cache connection manager
Ruby
5
star
23

agio

Pure Ruby HTML to Markdown Converter
Ruby
4
star
24

zsh-focused-dotfiles

Shell
3
star
25

text-formatting

Text Formatting tools for Ruby
Ruby
3
star
26

fish-utils-net

Network fish utilities
Shell
3
star
27

ruwiki

Ruwiki. This is a dead project and is only preserved for historical reasons.
Ruby
3
star
28

text-reform

Text::Reform reformats text according to formatting picture templates.
Ruby
2
star
29

fish-ssh-agent

SSH agent initialization for Fish
Shell
2
star
30

terraform-modules

Useful modules for Terraform
HCL
2
star
31

vim-config

My new vim config.
Vim Script
2
star
32

minitar-cli

Ruby minitar command-line tool
Ruby
2
star
33

fish-battery

Battery function for Fish - deprecated
Shell
2
star
34

kx

Elixir Version Manager
Shell
2
star
35

vuex-notes

Learn vuex with a notes app, based on a Coligo tutorial and updated for vue2 and vuex2
JavaScript
2
star
36

jruby-vijava

A simple wrapper around the VMware Infrastructure (vSphere) Java API for use with JRuby.
Ruby
2
star
37

fish-utils-core

Core fish utilities
Shell
2
star
38

rails-ansible-presentation

The Deckset presentation on Rails + Ansible
2
star
39

stockpile-redis

A Redis backend for stockpile (https://github.com/halostatue/stockpile).
Ruby
2
star
40

uninheritable

Sample code demontrating how to make a class uninheritable in Ruby
Ruby
1
star
41

canonical-attributes

Ruby
1
star
42

fish-dict

Dictionary functions for fish shell
Shell
1
star
43

vim-hz

Newer vim configurations
Vim Script
1
star
44

what-gem-why-gem-how-gem

Why build gems and how to build gems, presented for RailsGirls T.O. on 24 November 2015 at the Kinetic Cafe office
1
star
45

fisher-plugin

A template for making new fisher-compatible fish plugins
Makefile
1
star
46

tex-hyphen

A port of Perl's TeX::Hyphen to Ruby 1.6/1.8. This project has been superseded by Text::Hyphen
Ruby
1
star
47

poole

Ruby
1
star
48

gh-merge-upstream

A helper for gh cli to keep forks up-to-date
Shell
1
star
49

text-format

The text-format gem for Ruby, modernized and available on GitHub.
Ruby
1
star