No announcement yet.

Another wish list (& bug report)

  • Filter
  • Time
  • Show
Clear All
new posts
    Daniel Corbier

  • Daniel Corbier
    Michael, the way I've implemented it, the binary search serves
    equally for finding where to insert the data if it's not found.
    If the search finds the data in the array it returns a positive
    number. If not, it returns a negative number, the absolute value
    of which represents where the data should be inserted.
    Consider the following code:

    Function FindElement(text$, TheArray$()) As Long
       Dim Lower As Long, Upper As Long, MidPoint As Long
       Lower = LBound(TheArray$())
       Upper = UBound(TheArray$())
          MidPoint = (Lower + Upper) \ 2
          Select Case StrComp(text$, TheArray$(MidPoint))
             Case 0 ' %StrEqual
                FindElement = MidPoint
                Exit Function
             Case 1 ' %StrGreater
                Lower = MidPoint + 1
             Case -1 ' %StrLess
                Upper = MidPoint - 1
          End Select
       Loop While Lower <= Upper
       FindElement = -Lower ' Location for array insert
    End Function
    Let's say, you have MyArray$(1:5) = { "A", "B", "C", "D", "E" }
    If you do FindElement("B", MyArray$()) then it returns 2. But
    if you do FindElement("Bob", MyArray$()) it gives you -3, which
    means that you can insert "Bob" into array element 3.
    This works for me. (My actual code is different from the above,
    because my string array itself remains unsorted. New string
    elements are added to the end of the array. Instead, I
    maintain a numeric sort-order index array for the string array,
    but the concept is virtually the same).

    Lance, the equate idea is something I thought of when I was
    working with code like the above. I couldn't run that block of
    code by itself in the DLL context it was in. So I pasted the
    block of code to VB, and I wanted to replace %StrEqual, %StrLess,
    and %StrGreater with their literal values as I have done above.
    But I couldn't remember the values for %StrGreater and %StrLess
    off the top of my head (and I didn't want to scroll out of the
    location where I was to find the equate definitions.)

    The equate idea is not a major feature to worry about. Add it
    only if it doesn't take much extra work to do. But a built-in
    StrComp function on the other hand would be practical enough
    (as long as it's quicker than my non-optimized StrComp).
    Also, here are other features that would be helpful in the
    context of data searches and maintenance I want to do:

    - Extra parameters for Replace
    In a previous thread I requested Replace as a function. In
    addition to that, I now see the use for the following optional
    parameters: Start, and Count, which are pretty self-explanatory
    (but for more info, see the VB help file for Replace$).

    - a Start parameter for Tally
    This would allow you to count the number occurrences of the
    substring, starting at a given location (optional) which would
    not have to be the the beginning of the string. Likewise,
    perhaps you can also have an optional Finish param. So it
    would count the occurrences of a substring between Start
    and Finish. Perhaps there can be an optional Finish
    for Replace$() as well, as long as it's implemented in such a
    way that it wouldn't be confused with the Count paramenter.

    Daniel Corbier
    UCalc Fast Math Parser

    Leave a comment:

  • Michael Mattias

  • Michael Mattias
    ...might do up to 10,000 string comparisons before finding the
    location where to insert, whereas a binary search would do
    less than 15 string comparisons in its worst case (or around 30
    without StrComp).
    The problem with a binary search for your purposes is that a binary search only works for an "equals" condition. You are doing a "greater than n but less than m" comparison.

    That is assuming we are talking about a "binary search" in the classic sense of start in the middle of a sorted list, check if greater or less than target, go halfway toward the terminus of the list in the desired direction and test again; repeat until found or you have checked two adjacent list entries.

    I think I posted a binary search in the source code forum, but I'll check later today and if I didn't, I will.


    Leave a comment:

  • Lance Edmonds

  • Lance Edmonds
    To the best of my knowledge, array subscript data is always stored in "sequential" blocks in memory, but with the exception of Dynamic Strings (whose locations move around with each assignment). Note that when any array is REDIMmed, the array subscript data locations are not guaranteed to stay in the same block. The array descriptor will always stay in the same spot though.

    The equate idea is interesting, but as long as you know the name of the equate, how often would you need to know it's value?

    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:

  • Daniel Corbier

  • Daniel Corbier
    Lance, in the previous message, I should have stopped at the
    first paragraph. But while I was entering that message, I tried
    something or other which made ARRAY SCAN seem extremely fast.
    But I must have entered a typo for it to run so fast. When I
    tried it again today, ARRAY SCAN worked within the speed
    boundaries I would have expected, which was nowhere near the
    speed that I'd get from a binary search.

    But interestingly, while away from the computer, and wondering
    how (mistakenly) ARRAY SCAN could possibly run so fast if all it
    did was a sequential search, I came upon another idea which
    actually would run surprisingly fast. I haven't worked out the
    details yet, but let's say you have an array that doesn't change,
    except for new elements that can be added, and you want to
    find out if something is in the array or not. Then you can do
    something like this:

    For x = 0 to 10000
      AllArrayData$ = AllArrayData$ + chr$(0) + MyArray$(x)
    This is assuming that the above would need to be done once,
    and new elements are added to AllArrayData$ occasionally.
    Now if you wanted a superfast way of finding if data is in the
    array, you'd simply do:

    Result = Instr(AllArrayData$, chr$(0)+"Hello"+chr$(0))

    This would give you a very fast way of finding out if "Hello"
    is in the array. This only lets you quickly find out if the
    data is in the array or not. However, although I haven't worked
    it out yet, it seems like this concept can be combined with a
    sorted indexed list which would let you quickly find out exactly
    where the data is (assuming it's in the list), with only one
    string operation (Instr), and just a couple of Integer

    It would probably be difficult to adapt ARRAY statements to
    support all the ways a person would want to work with an array.
    So it will be easier for me to just continue handling my array
    data the way I'm doing it.

    I have a question regarding ASCIIZ string arrays (I can find
    out the answer, but I want it to be documented in the help file
    so I can know whether to rely on my findings). The help file
    explains how numeric arrays are organized in memory. How about
    strings? In particular I want to know if ASCIIZ array elements
    are also stored in consecutive blocks of memory like numeric
    arrays. How about fixed length strings, and variable length

    Here's one quick item to add to the wishlist. I'd like a tool
    tip to display the value of a constant while in the IDE.
    Sometimes I can't remember the value of a constant I'm looking
    at, yet I don't want to move anywhere to find out.

    Daniel Corbier
    UCalc Fast Math Parser

    Leave a comment:

  • Lance Edmonds

  • Lance Edmonds
    Eigel, QUAD alignment is on the wish list already, but thanks!

    Daniel, to the best of my knowledge, ARRAY SCAN has to do a sequential search since it does not "know" whether the array data is sorted... however, it is a very finely tuned piece of code, so you may still be hard pressed to beat it (except possibly using binary search methods on very large sorted arrays). I'm afraid I do not have any "specs" to offer you on it;s performance - all I can suggest is that you do some benchmarking against your own code.

    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:

  • E Dingsor

  • E Dingsor
    I have one wish which I've wished before, but still not an option.

    I would like to have QUAD aligment option i the TYPE statement.



    Leave a comment:

  • Daniel Corbier

  • Daniel Corbier
    Lance, the ARRAY SCAN/INSERT lines you mentioned would work.
    However, if it does a simple sequential search, then I'm not
    sure that it would be as fast as what I need. I haven't done
    a full comparison test yet. But if I have a 10,000 element
    string array, then ARRAY SCAN, if it searches sequentially,
    might do up to 10,000 string comparisons before finding the
    location where to insert, whereas a binary search would do
    less than 15 string comparisons in its worst case (or around 30
    without StrComp).

    Although I haven't looked into it deeply enough, a quick check
    seemed to reveal that ARRAY SCAN was significantly faster than
    doing a simple sequential search in a loop. It could be that
    after my efforts of creating my own binary insert, that I might
    end up not getting the speed advantage over ARRAY SCAN I thought
    I'd get. Can you comment on how ARRAY SCAN operates? You don't
    have to divulge any trade secrets. But I just want to know if
    ARRAY SCAN does more than just a sequential-type of search, and
    how it might compare to a regular binary search. Does ARRAY
    SCAN work faster on a sorted array? Does the element towards
    the end of the array take proportionally longer to search than
    one towards the beginning (for instance element at
    MyArray$(10000) vs the one at MyArray$(1))? How does the search
    speed for an element that is not found compare to one that is
    found? What is the worst case speed one can expect (in ratio
    to the element that would be found the fastest)? Which
    element in the array would be found the fastest with SCAN? Do
    ARRAY statements operate with the same efficiency on ASCIIZ
    arrays as variable length strings? What other things should
    one take into consideration when using the ARRAY statements?

    So far, I've avoided using the ARRAY statements in favor of my
    own routines, perhaps because I'm not sure how it all works.
    One time I tried an ARRAY statement, and it didn't seem
    too much more efficient than a non-optimized alternative, and
    now that I tried it again, ARRAY SCAN seems faster than what I
    remember. While I'm typing this now, I changed the SCAN
    criteria, and the performance though reasonably good, is not
    nearly as fast as what I tried just a short while ago.

    Daniel Corbier
    UCalc Fast Math Parser

    Leave a comment:

  • Peter Scheutz

  • Peter Scheutz
    Originally posted by Paul Dwyer:
    I have seen lines disappear from the IDE too.
    I always add a couple of extra [RETURN]'s to the end of the bas file.
    That seems to fix it.

    Best Regards
    Peter Scheutz


    Leave a comment:

  • Lance Edmonds

  • Lance Edmonds
    Thanks folks... these issues should be well sorted out in the next update to the IDE.

    Regarding SELECT CASE and IF/THEN, etc... R&D have noted that we have misreported SELECT CASE as using floating point for all CASE comparisons... the truth is that it always uses integer comparisons where possible, so there should be negligible difference in performance between SELECT CASE and IF-THEN blocks.

    Regarding ARRAY INSERT (sorted)... you can easily achieve this by using:
    ARRAY SCAN array$(), > "data", to Result&
    ARRAY INSERT array$(Result&), "data"
    However, the "wish list" items are also duly noted. Thanks!

    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:

  • Paul Dwyer
    Inactive Member

  • Paul Dwyer

    I have seen lines disappear from the IDE too.

    Sometime when your sub or functions ends on the last line of the IDE and you do a compile you get an error saying that the sub needs to end with "End Sub", but you can see it there. If you close the .bas file and open it again sure enough the compiler was right and the "End Sub" is gone, but it was being displayed. I have seen this 7 or 8 times now so if I get the error I just restart the IDE and retype the "End Sub" line. I shouldn't need to though.

    Paul Dwyer
    Network Engineer
    Aussie in Tokyo

    Leave a comment:

  • Kev Peel

  • Kev Peel

    Ok, I'll add my personal wish list as well...

    In order of preference...

    1./ Static Libraries
    2./ Report unused variables and unused procedures
    3./ Option to strip out unused procedures (not exports)
    4./ Variable length members in UDT's (Like in VB)
    5./ More array functions, notibly ARRAY COPY and ARRAY COMPARE (inc. ole strings)
    6./ Some sort of interface (DLL?) for 3rd party IDEs/Debuggers
    7./ Allow for compile & run in memory
    8./ Allow creation of OCX files (I bet PB would be wicked at this for size+speed)
    9./ Single-Line $If metastatement
    10./ Allow pre-defining of variables, ie: Local sText As String = "MyStr"


    Kev G Peel
    KGP Software, Bridgwater, UK.

    Leave a comment:

  • Daniel Corbier

  • Daniel Corbier
    started a topic Another wish list (& bug report)

    Another wish list (& bug report)

    Here is an additional wishlist, bug report, and items
    that may need clarification.

    - StrComp(string1, string2)
    Several compilers have a StrComp function which compares
    two strings and returns a 0 if the strings are equal, -1
    (or value <0) if string1 < string2, and 1 (or value >0) if
    string1 > string2. See 2nd paragraph of tagarray wish
    below for explanation of the usefulness of this function.
    (There's a slight difference in the way various compilers
    implement this. PB may want to combine the best features).

    - ARRAY INSERT (at a sorted position)
    Let's say I have a sorted list, and I want to insert an element.
    I don't want to necessarily insert it at the beginning or end,
    or at a pre-determined location. Instead I want to insert the
    data at a location in such a way that the array will remain
    sorted after the insert. (Resorting the whole array after
    each insert would likely be inefficient).

    - ARRAY SORT TAGARRAY enhancement
    I have a string array, and an integer array. I want a special
    sort feature that will sort the tagarray (the integer array)
    based on the sorted string array, however, without changing
    the order of the string array itself. The string array would
    need to remain in its original order. The elements of the
    integer array is what would move around. That array would
    serve as a sorted index for the string array, allowing you
    to later access the string array in powerful ways.

    Basically here is what I want to do. I have a string array.
    Every time I add an element, I want the string array to maintain
    it's sorted index order, so I can later do a fast binary search.
    It is also necessary for each string element not to move around,
    hence I sort the tagged index array, not the original string
    array. I have already implemented what I need without using the
    ARRAY functions. But one thing that would allow me to tweak it
    further would be the StrComp function. For every one comparison
    that StrComp would do, I am currently doing up to two string
    comparisons for the binary search. I couldn't find a way around

    I see that binary search has been suggested already, so I'm not
    adding it as a separate entry in today's wishlist.

    - Clarification needed for Select Case
    In another discussion, it was said that On/Goto and If/Then are
    faster than Select Case, whereas the help file seems to suggest
    just the opposite. It says that Select Case is more efficient
    than If/Then and On/Goto (the next to last paragraph of the
    Select Case help file topic). So I need some clarifications.
    Perhaps one is more efficient under some circumstances and less
    in other situations?

    - Please include an ASCII table in the help file

    - Small bug: Copy/paste adds extra space.
    If I highlight text up to the end of the line, but the mouse
    pointer goes beyond the end of line, and I copy the segment and
    paste it elsewhere, it adds extra spaces in the new location,
    even though it's not part of what's highlighted. I don't know
    if this is by design or not, but it seems a little unusual.

    - Bigger bug: The IDE sometimes deletes lines of code.
    To duplicate the problem, paste in the following code (at
    line 1, column 1):

    Function PbMain
       ' The following lines are
       ' there mostly to fill up
       ' space to demonstrate the
       ' IDE problem.
       ' Enter enough lines of code
       ' (or paste this function)
       ' so that the last line of
       ' text (the one that says
       ' "End Function") ends up on
       ' line 26 or beyond.
       ' Maximize the IDE screen.
       ' The last line should be just
       ' below the bottom, in such a
       ' way that there's a scroll
       ' bar at the right, and
       ' Function PBMain is not visible
       ' at the same time as End Function
       ' For x = 1 to 10
       '   y = x
       ' Next
       ' Etc...
    End Function
    Then press the PageUp & Home buttons so that you are at the very
    top left corner. Now go to line 4 (or beyond), and the press
    PageDown. Type in a function, or paste these 4 lines:

    ' The following function disappears
    Function ByeBye As Long
       MsgBox "Gone!"
    End Function
    Now save it, and load it again. The ByeBye function is gone.
    Even before saving it, you'll notice that the text is there, but
    you can't move the cursor to that location. Also, if you pasted
    those lines instead of typing it, you'll notice that the comment
    line wasn't pasted. In my current project, I've had to add
    " ' End of Program " at the end of my code, so that I know if
    the last few lines are intact or not.

    Daniel Corbier
    UCalc Fast Math Parser