Skip to main content

Myers Diff with realtime and plot support

Project description

PyMyers

  • a myers diff algorithm implementation which support realtime calculation and visualization

Features

  • Extended the myers algorithm to support realtime calculations
  • Diff trace can be drawn with animation
  • Using a tree data structure to store and track diff traces
  • Inputs can be easily logged and restored
  • code is well orgnized with black/isort/mypy/pytest

Installation

pip install pymyers

or install editablely

git clone https://github.com/leowooong/PyMyers.git
cd PyMyers
pip install -e ./

Usage

diff

from pymyers import MyersRealTime, Diff

# set two sequences
a = "ABCABBA"
b = "CBABAC"

# diff from a to b
matches = [(2, 0), (3, 2), (4, 3), (6, 4)]
deletes = [0, 1, 5]
inserts = [1, 5]
diff = Diff(matches, deletes, inserts)

# calculate diff
myers = MyersRealTime(a, b)
diff_re = myers.diff()
assert diff_re == diff

# show diff
print('matches:', [a[c[0]] for c in matches])
print('deletes:', [a[c] for c in deletes])
print('inserts:', [b[c] for c in inserts])

real-time diff

a = "0123456789"
b0 = ""
b1 = "0"
b2 = "34"
b3 = "687"
b4 = "890"
b = [b0, b1, b2, b3, b4]

myers = MyersRealTime(a, b[0], max_depth=50)
for bi in b[1:]:
    print(myers.update(bi))

plot

a = "ABCABBA"
b = "CBABAC"

myers = MyersRealTime(a, b, plot=True, animation = True, plot_size = 50)
diff_re = myers.diff()

log

a = "ABCABBA"
b = "CBABAC"

myers = MyersRealTime(a, b, log_path='./log')
diff_re = myers.diff()

# restore log
from pymyers import Debug
log_folder = "./log/log-myers-2022-12-21-18:19:11"
a, *b = Debug.read(log_folder)

custom compare function

a = [1, 2, 3, 4, 5]
b = "13456"
eq = lambda a, b: a == int(b)

myers = MyersRealTime(a, b, eq=eq)
diff_re = myers.diff()

References

  • Thanks to Eugene W. Myers for the development of the myers algorithm and James Coglan for the clear explanation to the myers algorithm

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymyers-0.2.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymyers-0.2.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pymyers-0.2.1.tar.gz.

File metadata

  • Download URL: pymyers-0.2.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for pymyers-0.2.1.tar.gz
Algorithm Hash digest
SHA256 710458a7bb6d3d062201c0cd0402de45dfb1d2ed6cc04b64296e770280402789
MD5 3831db4279212bf8fcb3781275960665
BLAKE2b-256 919f9fad0596649582027694e1f8abebb303df3742f2a4caa3e0f2531a5b0c5f

See more details on using hashes here.

File details

Details for the file pymyers-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pymyers-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for pymyers-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c997f9dcc6d2e8d5b2138fa45ca18c012a1fbb10a73d77431de58f522274b139
MD5 473eda0e3b85ab391234ccc39624435a
BLAKE2b-256 0a3c2a56bb52377d43e8256dfc2581b558290e8b6618cdf03a99b98bf888ca20

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page