Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Single occurrence in a string
Message
De
30/03/2015 07:19:14
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
À
30/03/2015 02:26:56
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01617326
Message ID:
01617374
Vues:
71
>>>>>>>>>Thanks to all (Dragan, Marcia and Tore). I wonder which solution is the fastest?
>>>>>>>>>
>>>>>>>>>Since you have all the code, why don't you test all the solutions and let us know?
>>>>>>>>
>>>>>>>>(Edit: This reply is for Yossi)
>>>>>>>>
>>>>>>>>I think Dranag's solution is the fastest and optimal, because analyze the string only once and using the minimal instruction set.
>>>>>>>>
>>>>>>>Imagine tcBig 650KB long with 10000 "A": the check will be done 10000 times,
>>>>>>>If the "A" is at the end of the resulting string, will take longer ;-)))
>>>>>>
>>>>>>You are right, and I didn't saw Marcia's algorithm that is excelent!
>>>>>>
>>>>>>This is the testing results of the 3 algorithms in my PC with a 50000 chars string:
>>>>>>
>>>>>>- Dragan: 52.5 secs and maintain the original order
>>>>>>- Tore: 30.9 secs and doesn't maintain original order (order is alphabetical because SQL)
>>>>>>- Marcia: 1.4 secs and maintain the original order => WINNER!
>>>>>>
>>>>>>Congrats Marcia! :D
>>>>>
>>>>>hmmm, Is it too late to enter the compiteition?
>>>>>
>>>>>
FUNCTION NonDupe(cString)
>>>>>LOCAL cNewStr 
>>>>> 
>>>>>cNewStr =""
>>>>>DO WHILE LEN(cString) > 0
>>>>>	cNewStr = cNewStr + LEFT(cString,1)
>>>>>	cString = STRTRAN(cString, LEFT(cString,1))
>>>>>ENDDO
>>>>>RETURN cNewStr
>>>>>ENDFUNC
>>>>>
>>>>>Which is shorter and faster than Marcia's alghorithm by 40% in my testing
>>>>>
>>>>>But all are nothing compared when you've got some C++ code working for you.
>>>>>The FoxTools.fll contains a function REDUCE() which is extremely fast on eliminating characters from a string.
>>>>>It has been written to reduce spaces but has a different role for other characters. It will remove them and replace with spaces.
>>>>>
>>>>>The following alghorith does not not work for detecting the space as a separate character, but if you're only concerned with non-space characters the following is about a 100 times faster than Marcia's routine.
>>>>>
>>>>>
>>>>>
FUNCTION NonDupe3(cString)
>>>>>LOCAL cNewStr 
>>>>> 
>>>>>cNewStr =""
>>>>>
>>>>>DO WHILE LEN(cString) > 0
>>>>>	cNewStr = cNewStr + LEFT(cString,1)
>>>>>	cString = LTRIM(REDUCE(cString, LEFT(cString,1)))
>>>>>ENDDO
>>>>>RETURN cNewStr
>>>>>ENDFUNC
>>>>>
>>>>>Walter,
>>>>
>>>>How is your entry competitive? You haven't done your own work, just refactored Marcia's entry. Easy to change what's been done rather than come up with a method yourself.
>>>
>>>John, How can be an entry of close to a 100x times faster, not be competitive?
>>>
>>>And no, my strategy is different: a cross between dragans and marcias... put on your glasses.
>>>On second look mine is just a minor variation on what Thomas wrote. However, I did not see that one (nor you) before I wrote mine.
>>>And I did not see anyone bring up REDUCE() in foxtools, did you?
>>>
>>>Boy you really have a problem with Dutch windmills huh?
>>
>>Your solution was identical to Marcia including the names, with the addition of 1 new command. Great Work.. You and Naomi win the prize for developerhood...
>
>Lets see:
>
>Marcia's solution;
>
>
>FUNCTION NonDupe(tcString)
>LOCAL lcNewString, lnI, lnLen, lcChar
>lcNewString = tcString
>lnLen = LEN(tcString)
>lnI = 1
>DO WHILE lnI < lnLen
>	lcChar = SUBSTR(lcNewString, lnI, 1)
>	IF OCCURS(lcChar, lcNewString) > 0
>		lcNewString = STRTRAN(lcNewString, lcChar, '', 2, -1, 2)
>		lnLen = LEN(lcNewString)
>	ENDIF 
>	lnI = lnI + 1 
>ENDDO 
>RETURN lcNewString
>
>
>My solution:
>
>FUNCTION NonDupe(cString)
>LOCAL cNewStr 
> 
>cNewStr =""
>DO WHILE LEN(cString) > 0
>	cNewStr = cNewStr + LEFT(cString,1)
>	cString = LTRIM(REDUCE(cString, LEFT(cString,1)))
>ENDDO
>RETURN cNewStr
>ENDFUNC
>
>Marcia used 13 lines of code, I 7. Marcia, used only 1 string to do the work. I used 2. Performance difference, 2 orders of magnitude.
>Marcia used SUBSTR(), OCCURS(), STRTRAN(), I used LTRIM(), LEFT() and REDUCE()
>Yep, really identical, john...
>
>So where is your contribution John? You sound like the other john... a lot of bla bla bla, but not ever shown any competence in programming, unlike Naomi you only excel in cowardly trolling. Is that what you are John?
>
>Awaiting your apologies. Lets see whether you've gut the guts...

How do you explain the same names? BTW, I haven't written fox code in nearly 10 years. So I have no example to show.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform