-
Notifications
You must be signed in to change notification settings - Fork 2
/
Woot.elm
126 lines (94 loc) · 3.08 KB
/
Woot.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module Woot where
import Debug
import Dict exposing (..)
import Model exposing (..)
import Constants exposing (..)
import String exposing (fromChar)
import Set exposing (..)
-- - - - - - - - - - U T I L I T I E S - - - - - - - - - -
isLaterWChar : WChar -> WChar -> Bool
isLaterWChar wA wB = wIdOrder wA wB /= LT -- TODO i flipped this!
wIdOrder : WChar -> WChar -> Order
wIdOrder wA wB =
let
(wASite, wAClock) = wA.id
(wBSite, wBClock) = wB.id
in
if wASite > wBSite then GT -- before was >
else if wASite < wBSite then LT
else if wAClock > wBClock then GT
else LT
wToString : WString -> String
wToString wStr =
case wStr of
[] -> ""
x :: xs -> if x.vis > 0
then String.cons x.ch (wToString xs)
else wToString xs
subSeq : WString -> WChar -> WChar -> WString
subSeq wStr start end =
case wStr of
[] -> Debug.crash "oh no"
x :: xs -> if x.id == start.id
then subSeqGrab xs end
else subSeq xs start end
subSeqGrab : WString -> WChar -> WString
subSeqGrab wStr end =
case wStr of
[] -> []--Debug.crash (toString end)
x :: xs -> if x.id == end.id
then []
else x :: subSeqGrab xs end
ithVisible : WString -> Int -> WChar
ithVisible wStr i =
if i == -1 then startChar else
case wStr of
[] -> endChar
-- error case!
x :: xs -> if i == 0 && isVisible x then x
else
if isVisible x then ithVisible xs (i - 1)
else ithVisible xs i
-- {ch = 'W', prev = startId, next = endId, vis = -1000, id = (66, 66)}
setInvisible : WString -> WId -> WString
setInvisible wStr id =
case wStr of
[] -> []
x :: xs -> if x.id == id
then {x | vis = -1} :: xs
else x :: (setInvisible xs id)
pos : WString -> WChar -> Int
pos wStr wCh =
case wStr of
[] -> 0
x :: xs ->
if isVisible x then if x.id == wCh.id then
0
else 1 + (pos xs wCh)
else (if x.id == wCh.id then 0 else pos xs wCh)
isVisible : WChar -> Bool
isVisible wCh =
if wCh.id == startId then True
else if wCh.id == endId then True
else if wCh.vis > 0 then True
else False
grabNext : WChar -> WString -> WChar
grabNext wCh wStr =
case wStr of
x :: xs -> if x.id == wCh.next then x else grabNext wCh xs
[] -> endChar
grabPrev : WChar -> WString -> WChar
grabPrev wCh wStr =
case wStr of
x :: xs -> if x.id == wCh.prev then x else grabPrev wCh xs
[] -> startChar
canIns : WChar -> Set WId -> Bool
canIns wCh set = Set.member wCh.next set && Set.member wCh.prev set
canDel : WChar -> Set WId -> Bool
canDel wCh set = Set.member wCh.id set
canIntegrate : WUpdate -> Set WId -> Bool
canIntegrate wUpdate dict =
case wUpdate of
Insert wCh -> canIns wCh dict
Delete wCh -> canDel wCh dict
_ -> False