From e88f9e4c96bd5e6f21bc9469e116fd35b4639f10 Mon Sep 17 00:00:00 2001 From: Roman Vishnevskii Date: Wed, 10 May 2017 18:51:13 +0700 Subject: [PATCH] Fix empty LIS --- src/karax.nim | 29 ++++++++++++++++++++++++----- tests/diffDomTests.nim | 8 ++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/karax.nim b/src/karax.nim index e661b78..0e58c4b 100644 --- a/src/karax.nim +++ b/src/karax.nim @@ -1,6 +1,6 @@ ## Karax -- Single page applications for Nim. -import dom, vdom, jstrutils, components, jdict, tables +import dom, vdom, jstrutils, components, jdict export dom.Event @@ -184,6 +184,9 @@ proc print(s: cstring, ident: int) = # kout cstring(result) proc longestIncreasingSubsequence(a: seq[int]): seq[int] = + if len(a) == 0: + return @[] + result.add 0 var parent = newSeq[int](len(a)) for i in 0.. leftNew: # remove redundant old nodes @@ -325,14 +336,22 @@ proc updateElement(parent, current: Node, newNode, oldNode: VNode, ident: int = detach(oldNode[i]) else: # permute elements using LIS - var positionByKey = newTable[VKey, int]() + var positionByKey = newJDict[VKey, int]() var positions = newSeq[int]() for i in leftOld..rightOld: positionByKey[oldNode[i].key] = i for i in leftNew..rightNew: - if positionByKey.hasKey(newNode[i].key): + if positionByKey.contains(newNode[i].key): positions.add positionByKey[newNode[i].key] + #if len(positions) > 0: + # kout cstring("new segment len = " & $(rightNew - leftNew + 1)) + # kout cstring("old segment len = " & $(rightOld - leftOld + 1)) + # var t = "" + # for i in 0..