Announcement

Collapse
No announcement yet.

Nice and pretty fast filter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adrian Verkuil
    replied
    He MM Thanks,

    You made me study Pointers now, still I will compare the two your's and my tally routine to see wich is actually faster
    Wondering if the select case is fast enough?

    MM a nice example for me to study thanks for your effort.

    Leave a comment:


  • Michael Mattias
    replied
    It's not a string searching problem if you think about it...
    Code:
    %CHAR_LOW  = 33?    ' high and low ASC() of searched characters
    %CHAR_HIGH = 255?
    
    ' TRUE ==> The string 'S DOES CONTAIN at least one character in range %CHAR_LOW to %CHAR_HIGH
    '          which occurs more than 'limit' times
    ' FALSE==> It don't.
    FUNCTION DoesStringContainMoreThan (s AS STRING, BYVAL limit as LONG) AS LONG
    
      LOCAL pChar AS BYTE PTR , nOccur() AS LONG 
      LOCAL lStr AS LONG, I AS LONG
    
      lStr = LEN(S)   ' number of characters to be inspected 
    
      pChar = STRPTR (S)   ' point at first character
      REDIM   nOccur (%CHAR_HIGH)   ' array big enough to support %CHAR_HIGH 
    
      FOR I = 1 TO  lStr
        SELECT CASE AS LONG @pChar
          CASE %CHAR_LOW TO %CHAR_HIGH
             INCR  nOccur (@pChar) 
             IF nOccur(@pChar) > limit THEN   ' it happened, we can stop looking now.
                FUNCTION = %TRUE
                EXIT FUNCTION
             END IF
        END SELECT
        INCR pChar    ' point to next character  of S 
       NEXT
    
       FUNCTION = 0   ' if we get here it didn't happen
    
    END FUNCTION
    Yes, there are many many many different ways to speed it up. BUt just getting rid of the string operations should do lots for you.

    MCM

    Leave a comment:


  • Adrian Verkuil
    replied
    Thanks Chris,

    Will do that.

    Leave a comment:


  • Chris Holbrook
    replied
    Adrian, see recent thread here about instr, where faster methods of string matching are described.

    Leave a comment:


  • Adrian Verkuil
    started a topic Nice and pretty fast filter

    Nice and pretty fast filter

    Hi guys needed this,

    294721 string 64 long in 30 seconds not bad for a filter like this!

    scan for to many repeating chars, put result for every char in array
    scan array to see if a char (any char in the range 33 to 255)
    is more then 5 times in the string.

    Works ok, so I thought lets share it.


    Code:
    WHILE NOT EOF(1)
      LINE INPUT #1, a$
                         
       FOR I = 33 TO 255              
         Z(i) = 0
         Z(i) = TALLY (a$, CHR$(I))  
       NEXT
                        
       ARRAY SCAN Z(33), >5, TO R
                         
        IF  R  THEN .......
                        WEND
    But if one off you know a faster way ...
Working...
X