I am trying to find the best way to write a subroutine of Array Intersection
I tried 3 methods.
- a sequential method (18 seconds)
- a dichotomous search method ( 9 seconds)
-and finally I learn or I try to understand how to use the SMcNeill tools and so I wrote a routine with the use of _MEM. It's difficult for me because I do not understand all the subtleties of the English language and even less those of the language "Basic" (12 seconds)
These tables are already sorted
I thought the 3rd method (with _Mem) would be faster, but no.
I think I have to make mistakes in using these instructions
Thank you in advance for your advice
'$INCLUDE:'SET.BI'
Read_tables
'MemSortSome ma, 0, 19
'MemSortSome mb, 0, 9
Intersec_sequentiel:
REM calcul intersection_Array methode sequentielle
PRINT "1 - Intersection_array methode sequentielle" PRINT "wait about 20 seconds...." commun# = 0
repet = 0
k = 0: ll% = 0
i = 0
j = 0
IF b
(i
) = a
(k
, j
) THEN commun#
= commun#
+ 1: ll%
= ll%
+ 1 j = j + 1
i = i + 1
result(ll%) = result(ll%) + 1
ll% = 0
k = k + 1
repet = repet + 1
temps1
= TIMER(0.001) - temps1
PRINT "Commun="; commun#
, "temps="; temps1
PRINT "Press a Key to continue"
Intersec_dicho:
PRINT "2 - Calcul Array_Intersection dichotomie " PRINT "wait about 20 seconds...." commun# = 0
repet = 0
k = 0: ll% = 0
'MemSortSome mc, 0, 19 (gain 9 seconds)
i = 0
inf% = 0: sup% = 19
RechercheCombi:
mil%
= INT((inf%
+ sup%
) / 2) IF b
(i
) = c
(mil%
) THEN commun#
= commun#
+ 1: ll%
= ll%
+ 1:
GOTO existepas
IF b
(i
) < c
(mil%
) THEN sup%
= mil%
- 1:
GOTO RechercheCombi
IF b
(i
) > c
(mil%
) THEN inf%
= mil%
+ 1:
GOTO RechercheCombi
existepas:
i = i + 1
result(ll%) = result(ll%) + 1
ll% = 0
k = k + 1
repet = repet + 1
temps6
= TIMER(0.001) - temps6
PRINT "Commun="; commun#
, "temps="; temps6
PRINT "Press a Key to continue";
";"
intersec_mem:
REM calcul intersection tableau avec
_mem PRINT "Calcul Array_Intersection with _mem " PRINT "wait about 20 seconds...." commun# = 0
repet = 0
k = 0: ll% = 0
'MemSortSome mc, 0, 19 (gain 9 seconds)
kk% = 0
index% = BinaryMemSearchSome(b(kk%), mc, 0, 19)
IF index%
<> -1 THEN commun#
= commun#
+ 1: ll%
= ll%
+ 1 kk% = kk% + 1
result(ll%) = result(ll%) + 1
ll% = 0
k = k + 1
repet = repet + 1
temps8
= TIMER(0.001) - temps8
PRINT "Commun="; commun#
, "temps="; temps8
DATA 1,2,3,5,9,11,13,14,24,27,32,45,47,58,60,64,65,67,69,70 DATA 2,4,5,7,11,12,22,23,27,28,31,41,44,46,48,53,54,62,66,70 DATA 3,5,9,16,21,24,28,33,36,37,39,42,43,44,46,53,57,60,65,70 DATA 5,7,10,17,26,28,32,33,35,36,39,42,44,46,49,52,57,58,60,68 DATA 3,7,8,9,11,12,18,22,26,29,30,33,40,46,48,49,55,58,60,63 DATA 1,2,6,10,11,16,17,21,27,35,42,45,49,56,59,63,66,68,69,70 DATA 4,13,14,23,26,29,36,37,39,41,42,45,46,52,53,54,56,61,63,65 DATA 5,9,11,15,19,21,22,25,30,36,38,41,42,45,56,57,60,65,66,68 DATA 5,7,8,12,16,24,25,26,28,32,33,41,42,43,48,50,52,57,62,65 DATA 3,11,15,16,20,21,33,34,47,49,50,51,52,54,57,58,61,62,66,70
DATA 2,8,9,10,13,18,19,22,23,24,28,33,34,37,41,42,43,45,51,61 DATA 2,4,7,11,12,14,15,16,28,36,38,40,44,45,56,63,65,67,68,70 DATA 7,9,12,13,15,19,21,29,30,31,34,36,37,39,41,48,53,62,64,68 DATA 3,5,10,13,14,15,16,22,26,29,30,34,36,41,43,47,48,55,66,67 DATA 2,3,7,8,15,20,22,32,35,41,49,50,51,53,54,58,59,60,69,70 DATA 1,6,10,14,20,21,23,24,25,27,32,36,37,38,47,53,56,59,62,63 DATA 4,11,12,15,25,28,30,31,33,35,39,43,45,49,51,56,59,63,66,69 DATA 1,4,6,7,8,10,15,24,27,33,34,35,37,38,46,50,58,67,68,70 DATA 10,11,12,14,15,17,18,23,25,37,38,42,52,53,54,55,63,64,65,68 DATA 1,2,5,7,15,16,19,23,24,27,33,38,39,47,54,59,60,62,64,65 DATA 1,3,11,21,28,32,45,58,60,70
'$INCLUDE:'SET.BM'
[ You are not allowed to view this attachment ] [ You are not allowed to view this attachment ] [ You are not allowed to view this attachment ]