Skip to content

Instantly share code, notes, and snippets.

@aboisvert
Created September 28, 2017 14:57
Show Gist options
  • Save aboisvert/2daf9ed487214d810e0689d3e3a3714f to your computer and use it in GitHub Desktop.
Save aboisvert/2daf9ed487214d810e0689d3e3a3714f to your computer and use it in GitHub Desktop.
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