none
Find Multiple Values within List Of RRS feed

  • Question

  • My app will regularly be reading 3,000+ files which can have 50 or more of these kinds of records so I want the code to be as efficient as possible and haven't done much in vb.net.

    So, my data looks like this

    nameID="3" platformID="1" platEncID="0" langID="0x0"
    nameID="2" platformID="3" platEncID="0" langID="0x0"
    nameID="5" platformID="1" platEncID="0" langID="0x0"

    and I've set up a structure that looks like this

        Public Structure TT_NAME_RECORD
            Public uPlatformID As UShort
            Public uEncodingID As UShort
            Public uLanguageID As UShort
            Public uNameID As UShort
            Public uStringLength As UShort
            Public uStringOffset As UShort ' from start of storage area
        End Structure
    

    I need to find a record that has multiple specific values. For example uNameID=3, uPlatformID=3 and uLanguageID=a given hex value.

    I know I can loop through the list of but I'd hate to be looping through a bunch of records I don't need.

    I'm guessing the find method would be faster. True? Unfortunately I've not worked out how to implement that with this.

    Any direction would be greatly appreciated,
    Ken

    Friday, July 12, 2019 1:53 AM

Answers

  • Not looking for any "magic," Wayne, just trying to get opinions from people who have more experience than I regarding the quickest way to search such records using .net, which is kind of what I thought these forums were all about. Sorry if my question falls short of your standards.

    For anyone finding this post, the search thing I was wondering about is this

    FoundIdx = RecsRead.FindIndex(Function(TheRec) TheRec.uNameID = 1 And TheRec.uPlatformID = 3 And TheRec.uLanguageID = 1330)

    where RecsRead is a List (of TT_NAME_RECORD) desrcibed above. Using just the Find on a List (of) returns the actual record.

    I tried timing both the find and looping through which were, indeed, pretty much the same. The Find had about a 0.2 quicker time over the 6,010 files, but that small a difference could have been almost any variable.

    I finally settled on reading ALL the records form the file into a List(of TT_NAME_RECORD) and using this FindInidex to get the index of the one I needed. If anyone has any constructive comments on what might be a faster way I'd grateful.

    All the Best,
    Ken


    • Marked as answer by KenKrugh Saturday, July 13, 2019 10:30 PM
    • Edited by KenKrugh Saturday, July 13, 2019 10:57 PM
    Saturday, July 13, 2019 10:30 PM

All replies


  • I need to find a record that has multiple specific values. For example uNameID=3, uPlatformID=3 and uLanguageID=a given hex value.

    I know I can loop through the list of but I'd hate to be looping through a bunch of records I don't need.

    I'm guessing the find method would be faster. True? 

    Just how do you think the Find method - or any other method - can identify
    which records/structures contain an arbitrary value? In any file or collection
    that doesn't have an associated index, there is no alternative to reading each
    and every record and comparing its contents. That can only be done by iterating
    over the collection one record at a time - which implies looping.

    There's no magic involved, nor any mysterious ultra-sophisticated way that
    library methods can find a needle in a haystack. They are doing implicitly what
    you would do explicitly - looping over all records to find one (or more) that
    matches.

    For a method to skip "a bunch of records I don't need" the selection process
    would have to have been done previously. How else could it "know" which records
    are needed and which are not without examining each record?

    - Wayne

    • Proposed as answer by Cor Ligthert Friday, July 12, 2019 10:18 AM
    Friday, July 12, 2019 4:29 AM
  • Not looking for any "magic," Wayne, just trying to get opinions from people who have more experience than I regarding the quickest way to search such records using .net, which is kind of what I thought these forums were all about. Sorry if my question falls short of your standards.

    For anyone finding this post, the search thing I was wondering about is this

    FoundIdx = RecsRead.FindIndex(Function(TheRec) TheRec.uNameID = 1 And TheRec.uPlatformID = 3 And TheRec.uLanguageID = 1330)

    where RecsRead is a List (of TT_NAME_RECORD) desrcibed above. Using just the Find on a List (of) returns the actual record.

    I tried timing both the find and looping through which were, indeed, pretty much the same. The Find had about a 0.2 quicker time over the 6,010 files, but that small a difference could have been almost any variable.

    I finally settled on reading ALL the records form the file into a List(of TT_NAME_RECORD) and using this FindInidex to get the index of the one I needed. If anyone has any constructive comments on what might be a faster way I'd grateful.

    All the Best,
    Ken


    • Marked as answer by KenKrugh Saturday, July 13, 2019 10:30 PM
    • Edited by KenKrugh Saturday, July 13, 2019 10:57 PM
    Saturday, July 13, 2019 10:30 PM
  • Hi

    Don't know if this will be of any use.

    Depending on your needs and the time/overheads of your final solution, here is an idea.

    I use an application I wrote some time ago to search file contents for a User entered string. This will provide a list of file names containing matches. An example run (first run as it is way and far the longest time wise) gives results as shown in the image below. Reasonable quick. Using something like this could isolate the particular search term (sudh as 'uNameID=3, uPlatformID=3 and uLanguageID=a given hex value').

    Irealize the UI of my app is of no use to you, but maybe a file content search could be efficient and low on memory usage. Of course, if you know that there is only one file that willcontain your search then everything could be streamlined even further.

    I have not posted any code as I suspect this idea is not what you want.


    Regards Les, Livingston, Scotland

    Saturday, July 13, 2019 11:33 PM
  • Thanks for responding, Les, but you're right, not quite what I need.

    The tables I'm reading have various indicators like that the record pertains to the copyright, what platform it's for (Windows, Mac, Unicode...) what encoding is used to store the byte array that is the actually text that goes along with the record.

    Thanks again,
    Ken

    Saturday, July 13, 2019 11:43 PM