Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Poor Person's Database

by TheoPetersen (Priest)
on Jun 20, 2001 at 16:37 UTC ( #89977=note: print w/replies, xml ) Need Help??

in reply to Poor Person's Database

By naming each file for its search term you are basically moving the search and lookup logic to the file system. While file systems are pretty good at looking up file names, you're not necessarily saving anything that a non-linear search of one big file would cost.

To search a file such as you described non-linearly you need to either build an index structure for it (which tells your program, say, what byte to seek to for search terms beginning with the letter 'k') or perform a binary search on the file itself while taking the irregular record structure into account. The latter approach is kind of fun to program; you seek to the middle of the file, cruise forward to the next newline, and then read the next line to see what keyword you are on. Adjust the target forwards or backwards and seek again.

Note that I said it was fun to program, not blindingly fast :) But it should be faster than a linear search for most data.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89977]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-05-23 06:00 GMT
Find Nodes?
    Voting Booth?