-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.vim
62 lines (57 loc) · 1.09 KB
/
merge.vim
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
source utils.vim
function! Merge(start, middle, stop) abort
let i = a:start
let j = a:middle + 1
while i < j || j <= a:stop
if i == j
return
endif
if i == j
let i = i + 1
let j = j + 1
elseif j > a:stop
let i = i + 1
else
let v1 = strlen(Getval(i))
let v2 = strlen(Getval(j))
if v2 < v1
call cursor(j, 1)
normal! V
redraw
sleep 10ms
normal! dd
call cursor(i, 1)
normal! P
normal! V
redraw
sleep 10ms
normal!
let i = i + 1
let j = j + 1
else
let i = i + 1
endif
endif
endwhile
endfunction
function! Mergesort(start, stop) abort
" if a:stop - a:start <= 1
" let s1 = Getval(a:start)
" let s2 = Getval(a:stop)
" if strlen(s1) > strlen(s2)
" call Setval(a:start, s2)
" call Setval(a:stop, s1)
" endif
" else
if a:stop > a:start
let middle = (a:start + a:stop) / 2
call Mergesort(a:start, middle)
call Mergesort(middle + 1, a:stop)
call Merge(a:start, middle, a:stop)
endif
endfunction
normal! G
let stime = reltime()
call Mergesort(1, line("."))
echomsg reltimestr(reltime(stime))
normal!