Code:
DECLARE FUNCTION getfrag$ ()DECLARE SUB setfrag (d$, ofs%, mf%)DECLARE SUB firsthole ()DECLARE SUB addhole (first%, last%)'Hole descriptorsTYPE hd first AS INTEGER last AS INTEGER set AS INTEGER 'If non-zero, it means this index has an entryEND TYPETYPE d first AS INTEGER last AS INTEGER more AS INTEGER dat AS STRING * 4000 'data in our fragmentEND TYPECONST maxhole = 1000 'Assume we deal with 1000 holes?DIM SHARED bigbuf AS STRING * 4000 'Our space of data after defragmentation is completeDIM SHARED hole(maxhole) AS hd, frag AS d'highest index in hole descriptor'increments when new entries are addedDIM SHARED nhs% nhs% = 0CALL firsthole'our fragment (will need more of these eventually)CALL setfrag("TEST", 0, 1)'run through each hole (this kills efficiency I think...)FOR hs% = 0 TO maxhole - 1 IF hole(hs%).set <> 0 THEN 'dont go through a hole if its not setup as a hole hf% = hole(hs%).first hl% = hole(hs%).last IF frag.first <= hl% AND frag.last >= hf% THEN 'This satisfies steps 2 and 3 of the algorithm hole(hs%).set = 0 'This satisfies step 4 mf = frag.more IF frag.first > hf% THEN CALL addhole(hf%, frag.first - 1) 'This satisfies step 5 IF frag.last < hl% AND mf% = 1 THEN CALL addhole(frag.last + 1, hl%) 'This satisfies step 6 hs% = -1 'redo count END IF END IFNEXT'All hole descriptors are processed so we jam in the data I guess??MID$(bigbuf, frag.first + 1, frag.last - frag.first) = getfrag$'then what???END'Here we add a hole to the new index and set it as a holeSUB addhole (first%, last%)nhs% = nhs% + 1hole(nhs%).set = 1hole(nhs%).first = first%hole(nhs%).last = last%END SUB'We setup the first hole per algorithm as 0 to length of output data spaceSUB firsthole'first hole = all spacehole(0).first = 0hole(0).last = LEN(bigbuf)hole(0).set = 1END SUB'We load our fragmentFUNCTION getfrag$getfrag$ = LEFT$(frag.dat, frag.last - frag.first)END FUNCTION'We setup our fragment. 2nd parameter is offset of fragment the "remote" host reports it to be.'3rd parameter if non-zero means remote host has set the MF (more fragments) flag.SUB setfrag (d$, ofs%, mf%)frag.dat = d$frag.first = ofs%frag.last = ofs% + LEN(d$)frag.more = 0IF mf% <> 0 THEN frag.more = 1END SUB
Statistics: Posted by mikefromca — Fri Feb 26, 2021 12:44 am