Skip to content

Commit

Permalink
shoot forgot
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Apr 15, 2024
1 parent acc9719 commit 13dfc0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 6 additions & 4 deletions docs/sorted.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h1><a class="toc-backref" href="#12">Procs</a></h1>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>


The equality comparison for SortedJsonTree is faster than the one for JsonTree.
<a href="https://github.com/planetis-m/jsonpak/tree/main/src/jsonpak/sorted.nim#L56" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/planetis-m/jsonpak/edit/main/src/jsonpak/sorted.nim#L56" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;

Expand All @@ -134,7 +134,9 @@ <h1><a class="toc-backref" href="#12">Procs</a></h1>
<dt><pre><span class="Keyword">proc</span> <a href="#deduplicate%2CSortedJsonTree"><span class="Identifier">deduplicate</span></a><span class="Other">(</span><span class="Identifier">tree</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sorted.html#SortedJsonTree"><span class="Identifier">SortedJsonTree</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>


<p>Deduplicates keys in <tt class="docutils literal"><span class="pre"><span class="Identifier">tree</span></span></tt> recursively. If duplicate keys are found, only the last occurrence of each key is kept.</p>
<p>The deduplication is performed in-place.</p>

<a href="https://github.com/planetis-m/jsonpak/tree/main/src/jsonpak/sorted.nim#L106" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/planetis-m/jsonpak/edit/main/src/jsonpak/sorted.nim#L106" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;

Expand All @@ -148,7 +150,7 @@ <h1><a class="toc-backref" href="#12">Procs</a></h1>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>


Sorts all the keys of <tt class="docutils literal"><span class="pre"><span class="Identifier">tree</span></span></tt> recursively, ensuring that the resulting tree has its keys in lexicographic order.
<a href="https://github.com/planetis-m/jsonpak/tree/main/src/jsonpak/sorted.nim#L34" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/planetis-m/jsonpak/edit/main/src/jsonpak/sorted.nim#L34" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;

Expand All @@ -166,7 +168,7 @@ <h1><a class="toc-backref" href="#12">Procs</a></h1>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-04-15 09:12:11 UTC</small>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-04-15 09:19:19 UTC</small>
</div>
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions src/jsonpak/sorted.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ proc rawSorted(result: var JsonTree; tree: JsonTree, n: NodePos) =
result.nodes.add tree.nodes[curr.int]

proc sorted*(tree: JsonTree): SortedJsonTree {.inline.} =
# Sorts all the keys of `tree` recursively, ensuring that
# the resulting tree has its keys in lexicographic order.
## Sorts all the keys of `tree` recursively, ensuring that
## the resulting tree has its keys in lexicographic order.
privateAccess(JsonTree)
result = JsonTree(nodes: newSeqOfCap[Node](tree.nodes.len)).SortedJsonTree
rawSorted(JsonTree(result), tree, rootNodeId)
Expand All @@ -54,7 +54,7 @@ proc rawTest(tree, value: JsonTree, n: NodePos): bool =
return true

proc `==`*(a, b: SortedJsonTree): bool {.inline.} =
# The equality comparison for SortedJsonTree is faster than the one for JsonTree.
## The equality comparison for SortedJsonTree is faster than the one for JsonTree.
privateAccess(JsonTree)
if JsonTree(a).nodes.len != JsonTree(b).nodes.len:
return false
Expand Down Expand Up @@ -104,9 +104,9 @@ proc rawDeduplicate(tree: var JsonTree, n: NodePos, parents: var seq[PatchPos])
discard

proc deduplicate*(tree: var SortedJsonTree) =
# Deduplicates keys in `tree` recursively. If duplicate keys are found,
# only the last occurrence of each key is kept.
#
# The deduplication is performed in-place.
## Deduplicates keys in `tree` recursively. If duplicate keys are found,
## only the last occurrence of each key is kept.
##
## The deduplication is performed in-place.
var parents: seq[PatchPos] = @[]
rawDeduplicate(JsonTree(tree), rootNodeId, parents)

0 comments on commit 13dfc0d

Please sign in to comment.