Using Array.FindAll

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry Spence1

    Using Array.FindAll

    I'm using VB2005

    I have an array of some 500,000 items which are of the form
    080715_175327_3 12.jpg. These are camera frames of the form
    YYMMDD_HHmmss_m s.jpg

    I want to create another array which contains all the items which are (>
    080715_1730) and (< 080716_0810)

    What is the fastest way? I've found FindAll and IndexOf, but I can't work
    out how to do it.

    Thanks

    -Jerry


  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: Using Array.FindAll

    Jerry Spence1 wrote:
    I'm using VB2005
    >
    I have an array of some 500,000 items which are of the form
    080715_175327_3 12.jpg. These are camera frames of the form
    YYMMDD_HHmmss_m s.jpg
    >
    I want to create another array which contains all the items which are (>
    080715_1730) and (< 080716_0810)
    >
    What is the fastest way? I've found FindAll and IndexOf, but I can't work
    out how to do it.
    >
    Thanks
    >
    -Jerry
    >
    Fortunately you have used an ISO 8601 like date format, which means that
    the strings can be compared without having to parse each single value
    into a DateTime value.

    If the array is sorted, you can use the Array.BinarySea rch method to
    find the first and the last item. That would be very much faster than
    looping through all the items.

    If the array is not sorted, you have to loop. If you want to use the
    FindAll method for that, you need a method like this to do the comparison:

    Function Compare(value As String) As Boolean
    Return value "080715_173 0" And value < "080716_081 0"
    End Function

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • Jerry Spence1

      #3
      Re: Using Array.FindAll

      Thanks Göran. It's the syntax of how to achieve this that I am struggling
      with. The array is already sorted which helps. The Binary Search only seems
      to produce values that are 'equals', rather than 'greater than ' AND 'less
      than.'

      -Jerry



      "Göran Andersson" <guffa@guffa.co mwrote in message
      news:upj2Csd8IH A.3384@TK2MSFTN GP04.phx.gbl...
      Jerry Spence1 wrote:
      >I'm using VB2005
      >>
      >I have an array of some 500,000 items which are of the form
      >080715_175327_ 312.jpg. These are camera frames of the form
      >YYMMDD_HHmmss_ ms.jpg
      >>
      >I want to create another array which contains all the items which are (>
      >080715_1730) and (< 080716_0810)
      >>
      >What is the fastest way? I've found FindAll and IndexOf, but I can't work
      >out how to do it.
      >>
      >Thanks
      >>
      >-Jerry
      >
      Fortunately you have used an ISO 8601 like date format, which means that
      the strings can be compared without having to parse each single value into
      a DateTime value.
      >
      If the array is sorted, you can use the Array.BinarySea rch method to find
      the first and the last item. That would be very much faster than looping
      through all the items.
      >
      If the array is not sorted, you have to loop. If you want to use the
      FindAll method for that, you need a method like this to do the comparison:
      >
      Function Compare(value As String) As Boolean
      Return value "080715_173 0" And value < "080716_081 0"
      End Function
      >
      --
      Göran Andersson
      _____
      http://www.guffa.com

      Comment

      • Andrew Morton

        #4
        Re: Using Array.FindAll

        Jerry Spence1 wrote:
        Thanks Göran. It's the syntax of how to achieve this that I am
        struggling with. The array is already sorted which helps. The Binary
        Search only seems to produce values that are 'equals', rather than
        'greater than ' AND 'less than.'
        If you look at the docs for BinarySearch, you'll find an overload which
        allows you to specify your own function as the comparer.

        The help for the Icomparer Interface shows how to implement that.

        Andrew


        Comment

        • =?ISO-8859-1?Q?G=F6ran_Andersson?=

          #5
          Re: Using Array.FindAll

          Jerry Spence1 wrote:
          Thanks Göran. It's the syntax of how to achieve this that I am struggling
          with. The array is already sorted which helps. The Binary Search only seems
          to produce values that are 'equals', rather than 'greater than ' AND 'less
          than.'
          The return value contains all the information that you need. If the
          value was found you get the index of the item. If it was not found you
          can get the index of the next item from the return value, then you know
          that the item before it is less, and that item is greater.

          --
          Göran Andersson
          _____
          Göran Anderssons privata hemsida.

          Comment

          Working...