One thing to consider is the cost to transform these strings into a format suitable for your regex to work with them. Presumably these strings live on your filesystem. They could all be in one huge file or each string can have its own file or anything in between these extremes.

A possible strategy could be to open the file(s) and upon reading each string immediately checking whether the string matches your query, discarding the string if not and keeping it if it does. This probably the fastest way, but will only work for one query. Each query would suffer again the cost of opening the file(s) and reading the strings.

If you need to run multiple queries, you must invent a data-structure to hold all the strings and timestamps (a hash of arrays or an array of arrays spring to mind). The set-up of these will also have a one-time cost and there is of course the memory issue to look into: too much memory needed and your machine will start swapping, which will degrade the performance of your queries. Fortunately memory if cheap, so adding another GigaByte of RAM will solve a lot of problems in that respect.

But you will still be re-inventing a lot of wheels and rather than playing at the "(re-)invent-a-database" game, why not dumping the data into a simple SQLite database and then running the usual SQL-queries against this database?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


In reply to Re: Creating an index on a string-collection by CountZero
in thread Creating an index on a string-collection by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.