Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Creating an index on a string-collection

by CountZero (Bishop)
on Feb 08, 2009 at 22:51 UTC ( [id://742292]=note: print w/replies, xml ) Need Help??


in reply to Creating an index on a string-collection

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

  • Comment on Re: Creating an index on a string-collection

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://742292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found