-
Notifications
You must be signed in to change notification settings - Fork 0
/
unUsed.jl
1927 lines (1540 loc) · 68.1 KB
/
unUsed.jl
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#unused functions
# no More #iterative function # TODO
#cause meeded to be called, on the next interval (iteratively )
#cause!() that does all: calls itself to proceed, further , into the next interval,
# where you record it's return (next lowerBound,upperBound
#1. in general : there aren't no right or left, only 1 function (2 subsequent effects
# 1.1. for the rigth -> calls cause right [m1, upperBound, OR m2,upperBound ])
#1.2. another left ->calls cause left pts (lowerBound,m1 always )
#2. makeVector -> collect [built-in]
#3. disccovered: append!(vector1, vector2)
#4. use
# collect
lowerbound = 8; upperbound= 9
v = collect((lowerbound: upperbound)) # [8,9]
# v = collect((1:_length)) #collect((1:_length))
#collect((1:_length))
#collect((a: _mop - 1))
# ERROR: LoadError: UndefVarError: swapContent not defined
using Base: @propagate_inbounds
include("helper.jl")
include("Utils.jl")
collect((lowerbound: upperbound - 1)) # [4,7]
collect((first(v): last(v))) # [8,9]
#newV = collect((lowerboundValue, upperboundValue-1)) # 4 #same as input interval
#newV = collect((lowerbound, upperbound))
newV = collect(lowerbound : upperbound) # 4
#say we calculated the next kernel value = 5
_next = 5
a = 1
collect(a : _next - 1) # vector [1,3] #now gives [2,3]
newV = collect(a _next) #- 1)) #[1,3] #experimential : warning
newV = collect(lowerbound : upperbound ) # commit this one #uncommentMe
lowerbound = [1,4,8][1]
#upperbound = copy(findNext([1, 4, 8], 1)) #+ nextUpperbound #
collect(lowerbound : upperbound) #define: collect()
"""
nextLowerbound= upperbound + 1
nextUpperbound= findNext([1, 4, 8], firstindex(nextLowerbound))
new = nextLowerbound + nextUpperbound
collect((nextLowerbound, new))
"""
v1 =[1,3]
v2=[8,9]
println(v1) #[3, 4, 5, 6, 7]
v = append!(v1,v2) #[first(v2),last(v2)]) # compiles
println("v = ", v)
#v = tuple(v1).push( v2) # LoadError: DimensionMismatch: dimensions must match: a has dims (Base.OneTo(2),), b has dims (Base.OneTo(5),), mismatch at 1
println(a) # a = 1
#v = collect((firstindex([1, 4, 8], lowerbound), lastindex([1, 4, 8], upperbound)))
#v = collect((firstindex([1, 4, 8], lowerbound), firstindex([1, 4, 8], upperbound))) #upperbound)) [1, 3]
# collect(([1,4,8][lowerbound],([1,4,8][upperbound])))
# a should be a =[1,2], then _first should be _first = 2
_first = 2 # feed in vector
_n1= append!(a:_first) # compiles
#handle last item
#issue arr ends at 8
# moved to upper scope of the function
# v = collect((firstindex([1,4,8],nextLowerbound), firstindex([1,4,8],nextLowerbound+1))) #[8,9]
# ========================
# Unknown Function f2
#to be named Meaningfully # uses collect #successs
function f2(i, ar=[1, 4, 8]; exceptionParameter = UnexpectedError) #,_first=nothing)#,lst=[])
if i > ar[1] && i <= length(ar) #b # i = 2 [4]
# ar[i] # 4
# ar[i]-1 #3 (to be collected with its pair 1)
if a == 2 # _first === nothing #side correct
# _first = ar[i] # collect((a,_first))
newV = collect((a: ar[i] - 1)) #TODO:check #secured the first
# push!(lst, newV)
#i += 1
return newV # , i
end
#the meat
# ar[i] # 8
ar[i] - 1 # 7
ar[i-1] # 4
#println("ar[i-1]=", ar[i-1]) #4
#println("ar[i]-1=", ar[i]-1)
#i += 1
newV = collect((ar[i-1], ar[i] - 1))
# push!(lst, newV)
return newV #, i
else
raise(exceptionParameter) #return
end
end
f2(2)
"""
#https://stackoverflow.com/questions/39586830/concatenating-arrays-in-julia
use the
Use the vcat and hcat functions:
# Example
julia> a, b = [1;2;3], [4;5;6]
julia> vcat(a, b)
6-element Array{Int64,1}:
1
2
3
4
5
6
"""
#----------
ar = [1, 4, 8] # collection of cut points
b = 9 # b was set to 2
ar
_lst = vcat(last(ar),b) # [8,9] (Expected) [now last vector is glued]
lst = tuple(_lst)
println("vcat _lst, lst) ",vcat(_lst,lst))
lst = vcat(_lst,lst) # lst = Any[8, 9, ([8, 9],), 8, 9]
println("_lst",_lst) # #Vector{Int64} # [8,9] #
#=
lst = []
#TODO: Inspect this function
for i = 2:3 #starts from 2 , length(ar)
push!(lst, f2(i))
end
=#
println("lst = ",lst) # 1st =Any[[1, 3], [4, 7]] # Expected
# println("typeof(lst[1]) = ",typeof(lst[1])) #Vector{Int64}
#concatenate(_lst,_lst)
lst = vcat(lst,_lst)
println("lst = ",lst)
##_lst = push!(ar, b) # [8, 9] #unCommentMe
##println("_lst = ", _lst)
#E(x) = ar = Any[[1, 3], [4, 7], [8,9]]
##result = vcat(last(_lst),_lst ) # collect(_lst:_lst) #unCommentMe
#result = pushlast(_lst,_lst)
##result = vcat(last(_lst),_lst ) #collect(_lst:_lst) #unCommentMe #todo:
##println("result = ",result) #unCommentMe
println("ar = ",ar)
#push!(lst, collect(last(ar), b))
println("\nlast(ar) = ",last(ar)) # 8
#ar2 = collect(last(ar): b) # [8,9]
#lst = append!(lst,ar2)
print("\n1st =",lst) # compiles
@inline function doCompare(a, b, _view;) #TODO: check?
#try
#try_block
#end
contentSwapped = nothing
aContent = _view[a] #view(_view, a) #arr[a]
bContent = _view[b] #view(_view, b) #arr[b]
triplet = 0 , 0, nothing
_length = copy(length(_view)) #ok
#a <= _length && b <= _length && a >= 0 && b >= 0
_linelength = lineLengthAcceptable(a,b,_length)
if _linelength == false
return triplet
elseif _linelength == true
if aContent > bContent # arr[a] > arr[b]
a,b,contentSwapped = swapContent(_view[a], _view[b], _view) #oldSchoolSwap(arr[a], arr[b], arr) #an inbounds swap #actual array swap
elseif aContent > bContent
#do nothing
contentSwapped = false
end
return a, b, contentSwapped
else raise(exception)
end
triplet
#catch
end
# remapCompare
function remapCompare(m2, upperBound, _view::SubArray)
m2, upperBound = remap(m2, upperBound)
println(" m2,upperBound = ", m2, upperBound)
_view = collect(m2:upperBound) |> v-> view(v, firstindex(v):lastindex(v))
m2, upperBound = doCompare(m2, upperBound, view(_view, m2:upperBound))
end
#1 function implementation
function cause!(_stack, kernel)
if _stack > 0
interval = pop!(_stack)
lowerBound = interval[1]
upperBound = interval[2]
effect!(lowerBound, upperBound, kernel)
end
end
#helpers of Util file:
#unused
"""returns the element, at lowerBound specific index"""
function elementOf(arr, n::Int64)
return first(arr, n)[n] #return the first n elements i.e. 2nd: [1:4] , [1:4][2] = 4
end
#--------
#=
function makeView(ab::UnitRange)#compiles
lowerBound = ab[1]
upperBound = ab[2]
println("upperBound = ", upperBound)
v = collect(lowerBound:upperBound)
return view(v, firstindex(v):lastindex(v))
# return view(collect(ab), (ab)[1]:(ab)[length(ab)])
end
v = collect(1:2)
view(v, 1:2)#done
=#
#=
function makeView(_view::SubArray, range) # Bug # this is not the the way
v = @view _view[range]
return v
end
=#
# ========================
# checkNextView #(question its integrity)
## next View, from lowerBound view, alont
"""main: checks from only lowerBound view """
function checkNextView(_view)
if length(_view) === Nothing
return #-1
#but lowerBound view can be at least 3(makes senselength 3->1 ) , or even 2 FOR 1 VIEW (We are finding the nextView )
elseif length(_view) >= 2 * 2 - 1 # at least the currrent count must be 4 = 2 * 2 (minimum bounds count(to be removed))
lowerBound = firstindex(_view)
upperBound = lastindex(_view)
println("firstindex(x)+1:lastindex(x)-1", firstindex(x)+1:lastindex(x)-1)
x = collect(lowerBound:upperBound)
return view(x, firstindex(x)+1:lastindex(x)-1)
end
end
""" specific: for lowerBound given bounds lowerBound, upperBound, calculates the next view """
function checkNextView(_view, lowerBound, upperBound)
if length(_view) === Nothing
return # -1 # -1 is part of the old thinking patter
#but lowerBound view can be at least 3(makes senselength 3->1 ) , or even 2 FOR 1 VIEW (We are finding the nextView )
elseif length(_view) >= 2 * 2 - 1 # at least the currrent count must be 4 = 2 * 2 (minimum bounds count(to be removed))
println("firstindex(x)+1:lastindex(x)-1", firstindex(x)+1:lastindex(x)-1)
x = collect(lowerBound:upperBound)
return view(x, firstindex(x)+1:lastindex(x)-1)
end
end
""" checks the next view, of type `naive`, via lowerBound function call, recursively
```input:
_view: current, selected view
lowerBound: current Lower Bound
upperBound: current Upper Bound
```
```output:
- if there is no `_view`: return nothing
- if there is (1) value: return the first value of `_view
- if there are (2) : return the bounds
```
"""
function checkNextView!(_view, lowerBound, upperBound) # warning: lowerBound,upperBound unused
if length(_view) === Nothing
return #-1
elseif length(_view) == 1
#TODO: Ponder: the usefulness of including lowerBound different dataType ( i.e. scalar typeof _view[1] )
return _view[1] #scalar: either lowerBound, or upperBound
elseif length(_view) >= 2
# return the current `_view` only
#return
v = collect(lowerBound:upperBound) #|>
_view = view(_view, firstindex(v):lastindex(v))
#TODO: comparebounds
lowerBound, upperBound, isSwapped = doCompare(lowerBound, upperBound, _view)# compare & sort
return _view
#but lowerBound view can be at least 3(makes senselength 3->1 ) , or even 2 FOR 1 VIEW (We are finding the nextView )
elseif length(_view) == 2 * 2 - 1 # at least the currrent count must be 4 = 2 * 2 (minimum bounds count(to be removed)) # can be 3 (3->1 )
#1 do something useful with new input fetch input
v = collect(lowerBound:upperBound) # |>
_view = view(v, firstindex(v):lastindex(v))
#TODO: compareTriad
println("firstindex(x)+1:lastindex(x)-1", firstindex(_view)+1:lastindex(_view)-1)
#2 calculate the next output : using lowerBound naive Algorithm
lowerBound = first(_view)
upperBound = last(_view)
#x = collect(lowerBound:upperBound)
if lowerBound + 1 <= upperBound - 1 # boundcheck is required
#return view(x, firstindex(x)+1:lastindex(x)-1)
return checkNextView!(_view, lowerBound + 1, upperBound - 1)
end
elseif length(_view) == 2 * 2 #
lowerBound = first(_view)
upperBound = last(_view)
m1 = _view[firstindex(_view)+1]
m2 = _view[lastindex(_view)-1]
compareQuartet(lowerBound, m1, m2, upperBound, _view)
elseif length(_view) > 4
#Subdivide further
end
end
#=
function checkNextView!(_view)
if length(_view) # === Nothing isa nothing #isa nothing
return #-1
elseif length(_view) == 1
#TODO: Contemplate the usefulness of including lowerBound different dataType ( i.e. scalar typeof _view[1] )
return _view[1] #scalar: either lowerBound, or upperBound
elseif length(_view) == 2
#only return the current _view
lowerBound = firstindex(_view)
upperBound = lastindex(_view)
return _view = collect(lowerBound:upperBound) |> _view -> _view -> view(_view, lowerBound:upperBound)
#but lowerBound view can be at least 3(makes sense; length 3->1) , or even 2 FOR 1 VIEW (We are finding the nextView )
elseif length(_view) >= 2 * 2 - 1 # at least the currrent count must be 4 = 2 * 2 (minimum bounds count(to be removed)) # can be 3 (3->1 )
#1 do something useful with new input fetch input
lowerBound = firstindex(_view)
upperBound = lastindex(_view)
_view = collect(lowerBound:upperBound) |> _view -> view(_view, firstindex(_view):lastindex(_view))
println("firstindex(x)+1:lastindex(x)-1", firstindex(_view)+1:lastindex(_view)-1) #<-------
#2 calculate the next output : using lowerBound naive Algorithm
lowerBound = firstindex(_view)
upperBound = lastindex(_view)
#x = collect(lowerBound:upperBound)
if lowerBound + 1 <= upperBound - 1 # m1(/m2) boundcheck is required
#return view(x, firstindex(x)+1:lastindex(x)-1)
return checkNextView!(_view, lowerBound + 1, upperBound - 1)
end
end
end
=#
#TODO: CheckNextView: check this Implementation: #note: needcheckNextView to to recursive i.e.
#checkNextView!(_view) #<----------
_view = nothing # TODO: replace with checkNextView!
_view = _view -> checkNextView(_view) #TODO: Complete CheckNextView() # checks CheckNextView (returns the nextView )
# =================
#-------
function traverse(_stack, lowerBound, upperBound) # traverse , lowerBound,upperBound #warning lowerBound,upperBound not used #TODO:
l = length(_stack)
if l == 1 #evaluate interval
interval = pop!(_stack) # first Interval [lowerBound,upperBound]
#do cause
# callCause(lowerBound, upperBound, interval) #, _stack)
elseif l == 2 #works best with 2
interval = pop!(_stack) # [lowerBound,upperBound]
#TODO: makeView
_view = collect(interval) |> _view -> view(_view, firstindex(_view):lastindex(_view)) |> x -> checkNextView(_view) # TODO check: checkNextView
# callCause(lowerBound, upperBound, interval)#, _stack)
else
#TOOO: compare : lowerBound[a1,b1], upperBound,# [a2,b2]
# compareQuartet(lowerBound[1], [2], upperBound[1], upperBound[2])
##Create lowerBound view for each interval Point
lowerBound = popat!(lowerBound, _stack) # [a1,b1]
_view = collect(lowerBound) |> x -> view(_view, firstindex(_view):lastindex(_view))
upperBound = popat!(upperBound - lowerBound, stack) # [a2,b2]
_view = collect(upperBound) |> x -> view(_view, firstindex(_view):lastindex(_view))
#Hint: better to function call traverse! accepting lowerBound _view for each of lowerBound & upperBound
end
end
function traverse2!(_stack, kernel)
l = length(_stack)
if l == 1 #evaluate interval
interval = pop!(_stack) # first Interval [lowerBound,upperBound]
lowerBound = indexOf(interval, interval[1])
upperBound = indexOf(interval, interval[2])
#do cause , instead call lowerBound kernet function
#kernelfunction call
kernel(lowerBound, upperBound, interval) #, _stack) #TODO: complete: q. what is its return( should be inner _stack) - with new points
#cause(interval[id][1], interval[id][upperBound], view(_stack, interval[id][1]:interval[id][upperBound]))
#end endAlgorithmSafely
else # >= 2 (i.e. 3, 4, or more )
#odd/even: divisibility by 2
isItEven = nothing
isEven(l) ? isItEven = true : isItEven = false
# traverse()
if isItEven == true # divide by 2 (always )- as it's an Even integer
n = l // 2 # returns an integer #- turnsout to be the middle # A trivial step (from checking even )
#idea: generalize to lowerBound partition function
#(based on lowerBound partition criteria)
#---- n + n = 2n #-------------
# _stack[0] # first
#_stack[n] #middle # ---- pop this
## Fetch from the _stack list, at that new, particular index
res = popat!(_stack, n) # after pop = 2*n -1 = odd
res[1] # lowerBound
res[2] # upperBound
#call kernet
# lowerBound,upperBound, at their index location
kernel(1, res, middle) #TODO: How to finish it (place lowerBound finish condition ) - _stack == [] otherwise redo that
# fetches lowerBound newer, smaller _stack of rest of the points
#if index = idx then res[offset],
#todo: what to do with value (call special kernel function )
#_stack[2n] # last
# _stack[length(_stack)]
# traverse(0, length(_stack), _stack)
#done on lowerBound higher level:
#for i in 1:length(_stack)
# traverse!(i, _stack)
# end
elseif isItEven == false #odd : 3, 5, 7, 9
#there is lowerBound middle
#TODO: traverse middle
end
#odd : 3, 5, 7, 9 ( 9/3) #least common divison #lcm
#via middle implementation : 3=2+1, 5=4+1, 7 = 6+1, 9 = 8+1
# 5, 7 are Prime : can't be divided
# 5 has lowerBound symmetry [left] [left] [middle] [right][right]
#idea: ask, isEven(3) can we divide 3 into 2 (intervals) , & 1 interval
# idea2 [odd]: 3 using three ranges : figure out mid (middle) left , & right ! [Better!]
#Even: 4,6,8 10 (4/2=2 6/2=3 8/2 =4 10/2=5)
# idea: for 4 items /2 (2*2 or is it 2^2 ) Evenly divde Into 2 [seperate intervals]
# so next time, 2 intervals would be Evaluated (compared) directly
#(checked if atomic, or not ) [& 2 / 2 = 1 ]
#maybe left calls left(), right calls right()
#or can we call directly cause (lowerBound la toute suite)
end
end
# Experimental
function traverse2!(_stack)
l = length(_stack)
if l == 1 #evaluate interval
interval = pop!(_stack) # first Interval [lowerBound,upperBound]
lowerBound = indexOf(interval, interval[1])
upperBound = indexOf(interval, interval[2])
#TODO: use lowerBound, upperBound
#do cause
#kernelfunction call
# callCause(lowerBound, upperBound, interval) #, _stack) #TODO:
#cause(interval[id][1], interval[id][upperBound], view(_stack, interval[id][1]:interval[id][upperBound]))
#end endAlgorithmSafely
else # >= 2 (i.e. 3, 4, or more )
#oddity
isItEven = nothing
isEven(l) ? isItEven = true : isItEven = false
# traverse()
if isItEven == true # divide by 2 (always )
n = l // 2 # returns an integer #- turnsout to be the middle
#---- n + n = 2n #-------------
# _stack[0] # first
#_stack[n] #middle # ---- pop this
res = popat!(_stack, n) # after pop = 2*n -1 = odd
res[1] # lowerBound
res[2] # upperBound
# lowerBound,upperBound, at their index location
kernel(1, res, middle)
#if index = idx then res[offset],
#todo: what to do with value (call special kernel function )
#_stack[2n] # last
# _stack[length(_stack)]
# traverse(0, length(_stack), _stack)
#done on lowerBound higher level:
#for i in 1:length(_stack)
# traverse!(i, _stack)
# end
elseif isItEven == false #odd : 3, 5, 7, 9
#there is lowerBound middle
#TODO: traverse middle
end
#odd : 3, 5, 7, 9 ( 9/3) #least common divison #lcm
#via middle implementation : 3=2+1, 5=4+1, 7 = 6+1, 9 = 8+1
# 5, 7 are Prime : can't be divided
# 5 has lowerBound symmetry [left] [left] [middle] [right][right]
#idea: ask, isEven(3) can we divide 3 into 2 (intervals), & 1 interval
# idea2 [odd]: 3 using three ranges : figure out mid (middle) left , & right ! [Better!]
#Even: 4,6,8 10 (4/2=2 6/2=3 8/2 =4 10/2=5)
# idea: for 4 items /2 (2*2 or is it 2^2 ) Evenly divde Into 2 [seperate intervals]
# so next time, 2 intervals would be Evaluated (compared) directly
#(checked if atomic, or not ) [& 2 / 2 = 1 ]
#maybe left calls left(), right calls right()
#or can we call directly cause (lowerBound la toute suite)
end
end
euclidDist(a::Int64, b::Int64) = -(a,b)+1
# remap
function remap(a::Int64, b::Int64) # 1 2 abs(max(a, b) - min(a, b)) + 1 ; 2 -1 = 1 + 1 = 2
b = euclidDist(a, b) + 1 # + 1 #warning you added 1 to the end: recheck new bounds (are all ranges fit) - some got to be out
a = 1 #always start at this #or offset
return a, b
end
remap(1, 10) #missing 1 at last +1 #fixed
remap(5, 10) # correct
# ================
# requires `rema`
function compareTriad(a, m1, b, _view) #applied remap
try
a, b, _isSwapped = doCompare(a, b, view(_view, a:b)) #compare bounds' content
a, m1, _isSwapped = doCompare(a, m1, view(_view, a:m1))
m1, b = remap(m1, b)
println("@view: m1, b = ", m1, b)
m1, b, _isSwapped = doCompare(m1, b, view(_view, m1:b)) #<------- remap is required
#push!(Middles, m1)
println("a, m1, b = ", a, m1, b)
a, b, m1
catch exceptionParameter #UnexpectedError
writeError(exceptionParameter)
#@error "Unexpected error" exception = (UnexpectedError, catch_backtrace())
end
#return a, b, m1
end
function compareTriad( a :: Int64, m1 :: Int64, b :: Int64, arr ; exceptionParameter = UnexpectedError) #applied remap
try
a, b, _isSwapped = doCompare(a, b, arr) #view(_view, a:b)) #compare bounds' content
a, m1, _isSwapped = doCompare(a, m1, arr) #view(_view, a:m1))
# m1, b = remap(m1, b)
# println("@view: m1, b = ", m1, b)
# classical doCompare [--no remap]
m1, b, _isSwapped = doCompare(m1, b, arr) #view(_view, m1:b)) #<------- remap is required
#push!(Middles, m1)
println("a, m1, b = ", a, m1, b)
a, b, m1
catch exceptionParameter #UnexpectedError
writeError(msg, exceptionParameter)
end
end
# =============
# mappedIndex
#newRow = view(arr, mappedIndex:newBound) # want to access sth larger than the () itself
#=UncommentMe
mappedIndex = firstindex(arr) +2 #+ 3 - 1 # firstindex(arr) + intervalBound1 -1
(first(arr, mappedIndex), mappedIndex)
# mappedIndex not defined
#collect(arr, mappedIndex:newBound)
#view(arr, mappedIndex:newBound)
mappedIndex = firstindex(arr) + intervalBound1 - 1 #3
# if mappedIndex > a && mappedIndex < b
newBound = +(mappedIndex, +1) # add either 0 if count not even, 1 if count is even
mappedIndex = +(mappedIndex, addition) # both equal half the time:
=#
# ---------
#=UncommentMe
if @assert newBound === mappedIndex
return true
end
if newBound === mappedIndex
return true
end
println("newMapped index = ", mappedIndex)
=#
# ----
"""arr[mappedIndex]+1 """
function evaluateValue(arr::Array{Int64,1}, mappedIndex::Int64; op=+)
return op(firstindex(arr, mappedIndex), 1) #,addition) ) #warning: Unassigned operation
end
#Intent: reach last index
mappedIndex = firstindex([1, 4, 8]) # + 2 # -1 # line: for view (only)
mappedIndex = lastindex([1, 4, 8]) # + 2 # -1 # line: for view (only)
# newBound = mappedIndex + 1 # arbitrary function #ERROR: index value is outside the array function
view([1, 4, 8], firstindex([1, 4, 8]): lowerbound) #correct
# v = collect((firstindex([1, 4, 8], lowerbound), firstindex([1, 4, 8], upperbound))) #upperbound)) [1, 3] # [1,1]
view([1, 4, 8], (firstindex([1, 4, 8]): lastindex([1,4,8])) ) #1
# newRow = view(arr, mappedIndex:newBound) # want to access sth larger than the () itself
arr = collect(1:9)
newRow = view(arr, mappedIndex-1:mappedIndex) # this works #[4 8] # Does not Work # Use ObjBounds
#return newRow
# ==========================================================
# findSubIntervals
## findSubIntervals
"""event driven function """
function findSubIntervals(arr::Array{Int64,1}, intervalBound1::Int64; op=+) #op can be - too
#0. init: define variables
a = firstindex(arr) #unrequired
b = lastindex(arr)
count = 0 #1
lista = []
intervalBound2 = nothing
#suggest : another function to handle main bounds :
#1. checkBound1 logic
if intervalBound1 >=a && count ==1
push!(lista, [a, intervalBound1]) #push first interval
# elseif intervalBound1 <= b
# push!(lista, [intervalBound1,b]) =# #redumdant with intervalBound2
end
#2 processing: ADD a new item
# arr[a] #uncommentMe
#op(arr[a],a)
intervalBound2 = op(a, intervalBound1 - 1)
#intervalBound2 = op(intervalBound1, 1) #TODO: (,arr[a]) # increment
#TODO: if we know distances till the next neighboring number
#OK
#=
if intervalBound2 === nothing
elseif intervalBound2 !== nothing && intervalBound2< b
end =#
#CheckBound
# index(lista,intervalBound1)
#if count> 1
#------
#---modifyInterval
if intervalBound2 < b # cruical #Check #< as intervalBound2 = intervalBound1-1 default
count += 1
print("count = ", count)
if count % 2 == 0 #if #if even return 1
addition = 1
elseif count % 2 != 0 # if it's odd
addition = 0
end
#--------
# push!(lista, [intervalBound2, intervalBound1])
#tmp = [intervalBound1, intervalBound2]
# if tmp != [] #!== nothing
mappedIndex = a + intervalBound1 - 1 # firstindex(arr) + intervalBound1 - 1 #3
# if mappedIndex > a && mappedIndex < b
newBound = op(mappedIndex, +1) # add either 0 if count not even, 1 if count is even
mappedIndex = op(mappedIndex, addition)
println("newMapped index = ", mappedIndex)
println("newBound index = ", newBound)
#handling scalars i.e. if newBound === mappedIndex
newRow = arr[mappedIndex:newBound]
#newRow = [first(arr,mappedIndex), mappedIndex]
push!(lista, newRow)
#count += 1
# else
# return
#elseif tmp === nothing
# println("nothing found")
#end
# end
end
#end
#3. finalize : if (bound2) is last item
#=
elseif intervalBound2 == b
return lista
# push!(lista, [b b])
#push!(lista, [b b])
#return lista
end =#
return lista
end
# index(3,)
#synthetic subinterval
findSubIntervals([1, 2, 3], 1)# [1,2]
findSubIntervals([1, 2, 3], 2)# [2,3]
findSubIntervals([1, 2, 3], 3)# last subinterval (uncalculated) , Done # n#1 thing
_stack = [[1,3],[4,7],[8,9]]
l = copy(length(_stack))
l.*2 #if vector i.e. d=1 : 2 *2
#----------------
#=
r == [] #when return an empty array this is true
typeof(r)
=#
ar = [4, 5, 3, 6]
tmp = findSubIntervals(ar, 2)
ar = [3, 6, 8] #
ar = sort(ar) # check index 1,2,3
mainstack = []
for i in 1:3
tmp = findSubIntervals(ar, i) #ar[i])
if tmp != [] # = nothing
#typeof(tmp)
push!(mainstack, tmp)
end
end
mainstack
# ==========================================================
## findSubIntervals2
function findSubIntervals2(arr::Array{Int64,1}, intervalBound1::Int64; op=+) #op can be - too
#0. init: define variables
a = firstindex(arr) #unrequired
b = lastindex(arr)
count = 1
addition = 0
lista = []
#intervalBound2 = nothing
#suggest : another function to handle main bounds :
#1. checkBound1 logic
#=
if intervalBound1 >=a && count ==1
push!(lista, [a, intervalBound1]) #push first interval
#= elseif intervalBound1 <= b
push!(lista, [intervalBound1,b]) =# #redumdant with intervalBound2
end
=#
#2 processing: ADD a new item
# arr[a]
#op(arr[a],a)
# first Bound
intervalBound0 = op(firstindex(arr), intervalBound1 - 1) #whats the Utility value of this action:0
#intervalBound2 = op(intervalBound1, 1) #TODO: (,arr[a]) # increment
#OK
#=
if intervalBound2 === nothing # correct condition
elseif intervalBound2 !== nothing && intervalBound2< b
end =#
#Check (Bouh (back?)
# index(lista,intervalBound1)
#if count> 1
if intervalBound1 < b # cruical #intervalBound0
count += 2
if count % 2 == 0
addition = 1
elseif count % 2 != 0
addition = 0
end
# push!(lista, [intervalBound2, intervalBound1])
#tmp = [intervalBound1, intervalBound2]
# if tmp != [] #!== nothing
mappedIndex = op(firstindex(arr), intervalBound1 - 1) #3 d(a,idx)
# if mappedIndex > a && mappedIndex < b
#arr[map]
newBound = op(mappedIndex, addition)
# mappedIndex #op(mappedIndex, +1) # add either 0 if count not even, 1 if count is even
# mappedIndex = # op(mappedIndex, addition)
println("newMapped index = ", mappedIndex)
println("newBound index = ", newBound)
# newRow = arr[mappedIndex:newBound]
if mappedIndex < b && newBound < b
newRow = view(arr, mappedIndex:newBound)
#newRow = [first(arr,mappedIndex), mappedIndex]
push!(lista, newRow)
end
#count += 1
# else
# return
#elseif tmp === nothing
# println("nothing found")
#end
# end
end
#end
#3. finalize : if (bound2) is last item
#=
elseif intervalBound2 == b
return lista
# push!(lista, [b b])
#push!(lista, [b b])
#return lista
end =#
return lista
end
""" find the subinterval, of an array """
## findSubIntervals3
function findSubIntervals3(arr::Array{Int64,1}, intervalBound1::Int64; op=+) #op can be - too
#0. init: define variables
a = firstindex(arr) #unrequired
b = lastindex(arr)
count = 1
addition = 0
lista = []
#intervalBound2 = nothing
#suggest : Another function, to handle main bounds :
#1. checkBound1 logic
#=
if intervalBound1 >=a && count ==1
push!(lista, [a, intervalBound1]) #push first interval
#= elseif intervalBound1 <= b
push!(lista, [intervalBound1,b]) =# #redumdant with intervalBound2
end
=#
#2 processing: ADD a new item
# arr[a]
#op(arr[a],a)
# first Bound
intervalBound0 = op(a, intervalBound1 - 1) #whats the Utility value :0 #depreciate
#intervalBound2 = op(intervalBound1, 1) #TODO: (,arr[a]) # increment
#OK
#=
if intervalBound2 === nothing
elseif intervalBound2 !== nothing && intervalBound2< b
end =#
#CheckBound
# index(lista,intervalBound1)
#if count> 1
if intervalBound1 < b # cruical #intervalBound0
count += 2
if count % 2 == 0
addition = 1
elseif count % 2 != 0
end
addition = 0
# push!(lista, [intervalBound2, intervalBound1])
#tmp = [intervalBound1, intervalBound2]
# if tmp != [] #!== nothing
mappedIndex = op(a, intervalBound1) #3 d(a,idx)
# if mappedIndex > a && mappedIndex < b
#---
arr[mappedIndex]
op(firstindex(arr, mappedIndex), 1) #,addition) ) #warning: Unassigned operation
#preferable DistanceNext
#newBound = op(mappedIndex, addition)
#count % 2 == 0 ? newBound = op(mappedIndex, addition) : newBound = op(mappedIndex, 1)
#---
#arr[map]
newBound = op(mappedIndex, addition + 1)
# mappedIndex #op(mappedIndex, +1) # add either 0 if count not even, 1 if count is even
# mappedIndex = # op(mappedIndex, addition)
println("newMapped index = ", mappedIndex)
println("newBound index = ", newBound)
# newRow = arr[mappedIndex:newBound]
if mappedIndex < b && newBound < b
newRow = view(arr, mappedIndex:newBound)
#newRow = [first(arr,mappedIndex), mappedIndex]
push!(lista, newRow)
end
#count += 1
# else
# return
#elseif tmp === nothing
# println("nothing found")
#end
# end
end
#end
#3. finalize : if (bound2) is last item
#=
elseif intervalBound2 == b
return lista
# push!(lista, [b b])
#push!(lista, [b b])
#return lista
end =#
return lista
end
# ==========================================================
findSubIntervals([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) # Any[[1, 2, 3], 3] # [3, 4]
findSubIntervals([1, 2, 3, 4, 5, 6, 7, 8, 9], 6) # Any[[1, 2, 3, 4, 5, 6], 6] # [6, 7]
#notdefined
findSubIntervals2([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) # Any[[1, 2, 3], 3] # [3, 4]
findSubIntervals2([1, 2, 3, 4, 5, 6, 7, 8, 9], 6) # Any[[1, 2, 3, 4, 5, 6], 6] # [6, 7]
r = findSubIntervals2([1, 2, 3, 4, 5, 6, 7, 8, 9], 8) # [8, 9]
findSubIntervals3([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) # Any[[1, 2, 3], 3] # [3, 4]
findSubIntervals3([1, 2, 3, 4, 5, 6, 7, 8, 9], 6) # Any[[1, 2, 3, 4, 5, 6], 6] # [6, 7]
r = findSubIntervals3([1, 2, 3, 4, 5, 6, 7, 8, 9], 8) # [8, 9]