| Next | Lightweight Databases | 48 |
There's a potential problem with the previous slide's code
Suppose there is no user #2
find_user_by_uid will go to the right place in the index
It will read 10 nonsense bytes
Then it will read from a nonsense position in the data file
Solution: Fill nonsense fields with a special 'no such user' value:
sub build_index_for_users {
my ($fh, $index_fh) = @_;
seek $fh, 0, SEEK_SET;
my $pos = tell $fh;
my @position;
while (<$fh>) {
my $uid = (split /:/)[1];
$position[$uid] = $pos;
$pos = tell $fh;
}
(Continued...)
| Next | ![]() |
Copyright © 2003 M. J. Dominus |