diff options
author | Billingsly Wetherfordshire <phowl.mouth@gmail.com> | 2014-06-02 18:13:56 -0500 |
---|---|---|
committer | Billingsly Wetherfordshire <phowl.mouth@gmail.com> | 2014-06-02 18:13:56 -0500 |
commit | ac797e1801b7b24df95b1513c37c4e2813f27c5a (patch) | |
tree | d83fc6f083cf1d6f41bbedafeef39aa51122157b | |
parent | 4099abc8675ca37e713098c211bfe73aabd34259 (diff) | |
download | Nim-ac797e1801b7b24df95b1513c37c4e2813f27c5a.tar.gz |
added json.hash
-rw-r--r-- | lib/pure/json.nim | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index b325c2905..c56589803 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -620,6 +620,7 @@ proc `%`*(elements: openArray[PJsonNode]): PJsonNode = for i, p in pairs(elements): result.elems[i] = p proc `==`* (a,b: PJsonNode): bool = + ## Check two nodes for equality if a.kind != b.kind: false else: case a.kind @@ -638,6 +639,24 @@ proc `==`* (a,b: PJsonNode): bool = of JObject: a.fields == b.fields +proc hash* (n:PJsonNode): THash = + ## Compute the hash for a JSON node + case n.kind + of jArray: + result = hash(n.elems) + of jObject: + result = hash(n.fields) + of jInt: + result = hash(n.num) + of jFloat: + result = hash(n.fnum) + of jBool: + result = hash(n.bval.int) + of jString: + result = hash(n.str) + of jNull: + result = hash(0) + proc len*(n: PJsonNode): int = ## If `n` is a `JArray`, it returns the number of elements. ## If `n` is a `JObject`, it returns the number of pairs. |