Skip to content

Commit

Permalink
doc hash
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Apr 18, 2024
1 parent 5455440 commit db4712f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ iterator pairs[T](tree: JsonTree; path: JsonPtr; t: typedesc[T]): (lent string,
proc sorted(tree: JsonTree): SortedJsonTree
proc `==`(a, b: SortedJsonTree): bool
proc deduplicate(tree: var SortedJsonTree)
proc hash(tree: SortedJsonTree): Hash
```

Expand Down Expand Up @@ -192,10 +193,11 @@ for i in items(x, JsonPtr"/b", int): echo i, " "
for k, v in pairs(x, JsonPtr"/d", JsonTree): echo (k, v), " "
# ("e", [7]) ("f", "foo")
# Sorting, deduplicating
# Sorting, deduplicating, repeatable hashes
var y = parseJson("""{"b":5,"a":1,"b":{"d":4,"c":2,"d":3}}""").sorted
deduplicate(y)
# {"a": 1, "b": {"c": 2, "d": 3}}
echo hash(y) # -3485509795705892506
```

Expand Down
1 change: 1 addition & 0 deletions tests/texample.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ for k, v in pairs(x, JsonPtr"/d", JsonTree): echo (k, v), " "
var y = parseJson("""{"b":5,"a":1,"b":{"d":4,"c":2,"d":3}}""").sorted
deduplicate(y)
assert y == SortedJsonTree(%*{"a": 1, "b": {"c": 2, "d": 3}})
echo hash(y)

0 comments on commit db4712f

Please sign in to comment.