GDBM_File WTF?
Andy Armstrong
andy at hexten.net
Thu Apr 5 16:03:24 BST 2007
On 5 Apr 2007, at 15:38, David Cantrell wrote:
> prints entries for foo151 through to foo200.
>
> What the fuck?
Mustn't like deleting while it's got a cursor active.
From:
http://ccrma.stanford.edu/planetccrma/man/man3/gdbm.3.html
File `visiting' is based on a `hash table'. gdbm_delete re-arranges
the hash table to make sure that any collisions in the table do not
leave some item `un-findable'. The original key order is NOT
guaran-
teed to remain unchanged in ALL instances. It is possible that some
key will not be visited if a loop like the following is executed:
key = gdbm_firstkey ( dbf );
while ( key.dptr ) {
nextkey = gdbm_nextkey ( dbf, key );
if ( some condition ) {
gdbm_delete ( dbf, key );
free ( key.dptr );
}
key = nextkey;
}
Seems a bit surprising that it misses /all/ of them - but I guess
it's not a good idea to iterate and modify at the same time.
--
Andy Armstrong, hexten.net
More information about the london.pm
mailing list