From 6fb58200b1229b822e242007ec0f64c090695128 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 14 Jun 2014 20:16:45 -0700 Subject: [PATCH] fix sorting and linked list bugs --- src/General/Index.coffee | 13 +++++-------- src/General/lib/randomaccesslist.class | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 942a1610c..aac594111 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -401,19 +401,16 @@ Index = return sortOnTop: (match) -> - offset = 0 {sortedNodes} = Index - threadRoot = sortedNodes.first + threadRoot = target = sortedNodes.first while threadRoot + {next} = threadRoot if match Get.threadFromRoot threadRoot.data - target = sortedNodes.first - j = 0 - while j++ < offset + if threadRoot is target target = target.next - unless threadRoot is target - offset++ + else sortedNodes.before target, threadRoot - threadRoot = threadRoot.next + threadRoot = next return buildIndex: -> diff --git a/src/General/lib/randomaccesslist.class b/src/General/lib/randomaccesslist.class index b161177b4..3547cfccd 100644 --- a/src/General/lib/randomaccesslist.class +++ b/src/General/lib/randomaccesslist.class @@ -29,7 +29,10 @@ class RandomAccessList root.prev = item item.next = root item.prev = prev - prev.next = item if prev + if prev + prev.next = item + else + @first = item after: (root, item) -> return if item.prev is root @@ -40,14 +43,20 @@ class RandomAccessList root.next = item item.prev = root item.next = next - next.prev = item if next + if next + next.prev = item + else + @last = item prepend: (item) -> {first} = @ return if item is first or not @[item.ID] @rmi item item.next = first - first.prev = item + if first + first.prev = item + else + @last = item @first = item delete item.prev @@ -77,4 +86,4 @@ class RandomAccessList if next next.prev = prev else - @last = prev \ No newline at end of file + @last = prev