Created
September 28, 2017 14:57
-
-
Save aboisvert/2daf9ed487214d810e0689d3e3a3714f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os, sets, hashes, strutils, sequtils | |
type | |
HString = object | |
str: string | |
hash: Hash | |
proc hash*(str: HString): Hash = | |
str.hash | |
proc toHString*(str: string): HString = | |
result.hash = hash(str) | |
shallowCopy(result.str, str) | |
converter toString*(str: HString): string = | |
str.str | |
if paramCount() != 2: | |
echo "mydiff file1 file2" | |
quit() | |
proc main(): void = | |
let old_lines = readFile(paramStr(1)).splitLines().mapIt(it.toHString) | |
let new_lines = readFile(paramStr(2)).splitLines().mapIt(it.toHString) | |
let old_lines_set = toSet(old_lines) | |
let new_lines_set = toSet(new_lines) | |
let old_added = old_lines_set - new_lines_set | |
let old_removed = new_lines_set - old_lines_set | |
for line in old_lines: | |
if line in old_added: | |
echo "-", line.strip() | |
elif line in old_removed: | |
echo "+", line.strip() | |
for line in new_lines: | |
if line in old_added: | |
echo "-", line.strip() | |
elif line in old_removed: | |
echo "+", line.strip() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment