summaryrefslogtreecommitdiffstats
path: root/TreeSearch.hs
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-01-13 00:46:04 +0100
committertv <tv@shackspace.de>2015-01-13 00:47:51 +0100
commitd23ab0fa1510a9e5efccf6bdc7fbe524beef08e9 (patch)
treea2e98006cb9d4bbef4badd1e94bf9ba861239c00 /TreeSearch.hs
parent7adef3622630f37bcd7cc3dacd29fe6eea0df0a7 (diff)
find*N: skip successive items with same ID
Diffstat (limited to 'TreeSearch.hs')
-rw-r--r--TreeSearch.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/TreeSearch.hs b/TreeSearch.hs
index 40b3c17..0a5df28 100644
--- a/TreeSearch.hs
+++ b/TreeSearch.hs
@@ -43,18 +43,18 @@ findPrev loc =
-findNextN :: Int -> TreePos Full a -> TreePos Full a
+findNextN :: Eq a => Int -> TreePos Full a -> TreePos Full a
findNextN n loc
| n <= 0 = loc
| otherwise =
- maybe loc (findNextN $ n - 1) (findNext loc)
+ maybe loc (findNextN $ n - 1) (skipSame findNext loc)
-findPrevN :: Int -> TreePos Full a -> TreePos Full a
+findPrevN :: Eq a => Int -> TreePos Full a -> TreePos Full a
findPrevN n loc
| n <= 0 = loc
| otherwise =
- maybe loc (findPrevN $ n - 1) (findPrev loc)
+ maybe loc (findPrevN $ n - 1) (skipSame findPrev loc)
@@ -72,3 +72,18 @@ linearPos =
rec i loc = case findPrev loc of
Just loc' -> rec (i + 1) loc'
Nothing -> i
+
+
+
+skipSame
+ :: Eq a =>
+ (TreePos Full a -> Maybe (TreePos Full a)) ->
+ TreePos Full a ->
+ Maybe (TreePos Full a)
+skipSame next loc =
+ case next loc of
+ Nothing -> Nothing
+ Just loc' ->
+ if label loc' == label loc
+ then skipSame next loc'
+ else Just loc'