summaryrefslogtreecommitdiffstats
path: root/TreeSearch.hs
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-12-28 02:07:51 +0100
committertv <tv@shackspace.de>2014-12-28 02:07:51 +0100
commitf0c2db8f449bc01db19f13c24f7c314bd2b29502 (patch)
tree02c454ab6e2cad2d6404763ae2356b104d8fb917 /TreeSearch.hs
parent43bccc37f81adb2f7c5f79017af59c4b33e88ec1 (diff)
trap cursor in screen ("ausgerudert")
Diffstat (limited to 'TreeSearch.hs')
-rw-r--r--TreeSearch.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/TreeSearch.hs b/TreeSearch.hs
index 7b2e93e..40b3c17 100644
--- a/TreeSearch.hs
+++ b/TreeSearch.hs
@@ -2,6 +2,7 @@ module TreeSearch where
import Data.Tree.Zipper
+
findTree :: (a -> Bool) -> TreePos Full a -> Maybe (TreePos Full a)
findTree p loc = if p (label loc)
then Just loc
@@ -41,8 +42,33 @@ findPrev loc =
Just x' -> trans_lastChild x'
+
+findNextN :: Int -> TreePos Full a -> TreePos Full a
+findNextN n loc
+ | n <= 0 = loc
+ | otherwise =
+ maybe loc (findNextN $ n - 1) (findNext loc)
+
+
+findPrevN :: Int -> TreePos Full a -> TreePos Full a
+findPrevN n loc
+ | n <= 0 = loc
+ | otherwise =
+ maybe loc (findPrevN $ n - 1) (findPrev loc)
+
+
+
findParent :: (a -> Bool) -> TreePos Full a -> Maybe (TreePos Full a)
findParent p loc =
if p (label loc)
then Just loc
else parent loc >>= findParent p
+
+
+linearPos :: TreePos Full a -> Int
+linearPos =
+ rec 0
+ where
+ rec i loc = case findPrev loc of
+ Just loc' -> rec (i + 1) loc'
+ Nothing -> i