Announcement

Collapse
No announcement yet.

Question about string compressor RtlCompress API

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

  • Question about string compressor RtlCompress API

    Hi Pierre
    Reference to your code at https://forum.powerbasic.com/forum/u...356#post795356

    What are these FragmentOffset and FragmentLen what are their significance?
    Are they a measure of "degrees" of empty spaces in the test strings?

    Appreciate your help here

    Code:
    FragmentOffset = 100 'Give offset as if it was in a decompressed buffer.
     FragmentLen    = 1024
     FragmentLen    = GetFragment(sCompressed, sFragment, FragmentOffset, FragmentLen)
     MessageBox(%HWND_DESKTOP, _
                "FragmentOffset " & $TAB & FORMAT$(FragmentOffset, "000,###,###") & $CRLF & _
                "FragmentLen "    & $TAB & FORMAT$(FragmentLen,    "000,###,###"), _
                $AppName & " - Fragment", %MB_OK OR %MB_TOPMOST)

  • #2
    Hi Tim,
    FragmentOffset and FragmentLen give you the awesome possibility to extract a part of a compressed string without the need to decompress the whole string first.

    Let say we got an uncompressed string as
    sUncompressed = REPEAT$(100, "A") & "Tim" & REPEAT$(100, "B")
    we then compress it in sCompressed wich will become 12 bytes in size.
    Compress(sUncompressed, sCompressed)
    Now we want the three characters string from position 100,
    but, for some reason, we do not want to uncompress the whole string,
    maybe data is so big that it won't fit in memory, maybe, maybe...

    Also decompressed only a part is faster if we don't need the whole thing.

    And how to get characters 100 to 102 when the compressed string is 12 bytes long!

    This is where FragmentOffset and FragmentLen shine,
    you ca extract part of the compressed string giving non-compressed arguments.
    GetFragment(sCompressed, sFragment, FragmentOffset, FragmentLen)

    Code:
     sUncompressed   = REPEAT$(100, "A") & "Tim" & REPEAT$(100, "B")
     UnCompressedLen = LEN(sUncompressed)
     CompressedLen   = Compress(sUncompressed, sCompressed)
    
     FragmentOffset = 100 'Give offset as if it was in a decompressed buffer.
     FragmentLen    = 3
     FragmentLen    = GetFragment(sCompressed, sFragment, FragmentOffset, FragmentLen)
    
     MessageBox(%HWND_DESKTOP, _
                "Fragment       " & $TAB & sFragment & $CRLF & _  
                "FragmentOffset " & $TAB & FORMAT$(FragmentOffset, "000,###,###") & $CRLF & _
                "FragmentLen    " & $TAB & FORMAT$(FragmentLen,    "000,###,###") & $CRLF & _
                "CompressedLen  " & $TAB & FORMAT$(CompressedLen,  "000,###,###"), _
                "Fragment compress", %MB_OK OR %MB_TOPMOST)

    Comment


    • #3
      Thanks Sir Pierre
      this is a very good and fast way to extract a sub string from a compressed string

      Comment

      Working...
      X